guard for fiat amount being null

This commit is contained in:
Robert Malikowski
2026-08-21 19:09:15 +02:00
parent d3a2966706
commit bf3e2e15a3
2 changed files with 14 additions and 3 deletions
@@ -135,7 +135,9 @@ class _BuySellProviderPageState extends State<BuySellProviderPage> {
" " +
(widget.buySellViewModel.cryptoCurrency.fullName ?? "");
ListItem quoteListItem(Quote quote) => ListItemRegularRow(
ListItem quoteListItem(Quote quote) {
final fiatAmount = widget.buySellViewModel.fiatAmountForQuote(quote);
return ListItemRegularRow(
keyValue: quote.provider.title,
label: quote.rampName ?? quote.provider.title,
secondaryLabel: quote.rampName != null ? quote.provider.title : null,
@@ -155,11 +157,13 @@ class _BuySellProviderPageState extends State<BuySellProviderPage> {
Text(widget.buySellViewModel
.amountForQuote(quote)
.toStringWithSymbol(fractionalDigits: 8)),
if(fiatAmount != null)
Text(
"= ${widget.buySellViewModel.fiatAmountForQuote(quote).toStringWithSymbol(fractionalDigits: 2, trimZeros: false)}",
"= ${fiatAmount.toStringWithSymbol(fractionalDigits: 2, trimZeros: false)}",
style: TextStyle(fontSize: 12, color: Theme.of(context).colorScheme.onSurfaceVariant))
],
));
}
void navigateToConfirmation(BuildContext context) {
final page = BuySellConfirmationPage(buySellViewModel: widget.buySellViewModel);
+8 -1
View File
@@ -175,11 +175,18 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
(double.parse(fiatAmount) / quote.rate).toStringAsFixed(cryptoCurrency.decimals),
cryptoCurrency);
Money fiatAmountForQuote(Quote quote) => Money.safeParse(
@computed
Money? fiatAmountForQuote(Quote quote) {
if(fiatConversionStore.prices[cryptoCurrency] == null) {
return null;
}
return 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 = {