Files
hash-wallet/lib/view_model/buy/buy_amount_view_model.dart
T
jwinterm 788318a3a2 style: format Dart at 100 columns, as upstream does
Upstream reformatted its whole tree in 16ddc0837. Matching it removes
formatting from the conflict surface of this and every later sync.
2026-10-24 22:48:17 -04:00

41 lines
967 B
Dart

import 'package:hash_wallet/di.dart';
import 'package:hash_wallet/store/settings_store.dart';
import 'package:mobx/mobx.dart';
import 'package:hash_wallet/entities/fiat_currency.dart';
part 'buy_amount_view_model.g.dart';
class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel;
abstract class BuyAmountViewModelBase with Store {
BuyAmountViewModelBase()
: amount = '',
fiatCurrency = FiatCurrency.usd {
int selectedIndex =
FiatCurrency.currenciesAvailableToBuyWith.indexOf(getIt.get<SettingsStore>().fiatCurrency);
if (selectedIndex != -1) {
fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex];
}
}
@observable
String amount;
@observable
FiatCurrency fiatCurrency;
@computed
double get doubleAmount {
double _amount;
try {
_amount = double.parse(amount.replaceAll(',', '.'));
} catch (_) {
_amount = 0.0;
}
return _amount;
}
}