stack_wallet/lib/models/contact_address_entry.dart

71 lines
1.6 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 'dart:convert';
2024-05-15 21:20:45 +00:00
import 'package:stackwallet/supported_coins.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
2022-08-26 08:11:35 +00:00
@Deprecated("Use lib/models/isar/models/contact_entry.dart instead")
2022-08-26 08:11:35 +00:00
class ContactAddressEntry {
2024-05-15 21:20:45 +00:00
final CryptoCurrency coin;
2022-08-26 08:11:35 +00:00
final String address;
final String label;
final String? other;
2022-08-26 08:11:35 +00:00
const ContactAddressEntry({
required this.coin,
required this.address,
required this.label,
this.other,
2022-08-26 08:11:35 +00:00
});
ContactAddressEntry copyWith({
2024-05-15 21:20:45 +00:00
CryptoCurrency? coin,
2022-08-26 08:11:35 +00:00
String? address,
String? label,
String? other,
2022-08-26 08:11:35 +00:00
}) {
return ContactAddressEntry(
coin: coin ?? this.coin,
address: address ?? this.address,
label: label ?? this.label,
other: other ?? this.other,
2022-08-26 08:11:35 +00:00
);
}
factory ContactAddressEntry.fromJson(Map<String, dynamic> jsonObject) {
return ContactAddressEntry(
2024-05-21 18:10:09 +00:00
coin: Coins.getCryptoCurrencyFor(jsonObject["coin"] as String),
2022-08-26 08:11:35 +00:00
address: jsonObject["address"] as String,
label: jsonObject["label"] as String,
other: jsonObject["other"] as String?,
2022-08-26 08:11:35 +00:00
);
}
Map<String, String> toMap() {
return {
"label": label,
"address": address,
2024-05-15 21:20:45 +00:00
"coin": coin.identifier,
"other": other ?? "",
2022-08-26 08:11:35 +00:00
};
}
String toJsonString() {
return jsonEncode(toMap());
}
@override
String toString() {
return "AddressBookEntry: ${toJsonString()}";
}
}