mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-05-03 11:22:20 +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/extensions/extensions.dart';
|
||||||
import '../../../utilities/text_styles.dart';
|
import '../../../utilities/text_styles.dart';
|
||||||
import '../../../wallets/crypto_currency/coins/banano.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/isar/providers/wallet_info_provider.dart';
|
||||||
import '../../../wallets/wallet/impl/banano_wallet.dart';
|
import '../../../wallets/wallet/impl/banano_wallet.dart';
|
||||||
|
import '../../../wallets/wallet/impl/firo_wallet.dart';
|
||||||
import '../../../widgets/conditional_parent.dart';
|
import '../../../widgets/conditional_parent.dart';
|
||||||
import 'wallet_balance_toggle_sheet.dart';
|
import 'wallet_balance_toggle_sheet.dart';
|
||||||
import 'wallet_refresh_button.dart';
|
import 'wallet_refresh_button.dart';
|
||||||
|
@ -45,7 +45,35 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
final String walletId;
|
final String walletId;
|
||||||
final WalletSyncStatus initialSyncStatus;
|
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>(
|
showModalBottomSheet<dynamic>(
|
||||||
backgroundColor: Colors.transparent,
|
backgroundColor: Colors.transparent,
|
||||||
context: context,
|
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
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
debugPrint("BUILD: $runtimeType");
|
debugPrint("BUILD: $runtimeType");
|
||||||
|
@ -87,8 +129,13 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
|
|
||||||
final Amount balanceToShow;
|
final Amount balanceToShow;
|
||||||
final String title;
|
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;
|
final type = ref.watch(publicPrivateBalanceStateProvider.state).state;
|
||||||
title =
|
title =
|
||||||
"${_showAvailable ? "Available" : "Full"} ${type.name.capitalize()} balance";
|
"${_showAvailable ? "Available" : "Full"} ${type.name.capitalize()} balance";
|
||||||
|
@ -140,9 +187,9 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: availableBalances.length > 1
|
||||||
showSheet(context);
|
? () => showSheet(context, ref)
|
||||||
},
|
: null,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
|
|
Loading…
Reference in a new issue