stack_wallet/lib/models/contact_address_entry_data.dart

91 lines
1.9 KiB
Dart
Raw Normal View History

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';
import 'isar/models/contact_entry.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
2022-08-26 08:11:35 +00:00
class AddressEntryData extends ChangeNotifier {
late int id;
AddressEntryData(this.id);
String? _addressLabel;
String? _address;
2024-05-15 21:20:45 +00:00
CryptoCurrency? _coin;
2022-08-26 08:11:35 +00:00
String? get addressLabel => _addressLabel;
set addressLabel(String? addressLabel) {
_addressLabel = addressLabel;
notifyListeners();
}
String? get address => _address;
set address(String? address) {
_address = address;
notifyListeners();
}
2024-05-15 21:20:45 +00:00
CryptoCurrency? get coin => _coin;
2022-08-26 08:11:35 +00:00
2024-05-15 21:20:45 +00:00
set coin(CryptoCurrency? coin) {
2022-08-26 08:11:35 +00:00
_coin = coin;
notifyListeners();
}
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 {
if (coin == null) {
return true;
}
if (_address == null) {
2022-08-26 08:11:35 +00:00
return false;
}
2024-05-15 21:20:45 +00:00
return _coin!.validateAddress(_address!);
2022-08-26 08:11:35 +00:00
}
ContactAddressEntry buildAddressEntry() {
return ContactAddressEntry()
2024-05-15 21:20:45 +00:00
..coinName = coin!.identifier
..address = address!
..other = null
..label = addressLabel!;
2022-08-26 08:11:35 +00:00
}
@override
String toString() {
2024-05-15 21:20:45 +00:00
return "AddressEntryData: { addressLabel: $addressLabel, address: $address, coin: ${coin?.identifier} }";
2022-08-26 08:11:35 +00:00
}
}