2023-08-01 22:19:04 +00:00
|
|
|
import 'package:cake_wallet/entities/template.dart';
|
|
|
|
import 'package:cake_wallet/view_model/send/output.dart';
|
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
|
|
|
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
|
|
|
|
|
|
part 'template_view_model.g.dart';
|
|
|
|
|
|
|
|
class TemplateViewModel = TemplateViewModelBase with _$TemplateViewModel;
|
|
|
|
|
|
|
|
abstract class TemplateViewModelBase with Store {
|
|
|
|
final WalletBase _wallet;
|
|
|
|
final SettingsStore _settingsStore;
|
|
|
|
final FiatConversionStore _fiatConversationStore;
|
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
TemplateViewModelBase({
|
|
|
|
required WalletBase wallet,
|
|
|
|
required SettingsStore settingsStore,
|
|
|
|
required FiatConversionStore fiatConversationStore,
|
|
|
|
}) : _wallet = wallet,
|
2023-08-01 22:19:04 +00:00
|
|
|
_settingsStore = settingsStore,
|
|
|
|
_fiatConversationStore = fiatConversationStore,
|
2023-08-04 17:01:49 +00:00
|
|
|
_currency = wallet.currency,
|
|
|
|
output = Output(wallet, settingsStore, fiatConversationStore, () => wallet.currency) {
|
|
|
|
output = Output(_wallet, _settingsStore, _fiatConversationStore, () => _currency);
|
2023-08-01 22:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
Output output;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
String name = '';
|
|
|
|
|
|
|
|
@observable
|
|
|
|
String address = '';
|
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
@observable
|
|
|
|
CryptoCurrency _currency;
|
|
|
|
|
2023-08-01 22:19:04 +00:00
|
|
|
@observable
|
2024-08-09 21:48:36 +00:00
|
|
|
bool isCryptoSelected = true;
|
2023-08-01 22:19:04 +00:00
|
|
|
|
|
|
|
@action
|
2024-08-09 21:48:36 +00:00
|
|
|
void setCryptoCurrency(bool value) => isCryptoSelected = value;
|
2023-08-01 22:19:04 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
void reset() {
|
|
|
|
name = '';
|
|
|
|
address = '';
|
2024-08-09 21:48:36 +00:00
|
|
|
isCryptoSelected = true;
|
2023-08-01 22:19:04 +00:00
|
|
|
output.reset();
|
|
|
|
}
|
|
|
|
|
2023-08-04 17:01:49 +00:00
|
|
|
Template toTemplate({required String cryptoCurrency, required String fiatCurrency}) {
|
2023-08-01 22:19:04 +00:00
|
|
|
return Template(
|
2024-08-09 21:48:36 +00:00
|
|
|
isCurrencySelectedRaw: isCryptoSelected,
|
2023-08-01 22:19:04 +00:00
|
|
|
nameRaw: name,
|
|
|
|
addressRaw: address,
|
|
|
|
cryptoCurrencyRaw: cryptoCurrency,
|
|
|
|
fiatCurrencyRaw: fiatCurrency,
|
|
|
|
amountRaw: output.cryptoAmount,
|
|
|
|
amountFiatRaw: output.fiatAmount);
|
|
|
|
}
|
2023-08-04 17:01:49 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
void changeSelectedCurrency(CryptoCurrency currency) {
|
2024-08-09 21:48:36 +00:00
|
|
|
isCryptoSelected = true;
|
2023-08-04 17:01:49 +00:00
|
|
|
_currency = currency;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
|
|
|
CryptoCurrency get selectedCurrency => _currency;
|
2023-08-01 22:19:04 +00:00
|
|
|
}
|