From f47f69080391a858eeaa836c492d2ebede106b60 Mon Sep 17 00:00:00 2001 From: Serhii Date: Wed, 3 May 2023 10:01:51 +0300 Subject: [PATCH] fix getting correct currency from template (#898) --- lib/exchange/exchange_template.dart | 29 ++++++++++++------ lib/src/screens/exchange/exchange_page.dart | 4 +-- .../exchange/exchange_template_page.dart | 8 +++-- .../templates/exchange_template_store.dart | 30 +++++++++++-------- .../exchange/exchange_view_model.dart | 8 +++-- 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/lib/exchange/exchange_template.dart b/lib/exchange/exchange_template.dart index 26e1fa761..dcfd8d8e8 100644 --- a/lib/exchange/exchange_template.dart +++ b/lib/exchange/exchange_template.dart @@ -4,14 +4,15 @@ part 'exchange_template.g.dart'; @HiveType(typeId: ExchangeTemplate.typeId) class ExchangeTemplate extends HiveObject { - ExchangeTemplate({ - required this.amountRaw, - required this.depositCurrencyRaw, - required this.receiveCurrencyRaw, - required this.providerRaw, - required this.depositAddressRaw, - required this.receiveAddressRaw - }); + ExchangeTemplate( + {required this.amountRaw, + required this.depositCurrencyRaw, + required this.receiveCurrencyRaw, + required this.providerRaw, + required this.depositAddressRaw, + required this.receiveAddressRaw, + required this.depositCurrencyTitleRaw, + required this.receiveCurrencyTitleRaw}); static const typeId = 7; static const boxName = 'ExchangeTemplate'; @@ -34,6 +35,12 @@ class ExchangeTemplate extends HiveObject { @HiveField(5) String? receiveAddressRaw; + @HiveField(6) + String? depositCurrencyTitleRaw; + + @HiveField(7) + String? receiveCurrencyTitleRaw; + String get amount => amountRaw ?? ''; String get depositCurrency => depositCurrencyRaw ?? ''; @@ -45,4 +52,8 @@ class ExchangeTemplate extends HiveObject { String get depositAddress => depositAddressRaw ?? ''; String get receiveAddress => receiveAddressRaw ?? ''; -} \ No newline at end of file + + String get depositCurrencyTitle => depositCurrencyTitleRaw ?? ''; + + String get receiveCurrencyTitle => receiveCurrencyTitleRaw ?? ''; +} diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index fa3b3b825..0254ef0d4 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -280,8 +280,8 @@ class ExchangePage extends BasePage { return TemplateTile( key: UniqueKey(), amount: template.amount, - from: template.depositCurrency, - to: template.receiveCurrency, + from: template.depositCurrencyTitle, + to: template.receiveCurrencyTitle, onTap: () { applyTemplate(context, exchangeViewModel, template); }, diff --git a/lib/src/screens/exchange/exchange_template_page.dart b/lib/src/screens/exchange/exchange_template_page.dart index 50faf7eb2..00eee49c2 100644 --- a/lib/src/screens/exchange/exchange_template_page.dart +++ b/lib/src/screens/exchange/exchange_template_page.dart @@ -239,9 +239,13 @@ class ExchangeTemplatePage extends BasePage { exchangeViewModel.addTemplate( amount: exchangeViewModel.depositAmount, depositCurrency: - exchangeViewModel.depositCurrency.toString(), + exchangeViewModel.depositCurrency.name, + depositCurrencyTitle: exchangeViewModel + .depositCurrency.title + ' ${exchangeViewModel.depositCurrency.tag ?? ''}', receiveCurrency: - exchangeViewModel.receiveCurrency.toString(), + exchangeViewModel.receiveCurrency.name, + receiveCurrencyTitle: exchangeViewModel + .receiveCurrency.title + ' ${exchangeViewModel.receiveCurrency.tag ?? ''}', provider: exchangeViewModel.provider.toString(), depositAddress: exchangeViewModel.depositAddress, receiveAddress: exchangeViewModel.receiveAddress); diff --git a/lib/store/templates/exchange_template_store.dart b/lib/store/templates/exchange_template_store.dart index a63c2f56e..97e1f41dc 100644 --- a/lib/store/templates/exchange_template_store.dart +++ b/lib/store/templates/exchange_template_store.dart @@ -8,8 +8,8 @@ part 'exchange_template_store.g.dart'; class ExchangeTemplateStore = ExchangeTemplateBase with _$ExchangeTemplateStore; abstract class ExchangeTemplateBase with Store { - ExchangeTemplateBase({required this.templateSource}) - : templates = ObservableList() { + ExchangeTemplateBase({required this.templateSource}) + : templates = ObservableList() { templates = ObservableList(); update(); } @@ -20,27 +20,31 @@ abstract class ExchangeTemplateBase with Store { Box templateSource; @action - void update() => - templates.replaceRange(0, templates.length, templateSource.values.toList()); + void update() => templates.replaceRange(0, templates.length, templateSource.values.toList()); @action Future addTemplate({ - required String amount, - required String depositCurrency, - required String receiveCurrency, - required String provider, - required String depositAddress, - required String receiveAddress}) async { + required String amount, + required String depositCurrency, + required String receiveCurrency, + required String provider, + required String depositAddress, + required String receiveAddress, + required String depositCurrencyTitle, + required String receiveCurrencyTitle, + }) async { final template = ExchangeTemplate( amountRaw: amount, depositCurrencyRaw: depositCurrency, receiveCurrencyRaw: receiveCurrency, providerRaw: provider, depositAddressRaw: depositAddress, - receiveAddressRaw: receiveAddress); + receiveAddressRaw: receiveAddress, + depositCurrencyTitleRaw: depositCurrencyTitle, + receiveCurrencyTitleRaw: receiveCurrencyTitle); await templateSource.add(template); } @action - Future remove({required ExchangeTemplate template}) async => await template.delete(); -} \ No newline at end of file + Future remove({required ExchangeTemplate template}) async => await template.delete(); +} diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 1e25f1353..3c016d4b0 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -578,14 +578,18 @@ abstract class ExchangeViewModelBase with Store { required String receiveCurrency, required String provider, required String depositAddress, - required String receiveAddress}) => + required String receiveAddress, + required String depositCurrencyTitle, + required String receiveCurrencyTitle}) => _exchangeTemplateStore.addTemplate( amount: amount, depositCurrency: depositCurrency, receiveCurrency: receiveCurrency, provider: provider, depositAddress: depositAddress, - receiveAddress: receiveAddress); + receiveAddress: receiveAddress, + depositCurrencyTitle: depositCurrencyTitle, + receiveCurrencyTitle: receiveCurrencyTitle); void removeTemplate({required ExchangeTemplate template}) => _exchangeTemplateStore.remove(template: template);