-
Notifications
You must be signed in to change notification settings - Fork 24
/
contact.dart
86 lines (72 loc) · 2.09 KB
/
contact.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:aewallet/infrastructure/datasources/appdb.hive.dart';
import 'package:aewallet/model/data/account_balance.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hive/hive.dart';
part 'contact.g.dart';
class ContactConverter implements JsonConverter<Contact, Map<String, dynamic>> {
const ContactConverter();
@override
Contact fromJson(Map<String, dynamic> json) {
return Contact(
name: json['name'] as String,
address: json['address'] as String,
genesisAddress: json['genesisAddress'] as String,
type: json['type'] as String,
publicKey: json['publicKey'] as String,
favorite: json['favorite'] == null ? null : json['favorite'] as bool,
balance: json['balance'] == null
? null
: const AccountBalanceConverter()
.fromJson(json['balance'] as Map<String, dynamic>),
);
}
@override
Map<String, dynamic> toJson(Contact contact) {
return {
'name': contact.name,
'address': contact.address,
'genesisAddress': contact.genesisAddress,
'type': contact.type,
'publicKey': contact.publicKey,
'favorite': contact.favorite,
'balance': const AccountBalanceConverter().toJson(contact.balance!),
};
}
}
enum ContactType { keychainService, externalContact }
/// Next field available : 9
@HiveType(typeId: HiveTypeIds.contact)
@AccountBalanceConverter()
class Contact extends HiveObject {
Contact({
required this.name,
required this.address,
required this.type,
required this.publicKey,
required this.genesisAddress,
this.balance,
this.favorite,
});
/// Name
@HiveField(0)
String name;
/// Address
@HiveField(1)
String address;
/// Type contact - Keychain Service / External contact
@HiveField(4)
String type;
/// Public Key
@HiveField(5, defaultValue: '')
String publicKey;
/// Favorite
@HiveField(6)
bool? favorite;
/// Balance
@HiveField(7)
AccountBalance? balance;
/// Genesis Address
@HiveField(8)
String? genesisAddress;
}