mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
switch to safeParse
This commit is contained in:
@@ -25,6 +25,14 @@ class Money implements Comparable<Money> {
|
||||
return Money(amount, currency);
|
||||
}
|
||||
|
||||
factory Money.safeParse(source, Currency currency, {bool isBaseUnit = false}) {
|
||||
final amount = isBaseUnit
|
||||
? BigInt.parse(source.toString())
|
||||
: parseFixed(source.toString().withDecimals(currency.decimals), currency.decimals);
|
||||
|
||||
return Money(amount, currency);
|
||||
}
|
||||
|
||||
/// Parse the [source] and turn it into [Money] if possible
|
||||
///
|
||||
/// As [parse] except that this method returns `null` if the input is not
|
||||
|
||||
@@ -171,17 +171,15 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
|
||||
return maxAmount.toStringAsFixed(2);
|
||||
}
|
||||
|
||||
Money amountForQuote(Quote quote) => Money.parse(
|
||||
Money amountForQuote(Quote quote) => Money.safeParse(
|
||||
(double.parse(fiatAmount) / quote.rate).toStringAsFixed(cryptoCurrency.decimals),
|
||||
cryptoCurrency);
|
||||
|
||||
Money fiatAmountForQuote(Quote quote) {
|
||||
return Money.parse(
|
||||
Money fiatAmountForQuote(Quote quote) => Money.safeParse(
|
||||
(fiatConversionStore.prices[cryptoCurrency]! *
|
||||
double.parse(amountForQuote(quote).toString()))
|
||||
.toStringAsFixed(2),
|
||||
fiatCurrency);
|
||||
}
|
||||
|
||||
// based on usd values, should have roughly equal worth (was done with ai though so it's subject to correction)
|
||||
static final Map<FiatCurrency, List<String>> _defaultAmountsMap = {
|
||||
|
||||
Reference in New Issue
Block a user