2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2023-05-15 20:12:06 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/address_utils.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
|
|
|
|
class AddressEntryData extends ChangeNotifier {
|
|
|
|
late int id;
|
|
|
|
|
|
|
|
AddressEntryData(this.id);
|
|
|
|
|
|
|
|
String? _addressLabel;
|
|
|
|
String? _address;
|
|
|
|
Coin? _coin;
|
|
|
|
|
|
|
|
String? get addressLabel => _addressLabel;
|
|
|
|
|
|
|
|
set addressLabel(String? addressLabel) {
|
|
|
|
_addressLabel = addressLabel;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
String? get address => _address;
|
|
|
|
|
|
|
|
set address(String? address) {
|
|
|
|
_address = address;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
Coin? get coin => _coin;
|
|
|
|
|
|
|
|
set coin(Coin? coin) {
|
|
|
|
_coin = coin;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-11-29 16:33:40 +00:00
|
|
|
bool get isEmpty {
|
|
|
|
if (address != null && address!.isNotEmpty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (addressLabel != null && addressLabel!.isNotEmpty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (coin != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
bool get isValid {
|
|
|
|
if (_address == null || coin == null || _addressLabel == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (_address!.isEmpty || _addressLabel!.isEmpty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isValidAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool get isValidAddress {
|
2023-05-15 20:12:06 +00:00
|
|
|
if (coin == null) {
|
2023-03-28 15:17:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (_address == null) {
|
2022-08-26 08:11:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return AddressUtils.validateAddress(_address!, _coin!);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContactAddressEntry buildAddressEntry() {
|
2023-05-15 20:12:06 +00:00
|
|
|
return ContactAddressEntry()
|
|
|
|
..coinName = coin!.name
|
|
|
|
..address = address!
|
|
|
|
..other = null
|
|
|
|
..label = addressLabel!;
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "AddressEntryData: { addressLabel: $addressLabel, address: $address, coin: ${coin?.name} }";
|
|
|
|
}
|
|
|
|
}
|