| 1 | import 'package:cake_wallet/di.dart'; |
| 2 | import 'package:cake_wallet/store/settings_store.dart'; |
| 3 | import 'package:mobx/mobx.dart'; |
| 4 | import 'package:cake_wallet/entities/fiat_currency.dart'; |
| 5 | |
| 6 | part 'buy_amount_view_model.g.dart'; |
| 7 | |
| 8 | class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel; |
| 9 | |
| 10 | abstract class BuyAmountViewModelBase with Store { |
| 11 | BuyAmountViewModelBase() |
| 12 | : amount = '', |
| 13 | fiatCurrency = FiatCurrency.usd { |
| 14 | int selectedIndex = |
| 15 | FiatCurrency.currenciesAvailableToBuyWith.indexOf(getIt.get<SettingsStore>().fiatCurrency); |
| 16 | |
| 17 | if (selectedIndex != -1) { |
| 18 | fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex]; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | @observable |
| 23 | String amount; |
| 24 | |
| 25 | @observable |
| 26 | FiatCurrency fiatCurrency; |
| 27 | |
| 28 | @computed |
| 29 | double get doubleAmount { |
| 30 | double _amount; |
| 31 | |
| 32 | try { |
| 33 | _amount = double.parse(amount.replaceAll(',', '.')); |
| 34 | } catch (_) { |
| 35 | _amount = 0.0; |
| 36 | } |
| 37 | |
| 38 | return _amount; |
| 39 | } |
| 40 | } |