import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart'; import 'package:cake_wallet/bitcoin/electrum_wallet.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/view_model/send/output.dart'; import 'package:cake_wallet/view_model/send/send_template_view_model.dart'; import 'package:cake_wallet/view_model/settings/settings_view_model.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/entities/template.dart'; import 'package:cake_wallet/core/address_validator.dart'; import 'package:cake_wallet/core/amount_validator.dart'; import 'package:cake_wallet/core/pending_transaction.dart'; import 'package:cake_wallet/core/validator.dart'; import 'package:cake_wallet/core/wallet_base.dart'; import 'package:cake_wallet/core/execution_state.dart'; import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart'; import 'package:cake_wallet/monero/monero_transaction_creation_credentials.dart'; import 'package:cake_wallet/entities/sync_status.dart'; import 'package:cake_wallet/entities/crypto_currency.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/entities/monero_transaction_priority.dart'; import 'package:cake_wallet/entities/calculate_fiat_amount.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/view_model/send/send_view_model_state.dart'; part 'send_view_model.g.dart'; class SendViewModel = SendViewModelBase with _$SendViewModel; abstract class SendViewModelBase with Store { SendViewModelBase(this._wallet, this._settingsStore, this.sendTemplateViewModel, this._fiatConversationStore, this.transactionDescriptionBox) : state = InitialExecutionState() { final priority = _settingsStore.priority[_wallet.type]; final priorities = priorityForWalletType(_wallet.type); if (!priorityForWalletType(_wallet.type).contains(priority)) { _settingsStore.priority[_wallet.type] = priorities.first; } outputs = ObservableList() ..add(Output(_wallet, _settingsStore, _fiatConversationStore)); } @observable ExecutionState state; ObservableList outputs; @action void addOutput() { outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore)); } @action void removeOutput(Output output) { if (isBatchSending) { outputs.remove(output); } } @action void clearOutputs() { outputs.clear(); addOutput(); } @computed bool get isBatchSending => outputs.length > 1; @computed String get pendingTransactionFiatAmount { try { if (pendingTransaction != null) { final fiat = calculateFiatAmount( price: _fiatConversationStore.prices[_wallet.currency], cryptoAmount: pendingTransaction.amountFormatted); return fiat; } else { return '0.00'; } } catch (_) { return '0.00'; } } @computed String get pendingTransactionFeeFiatAmount { try { if (pendingTransaction != null) { final fiat = calculateFiatAmount( price: _fiatConversationStore.prices[_wallet.currency], cryptoAmount: pendingTransaction.feeFormatted); return fiat; } else { return '0.00'; } } catch (_) { return '0.00'; } } FiatCurrency get fiat => _settingsStore.fiatCurrency; TransactionPriority get transactionPriority => _settingsStore.priority[_wallet.type]; CryptoCurrency get currency => _wallet.currency; Validator get amountValidator => AmountValidator(type: _wallet.type); Validator get allAmountValidator => AllAmountValidator(); Validator get addressValidator => AddressValidator(type: _wallet.currency); Validator get textValidator => TextValidator(); @observable PendingTransaction pendingTransaction; @computed String get balance => _wallet.balance.formattedAvailableBalance ?? '0.0'; @computed bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus; @computed ObservableList