mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
nullable amountForQuote
This commit is contained in:
@@ -45,6 +45,14 @@ class Money implements Comparable<Money> {
|
||||
return amount != null ? Money(amount, currency) : null;
|
||||
}
|
||||
|
||||
static Money? trySafeParse(source, Currency currency, {bool isBaseUnit = false}) {
|
||||
final amount = isBaseUnit
|
||||
? BigInt.tryParse(source.toString())
|
||||
: tryParseFixed(source.toString().withDecimals(currency.decimals), currency.decimals);
|
||||
|
||||
return amount != null ? Money(amount, currency) : null;
|
||||
}
|
||||
|
||||
final BigInt amount;
|
||||
final Currency currency;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class BuySellConfirmationPage extends StatelessWidget {
|
||||
style: TextStyle(fontSize: 32),
|
||||
),
|
||||
Text(
|
||||
"≈ ${buySellViewModel.amountForQuote(buySellViewModel.selectedQuote!).toStringWithSymbol(fractionalDigits: 8)}",
|
||||
"≈ ${buySellViewModel.amountForQuote(buySellViewModel.selectedQuote!)?.toStringWithSymbol(fractionalDigits: 8)}",
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w500),
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:cake_wallet/view_model/buy/buy_sell_view_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import "package:modal_bottom_sheet/modal_bottom_sheet.dart";
|
||||
|
||||
class BuySellProviderPage extends StatefulWidget {
|
||||
const BuySellProviderPage({super.key, required this.buySellViewModel});
|
||||
@@ -88,40 +89,43 @@ class _BuySellProviderPageState extends State<BuySellProviderPage> {
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18),
|
||||
child: NewListSections(showHeader: true, sections: {
|
||||
"": [
|
||||
ListItemRegularRow(
|
||||
keyValue: "payment method",
|
||||
label: S.of(context).payment_method,
|
||||
showArrow: true,
|
||||
onTap: () {
|
||||
final page =
|
||||
BuySellPaymentMethodPage(buySellViewModel: widget.buySellViewModel);
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => Material(
|
||||
color: Colors.transparent,
|
||||
child: page,
|
||||
)));
|
||||
},
|
||||
trailingText: widget.buySellViewModel.selectedPaymentMethod?.title)
|
||||
],
|
||||
S.of(context).available_providers: [
|
||||
...widget.buySellViewModel.sortedRecommendedQuotes.map(quoteListItem),
|
||||
if (widget.buySellViewModel.sortedQuotes.isNotEmpty)
|
||||
ListItemDropdown(
|
||||
keyValue: "more options",
|
||||
label: S.of(context).more_options,
|
||||
return SingleChildScrollView(
|
||||
controller: ModalScrollController.of(context),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18),
|
||||
child: NewListSections(showHeader: true, sections: {
|
||||
"": [
|
||||
ListItemRegularRow(
|
||||
keyValue: "payment method",
|
||||
label: S.of(context).payment_method,
|
||||
showArrow: true,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_allProvidersExpanded = !_allProvidersExpanded;
|
||||
});
|
||||
}),
|
||||
if (_allProvidersExpanded)
|
||||
...widget.buySellViewModel.sortedQuotes.map(quoteListItem)
|
||||
]
|
||||
}),
|
||||
final page =
|
||||
BuySellPaymentMethodPage(buySellViewModel: widget.buySellViewModel);
|
||||
Navigator.of(context).push(CupertinoPageRoute(
|
||||
builder: (context) => Material(
|
||||
color: Colors.transparent,
|
||||
child: page,
|
||||
)));
|
||||
},
|
||||
trailingText: widget.buySellViewModel.selectedPaymentMethod?.title)
|
||||
],
|
||||
S.of(context).available_providers: [
|
||||
...widget.buySellViewModel.sortedRecommendedQuotes.map(quoteListItem),
|
||||
if (widget.buySellViewModel.sortedQuotes.isNotEmpty)
|
||||
ListItemDropdown(
|
||||
keyValue: "more options",
|
||||
label: S.of(context).more_options,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_allProvidersExpanded = !_allProvidersExpanded;
|
||||
});
|
||||
}),
|
||||
if (_allProvidersExpanded)
|
||||
...widget.buySellViewModel.sortedQuotes.map(quoteListItem)
|
||||
]
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
))
|
||||
@@ -156,11 +160,12 @@ class _BuySellProviderPageState extends State<BuySellProviderPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
spacing: 4,
|
||||
children: [
|
||||
Text(widget.buySellViewModel
|
||||
.amountForQuote(quote)
|
||||
.toStringWithSymbol(fractionalDigits: 8)),
|
||||
if(fiatAmount != null)
|
||||
Text(
|
||||
Text(widget.buySellViewModel
|
||||
.amountForQuote(quote)
|
||||
?.toStringWithSymbol(fractionalDigits: 8) ??
|
||||
""),
|
||||
if (fiatAmount != null)
|
||||
Text(
|
||||
"= ${fiatAmount.toStringWithSymbol(fractionalDigits: 2, trimZeros: false)}",
|
||||
style: TextStyle(fontSize: 12, color: Theme.of(context).colorScheme.onSurfaceVariant))
|
||||
],
|
||||
|
||||
@@ -98,7 +98,7 @@ class _BuySellRedirectingPageState extends State<BuySellRedirectingPage> {
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Text(
|
||||
"${widget.buySellViewModel.fiatAmount} ${widget.buySellViewModel.fiatCurrency} → ${widget.buySellViewModel.amountForQuote(widget.buySellViewModel.selectedQuote!).toStringWithSymbol(fractionalDigits: 8)}")
|
||||
"${widget.buySellViewModel.fiatAmount} ${widget.buySellViewModel.fiatCurrency} → ${widget.buySellViewModel.amountForQuote(widget.buySellViewModel.selectedQuote!)?.toStringWithSymbol(fractionalDigits: 8)}")
|
||||
],
|
||||
)
|
||||
],
|
||||
|
||||
@@ -171,7 +171,7 @@ abstract class BuySellViewModelBase extends WalletChangeListenerViewModel with S
|
||||
return maxAmount.toStringAsFixed(2);
|
||||
}
|
||||
|
||||
Money amountForQuote(Quote quote) => Money.safeParse(
|
||||
Money? amountForQuote(Quote quote) => Money.trySafeParse(
|
||||
(double.parse(fiatAmount) / quote.rate).toStringAsFixed(min(20, cryptoCurrency.decimals)),
|
||||
cryptoCurrency);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user