2022-08-26 08:11:35 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
|
|
|
|
class ContactAddressEntry {
|
|
|
|
final Coin coin;
|
|
|
|
final String address;
|
|
|
|
final String label;
|
2022-09-14 16:38:49 +00:00
|
|
|
final String? other;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
const ContactAddressEntry({
|
|
|
|
required this.coin,
|
|
|
|
required this.address,
|
|
|
|
required this.label,
|
2022-09-14 16:38:49 +00:00
|
|
|
this.other,
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ContactAddressEntry copyWith({
|
|
|
|
Coin? coin,
|
|
|
|
String? address,
|
|
|
|
String? label,
|
2022-09-14 16:38:49 +00:00
|
|
|
String? other,
|
2022-08-26 08:11:35 +00:00
|
|
|
}) {
|
|
|
|
return ContactAddressEntry(
|
|
|
|
coin: coin ?? this.coin,
|
|
|
|
address: address ?? this.address,
|
|
|
|
label: label ?? this.label,
|
2022-09-14 16:38:49 +00:00
|
|
|
other: other ?? this.other,
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory ContactAddressEntry.fromJson(Map<String, dynamic> jsonObject) {
|
|
|
|
return ContactAddressEntry(
|
|
|
|
coin: Coin.values.byName(jsonObject["coin"] as String),
|
|
|
|
address: jsonObject["address"] as String,
|
|
|
|
label: jsonObject["label"] as String,
|
2022-09-14 16:38:49 +00:00
|
|
|
other: jsonObject["other"] as String?,
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, String> toMap() {
|
|
|
|
return {
|
|
|
|
"label": label,
|
|
|
|
"address": address,
|
|
|
|
"coin": coin.name,
|
2022-09-14 16:38:49 +00:00
|
|
|
"other": other ?? "",
|
2022-08-26 08:11:35 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
String toJsonString() {
|
|
|
|
return jsonEncode(toMap());
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "AddressBookEntry: ${toJsonString()}";
|
|
|
|
}
|
|
|
|
}
|