2020-07-29 16:55:42 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
import 'package:cake_wallet/exchange/exchange_template.dart';
|
2020-07-29 16:55:42 +00:00
|
|
|
|
|
|
|
part 'exchange_template_store.g.dart';
|
|
|
|
|
|
|
|
class ExchangeTemplateStore = ExchangeTemplateBase with _$ExchangeTemplateStore;
|
|
|
|
|
|
|
|
abstract class ExchangeTemplateBase with Store {
|
2023-05-03 07:01:51 +00:00
|
|
|
ExchangeTemplateBase({required this.templateSource})
|
|
|
|
: templates = ObservableList<ExchangeTemplate>() {
|
2020-07-29 16:55:42 +00:00
|
|
|
templates = ObservableList<ExchangeTemplate>();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
ObservableList<ExchangeTemplate> templates;
|
|
|
|
|
|
|
|
Box<ExchangeTemplate> templateSource;
|
|
|
|
|
|
|
|
@action
|
2023-05-03 07:01:51 +00:00
|
|
|
void update() => templates.replaceRange(0, templates.length, templateSource.values.toList());
|
2020-07-29 16:55:42 +00:00
|
|
|
|
|
|
|
@action
|
2022-11-01 21:43:39 +00:00
|
|
|
Future<void> addTemplate({
|
2023-05-03 07:01:51 +00:00
|
|
|
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 {
|
2020-07-29 16:55:42 +00:00
|
|
|
final template = ExchangeTemplate(
|
2022-11-01 21:43:39 +00:00
|
|
|
amountRaw: amount,
|
|
|
|
depositCurrencyRaw: depositCurrency,
|
|
|
|
receiveCurrencyRaw: receiveCurrency,
|
|
|
|
providerRaw: provider,
|
|
|
|
depositAddressRaw: depositAddress,
|
2023-05-03 07:01:51 +00:00
|
|
|
receiveAddressRaw: receiveAddress,
|
|
|
|
depositCurrencyTitleRaw: depositCurrencyTitle,
|
|
|
|
receiveCurrencyTitleRaw: receiveCurrencyTitle);
|
2020-07-29 16:55:42 +00:00
|
|
|
await templateSource.add(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2023-05-03 07:01:51 +00:00
|
|
|
Future<void> remove({required ExchangeTemplate template}) async => await template.delete();
|
|
|
|
}
|