mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-20 14:19:07 +00:00
mobile balance toggle update
This commit is contained in:
parent
e91daa943a
commit
90aae703aa
1 changed files with 22 additions and 43 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,17 +45,7 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
final String walletId;
|
final String walletId;
|
||||||
final WalletSyncStatus initialSyncStatus;
|
final WalletSyncStatus initialSyncStatus;
|
||||||
|
|
||||||
void showSheet(
|
void showSheet(BuildContext context) {
|
||||||
BuildContext context, WidgetRef ref, List<FiroType> availableBalances) {
|
|
||||||
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,
|
||||||
|
@ -70,25 +60,6 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FiroType> getAvailableBalances(FiroWallet firoWallet) {
|
|
||||||
final List<FiroType> availableBalances = [];
|
|
||||||
if (firoWallet.info.cachedBalanceTertiary.spendable.raw > BigInt.zero ||
|
|
||||||
firoWallet.info.cachedBalanceTertiary.pendingSpendable.raw >
|
|
||||||
BigInt.zero) {
|
|
||||||
availableBalances.add(FiroType.spark);
|
|
||||||
}
|
|
||||||
if (firoWallet.info.cachedBalanceSecondary.spendable.raw > BigInt.zero ||
|
|
||||||
firoWallet.info.cachedBalanceSecondary.pendingSpendable.raw >
|
|
||||||
BigInt.zero) {
|
|
||||||
availableBalances.add(FiroType.lelantus);
|
|
||||||
}
|
|
||||||
if (firoWallet.info.cachedBalance.spendable.raw > BigInt.zero ||
|
|
||||||
firoWallet.info.cachedBalance.pendingSpendable.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");
|
||||||
|
@ -98,8 +69,6 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
);
|
);
|
||||||
final coin = ref.watch(pWalletCoin(walletId));
|
final coin = ref.watch(pWalletCoin(walletId));
|
||||||
final balance = ref.watch(pWalletBalance(walletId));
|
final balance = ref.watch(pWalletBalance(walletId));
|
||||||
final wallet =
|
|
||||||
ref.watch(pWallets.select((value) => value.getWallet(walletId)));
|
|
||||||
|
|
||||||
final locale = ref.watch(
|
final locale = ref.watch(
|
||||||
localeServiceChangeNotifierProvider.select((value) => value.locale),
|
localeServiceChangeNotifierProvider.select((value) => value.locale),
|
||||||
|
@ -112,17 +81,16 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
priceAnd24hChangeNotifierProvider.select((value) => value.getPrice(coin)),
|
priceAnd24hChangeNotifierProvider.select((value) => value.getPrice(coin)),
|
||||||
);
|
);
|
||||||
|
|
||||||
final _showAvailable =
|
final _showAvailable = ref.watch(walletBalanceToggleStateProvider) ==
|
||||||
ref.watch(walletBalanceToggleStateProvider.state).state ==
|
WalletBalanceToggleState.available;
|
||||||
WalletBalanceToggleState.available;
|
|
||||||
|
|
||||||
final Amount balanceToShow;
|
final Amount balanceToShow;
|
||||||
final String title;
|
final String title;
|
||||||
List<FiroType> availableBalances = [];
|
|
||||||
|
|
||||||
if (wallet is FiroWallet) {
|
final bool toggleBalance;
|
||||||
availableBalances = getAvailableBalances(wallet);
|
|
||||||
|
|
||||||
|
if (coin is Firo) {
|
||||||
|
toggleBalance = false;
|
||||||
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";
|
||||||
|
@ -143,6 +111,7 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
toggleBalance = true;
|
||||||
balanceToShow = _showAvailable ? balance.spendable : balance.total;
|
balanceToShow = _showAvailable ? balance.spendable : balance.total;
|
||||||
title = _showAvailable ? "Available balance" : "Full balance";
|
title = _showAvailable ? "Available balance" : "Full balance";
|
||||||
}
|
}
|
||||||
|
@ -175,9 +144,19 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (availableBalances.isNotEmpty &&
|
if (toggleBalance) {
|
||||||
availableBalances.length > 1) {
|
if (ref.read(walletBalanceToggleStateProvider) ==
|
||||||
showSheet(context, ref, availableBalances);
|
WalletBalanceToggleState.available) {
|
||||||
|
ref
|
||||||
|
.read(walletBalanceToggleStateProvider.notifier)
|
||||||
|
.state = WalletBalanceToggleState.full;
|
||||||
|
} else {
|
||||||
|
ref
|
||||||
|
.read(walletBalanceToggleStateProvider.notifier)
|
||||||
|
.state = WalletBalanceToggleState.available;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
showSheet(context);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Row(
|
child: Row(
|
||||||
|
@ -190,7 +169,7 @@ class WalletSummaryInfo extends ConsumerWidget {
|
||||||
.textFavoriteCard,
|
.textFavoriteCard,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (availableBalances.length > 1) ...[
|
if (!toggleBalance) ...[
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 4,
|
width: 4,
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue