2022-07-01 11:04:00 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
2021-04-12 18:22:22 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
|
|
|
|
|
|
|
part 'buy_amount_view_model.g.dart';
|
|
|
|
|
|
|
|
class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel;
|
|
|
|
|
|
|
|
abstract class BuyAmountViewModelBase with Store {
|
2022-10-12 17:09:57 +00:00
|
|
|
BuyAmountViewModelBase()
|
2022-10-17 21:01:50 +00:00
|
|
|
: amount = '',
|
|
|
|
fiatCurrency = FiatCurrency.usd {
|
2022-07-01 11:04:00 +00:00
|
|
|
int selectedIndex = FiatCurrency.currenciesAvailableToBuyWith
|
|
|
|
.indexOf(getIt.get<SettingsStore>().fiatCurrency);
|
|
|
|
|
2022-10-17 21:01:50 +00:00
|
|
|
if (selectedIndex != -1) {
|
|
|
|
fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex];
|
2022-07-01 11:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-12 18:22:22 +00:00
|
|
|
|
|
|
|
@observable
|
|
|
|
String amount;
|
|
|
|
|
2022-07-01 11:04:00 +00:00
|
|
|
@observable
|
2022-10-17 21:01:50 +00:00
|
|
|
FiatCurrency fiatCurrency;
|
2021-04-12 18:22:22 +00:00
|
|
|
|
|
|
|
@computed
|
|
|
|
double get doubleAmount {
|
|
|
|
double _amount;
|
|
|
|
|
|
|
|
try {
|
2022-10-12 17:09:57 +00:00
|
|
|
_amount = double.parse(amount.replaceAll(',', '.'));
|
|
|
|
} catch (_) {
|
2021-04-12 18:22:22 +00:00
|
|
|
_amount = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _amount;
|
|
|
|
}
|
2022-07-01 11:04:00 +00:00
|
|
|
}
|