diff --git a/lib/pages/wallet_view/sub_widgets/wallet_balance_toggle_sheet.dart b/lib/pages/wallet_view/sub_widgets/wallet_balance_toggle_sheet.dart index afdac6d8e..c9ff64393 100644 --- a/lib/pages/wallet_view/sub_widgets/wallet_balance_toggle_sheet.dart +++ b/lib/pages/wallet_view/sub_widgets/wallet_balance_toggle_sheet.dart @@ -1,3 +1,4 @@ +import 'package:decimal/decimal.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/providers/providers.dart'; @@ -8,6 +9,8 @@ import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/services/coins/firo/firo_wallet.dart'; + class WalletBalanceToggleSheet extends ConsumerWidget { const WalletBalanceToggleSheet({ Key? key, @@ -23,6 +26,22 @@ class WalletBalanceToggleSheet extends ConsumerWidget { final coin = ref.watch(walletsChangeNotifierProvider .select((value) => value.getManager(walletId).coin)); + Future? totalBalanceFuture; + Future? availableBalanceFuture; + if (coin == Coin.firo || coin == Coin.firoTestNet) { + final firoWallet = ref + .watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId))) + .wallet as FiroWallet; + totalBalanceFuture = firoWallet.availablePublicBalance(); + availableBalanceFuture = firoWallet.availablePrivateBalance(); + } else { + final wallet = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId))); + totalBalanceFuture = wallet.totalBalance; + availableBalanceFuture = wallet.availableBalance; + } + return Container( decoration: BoxDecoration( color: Theme.of(context).extension()!.popupBG, @@ -125,15 +144,35 @@ class WalletBalanceToggleSheet extends ConsumerWidget { const SizedBox( height: 2, ), - Text( - "Current spendable (unlocked) balance", - style: - STextStyles.itemSubtitle12(context).copyWith( - color: Theme.of(context) - .extension()! - .textSubtitle1, - ), - ), + FutureBuilder( + future: availableBalanceFuture, + builder: (fbContext, + AsyncSnapshot snapshot) { + if (snapshot.connectionState == + ConnectionState.done && + snapshot.hasData && + snapshot.data != null) { + return Text( + "${snapshot.data!}", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } else { + return Text( + "", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } + }), ], ), if (coin == Coin.firo || coin == Coin.firoTestNet) @@ -147,15 +186,35 @@ class WalletBalanceToggleSheet extends ConsumerWidget { const SizedBox( height: 2, ), - Text( - "Current private spendable (unlocked) balance", - style: - STextStyles.itemSubtitle12(context).copyWith( - color: Theme.of(context) - .extension()! - .textSubtitle1, - ), - ), + FutureBuilder( + future: availableBalanceFuture, + builder: (fbContext, + AsyncSnapshot snapshot) { + if (snapshot.connectionState == + ConnectionState.done && + snapshot.hasData && + snapshot.data != null) { + return Text( + "${snapshot.data!}", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } else { + return Text( + "", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } + }), ], ), ], @@ -219,15 +278,35 @@ class WalletBalanceToggleSheet extends ConsumerWidget { const SizedBox( height: 2, ), - Text( - "Total wallet balance", - style: - STextStyles.itemSubtitle12(context).copyWith( - color: Theme.of(context) - .extension()! - .textSubtitle1, - ), - ), + FutureBuilder( + future: totalBalanceFuture, + builder: (fbContext, + AsyncSnapshot snapshot) { + if (snapshot.connectionState == + ConnectionState.done && + snapshot.hasData && + snapshot.data != null) { + return Text( + "${snapshot.data!}", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } else { + return Text( + "", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } + }), ], ), if (coin == Coin.firo || coin == Coin.firoTestNet) @@ -241,15 +320,35 @@ class WalletBalanceToggleSheet extends ConsumerWidget { const SizedBox( height: 2, ), - Text( - "Current public spendable (unlocked) balance", - style: - STextStyles.itemSubtitle12(context).copyWith( - color: Theme.of(context) - .extension()! - .textSubtitle1, - ), - ), + FutureBuilder( + future: totalBalanceFuture, + builder: (fbContext, + AsyncSnapshot snapshot) { + if (snapshot.connectionState == + ConnectionState.done && + snapshot.hasData && + snapshot.data != null) { + return Text( + "${snapshot.data!}", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } else { + return Text( + "", + style: STextStyles.itemSubtitle12(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textSubtitle1, + ), + ); + } + }), ], ), ],