Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cw 514 add sort functionality for addressbook mywallets and contacts #1309

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
9 changes: 6 additions & 3 deletions lib/entities/contact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ part 'contact.g.dart';

@HiveType(typeId: Contact.typeId)
class Contact extends HiveObject with Keyable {
Contact({required this.name, required this.address, CryptoCurrency? type}) {
Contact({required this.name, required this.address, CryptoCurrency? type, DateTime? lastChange}) {
if (type != null) {
raw = type.raw;
}
this.lastChange = lastChange ?? DateTime.now();
}

static const typeId = CONTACT_TYPE_ID;
Expand All @@ -25,6 +26,9 @@ class Contact extends HiveObject with Keyable {
@HiveField(2, defaultValue: 0)
late int raw;

@HiveField(3)
late DateTime lastChange;

CryptoCurrency get type => CryptoCurrency.deserialize(raw: raw);

@override
Expand All @@ -36,6 +40,5 @@ class Contact extends HiveObject with Keyable {
@override
int get hashCode => key.hashCode;

void updateCryptoCurrency({required CryptoCurrency currency}) =>
raw = currency.raw;
void updateCryptoCurrency({required CryptoCurrency currency}) => raw = currency.raw;
}
23 changes: 11 additions & 12 deletions lib/entities/contact_record.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/contact.dart';
import 'package:cw_core/crypto_currency.dart';
import 'package:cake_wallet/entities/record.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 {
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,
super(source, original);
lastChange = original.lastChange,
super(source, original);

@override
@observable
Expand All @@ -30,14 +29,14 @@ abstract class ContactRecordBase extends Record<Contact>
@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));
reaction((_) => type,
(CryptoCurrency currency) => original.updateCryptoCurrency(currency: currency));
}

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/entities/preferences_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class PreferencesKey {
static const disableBulletinKey = 'disable_bulletin';
static const defaultBuyProvider = 'default_buy_provider';
static const walletListOrder = 'wallet_list_order';
static const contactListOrder = 'contact_list_order';
static const walletListAscending = 'wallet_list_ascending';
static const contactListAscending = 'contact_list_ascending';
static const currentFiatApiModeKey = 'current_fiat_api_mode';
static const failedTotpTokenTrials = 'failed_token_trials';
static const disableExchangeKey = 'disable_exchange';
Expand Down
10 changes: 5 additions & 5 deletions lib/entities/wallet_list_order_types.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:cake_wallet/generated/i18n.dart';

enum WalletListOrderType {
enum FilterListOrderType {
CreationDate,
Alphabetical,
GroupByType,
Expand All @@ -9,13 +9,13 @@ enum WalletListOrderType {
@override
String toString() {
switch (this) {
case WalletListOrderType.CreationDate:
case FilterListOrderType.CreationDate:
return S.current.creation_date;
case WalletListOrderType.Alphabetical:
case FilterListOrderType.Alphabetical:
return S.current.alphabetical;
case WalletListOrderType.GroupByType:
case FilterListOrderType.GroupByType:
return S.current.group_by_type;
case WalletListOrderType.Custom:
case FilterListOrderType.Custom:
return S.current.custom_drag;
}
}
Expand Down
Loading
Loading