update balance toggle logic

see https://github.com/cypherstack/stack_wallet/pull/904
This commit is contained in:
sneurlax 2024-08-26 17:51:20 -05:00
parent 2145334152
commit 90aaf5d523

View file

@ -87,10 +87,12 @@ class WalletSummaryInfo extends ConsumerWidget {
final Amount balanceToShow; final Amount balanceToShow;
final String title; final String title;
final bool toggleBalance; final bool useSimpleToggle;
final bool hasMultipleBalances;
if (coin is Firo) { if (coin is Firo) {
toggleBalance = false; useSimpleToggle = false;
hasMultipleBalances = true; // Firo always has multiple balance types.
final type = ref.watch(publicPrivateBalanceStateProvider.state).state; final type = ref.watch(publicPrivateBalanceStateProvider.state).state;
title = title =
"${_showAvailable ? "Available" : "Full"} ${type.name.capitalize()} balance"; "${_showAvailable ? "Available" : "Full"} ${type.name.capitalize()} balance";
@ -111,7 +113,9 @@ class WalletSummaryInfo extends ConsumerWidget {
break; break;
} }
} else { } else {
toggleBalance = true; useSimpleToggle = true;
// Update hasMultipleBalances based on if all of the balances are equal.
hasMultipleBalances = balance.spendable != balance.total;
balanceToShow = _showAvailable ? balance.spendable : balance.total; balanceToShow = _showAvailable ? balance.spendable : balance.total;
title = _showAvailable ? "Available balance" : "Full balance"; title = _showAvailable ? "Available balance" : "Full balance";
} }
@ -144,7 +148,7 @@ class WalletSummaryInfo extends ConsumerWidget {
children: [ children: [
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (toggleBalance) { if (useSimpleToggle) {
if (ref.read(walletBalanceToggleStateProvider) == if (ref.read(walletBalanceToggleStateProvider) ==
WalletBalanceToggleState.available) { WalletBalanceToggleState.available) {
ref ref
@ -169,7 +173,7 @@ class WalletSummaryInfo extends ConsumerWidget {
.textFavoriteCard, .textFavoriteCard,
), ),
), ),
if (!toggleBalance) ...[ if (hasMultipleBalances) ...[
const SizedBox( const SizedBox(
width: 4, width: 4,
), ),