fix getting correct currency from template (#898)

This commit is contained in:
Serhii 2023-05-03 10:01:51 +03:00 committed by GitHub
parent 0a35e5c3e1
commit f47f690803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 28 deletions

View file

@ -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 ?? '';
}
String get depositCurrencyTitle => depositCurrencyTitleRaw ?? '';
String get receiveCurrencyTitle => receiveCurrencyTitleRaw ?? '';
}

View file

@ -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);
},

View file

@ -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);

View file

@ -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<ExchangeTemplate>() {
ExchangeTemplateBase({required this.templateSource})
: templates = ObservableList<ExchangeTemplate>() {
templates = ObservableList<ExchangeTemplate>();
update();
}
@ -20,27 +20,31 @@ abstract class ExchangeTemplateBase with Store {
Box<ExchangeTemplate> templateSource;
@action
void update() =>
templates.replaceRange(0, templates.length, templateSource.values.toList());
void update() => templates.replaceRange(0, templates.length, templateSource.values.toList());
@action
Future<void> 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<void> remove({required ExchangeTemplate template}) async => await template.delete();
}
Future<void> remove({required ExchangeTemplate template}) async => await template.delete();
}

View file

@ -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);