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/entities/template.dart';
|
2020-07-29 16:55:42 +00:00
|
|
|
|
|
|
|
part 'send_template_store.g.dart';
|
|
|
|
|
|
|
|
class SendTemplateStore = SendTemplateBase with _$SendTemplateStore;
|
|
|
|
|
|
|
|
abstract class SendTemplateBase with Store {
|
2022-10-12 17:09:57 +00:00
|
|
|
SendTemplateBase({required this.templateSource})
|
|
|
|
: templates = ObservableList<Template>() {
|
2020-07-29 16:55:42 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
ObservableList<Template> templates;
|
|
|
|
|
|
|
|
Box<Template> templateSource;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void update() =>
|
|
|
|
templates.replaceRange(0, templates.length, templateSource.values.toList());
|
|
|
|
|
|
|
|
@action
|
2022-11-01 21:43:39 +00:00
|
|
|
Future<void> addTemplate({
|
2022-10-12 17:09:57 +00:00
|
|
|
required String name,
|
|
|
|
required bool isCurrencySelected,
|
|
|
|
required String address,
|
|
|
|
required String cryptoCurrency,
|
|
|
|
required String fiatCurrency,
|
|
|
|
required String amount,
|
|
|
|
required String amountFiat}) async {
|
|
|
|
final template = Template(
|
2022-11-01 21:43:39 +00:00
|
|
|
nameRaw: name,
|
|
|
|
isCurrencySelectedRaw: isCurrencySelected,
|
|
|
|
addressRaw: address,
|
|
|
|
cryptoCurrencyRaw: cryptoCurrency,
|
|
|
|
fiatCurrencyRaw: fiatCurrency,
|
|
|
|
amountRaw: amount,
|
|
|
|
amountFiatRaw: amountFiat);
|
2020-07-29 16:55:42 +00:00
|
|
|
await templateSource.add(template);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-11-01 21:43:39 +00:00
|
|
|
Future<void> remove({required Template template}) async => await template.delete();
|
2020-07-29 16:55:42 +00:00
|
|
|
}
|