mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-29 21:55:58 +00:00
feat: WIP use amount formatter in GUI
This commit is contained in:
parent
86cd5bea3e
commit
1b1c61a3a3
37 changed files with 535 additions and 523 deletions
|
@ -8,11 +8,11 @@ import 'package:stackwallet/db/isar/main_db.dart';
|
|||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/pages/coin_control/utxo_card.dart';
|
||||
import 'package:stackwallet/pages/coin_control/utxo_details_view.dart';
|
||||
import 'package:stackwallet/providers/global/locale_provider.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/services/mixins/coin_control_interface.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -687,14 +687,9 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
|
|||
fractionDigits: coin.decimals,
|
||||
);
|
||||
return Text(
|
||||
"${selectedSum.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(selectedSum),
|
||||
style: widget.requestedTotal == null
|
||||
? STextStyles.w600_14(context)
|
||||
: STextStyles.w600_14(context).copyWith(
|
||||
|
@ -735,14 +730,9 @@ class _CoinControlViewState extends ConsumerState<CoinControlView> {
|
|||
style: STextStyles.w600_14(context),
|
||||
),
|
||||
Text(
|
||||
"${widget.requestedTotal!.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(widget.requestedTotal!),
|
||||
style: STextStyles.w600_14(context),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/providers/global/locale_provider.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -124,15 +124,11 @@ class _UtxoCardState extends ConsumerState<UtxoCard> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"${utxo.value.toAmountAsRaw(
|
||||
fractionDigits: coin.decimals,
|
||||
).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
utxo.value.toAmountAsRaw(
|
||||
fractionDigits: coin.decimals,
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
),
|
||||
style: STextStyles.w600_14(context),
|
||||
),
|
||||
const SizedBox(
|
||||
|
|
|
@ -6,10 +6,10 @@ import 'package:isar/isar.dart';
|
|||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/transaction_views/transaction_details_view.dart';
|
||||
import 'package:stackwallet/providers/global/locale_provider.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
@ -240,13 +240,11 @@ class _UtxoDetailsViewState extends ConsumerState<UtxoDetailsView> {
|
|||
width: 16,
|
||||
),
|
||||
Text(
|
||||
"${utxo!.value.toAmountAsRaw(fractionDigits: coin.decimals).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
utxo!.value.toAmountAsRaw(
|
||||
fractionDigits: coin.decimals,
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
),
|
||||
style: STextStyles.pageTitleH2(context),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -13,6 +13,7 @@ import 'package:stackwallet/route_generator.dart';
|
|||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -366,20 +367,19 @@ class _ConfirmChangeNowSendViewState
|
|||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
"${(transactionInfo["fee"] is Amount ? transactionInfo["fee"] as Amount : (transactionInfo["fee"] as int).toAmountAsRaw(
|
||||
fractionDigits: ref.watch(
|
||||
managerProvider
|
||||
.select((value) => value.coin.decimals),
|
||||
),
|
||||
)).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${ref.watch(
|
||||
ref
|
||||
.watch(pAmountFormatter(ref.watch(
|
||||
managerProvider.select((value) => value.coin),
|
||||
).ticker}",
|
||||
)))
|
||||
.format(transactionInfo["fee"] is Amount
|
||||
? transactionInfo["fee"] as Amount
|
||||
: (transactionInfo["fee"] as int)
|
||||
.toAmountAsRaw(
|
||||
fractionDigits: ref.watch(
|
||||
managerProvider.select(
|
||||
(value) => value.coin.decimals),
|
||||
),
|
||||
)),
|
||||
style:
|
||||
STextStyles.desktopTextExtraExtraSmall(context)
|
||||
.copyWith(
|
||||
|
@ -423,16 +423,9 @@ class _ConfirmChangeNowSendViewState
|
|||
final amount =
|
||||
transactionInfo["recipientAmt"] as Amount;
|
||||
final total = amount + fee;
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
);
|
||||
|
||||
return Text(
|
||||
"${total.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)}"
|
||||
" ${coin.ticker}",
|
||||
ref.watch(pAmountFormatter(coin)).format(total),
|
||||
style: STextStyles.itemSubtitle12(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
|
@ -605,7 +598,7 @@ class _ConfirmChangeNowSendViewState
|
|||
);
|
||||
|
||||
return Text(
|
||||
" | ${value.localizedStringAsFixed(locale: locale)} $currency",
|
||||
" | ${value.fiatString(locale: locale)} $currency",
|
||||
style:
|
||||
STextStyles.desktopTextExtraExtraSmall(context)
|
||||
.copyWith(
|
||||
|
@ -618,15 +611,11 @@ class _ConfirmChangeNowSendViewState
|
|||
],
|
||||
),
|
||||
child: Text(
|
||||
"${(transactionInfo["recipientAmt"] as Amount).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${ref.watch(
|
||||
managerProvider.select((value) => value.coin),
|
||||
).ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(ref.watch(
|
||||
walletsChangeNotifierProvider.select(
|
||||
(value) => value.getManager(walletId).coin))))
|
||||
.format((transactionInfo["recipientAmt"] as Amount)),
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
|
@ -652,19 +641,20 @@ class _ConfirmChangeNowSendViewState
|
|||
style: STextStyles.smallMed12(context),
|
||||
),
|
||||
Text(
|
||||
"${(transactionInfo["fee"] is Amount ? transactionInfo["fee"] as Amount : (transactionInfo["fee"] as int).toAmountAsRaw(fractionDigits: ref.watch(
|
||||
managerProvider.select(
|
||||
(value) => value.coin.decimals,
|
||||
),
|
||||
))).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${ref.watch(
|
||||
ref
|
||||
.watch(pAmountFormatter(ref.watch(
|
||||
managerProvider.select((value) => value.coin),
|
||||
).ticker}",
|
||||
)))
|
||||
.format(
|
||||
(transactionInfo["fee"] is Amount
|
||||
? transactionInfo["fee"] as Amount
|
||||
: (transactionInfo["fee"] as int).toAmountAsRaw(
|
||||
fractionDigits: ref.watch(
|
||||
managerProvider.select(
|
||||
(value) => value.coin.decimals,
|
||||
),
|
||||
))),
|
||||
),
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
|
@ -756,16 +746,9 @@ class _ConfirmChangeNowSendViewState
|
|||
final amount =
|
||||
transactionInfo["recipientAmt"] as Amount;
|
||||
final total = amount + fee;
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
);
|
||||
|
||||
return Text(
|
||||
"${total.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)}"
|
||||
" ${coin.ticker}",
|
||||
ref.watch(pAmountFormatter(coin)).format(total),
|
||||
style: STextStyles.itemSubtitle12(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
|
|
@ -18,6 +18,7 @@ import 'package:stackwallet/route_generator.dart';
|
|||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
|
@ -161,18 +162,15 @@ class _Step4ViewState extends ConsumerState<Step4View> {
|
|||
),
|
||||
SecondaryButton(
|
||||
label:
|
||||
"${firoWallet.balancePrivate.spendable.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} (private)",
|
||||
"${ref.watch(pAmountFormatter(firoWallet.coin)).format(firoWallet.balancePrivate.spendable)} (private)",
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
),
|
||||
SecondaryButton(
|
||||
label: "${firoWallet.balance.spendable.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} (public)",
|
||||
label:
|
||||
"${ref.watch(pAmountFormatter(firoWallet.coin)).format(firoWallet.balance.spendable)} (public)",
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
const SizedBox(
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'package:stackwallet/services/coins/manager.dart';
|
|||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -147,13 +148,7 @@ class _SendFromViewState extends ConsumerState<SendFromView> {
|
|||
Row(
|
||||
children: [
|
||||
Text(
|
||||
"You need to send ${amount.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
"You need to send ${ref.watch(pAmountFormatter(coin)).format(amount)}",
|
||||
style: isDesktop
|
||||
? STextStyles.desktopTextExtraExtraSmall(context)
|
||||
: STextStyles.itemSubtitle(context),
|
||||
|
@ -453,9 +448,10 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
|
|||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
Text(
|
||||
"${(manager.wallet as FiroWallet).availablePrivateBalance().localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
(manager.wallet as FiroWallet)
|
||||
.availablePrivateBalance(),
|
||||
),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
],
|
||||
|
@ -515,9 +511,9 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
|
|||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
Text(
|
||||
"${(manager.wallet as FiroWallet).availablePublicBalance().localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
(manager.wallet as FiroWallet)
|
||||
.availablePublicBalance()),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
],
|
||||
|
@ -605,9 +601,9 @@ class _SendFromCardState extends ConsumerState<SendFromCard> {
|
|||
),
|
||||
if (!isFiro)
|
||||
Text(
|
||||
"${manager.balance.spendable.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(manager.balance.spendable),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -8,6 +8,8 @@ import 'package:stackwallet/providers/global/locale_provider.dart';
|
|||
import 'package:stackwallet/services/exchange/exchange.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_unit.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart';
|
||||
|
@ -97,13 +99,32 @@ class _ExchangeOptionState extends ConsumerState<ExchangeOption> {
|
|||
.toAmount(fractionDigits: decimals);
|
||||
}
|
||||
|
||||
final rateString =
|
||||
"1 ${sendCurrency.ticker.toUpperCase()} ~ ${rate.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
),
|
||||
)} ${receivingCurrency.ticker.toUpperCase()}";
|
||||
Coin? coin;
|
||||
try {
|
||||
coin = coinFromTickerCaseInsensitive(
|
||||
receivingCurrency.ticker);
|
||||
} catch (_) {
|
||||
coin = null;
|
||||
}
|
||||
|
||||
final String rateString;
|
||||
if (coin != null) {
|
||||
rateString = "1 ${sendCurrency.ticker.toUpperCase()} "
|
||||
"~ ${ref.watch(pAmountFormatter(coin)).format(rate)}";
|
||||
} else {
|
||||
final formatter = AmountFormatter(
|
||||
unit: AmountUnit.normal,
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
),
|
||||
coin: Coin.bitcoin, // some sane default
|
||||
maxDecimals: 8, // some sane default
|
||||
);
|
||||
rateString = "1 ${sendCurrency.ticker.toUpperCase()} "
|
||||
"~ ${formatter.format(rate, withUnitName: false)}"
|
||||
" ${receivingCurrency.ticker.toUpperCase()}";
|
||||
}
|
||||
|
||||
return ConditionalParent(
|
||||
condition: i > 0,
|
||||
|
|
|
@ -26,6 +26,7 @@ import 'package:stackwallet/services/exchange/trocador/trocador_exchange.dart';
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/themes/theme_providers.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
|
@ -356,13 +357,9 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
|
|||
trade.payInCurrency);
|
||||
final amount = sendAmount.toAmount(
|
||||
fractionDigits: coin.decimals);
|
||||
text = amount.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
);
|
||||
text = ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(amount);
|
||||
} catch (_) {
|
||||
text = sendAmount.toStringAsFixed(
|
||||
trade.payInCurrency.toLowerCase() == "xmr"
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -12,7 +14,7 @@ import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
|||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||
import 'package:stackwallet/widgets/stack_dialog.dart';
|
||||
|
||||
class ConfirmPaynymConnectDialog extends StatelessWidget {
|
||||
class ConfirmPaynymConnectDialog extends ConsumerWidget {
|
||||
const ConfirmPaynymConnectDialog({
|
||||
Key? key,
|
||||
required this.nymName,
|
||||
|
@ -30,14 +32,14 @@ class ConfirmPaynymConnectDialog extends StatelessWidget {
|
|||
|
||||
String get title => "Connect to $nymName";
|
||||
|
||||
String get message => "A one-time connection fee of "
|
||||
"${amount.localizedStringAsFixed(locale: locale)} ${coin.ticker} "
|
||||
String message(String amountString) => "A one-time connection fee of "
|
||||
"$amountString "
|
||||
"will be charged to connect to this PayNym.\n\nThis fee "
|
||||
"covers the cost of creating a one-time transaction to create a "
|
||||
"record on the blockchain. This keeps PayNyms decentralized.";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
if (Util.isDesktop) {
|
||||
return DesktopDialog(
|
||||
maxHeight: double.infinity,
|
||||
|
@ -76,7 +78,7 @@ class ConfirmPaynymConnectDialog extends StatelessWidget {
|
|||
right: 40,
|
||||
),
|
||||
child: Text(
|
||||
message,
|
||||
message(ref.watch(pAmountFormatter(coin)).format(amount)),
|
||||
style: STextStyles.desktopTextMedium(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
|
@ -123,7 +125,7 @@ class ConfirmPaynymConnectDialog extends StatelessWidget {
|
|||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
message: message,
|
||||
message: message(ref.watch(pAmountFormatter(coin)).format(amount)),
|
||||
leftButton: SecondaryButton(
|
||||
buttonHeight: ButtonHeight.xl,
|
||||
label: "Cancel",
|
||||
|
|
|
@ -22,6 +22,7 @@ import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/themes/theme_providers.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -277,13 +278,15 @@ class _ConfirmTransactionViewState
|
|||
final managerProvider = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManagerProvider(walletId)));
|
||||
|
||||
final coin = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManager(walletId).coin));
|
||||
|
||||
final String unit;
|
||||
if (widget.isTokenTx) {
|
||||
unit = ref.watch(
|
||||
tokenServiceProvider.select((value) => value!.tokenContract.symbol));
|
||||
} else {
|
||||
unit = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManager(walletId).coin.ticker));
|
||||
unit = coin.ticker;
|
||||
}
|
||||
|
||||
return ConditionalParent(
|
||||
|
@ -411,12 +414,12 @@ class _ConfirmTransactionViewState
|
|||
style: STextStyles.smallMed12(context),
|
||||
),
|
||||
Text(
|
||||
"${(transactionInfo["recipientAmt"] as Amount).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
),
|
||||
)} $unit",
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
transactionInfo["recipientAmt"] as Amount,
|
||||
ethContract: ref
|
||||
.watch(tokenServiceProvider)
|
||||
?.tokenContract,
|
||||
),
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
|
@ -435,20 +438,18 @@ class _ConfirmTransactionViewState
|
|||
style: STextStyles.smallMed12(context),
|
||||
),
|
||||
Text(
|
||||
"${(transactionInfo["fee"] is Amount ? transactionInfo["fee"] as Amount : (transactionInfo["fee"] as int).toAmountAsRaw(
|
||||
fractionDigits: ref.watch(
|
||||
managerProvider.select(
|
||||
(value) => value.coin.decimals,
|
||||
),
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
(transactionInfo["fee"] is Amount
|
||||
? transactionInfo["fee"] as Amount
|
||||
: (transactionInfo["fee"] as int)
|
||||
.toAmountAsRaw(
|
||||
fractionDigits: ref.watch(
|
||||
managerProvider.select(
|
||||
(value) => value.coin.decimals,
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
)).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
),
|
||||
)} ${ref.watch(
|
||||
managerProvider.select((value) => value.coin),
|
||||
).ticker}",
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
|
@ -585,7 +586,7 @@ class _ConfirmTransactionViewState
|
|||
if (price > Decimal.zero) {
|
||||
fiatAmount = (amount.decimal * price)
|
||||
.toAmount(fractionDigits: 2)
|
||||
.localizedStringAsFixed(
|
||||
.fiatString(
|
||||
locale: ref
|
||||
.read(
|
||||
localeServiceChangeNotifierProvider)
|
||||
|
@ -597,12 +598,11 @@ class _ConfirmTransactionViewState
|
|||
return Row(
|
||||
children: [
|
||||
Text(
|
||||
"${amount.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
),
|
||||
)} $unit",
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
amount,
|
||||
ethContract: ref
|
||||
.read(tokenServiceProvider)
|
||||
?.tokenContract),
|
||||
style: STextStyles
|
||||
.desktopTextExtraExtraSmall(
|
||||
context)
|
||||
|
@ -712,14 +712,9 @@ class _ConfirmTransactionViewState
|
|||
);
|
||||
|
||||
return Text(
|
||||
"${fee.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(fee),
|
||||
style:
|
||||
STextStyles.desktopTextExtraExtraSmall(
|
||||
context)
|
||||
|
@ -892,13 +887,7 @@ class _ConfirmTransactionViewState
|
|||
);
|
||||
|
||||
return Text(
|
||||
"${fee.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
ref.watch(pAmountFormatter(coin)).format(fee),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
);
|
||||
},
|
||||
|
@ -952,18 +941,13 @@ class _ConfirmTransactionViewState
|
|||
? transactionInfo["fee"] as Amount
|
||||
: (transactionInfo["fee"] as int)
|
||||
.toAmountAsRaw(fractionDigits: coin.decimals);
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
);
|
||||
|
||||
final amount =
|
||||
transactionInfo["recipientAmt"] as Amount;
|
||||
return Text(
|
||||
"${(amount + fee).localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${ref.watch(
|
||||
managerProvider.select((value) => value.coin),
|
||||
).ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(amount + fee),
|
||||
style: isDesktop
|
||||
? STextStyles.desktopTextExtraExtraSmall(context)
|
||||
.copyWith(
|
||||
|
|
|
@ -29,6 +29,7 @@ import 'package:stackwallet/themes/coin_icon_provider.dart';
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/address_utils.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
|
@ -139,7 +140,7 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
.toAmount(
|
||||
fractionDigits: 2,
|
||||
)
|
||||
.localizedStringAsFixed(
|
||||
.fiatString(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
}
|
||||
|
@ -285,7 +286,10 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
}
|
||||
|
||||
fee = await manager.estimateFeeFor(amount, specialMoneroId.raw!);
|
||||
cachedFees[amount] = fee.localizedStringAsFixed(locale: locale);
|
||||
cachedFees[amount] = ref.read(pAmountFormatter(coin)).format(
|
||||
fee,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
return cachedFees[amount]!;
|
||||
} else if (coin == Coin.firo || coin == Coin.firoTestNet) {
|
||||
|
@ -293,22 +297,29 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
"Private") {
|
||||
fee = await manager.estimateFeeFor(amount, feeRate);
|
||||
|
||||
cachedFiroPrivateFees[amount] =
|
||||
fee.localizedStringAsFixed(locale: locale);
|
||||
cachedFiroPrivateFees[amount] = ref.read(pAmountFormatter(coin)).format(
|
||||
fee,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
return cachedFiroPrivateFees[amount]!;
|
||||
} else {
|
||||
fee = await (manager.wallet as FiroWallet)
|
||||
.estimateFeeForPublic(amount, feeRate);
|
||||
|
||||
cachedFiroPublicFees[amount] =
|
||||
fee.localizedStringAsFixed(locale: locale);
|
||||
cachedFiroPublicFees[amount] = ref.read(pAmountFormatter(coin)).format(
|
||||
fee,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
return cachedFiroPublicFees[amount]!;
|
||||
}
|
||||
} else {
|
||||
fee = await manager.estimateFeeFor(amount, feeRate);
|
||||
cachedFees[amount] = fee.localizedStringAsFixed(locale: locale);
|
||||
cachedFees[amount] = ref.read(pAmountFormatter(coin)).format(
|
||||
fee,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
return cachedFees[amount]!;
|
||||
}
|
||||
|
@ -327,9 +338,10 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
balance = wallet.availablePublicBalance();
|
||||
}
|
||||
|
||||
return balance.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
return ref.read(pAmountFormatter(coin)).format(
|
||||
balance,
|
||||
withUnitName: false,
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -831,10 +843,12 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
if (_cachedBalance != null) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
cryptoAmountController.text =
|
||||
_cachedBalance!
|
||||
.localizedStringAsFixed(
|
||||
locale: locale);
|
||||
cryptoAmountController.text = ref
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(
|
||||
_cachedBalance!,
|
||||
withUnitName: false,
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
|
@ -843,9 +857,10 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
"${_cachedBalance!.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(
|
||||
coin))
|
||||
.format(_cachedBalance!),
|
||||
style:
|
||||
STextStyles.titleBold12(
|
||||
context)
|
||||
|
@ -857,7 +872,7 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
Text(
|
||||
"${(_cachedBalance!.decimal * ref.watch(priceAnd24hChangeNotifierProvider.select((value) => value.getPrice(coin).item1))).toAmount(
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: locale,
|
||||
)} ${ref.watch(prefsChangeNotifierProvider.select((value) => value.currency))}",
|
||||
style: STextStyles.subtitle(
|
||||
|
@ -1149,10 +1164,15 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
);
|
||||
cryptoAmountController
|
||||
.text =
|
||||
amount
|
||||
.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
);
|
||||
ref
|
||||
.read(
|
||||
pAmountFormatter(
|
||||
coin))
|
||||
.format(
|
||||
amount,
|
||||
withUnitName:
|
||||
false,
|
||||
);
|
||||
_amountToSend = amount;
|
||||
}
|
||||
|
||||
|
@ -1413,23 +1433,32 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
.state)
|
||||
.state ==
|
||||
"Private") {
|
||||
cryptoAmountController.text = firoWallet
|
||||
.availablePrivateBalance()
|
||||
.localizedStringAsFixed(
|
||||
locale: locale);
|
||||
cryptoAmountController.text = ref
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(
|
||||
firoWallet
|
||||
.availablePrivateBalance(),
|
||||
withUnitName: false,
|
||||
);
|
||||
} else {
|
||||
cryptoAmountController.text = firoWallet
|
||||
.availablePublicBalance()
|
||||
.localizedStringAsFixed(
|
||||
locale: locale);
|
||||
cryptoAmountController.text = ref
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(
|
||||
firoWallet
|
||||
.availablePublicBalance(),
|
||||
withUnitName: false,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
cryptoAmountController.text = ref
|
||||
.read(provider)
|
||||
.balance
|
||||
.spendable
|
||||
.localizedStringAsFixed(
|
||||
locale: locale);
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(
|
||||
ref
|
||||
.read(provider)
|
||||
.balance
|
||||
.spendable,
|
||||
withUnitName: false,
|
||||
);
|
||||
}
|
||||
_cryptoAmountChanged();
|
||||
},
|
||||
|
@ -1568,12 +1597,10 @@ class _SendViewState extends ConsumerState<SendView> {
|
|||
level: LogLevel.Info);
|
||||
|
||||
final amountString =
|
||||
_amountToSend!.localizedStringAsFixed(
|
||||
locale: ref
|
||||
.read(
|
||||
localeServiceChangeNotifierProvider)
|
||||
.locale,
|
||||
);
|
||||
ref.read(pAmountFormatter(coin)).format(
|
||||
_amountToSend!,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
_cryptoAmountChangeLock = true;
|
||||
cryptoAmountController.text = amountString;
|
||||
|
|
|
@ -4,8 +4,8 @@ import 'package:stackwallet/providers/providers.dart';
|
|||
import 'package:stackwallet/providers/wallet/public_private_balance_state_provider.dart';
|
||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
||||
class FiroBalanceSelectionSheet extends ConsumerStatefulWidget {
|
||||
|
@ -152,14 +152,11 @@ class _FiroBalanceSelectionSheetState
|
|||
width: 2,
|
||||
),
|
||||
Text(
|
||||
"${firoWallet.availablePrivateBalance().localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${manager.coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(manager.coin))
|
||||
.format(
|
||||
firoWallet.availablePrivateBalance(),
|
||||
),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
|
@ -233,14 +230,11 @@ class _FiroBalanceSelectionSheetState
|
|||
width: 2,
|
||||
),
|
||||
Text(
|
||||
"${firoWallet.availablePublicBalance().localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${manager.coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(manager.coin))
|
||||
.format(
|
||||
firoWallet.availablePublicBalance(),
|
||||
),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:stackwallet/services/coins/manager.dart';
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/address_utils.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
|
@ -166,9 +167,10 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
final Amount amount = Decimal.parse(results["amount"]!).toAmount(
|
||||
fractionDigits: tokenContract.decimals,
|
||||
);
|
||||
cryptoAmountController.text = amount.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
cryptoAmountController.text = ref.read(pAmountFormatter(coin)).format(
|
||||
amount,
|
||||
withUnitName: false,
|
||||
);
|
||||
_amountToSend = amount;
|
||||
}
|
||||
|
||||
|
@ -238,9 +240,10 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
level: LogLevel.Info);
|
||||
|
||||
_cryptoAmountChangeLock = true;
|
||||
cryptoAmountController.text = _amountToSend!.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
cryptoAmountController.text = ref.read(pAmountFormatter(coin)).format(
|
||||
_amountToSend!,
|
||||
withUnitName: false,
|
||||
);
|
||||
_cryptoAmountChangeLock = false;
|
||||
} else {
|
||||
_amountToSend = Amount.zero;
|
||||
|
@ -285,7 +288,7 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
.toAmount(
|
||||
fractionDigits: 2,
|
||||
)
|
||||
.localizedStringAsFixed(
|
||||
.fiatString(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
}
|
||||
|
@ -356,9 +359,10 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
}
|
||||
|
||||
final Amount fee = wallet.estimateFeeFor(feeRate);
|
||||
cachedFees = fee.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
cachedFees = ref.read(pAmountFormatter(coin)).format(
|
||||
fee,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
return cachedFees;
|
||||
}
|
||||
|
@ -674,14 +678,13 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
GestureDetector(
|
||||
onTap: () {
|
||||
cryptoAmountController.text = ref
|
||||
.read(tokenServiceProvider)!
|
||||
.balance
|
||||
.spendable
|
||||
.localizedStringAsFixed(
|
||||
locale: ref
|
||||
.read(
|
||||
localeServiceChangeNotifierProvider)
|
||||
.locale,
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(
|
||||
ref
|
||||
.read(tokenServiceProvider)!
|
||||
.balance
|
||||
.spendable,
|
||||
withUnitName: false,
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
|
@ -691,20 +694,22 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
"${ref.watch(
|
||||
tokenServiceProvider.select(
|
||||
(value) => value!
|
||||
.balance.spendable
|
||||
.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(
|
||||
ref.watch(
|
||||
tokenServiceProvider.select(
|
||||
(value) => value!
|
||||
.balance.spendable,
|
||||
),
|
||||
),
|
||||
ethContract: ref.watch(
|
||||
tokenServiceProvider.select(
|
||||
(value) =>
|
||||
value!.tokenContract,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)} ${tokenContract.symbol}",
|
||||
style:
|
||||
STextStyles.titleBold12(context)
|
||||
.copyWith(
|
||||
|
@ -715,7 +720,7 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
|
|||
Text(
|
||||
"${(ref.watch(tokenServiceProvider.select((value) => value!.balance.spendable.decimal)) * ref.watch(priceAnd24hChangeNotifierProvider.select((value) => value.getTokenPrice(tokenContract.address).item1))).toAmount(
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: locale,
|
||||
)} ${ref.watch(prefsChangeNotifierProvider.select((value) => value.currency))}",
|
||||
style: STextStyles.subtitle(context)
|
||||
|
|
|
@ -6,8 +6,8 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/sync_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
@ -147,14 +147,10 @@ class WalletSyncingOptionsView extends ConsumerWidget {
|
|||
height: 2,
|
||||
),
|
||||
Text(
|
||||
"${manager.balance.total.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${manager.coin.ticker}",
|
||||
ref
|
||||
.watch(pAmountFormatter(
|
||||
manager.coin))
|
||||
.format(manager.balance.total),
|
||||
style:
|
||||
STextStyles.itemSubtitle(context),
|
||||
)
|
||||
|
|
|
@ -10,7 +10,9 @@ import 'package:stackwallet/services/ethereum/cached_eth_token_balance.dart';
|
|||
import 'package:stackwallet/services/ethereum/ethereum_token_service.dart';
|
||||
import 'package:stackwallet/services/transaction_notification_tracker.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/show_loading.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
@ -163,14 +165,10 @@ class _MyTokenSelectItemState extends ConsumerState<MyTokenSelectItem> {
|
|||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
"${cachedBalance.getCachedBalance().total.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} "
|
||||
"${widget.token.symbol}",
|
||||
ref.watch(pAmountFormatter(Coin.ethereum)).format(
|
||||
cachedBalance.getCachedBalance().total,
|
||||
ethContract: widget.token,
|
||||
),
|
||||
style: isDesktop
|
||||
? STextStyles.desktopTextExtraSmall(context)
|
||||
.copyWith(
|
||||
|
|
|
@ -19,6 +19,7 @@ import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/themes/theme_providers.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -86,14 +87,10 @@ class TokenSummary extends ConsumerWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"${balance.total.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
ref.watch(pAmountFormatter(Coin.ethereum)).format(
|
||||
balance.total,
|
||||
ethContract: token,
|
||||
),
|
||||
),
|
||||
)}"
|
||||
" ${token.symbol}",
|
||||
style: STextStyles.pageTitleH1(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
@ -118,7 +115,7 @@ class TokenSummary extends ConsumerWidget {
|
|||
),
|
||||
)).toAmount(
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:stackwallet/providers/wallet/wallet_balance_toggle_state_provide
|
|||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
|
||||
|
@ -278,13 +279,7 @@ class BalanceSelector<T> extends ConsumerWidget {
|
|||
height: 2,
|
||||
),
|
||||
Text(
|
||||
"${balance.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
"${ref.watch(pAmountFormatter(coin)).format(balance)} ${coin.ticker}",
|
||||
style: STextStyles.itemSubtitle12(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
|||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
|
||||
|
@ -150,9 +151,7 @@ class _WalletSummaryInfoState extends ConsumerState<WalletSummaryInfo> {
|
|||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: SelectableText(
|
||||
"${balanceToShow.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
"${ref.watch(pAmountFormatter(coin)).format(balanceToShow)} ${coin.ticker}",
|
||||
style: STextStyles.pageTitleH1(context).copyWith(
|
||||
fontSize: 24,
|
||||
color: Theme.of(context)
|
||||
|
@ -165,7 +164,7 @@ class _WalletSummaryInfoState extends ConsumerState<WalletSummaryInfo> {
|
|||
Text(
|
||||
"${(priceTuple.item1 * balanceToShow.decimal).toAmount(
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: locale,
|
||||
)} $baseCurrency",
|
||||
style: STextStyles.subtitle500(context).copyWith(
|
||||
|
|
|
@ -15,6 +15,7 @@ import 'package:stackwallet/providers/providers.dart';
|
|||
import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -958,9 +959,7 @@ class _DesktopTransactionCardRowState
|
|||
builder: (_) {
|
||||
final amount = _transaction.realAmount;
|
||||
return Text(
|
||||
"$prefix${amount.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
"$prefix${ref.watch(pAmountFormatter(coin)).format(amount)}",
|
||||
style: STextStyles.desktopTextExtraExtraSmall(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
|
@ -982,7 +981,7 @@ class _DesktopTransactionCardRowState
|
|||
return Text(
|
||||
"$prefix${(amount.decimal * price).toAmount(
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: locale,
|
||||
)} $baseCurrency",
|
||||
style: STextStyles.desktopTextExtraExtraSmall(context),
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/receive_view/addresses/address_details_view.dart';
|
||||
import 'package:stackwallet/pages/wallet_view/sub_widgets/tx_icon.dart';
|
||||
|
@ -19,6 +20,7 @@ import 'package:stackwallet/services/coins/epiccash/epiccash_wallet.dart';
|
|||
import 'package:stackwallet/services/coins/manager.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/block_explorers.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
|
@ -73,6 +75,7 @@ class _TransactionDetailsViewState
|
|||
late final String amountPrefix;
|
||||
late final String unit;
|
||||
late final bool isTokenTx;
|
||||
late final EthContract? ethContract;
|
||||
|
||||
bool showFeePending = false;
|
||||
|
||||
|
@ -94,12 +97,11 @@ class _TransactionDetailsViewState
|
|||
amountPrefix = _transaction.type == TransactionType.outgoing ? "-" : "+";
|
||||
}
|
||||
|
||||
unit = isTokenTx
|
||||
? ref
|
||||
.read(mainDBProvider)
|
||||
.getEthContractSync(_transaction.otherData!)!
|
||||
.symbol
|
||||
: coin.ticker;
|
||||
ethContract = isTokenTx
|
||||
? ref.read(mainDBProvider).getEthContractSync(_transaction.otherData!)
|
||||
: null;
|
||||
|
||||
unit = isTokenTx ? ethContract!.symbol : coin.ticker;
|
||||
|
||||
// if (coin == Coin.firo || coin == Coin.firoTestNet) {
|
||||
// showFeePending = true;
|
||||
|
@ -446,13 +448,7 @@ class _TransactionDetailsViewState
|
|||
: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SelectableText(
|
||||
"$amountPrefix${amount.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) =>
|
||||
value.locale),
|
||||
),
|
||||
)} $unit",
|
||||
"$amountPrefix${ref.watch(pAmountFormatter(coin)).format(amount, ethContract: ethContract)}",
|
||||
style: isDesktop
|
||||
? STextStyles
|
||||
.desktopTextExtraExtraSmall(
|
||||
|
@ -486,7 +482,7 @@ class _TransactionDetailsViewState
|
|||
.getPrice(
|
||||
coin)
|
||||
.item1),
|
||||
)).toAmount(fractionDigits: 2).localizedStringAsFixed(
|
||||
)).toAmount(fractionDigits: 2).fiatString(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
|
@ -941,23 +937,17 @@ class _TransactionDetailsViewState
|
|||
currentHeight,
|
||||
coin.requiredConfirmations,
|
||||
)
|
||||
? fee.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select(
|
||||
(value) => value.locale),
|
||||
),
|
||||
)
|
||||
? ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(
|
||||
fee,
|
||||
withUnitName: isTokenTx,
|
||||
)
|
||||
: "Pending"
|
||||
: fee.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale),
|
||||
),
|
||||
);
|
||||
if (isTokenTx) {
|
||||
feeString += " ${coin.ticker}";
|
||||
}
|
||||
: ref.watch(pAmountFormatter(coin)).format(
|
||||
fee,
|
||||
withUnitName: isTokenTx,
|
||||
);
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment:
|
||||
|
|
|
@ -5,11 +5,11 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||
import 'package:flutter_rounded_date_picker/flutter_rounded_date_picker.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:stackwallet/models/transaction_filter.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/providers/ui/transaction_filter_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/themes/theme_providers.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -76,11 +76,12 @@ class _TransactionSearchViewState
|
|||
_toDateString =
|
||||
_selectedToDate == null ? "" : Format.formatDate(_selectedToDate!);
|
||||
|
||||
final String amount = filterState.amount?.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
decimalPlaces: widget.coin.decimals,
|
||||
) ??
|
||||
"";
|
||||
final String amount = filterState.amount == null
|
||||
? ""
|
||||
: ref.read(pAmountFormatter(widget.coin)).format(
|
||||
filterState.amount!,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
_amountTextEditingController.text = amount;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
|||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -272,14 +273,7 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
|||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
"${total.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
decimalPlaces: coin.decimals,
|
||||
)} ${coin.ticker}",
|
||||
ref.watch(pAmountFormatter(coin)).format(total),
|
||||
style: STextStyles.titleBold12(context).copyWith(
|
||||
fontSize: 16,
|
||||
color: Theme.of(context)
|
||||
|
@ -294,13 +288,12 @@ class _FavoriteCardState extends ConsumerState<FavoriteCard> {
|
|||
),
|
||||
if (externalCalls)
|
||||
Text(
|
||||
"${fiatTotal.localizedStringAsFixed(
|
||||
"${fiatTotal.fiatString(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
decimalPlaces: 2,
|
||||
)} ${ref.watch(
|
||||
prefsChangeNotifierProvider.select(
|
||||
(value) => value.currency,
|
||||
|
|
|
@ -98,12 +98,12 @@ class WalletListItem extends ConsumerWidget {
|
|||
final calls =
|
||||
ref.watch(prefsChangeNotifierProvider).externalCalls;
|
||||
|
||||
final priceString = tuple.item1
|
||||
.toAmount(fractionDigits: 2)
|
||||
.localizedStringAsFixed(
|
||||
locale: ref.watch(localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale)),
|
||||
);
|
||||
final priceString =
|
||||
tuple.item1.toAmount(fractionDigits: 2).fiatString(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider
|
||||
.select((value) => value.locale)),
|
||||
);
|
||||
|
||||
final double percentChange = tuple.item2;
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ import 'package:isar/isar.dart';
|
|||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/pages/coin_control/utxo_details_view.dart';
|
||||
import 'package:stackwallet/providers/global/locale_provider.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
|
@ -144,16 +144,12 @@ class _UtxoRowState extends ConsumerState<UtxoRow> {
|
|||
),
|
||||
if (!widget.compact)
|
||||
Text(
|
||||
"${Amount(
|
||||
rawValue: BigInt.from(utxo.value),
|
||||
fractionDigits: coin.decimals,
|
||||
).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
Amount(
|
||||
rawValue: BigInt.from(utxo.value),
|
||||
fractionDigits: coin.decimals,
|
||||
),
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
textAlign: TextAlign.right,
|
||||
style: STextStyles.w600_14(context),
|
||||
),
|
||||
|
@ -170,16 +166,12 @@ class _UtxoRowState extends ConsumerState<UtxoRow> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
"${Amount(
|
||||
rawValue: BigInt.from(utxo.value),
|
||||
fractionDigits: coin.decimals,
|
||||
).localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
ref.watch(pAmountFormatter(coin)).format(
|
||||
Amount(
|
||||
rawValue: BigInt.from(utxo.value),
|
||||
fractionDigits: coin.decimals,
|
||||
),
|
||||
),
|
||||
),
|
||||
)} ${coin.ticker}",
|
||||
textAlign: TextAlign.right,
|
||||
style: STextStyles.w600_14(context),
|
||||
),
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:stackwallet/providers/providers.dart';
|
|||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -279,8 +280,6 @@ class _BalanceDisplay extends ConsumerWidget {
|
|||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final manager = ref.watch(walletsChangeNotifierProvider
|
||||
.select((value) => value.getManager(walletId)));
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider.select((value) => value.locale));
|
||||
|
||||
Amount total = manager.balance.total;
|
||||
if (manager.coin == Coin.firo || manager.coin == Coin.firoTestNet) {
|
||||
|
@ -289,8 +288,7 @@ class _BalanceDisplay extends ConsumerWidget {
|
|||
}
|
||||
|
||||
return Text(
|
||||
"${total.localizedStringAsFixed(locale: locale)} "
|
||||
"${manager.coin.ticker}",
|
||||
ref.watch(pAmountFormatter(manager.coin)).format(total),
|
||||
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textSubtitle1,
|
||||
),
|
||||
|
|
|
@ -15,6 +15,7 @@ import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
|||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
@ -124,15 +125,24 @@ class _DesktopPaynymSendDialogState
|
|||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
"${!isFiro ? manager.balance.spendable.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
) : ref.watch(
|
||||
publicPrivateBalanceStateProvider.state,
|
||||
).state == "Private" ? (manager.wallet as FiroWallet).availablePrivateBalance().localizedStringAsFixed(
|
||||
locale: locale,
|
||||
) : (manager.wallet as FiroWallet).availablePublicBalance().localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} ${coin.ticker}",
|
||||
!isFiro
|
||||
? ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(manager.balance.spendable)
|
||||
: ref
|
||||
.watch(
|
||||
publicPrivateBalanceStateProvider
|
||||
.state,
|
||||
)
|
||||
.state ==
|
||||
"Private"
|
||||
? ref.watch(pAmountFormatter(coin)).format(
|
||||
(manager.wallet as FiroWallet)
|
||||
.availablePrivateBalance())
|
||||
: ref.watch(pAmountFormatter(coin)).format(
|
||||
(manager.wallet as FiroWallet)
|
||||
.availablePublicBalance(),
|
||||
),
|
||||
style: STextStyles.titleBold12(context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
|
@ -140,7 +150,15 @@ class _DesktopPaynymSendDialogState
|
|||
height: 2,
|
||||
),
|
||||
Text(
|
||||
"${((!isFiro ? manager.balance.spendable.decimal : ref.watch(publicPrivateBalanceStateProvider.state).state == "Private" ? (manager.wallet as FiroWallet).availablePrivateBalance().decimal : (manager.wallet as FiroWallet).availablePublicBalance().decimal) * ref.watch(priceAnd24hChangeNotifierProvider.select((value) => value.getPrice(coin).item1))).toAmount(fractionDigits: 2).localizedStringAsFixed(locale: locale)} ${ref.watch(prefsChangeNotifierProvider.select((value) => value.currency))}",
|
||||
"${((!isFiro ? manager.balance.spendable.decimal : ref.watch(publicPrivateBalanceStateProvider.state).state == "Private" ? (manager.wallet as FiroWallet).availablePrivateBalance().decimal : (manager.wallet as FiroWallet).availablePublicBalance().decimal) * ref.watch(
|
||||
priceAnd24hChangeNotifierProvider.select(
|
||||
(value) => value.getPrice(coin).item1,
|
||||
),
|
||||
)).toAmount(fractionDigits: 2).fiatString(
|
||||
locale: locale,
|
||||
)} ${ref.watch(prefsChangeNotifierProvider.select(
|
||||
(value) => value.currency,
|
||||
))}",
|
||||
style: STextStyles.baseXS(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
|
|
|
@ -214,13 +214,12 @@ class TablePriceInfo extends ConsumerWidget {
|
|||
final priceString = Amount.fromDecimal(
|
||||
tuple.item1,
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: ref
|
||||
.watch(
|
||||
localeServiceChangeNotifierProvider.notifier,
|
||||
)
|
||||
.locale,
|
||||
decimalPlaces: 2,
|
||||
);
|
||||
|
||||
final double percentChange = tuple.item2;
|
||||
|
|
|
@ -27,6 +27,7 @@ import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/address_utils.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
|
@ -452,7 +453,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
if (price > Decimal.zero) {
|
||||
final String fiatAmountString = (_amountToSend!.decimal * price)
|
||||
.toAmount(fractionDigits: 2)
|
||||
.localizedStringAsFixed(
|
||||
.fiatString(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
|
||||
|
@ -506,10 +507,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
} else {
|
||||
balance = wallet.availablePublicBalance();
|
||||
}
|
||||
return balance.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
decimalPlaces: coin.decimals,
|
||||
);
|
||||
return ref.read(pAmountFormatter(coin)).format(balance);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -583,11 +581,9 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
final amount = Decimal.parse(results["amount"]!).toAmount(
|
||||
fractionDigits: coin.decimals,
|
||||
);
|
||||
cryptoAmountController.text = amount.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
decimalPlaces: Constants.decimalPlacesForCoin(coin),
|
||||
);
|
||||
amount.toString();
|
||||
cryptoAmountController.text = ref
|
||||
.read(pAmountFormatter(coin))
|
||||
.format(amount, withUnitName: false);
|
||||
_amountToSend = amount;
|
||||
}
|
||||
|
||||
|
@ -669,10 +665,10 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
|
|||
Logging.instance.log("it changed $_amountToSend $_cachedAmountToSend",
|
||||
level: LogLevel.Info);
|
||||
|
||||
final amountString = _amountToSend!.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
decimalPlaces: coin.decimals,
|
||||
);
|
||||
final amountString = ref.read(pAmountFormatter(coin)).format(
|
||||
_amountToSend!,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
_cryptoAmountChangeLock = true;
|
||||
cryptoAmountController.text = amountString;
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:stackwallet/services/coins/manager.dart';
|
|||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/address_utils.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/barcode_scanner_interface.dart';
|
||||
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
|
@ -383,9 +384,8 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
|
|||
final String fiatAmountString = Amount.fromDecimal(
|
||||
_amountToSend!.decimal * price,
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
decimalPlaces: 2,
|
||||
);
|
||||
|
||||
baseAmountController.text = fiatAmountString;
|
||||
|
@ -453,11 +453,11 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
|
|||
fractionDigits:
|
||||
ref.read(tokenServiceProvider)!.tokenContract.decimals,
|
||||
);
|
||||
cryptoAmountController.text = amount.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
);
|
||||
cryptoAmountController.text = ref.read(pAmountFormatter(coin)).format(
|
||||
amount,
|
||||
withUnitName: false,
|
||||
);
|
||||
|
||||
amount.toString();
|
||||
_amountToSend = amount;
|
||||
}
|
||||
|
||||
|
@ -541,10 +541,11 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
|
|||
Logging.instance.log("it changed $_amountToSend $_cachedAmountToSend",
|
||||
level: LogLevel.Info);
|
||||
|
||||
final amountString = _amountToSend!.localizedStringAsFixed(
|
||||
locale: ref.read(localeServiceChangeNotifierProvider).locale,
|
||||
decimalPlaces: tokenDecimals,
|
||||
);
|
||||
final amountString = ref.read(pAmountFormatter(coin)).format(
|
||||
_amountToSend!,
|
||||
withUnitName: false,
|
||||
ethContract: ref.read(tokenServiceProvider)!.tokenContract,
|
||||
);
|
||||
|
||||
_cryptoAmountChangeLock = true;
|
||||
cryptoAmountController.text = amountString;
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
|||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -60,10 +61,14 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
|
|||
final baseCurrency = ref
|
||||
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
|
||||
|
||||
final tokenContract = widget.isToken
|
||||
? ref
|
||||
.watch(tokenServiceProvider.select((value) => value!.tokenContract))
|
||||
: null;
|
||||
|
||||
final priceTuple = widget.isToken
|
||||
? ref.watch(priceAnd24hChangeNotifierProvider.select((value) =>
|
||||
value.getTokenPrice(ref.watch(tokenServiceProvider
|
||||
.select((value) => value!.tokenContract.address)))))
|
||||
? ref.watch(priceAnd24hChangeNotifierProvider
|
||||
.select((value) => value.getTokenPrice(tokenContract!.address)))
|
||||
: ref.watch(priceAnd24hChangeNotifierProvider
|
||||
.select((value) => value.getPrice(coin)));
|
||||
|
||||
|
@ -71,15 +76,6 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
|
|||
ref.watch(walletBalanceToggleStateProvider.state).state ==
|
||||
WalletBalanceToggleState.available;
|
||||
|
||||
final unit = widget.isToken
|
||||
? ref.watch(
|
||||
tokenServiceProvider.select((value) => value!.tokenContract.symbol))
|
||||
: coin.ticker;
|
||||
final decimalPlaces = widget.isToken
|
||||
? ref.watch(tokenServiceProvider
|
||||
.select((value) => value!.tokenContract.decimals))
|
||||
: coin.decimals;
|
||||
|
||||
Balance balance = widget.isToken
|
||||
? ref.watch(tokenServiceProvider.select((value) => value!.balance))
|
||||
: ref.watch(walletsChangeNotifierProvider
|
||||
|
@ -124,10 +120,9 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
|
|||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
"${balanceToShow.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
decimalPlaces: decimalPlaces,
|
||||
)} $unit",
|
||||
ref
|
||||
.watch(pAmountFormatter(coin))
|
||||
.format(balanceToShow, ethContract: tokenContract),
|
||||
style: STextStyles.desktopH3(context),
|
||||
),
|
||||
),
|
||||
|
@ -136,9 +131,8 @@ class _WDesktopWalletSummaryState extends ConsumerState<DesktopWalletSummary> {
|
|||
"${Amount.fromDecimal(
|
||||
priceTuple.item1 * balanceToShow.decimal,
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: locale,
|
||||
decimalPlaces: 2,
|
||||
)} $baseCurrency",
|
||||
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||
color: Theme.of(context)
|
||||
|
|
|
@ -52,19 +52,11 @@ class Amount {
|
|||
return jsonEncode(toMap());
|
||||
}
|
||||
|
||||
String localizedStringAsFixed({
|
||||
String fiatString({
|
||||
required String locale,
|
||||
int? decimalPlaces,
|
||||
}) {
|
||||
decimalPlaces ??= fractionDigits;
|
||||
assert(decimalPlaces >= 0);
|
||||
|
||||
final wholeNumber = decimal.truncate();
|
||||
|
||||
if (decimalPlaces == 0) {
|
||||
return wholeNumber.toStringAsFixed(0);
|
||||
}
|
||||
|
||||
final String separator =
|
||||
(numberFormatSymbols[locale] as NumberSymbols?)?.DECIMAL_SEP ??
|
||||
(numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?)
|
||||
|
@ -73,8 +65,31 @@ class Amount {
|
|||
|
||||
final fraction = decimal - wholeNumber;
|
||||
|
||||
return "${wholeNumber.toStringAsFixed(0)}$separator${fraction.toStringAsFixed(decimalPlaces).substring(2)}";
|
||||
return "${wholeNumber.toStringAsFixed(0)}$separator${fraction.toStringAsFixed(2).substring(2)}";
|
||||
}
|
||||
// String localizedStringAsFixed({
|
||||
// required String locale,
|
||||
// int? decimalPlaces,
|
||||
// }) {
|
||||
// decimalPlaces ??= fractionDigits;
|
||||
// assert(decimalPlaces >= 0);
|
||||
//
|
||||
// final wholeNumber = decimal.truncate();
|
||||
//
|
||||
// if (decimalPlaces == 0) {
|
||||
// return wholeNumber.toStringAsFixed(0);
|
||||
// }
|
||||
//
|
||||
// final String separator =
|
||||
// (numberFormatSymbols[locale] as NumberSymbols?)?.DECIMAL_SEP ??
|
||||
// (numberFormatSymbols[locale.substring(0, 2)] as NumberSymbols?)
|
||||
// ?.DECIMAL_SEP ??
|
||||
// ".";
|
||||
//
|
||||
// final fraction = decimal - wholeNumber;
|
||||
//
|
||||
// return "${wholeNumber.toStringAsFixed(0)}$separator${fraction.toStringAsFixed(decimalPlaces).substring(2)}";
|
||||
// }
|
||||
|
||||
// ===========================================================================
|
||||
// ======= Deserialization ===================================================
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/providers/global/locale_provider.dart';
|
||||
import 'package:stackwallet/providers/global/prefs_provider.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
|
@ -44,12 +45,20 @@ class AmountFormatter {
|
|||
required this.maxDecimals,
|
||||
});
|
||||
|
||||
String format(Amount amount) {
|
||||
String format(
|
||||
Amount amount, {
|
||||
String? overrideUnit,
|
||||
EthContract? ethContract,
|
||||
bool withUnitName = true,
|
||||
}) {
|
||||
return unit.displayAmount(
|
||||
amount: amount,
|
||||
locale: locale,
|
||||
coin: coin,
|
||||
maxDecimalPlaces: maxDecimals,
|
||||
withUnitName: withUnitName,
|
||||
overrideUnit: overrideUnit,
|
||||
tokenContract: ethContract,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:math' as math;
|
|||
import 'package:decimal/decimal.dart';
|
||||
import 'package:intl/number_symbols.dart';
|
||||
import 'package:intl/number_symbols_data.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
|
||||
|
@ -61,13 +62,36 @@ extension AmountUnitExt on AmountUnit {
|
|||
}
|
||||
}
|
||||
|
||||
String unitForContract(EthContract contract) {
|
||||
switch (this) {
|
||||
case AmountUnit.normal:
|
||||
return contract.symbol;
|
||||
case AmountUnit.milli:
|
||||
return "m${contract.symbol}";
|
||||
case AmountUnit.micro:
|
||||
return "µ${contract.symbol}";
|
||||
case AmountUnit.nano:
|
||||
return "gwei";
|
||||
case AmountUnit.pico:
|
||||
return "mwei";
|
||||
case AmountUnit.femto:
|
||||
return "kwei";
|
||||
case AmountUnit.atto:
|
||||
return "wei";
|
||||
}
|
||||
}
|
||||
|
||||
String displayAmount({
|
||||
required Amount amount,
|
||||
required String locale,
|
||||
required Coin coin,
|
||||
required int maxDecimalPlaces,
|
||||
bool withUnitName = true,
|
||||
String? overrideUnit,
|
||||
EthContract? tokenContract,
|
||||
}) {
|
||||
assert(maxDecimalPlaces >= 0);
|
||||
|
||||
// ensure we don't shift past minimum atomic value
|
||||
final realShift = math.min(shift, amount.fractionDigits);
|
||||
|
||||
|
@ -88,11 +112,27 @@ extension AmountUnitExt on AmountUnit {
|
|||
// get the fractional value
|
||||
final Decimal fraction = shifted - shifted.truncate();
|
||||
|
||||
// get final decimal based on max precision wanted
|
||||
final int actualDecimalPlaces = math.min(places, maxDecimalPlaces);
|
||||
// get final decimal based on max precision wanted while ensuring that
|
||||
// maxDecimalPlaces doesn't exceed the max per coin
|
||||
final int updatedMax;
|
||||
if (tokenContract != null) {
|
||||
updatedMax = maxDecimalPlaces > tokenContract.decimals
|
||||
? tokenContract.decimals
|
||||
: maxDecimalPlaces;
|
||||
} else {
|
||||
updatedMax =
|
||||
maxDecimalPlaces > coin.decimals ? coin.decimals : maxDecimalPlaces;
|
||||
}
|
||||
final int actualDecimalPlaces = math.min(places, updatedMax);
|
||||
|
||||
// get remainder string without the prepending "0."
|
||||
String remainder = fraction.toString().substring(2);
|
||||
final fractionString = fraction.toString();
|
||||
String remainder;
|
||||
if (fractionString.length > 2) {
|
||||
remainder = fraction.toString().substring(2);
|
||||
} else {
|
||||
remainder = "0";
|
||||
}
|
||||
|
||||
if (remainder.length > actualDecimalPlaces) {
|
||||
// trim unwanted trailing digits
|
||||
|
@ -115,7 +155,14 @@ extension AmountUnitExt on AmountUnit {
|
|||
returnValue += "$separator$remainder";
|
||||
}
|
||||
|
||||
if (!withUnitName) {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
// return the value with the proper unit symbol
|
||||
return "$returnValue ${unitForCoin(coin)}";
|
||||
if (tokenContract != null) {
|
||||
overrideUnit = unitForContract(tokenContract);
|
||||
}
|
||||
return "$returnValue ${overrideUnit ?? unitForCoin(coin)}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
|||
import 'package:stackwallet/themes/coin_icon_provider.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -131,14 +132,11 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
|
|||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
"${total.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
decimalPlaces: manager.coin.decimals,
|
||||
)} ${manager.coin.ticker}",
|
||||
ref
|
||||
.watch(
|
||||
pAmountFormatter(manager.coin),
|
||||
)
|
||||
.format(total),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
),
|
||||
|
@ -174,14 +172,11 @@ class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
|
|||
height: 2,
|
||||
),
|
||||
Text(
|
||||
"${total.localizedStringAsFixed(
|
||||
locale: ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
),
|
||||
decimalPlaces: manager.coin.decimals,
|
||||
)} ${manager.coin.ticker}",
|
||||
ref
|
||||
.watch(
|
||||
pAmountFormatter(manager.coin),
|
||||
)
|
||||
.format(total),
|
||||
style: STextStyles.itemSubtitle(context),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:stackwallet/providers/db/main_db_provider.dart';
|
|||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/format.dart';
|
||||
|
@ -39,6 +40,7 @@ class _TransactionCardState extends ConsumerState<TransactionCard> {
|
|||
late final String prefix;
|
||||
late final String unit;
|
||||
late final Coin coin;
|
||||
late final EthContract? tokenContract;
|
||||
|
||||
String whatIsIt(
|
||||
TransactionType type,
|
||||
|
@ -116,12 +118,11 @@ class _TransactionCardState extends ConsumerState<TransactionCard> {
|
|||
.getManager(widget.walletId)
|
||||
.coin;
|
||||
|
||||
unit = isTokenTx
|
||||
? ref
|
||||
.read(mainDBProvider)
|
||||
.getEthContractSync(_transaction.otherData!)!
|
||||
.symbol
|
||||
: coin.ticker;
|
||||
tokenContract = ref
|
||||
.read(mainDBProvider)
|
||||
.getEthContractSync(_transaction.otherData ?? "");
|
||||
|
||||
unit = isTokenTx ? tokenContract!.symbol : coin.ticker;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -240,9 +241,7 @@ class _TransactionCardState extends ConsumerState<TransactionCard> {
|
|||
final amount = _transaction.realAmount;
|
||||
|
||||
return Text(
|
||||
"$prefix${amount.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
)} $unit",
|
||||
"$prefix${ref.watch(pAmountFormatter(coin)).format(amount, ethContract: tokenContract)}",
|
||||
style: STextStyles.itemSubtitle12(context),
|
||||
);
|
||||
},
|
||||
|
@ -285,9 +284,8 @@ class _TransactionCardState extends ConsumerState<TransactionCard> {
|
|||
"$prefix${Amount.fromDecimal(
|
||||
amount.decimal * price,
|
||||
fractionDigits: 2,
|
||||
).localizedStringAsFixed(
|
||||
).fiatString(
|
||||
locale: locale,
|
||||
decimalPlaces: 2,
|
||||
)} $baseCurrency",
|
||||
style: STextStyles.label(context),
|
||||
);
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/ethereum/eth_contract.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/services/coins/ethereum/ethereum_wallet.dart';
|
||||
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
|
@ -26,36 +28,25 @@ class WalletInfoRowBalance extends ConsumerWidget {
|
|||
.watch(walletsChangeNotifierProvider.notifier)
|
||||
.getManagerProvider(walletId));
|
||||
|
||||
final locale = ref.watch(
|
||||
localeServiceChangeNotifierProvider.select(
|
||||
(value) => value.locale,
|
||||
),
|
||||
);
|
||||
|
||||
Amount totalBalance;
|
||||
int decimals;
|
||||
String unit;
|
||||
EthContract? contract;
|
||||
if (contractAddress == null) {
|
||||
totalBalance = manager.balance.total;
|
||||
if (manager.coin == Coin.firo || manager.coin == Coin.firoTestNet) {
|
||||
totalBalance =
|
||||
totalBalance + (manager.wallet as FiroWallet).balancePrivate.total;
|
||||
}
|
||||
unit = manager.coin.ticker;
|
||||
decimals = manager.coin.decimals;
|
||||
contract = null;
|
||||
} else {
|
||||
final ethWallet = manager.wallet as EthereumWallet;
|
||||
final contract = MainDB.instance.getEthContractSync(contractAddress!)!;
|
||||
contract = MainDB.instance.getEthContractSync(contractAddress!)!;
|
||||
totalBalance = ethWallet.getCachedTokenBalance(contract).total;
|
||||
unit = contract.symbol;
|
||||
decimals = contract.decimals;
|
||||
}
|
||||
|
||||
return Text(
|
||||
"${totalBalance.localizedStringAsFixed(
|
||||
locale: locale,
|
||||
decimalPlaces: decimals,
|
||||
)} $unit",
|
||||
ref
|
||||
.watch(pAmountFormatter(manager.coin))
|
||||
.format(totalBalance, ethContract: contract),
|
||||
style: Util.isDesktop
|
||||
? STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textSubtitle1,
|
||||
|
|
|
@ -78,33 +78,33 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test("localizedStringAsFixed", () {
|
||||
expect(
|
||||
Amount(rawValue: BigInt.two, fractionDigits: 8)
|
||||
.localizedStringAsFixed(locale: "en_US"),
|
||||
"0.00000002",
|
||||
);
|
||||
expect(
|
||||
Amount(rawValue: BigInt.two, fractionDigits: 8)
|
||||
.localizedStringAsFixed(locale: "en_US", decimalPlaces: 2),
|
||||
"0.00",
|
||||
);
|
||||
expect(
|
||||
Amount.fromDecimal(Decimal.fromInt(2), fractionDigits: 8)
|
||||
.localizedStringAsFixed(locale: "en_US"),
|
||||
"2.00000000",
|
||||
);
|
||||
expect(
|
||||
Amount.fromDecimal(Decimal.fromInt(2), fractionDigits: 8)
|
||||
.localizedStringAsFixed(locale: "en_US", decimalPlaces: 4),
|
||||
"2.0000",
|
||||
);
|
||||
expect(
|
||||
Amount.fromDecimal(Decimal.fromInt(2), fractionDigits: 8)
|
||||
.localizedStringAsFixed(locale: "en_US", decimalPlaces: 0),
|
||||
"2",
|
||||
);
|
||||
});
|
||||
// test("localizedStringAsFixed", () {
|
||||
// expect(
|
||||
// Amount(rawValue: BigInt.two, fractionDigits: 8)
|
||||
// .localizedStringAsFixed(locale: "en_US"),
|
||||
// "0.00000002",
|
||||
// );
|
||||
// expect(
|
||||
// Amount(rawValue: BigInt.two, fractionDigits: 8)
|
||||
// .localizedStringAsFixed(locale: "en_US", decimalPlaces: 2),
|
||||
// "0.00",
|
||||
// );
|
||||
// expect(
|
||||
// Amount.fromDecimal(Decimal.fromInt(2), fractionDigits: 8)
|
||||
// .localizedStringAsFixed(locale: "en_US"),
|
||||
// "2.00000000",
|
||||
// );
|
||||
// expect(
|
||||
// Amount.fromDecimal(Decimal.fromInt(2), fractionDigits: 8)
|
||||
// .localizedStringAsFixed(locale: "en_US", decimalPlaces: 4),
|
||||
// "2.0000",
|
||||
// );
|
||||
// expect(
|
||||
// Amount.fromDecimal(Decimal.fromInt(2), fractionDigits: 8)
|
||||
// .localizedStringAsFixed(locale: "en_US", decimalPlaces: 0),
|
||||
// "2",
|
||||
// );
|
||||
// });
|
||||
});
|
||||
|
||||
group("deserialization", () {
|
||||
|
|
Loading…
Reference in a new issue