From b182c26ff2ed6cb97a0f7ec0843459ce6b1ed952 Mon Sep 17 00:00:00 2001 From: mkyq <53115730+mkyq@users.noreply.github.com> Date: Tue, 1 Nov 2022 17:43:39 -0400 Subject: [PATCH] Update hive types: UnspentCoinsInfo, Template, ExchangeTemplate. (#583) --- cw_bitcoin/lib/electrum_wallet.dart | 2 +- cw_core/lib/unspent_coins_info.dart | 8 +++- lib/entities/template.dart | 42 ++++++++++++------- lib/exchange/exchange_template.dart | 36 ++++++++++------ .../templates/exchange_template_store.dart | 16 +++---- lib/store/templates/send_template_store.dart | 18 ++++---- 6 files changed, 76 insertions(+), 46 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index ffe378069..7abed8c07 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -495,7 +495,7 @@ abstract class ElectrumWalletBase extends WalletBase noteRaw ?? ''; + + set note(String value) => noteRaw = value; } \ No newline at end of file diff --git a/lib/entities/template.dart b/lib/entities/template.dart index e05c423fd..c26e3a501 100644 --- a/lib/entities/template.dart +++ b/lib/entities/template.dart @@ -5,36 +5,50 @@ part 'template.g.dart'; @HiveType(typeId: Template.typeId) class Template extends HiveObject { Template({ - required this.name, - required this.isCurrencySelected, - required this.address, - required this.cryptoCurrency, - required this.amount, - required this.fiatCurrency, - required this.amountFiat}); + required this.nameRaw, + required this.isCurrencySelectedRaw, + required this.addressRaw, + required this.cryptoCurrencyRaw, + required this.amountRaw, + required this.fiatCurrencyRaw, + required this.amountFiatRaw}); static const typeId = 6; static const boxName = 'Template'; @HiveField(0) - String name; + String? nameRaw; @HiveField(1) - String address; + String? addressRaw; @HiveField(2) - String cryptoCurrency; + String? cryptoCurrencyRaw; @HiveField(3) - String amount; + String? amountRaw; @HiveField(4) - String fiatCurrency; + String? fiatCurrencyRaw; @HiveField(5) - bool isCurrencySelected; + bool? isCurrencySelectedRaw; @HiveField(6) - String amountFiat; + String? amountFiatRaw; + + bool get isCurrencySelected => isCurrencySelectedRaw ?? false; + + String get fiatCurrency => fiatCurrencyRaw ?? ''; + + String get amountFiat => amountFiatRaw ?? ''; + + String get name => nameRaw ?? ''; + + String get address => addressRaw ?? ''; + + String get cryptoCurrency => cryptoCurrencyRaw ?? ''; + + String get amount => amountRaw ?? ''; } diff --git a/lib/exchange/exchange_template.dart b/lib/exchange/exchange_template.dart index 93d8b851e..26e1fa761 100644 --- a/lib/exchange/exchange_template.dart +++ b/lib/exchange/exchange_template.dart @@ -5,32 +5,44 @@ part 'exchange_template.g.dart'; @HiveType(typeId: ExchangeTemplate.typeId) class ExchangeTemplate extends HiveObject { ExchangeTemplate({ - required this.amount, - required this.depositCurrency, - required this.receiveCurrency, - required this.provider, - required this.depositAddress, - required this.receiveAddress + required this.amountRaw, + required this.depositCurrencyRaw, + required this.receiveCurrencyRaw, + required this.providerRaw, + required this.depositAddressRaw, + required this.receiveAddressRaw }); static const typeId = 7; static const boxName = 'ExchangeTemplate'; @HiveField(0) - String amount; + String? amountRaw; @HiveField(1) - String depositCurrency; + String? depositCurrencyRaw; @HiveField(2) - String receiveCurrency; + String? receiveCurrencyRaw; @HiveField(3) - String provider; + String? providerRaw; @HiveField(4) - String depositAddress; + String? depositAddressRaw; @HiveField(5) - String receiveAddress; + String? receiveAddressRaw; + + String get amount => amountRaw ?? ''; + + String get depositCurrency => depositCurrencyRaw ?? ''; + + String get receiveCurrency => receiveCurrencyRaw ?? ''; + + String get provider => providerRaw ?? ''; + + String get depositAddress => depositAddressRaw ?? ''; + + String get receiveAddress => receiveAddressRaw ?? ''; } \ No newline at end of file diff --git a/lib/store/templates/exchange_template_store.dart b/lib/store/templates/exchange_template_store.dart index 9e61dee4c..a63c2f56e 100644 --- a/lib/store/templates/exchange_template_store.dart +++ b/lib/store/templates/exchange_template_store.dart @@ -24,7 +24,7 @@ abstract class ExchangeTemplateBase with Store { templates.replaceRange(0, templates.length, templateSource.values.toList()); @action - Future addTemplate({ + Future addTemplate({ required String amount, required String depositCurrency, required String receiveCurrency, @@ -32,15 +32,15 @@ abstract class ExchangeTemplateBase with Store { required String depositAddress, required String receiveAddress}) async { final template = ExchangeTemplate( - amount: amount, - depositCurrency: depositCurrency, - receiveCurrency: receiveCurrency, - provider: provider, - depositAddress: depositAddress, - receiveAddress: receiveAddress); + amountRaw: amount, + depositCurrencyRaw: depositCurrency, + receiveCurrencyRaw: receiveCurrency, + providerRaw: provider, + depositAddressRaw: depositAddress, + receiveAddressRaw: receiveAddress); await templateSource.add(template); } @action - Future remove({required ExchangeTemplate template}) async => await template.delete(); + Future remove({required ExchangeTemplate template}) async => await template.delete(); } \ No newline at end of file diff --git a/lib/store/templates/send_template_store.dart b/lib/store/templates/send_template_store.dart index b1a5ce44b..d5181c0ce 100644 --- a/lib/store/templates/send_template_store.dart +++ b/lib/store/templates/send_template_store.dart @@ -23,7 +23,7 @@ abstract class SendTemplateBase with Store { templates.replaceRange(0, templates.length, templateSource.values.toList()); @action - Future addTemplate({ + Future addTemplate({ required String name, required bool isCurrencySelected, required String address, @@ -32,16 +32,16 @@ abstract class SendTemplateBase with Store { required String amount, required String amountFiat}) async { final template = Template( - name: name, - isCurrencySelected: isCurrencySelected, - address: address, - cryptoCurrency: cryptoCurrency, - fiatCurrency: fiatCurrency, - amount: amount, - amountFiat: amountFiat); + nameRaw: name, + isCurrencySelectedRaw: isCurrencySelected, + addressRaw: address, + cryptoCurrencyRaw: cryptoCurrency, + fiatCurrencyRaw: fiatCurrency, + amountRaw: amount, + amountFiatRaw: amountFiat); await templateSource.add(template); } @action - Future remove({required Template template}) async => await template.delete(); + Future remove({required Template template}) async => await template.delete(); } \ No newline at end of file