2021-08-10 14:52:35 +00:00
|
|
|
import 'package:cake_wallet/view_model/send/output.dart';
|
2023-03-15 17:22:08 +00:00
|
|
|
import 'package:cw_core/wallet_type.dart';
|
2021-07-16 09:32:36 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/entities/template.dart';
|
|
|
|
import 'package:cake_wallet/store/templates/send_template_store.dart';
|
|
|
|
import 'package:cake_wallet/core/template_validator.dart';
|
|
|
|
import 'package:cake_wallet/core/address_validator.dart';
|
|
|
|
import 'package:cake_wallet/core/amount_validator.dart';
|
|
|
|
import 'package:cake_wallet/core/validator.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2021-07-16 09:32:36 +00:00
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
|
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
|
|
|
|
part 'send_template_view_model.g.dart';
|
|
|
|
|
|
|
|
class SendTemplateViewModel = SendTemplateViewModelBase
|
|
|
|
with _$SendTemplateViewModel;
|
|
|
|
|
|
|
|
abstract class SendTemplateViewModelBase with Store {
|
|
|
|
SendTemplateViewModelBase(this._wallet, this._settingsStore,
|
2022-10-12 17:09:57 +00:00
|
|
|
this._sendTemplateStore, this._fiatConversationStore)
|
|
|
|
: output = Output(_wallet, _settingsStore, _fiatConversationStore, () => _wallet.currency) {
|
2022-03-30 15:57:04 +00:00
|
|
|
output = Output(_wallet, _settingsStore, _fiatConversationStore, () => currency);
|
2021-07-16 09:32:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
Output output;
|
2021-07-16 09:32:36 +00:00
|
|
|
|
2023-03-15 17:22:08 +00:00
|
|
|
Validator get amountValidator =>
|
|
|
|
AmountValidator(currency: walletTypeToCryptoCurrency(_wallet.type));
|
2021-07-16 09:32:36 +00:00
|
|
|
|
|
|
|
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
|
|
|
|
|
|
|
Validator get templateValidator => TemplateValidator();
|
|
|
|
|
|
|
|
CryptoCurrency get currency => _wallet.currency;
|
|
|
|
|
|
|
|
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
|
|
|
|
2022-05-03 10:44:13 +00:00
|
|
|
@observable
|
|
|
|
bool isCurrencySelected = true;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
bool isFiatSelected = false;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void selectCurrency () {
|
|
|
|
isCurrencySelected = true;
|
|
|
|
isFiatSelected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
void selectFiat () {
|
|
|
|
isFiatSelected = true;
|
|
|
|
isCurrencySelected = false;
|
|
|
|
}
|
|
|
|
|
2021-07-16 09:32:36 +00:00
|
|
|
@computed
|
|
|
|
ObservableList<Template> get templates => _sendTemplateStore.templates;
|
|
|
|
|
|
|
|
final WalletBase _wallet;
|
|
|
|
final SettingsStore _settingsStore;
|
|
|
|
final SendTemplateStore _sendTemplateStore;
|
|
|
|
final FiatConversionStore _fiatConversationStore;
|
|
|
|
|
|
|
|
void updateTemplate() => _sendTemplateStore.update();
|
|
|
|
|
|
|
|
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}) {
|
2021-07-16 09:32:36 +00:00
|
|
|
_sendTemplateStore.addTemplate(
|
|
|
|
name: name,
|
2022-05-03 10:44:13 +00:00
|
|
|
isCurrencySelected: isCurrencySelected,
|
2021-07-16 09:32:36 +00:00
|
|
|
address: address,
|
|
|
|
cryptoCurrency: cryptoCurrency,
|
2022-05-03 10:44:13 +00:00
|
|
|
fiatCurrency: fiatCurrency,
|
|
|
|
amount: amount,
|
|
|
|
amountFiat: amountFiat);
|
2021-07-16 09:32:36 +00:00
|
|
|
updateTemplate();
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
void removeTemplate({required Template template}) {
|
2021-07-16 09:32:36 +00:00
|
|
|
_sendTemplateStore.remove(template: template);
|
|
|
|
updateTemplate();
|
|
|
|
}
|
|
|
|
}
|