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 {
|
2022-10-12 17:09:57 +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
|
|
|
|
void update() =>
|
|
|
|
templates.replaceRange(0, templates.length, templateSource.values.toList());
|
|
|
|
|
|
|
|
@action
|
2022-10-12 17:09:57 +00:00
|
|
|
Future addTemplate({
|
|
|
|
required String amount,
|
|
|
|
required String depositCurrency,
|
|
|
|
required String receiveCurrency,
|
|
|
|
required String provider,
|
|
|
|
required String depositAddress,
|
|
|
|
required String receiveAddress}) async {
|
2020-07-29 16:55:42 +00:00
|
|
|
final template = ExchangeTemplate(
|
|
|
|
amount: amount,
|
|
|
|
depositCurrency: depositCurrency,
|
|
|
|
receiveCurrency: receiveCurrency,
|
|
|
|
provider: provider,
|
|
|
|
depositAddress: depositAddress,
|
|
|
|
receiveAddress: receiveAddress);
|
|
|
|
await templateSource.add(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-10-12 17:09:57 +00:00
|
|
|
Future remove({required ExchangeTemplate template}) async => await template.delete();
|
2020-07-29 16:55:42 +00:00
|
|
|
}
|