| 1 | import 'package:cake_wallet/entities/contact.dart'; |
| 2 | import 'package:cake_wallet/entities/contact_base.dart'; |
| 3 | import 'package:cake_wallet/entities/record.dart'; |
| 4 | import 'package:cw_core/crypto_currency.dart'; |
| 5 | import 'package:hive/hive.dart'; |
| 6 | import 'package:mobx/mobx.dart'; |
| 7 | |
| 8 | part 'contact_record.g.dart'; |
| 9 | |
| 10 | class ContactRecord = ContactRecordBase with _$ContactRecord; |
| 11 | |
| 12 | abstract class ContactRecordBase extends Record<Contact> with Store implements ContactBase { |
| 13 | ContactRecordBase(Box<Contact> source, Contact original) |
| 14 | : name = original.name, |
| 15 | address = original.address, |
| 16 | type = original.type, |
| 17 | displayName = original.displayName, |
| 18 | lastChange = original.lastChange, |
| 19 | super(source, original); |
| 20 | |
| 21 | @override |
| 22 | @observable |
| 23 | String name; |
| 24 | |
| 25 | @override |
| 26 | @observable |
| 27 | String address; |
| 28 | |
| 29 | @override |
| 30 | @observable |
| 31 | CryptoCurrency type; |
| 32 | |
| 33 | @override |
| 34 | @observable |
| 35 | String displayName; |
| 36 | |
| 37 | DateTime? lastChange; |
| 38 | |
| 39 | @override |
| 40 | void toBind(Contact original) { |
| 41 | reaction((_) => name, (String name) => original.name = name); |
| 42 | reaction((_) => address, (String address) => original.address = address); |
| 43 | reaction((_) => type, |
| 44 | (CryptoCurrency currency) => original.updateCryptoCurrency(currency: currency)); |
| 45 | } |
| 46 | |
| 47 | @override |
| 48 | void fromBind(Contact original) { |
| 49 | name = original.name; |
| 50 | address = original.address; |
| 51 | type = original.type; |
| 52 | } |
| 53 | } |