cake_wallet/lib/entities/contact_record.dart
Serhii 109d9b458e
Cw 514 add sort functionality for addressbook mywallets and contacts (#1309)
* add sort function to contact list

* fix UI

* prevent duplicate contact names

* dispose contact source subscription

* fix custom order issue

* update the address book UI

* fix saving custom order

* fix merge conflict issue

* review fixes [skip ci]

* revert to single scroll for entire page

* tabBarView address book

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2024-11-07 03:26:14 +02:00

48 lines
1.3 KiB
Dart

import 'package:cake_wallet/entities/contact.dart';
import 'package:cake_wallet/entities/contact_base.dart';
import 'package:cake_wallet/entities/record.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
part 'contact_record.g.dart';
class ContactRecord = ContactRecordBase with _$ContactRecord;
abstract class ContactRecordBase extends Record<Contact> with Store implements ContactBase {
ContactRecordBase(Box<Contact> source, Contact original)
: name = original.name,
address = original.address,
type = original.type,
lastChange = original.lastChange,
super(source, original);
@override
@observable
String name;
@override
@observable
String address;
@override
@observable
CryptoCurrency type;
DateTime? lastChange;
@override
void toBind(Contact original) {
reaction((_) => name, (String name) => original.name = name);
reaction((_) => address, (String address) => original.address = address);
reaction((_) => type,
(CryptoCurrency currency) => original.updateCryptoCurrency(currency: currency));
}
@override
void fromBind(Contact original) {
name = original.name;
address = original.address;
type = original.type;
}
}