mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-31 06:35:53 +00:00
quick toggle balances as appropriate
if only 2 balances exist, toggle them instead of showing the dialog.
This commit is contained in:
parent
b98cd05e83
commit
a2308d3e78
1 changed files with 53 additions and 6 deletions
|
@ -28,9 +28,9 @@ import '../../../utilities/enums/wallet_balance_toggle_state.dart';
|
|||
import '../../../utilities/extensions/extensions.dart';
|
||||
import '../../../utilities/text_styles.dart';
|
||||
import '../../../wallets/crypto_currency/coins/banano.dart';
|
||||
import '../../../wallets/crypto_currency/coins/firo.dart';
|
||||
import '../../../wallets/isar/providers/wallet_info_provider.dart';
|
||||
import '../../../wallets/wallet/impl/banano_wallet.dart';
|
||||
import '../../../wallets/wallet/impl/firo_wallet.dart';
|
||||
import '../../../widgets/conditional_parent.dart';
|
||||
import 'wallet_balance_toggle_sheet.dart';
|
||||
import 'wallet_refresh_button.dart';
|
||||
|
@ -45,7 +45,35 @@ class WalletSummaryInfo extends ConsumerWidget {
|
|||
final String walletId;
|
||||
final WalletSyncStatus initialSyncStatus;
|
||||
|
||||
void showSheet(BuildContext context) {
|
||||
void showSheet(BuildContext context, WidgetRef ref) {
|
||||
final wallet =
|
||||
ref.watch(pWallets.select((value) => value.getWallet(walletId)));
|
||||
final firoWallet = wallet as FiroWallet;
|
||||
final availableBalances = getAvailableBalances(firoWallet);
|
||||
|
||||
// Remove any elements whose balance is zero.
|
||||
availableBalances.removeWhere((element) {
|
||||
switch (element) {
|
||||
case FiroType.spark:
|
||||
return firoWallet.info.cachedBalanceTertiary.spendable.raw ==
|
||||
BigInt.zero;
|
||||
case FiroType.lelantus:
|
||||
return firoWallet.info.cachedBalanceSecondary.spendable.raw ==
|
||||
BigInt.zero;
|
||||
case FiroType.public:
|
||||
return firoWallet.info.cachedBalance.spendable.raw == BigInt.zero;
|
||||
}
|
||||
});
|
||||
|
||||
if (availableBalances.length <= 2) {
|
||||
final state = ref.read(publicPrivateBalanceStateProvider.state).state;
|
||||
final newState = availableBalances.firstWhere(
|
||||
(balanceType) => balanceType != state,
|
||||
orElse: () => availableBalances.first);
|
||||
ref.read(publicPrivateBalanceStateProvider.state).state = newState;
|
||||
return;
|
||||
}
|
||||
|
||||
showModalBottomSheet<dynamic>(
|
||||
backgroundColor: Colors.transparent,
|
||||
context: context,
|
||||
|
@ -60,6 +88,20 @@ class WalletSummaryInfo extends ConsumerWidget {
|
|||
);
|
||||
}
|
||||
|
||||
List<FiroType> getAvailableBalances(FiroWallet firoWallet) {
|
||||
final List<FiroType> availableBalances = [];
|
||||
if (firoWallet.info.cachedBalanceTertiary.spendable.raw > BigInt.zero) {
|
||||
availableBalances.add(FiroType.spark);
|
||||
}
|
||||
if (firoWallet.info.cachedBalanceSecondary.spendable.raw > BigInt.zero) {
|
||||
availableBalances.add(FiroType.lelantus);
|
||||
}
|
||||
if (firoWallet.info.cachedBalance.spendable.raw > BigInt.zero) {
|
||||
availableBalances.add(FiroType.public);
|
||||
}
|
||||
return availableBalances;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
|
@ -87,8 +129,13 @@ class WalletSummaryInfo extends ConsumerWidget {
|
|||
|
||||
final Amount balanceToShow;
|
||||
final String title;
|
||||
final wallet =
|
||||
ref.watch(pWallets.select((value) => value.getWallet(walletId)));
|
||||
List<FiroType> availableBalances = [];
|
||||
|
||||
if (wallet is FiroWallet) {
|
||||
availableBalances = getAvailableBalances(wallet);
|
||||
|
||||
if (coin is Firo) {
|
||||
final type = ref.watch(publicPrivateBalanceStateProvider.state).state;
|
||||
title =
|
||||
"${_showAvailable ? "Available" : "Full"} ${type.name.capitalize()} balance";
|
||||
|
@ -140,9 +187,9 @@ class WalletSummaryInfo extends ConsumerWidget {
|
|||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
showSheet(context);
|
||||
},
|
||||
onTap: availableBalances.length > 1
|
||||
? () => showSheet(context, ref)
|
||||
: null,
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
|
|
Loading…
Reference in a new issue