fix: Add frozen balance into consideration when taking available balance and add field to make full balance display only on bitcoin and litecoin wallets

This commit is contained in:
Blazebrain 2024-05-21 15:08:41 +01:00
parent ef04ec518b
commit 48e29e39a4
3 changed files with 12 additions and 5 deletions

View file

@ -26,7 +26,8 @@ class ElectrumBalance extends Balance {
@override @override
String get formattedAvailableBalance { String get formattedAvailableBalance {
bool isOutgoingTx = unconfirmed.isNegative; bool isOutgoingTx = unconfirmed.isNegative;
final availableBalance = isOutgoingTx ? (confirmed + unconfirmed) : (confirmed); final availableBalance =
isOutgoingTx ? ((confirmed + unconfirmed) - frozen) : (confirmed - frozen);
return bitcoinAmountToString(amount: availableBalance); return bitcoinAmountToString(amount: availableBalance);
} }
@ -42,9 +43,8 @@ class ElectrumBalance extends Balance {
@override @override
String get formattedFullBalance { String get formattedFullBalance {
bool isOutgoingTx = unconfirmed.isNegative; bool isOutgoingTx = unconfirmed.isNegative;
final fullBalance = isOutgoingTx final fullBalance =
? (confirmed + frozen) isOutgoingTx ? (confirmed + frozen) : (confirmed + (unconfirmed.abs()) + frozen);
: (confirmed + (unconfirmed.abs()) + frozen);
final result = bitcoinAmountToString(amount: fullBalance); final result = bitcoinAmountToString(amount: fullBalance);
return result; return result;

View file

@ -230,6 +230,7 @@ class CryptoBalanceWidget extends StatelessWidget {
'${dashboardViewModel.balanceViewModel.additionalBalanceLabel}', '${dashboardViewModel.balanceViewModel.additionalBalanceLabel}',
additionalBalance: balance.additionalBalance, additionalBalance: balance.additionalBalance,
additionalFiatBalance: balance.fiatAdditionalBalance, additionalFiatBalance: balance.fiatAdditionalBalance,
hasFullBalance: dashboardViewModel.balanceViewModel.hasFullBalance,
fullBalanceLabel: '${dashboardViewModel.balanceViewModel.fullBalanceLabel}', fullBalanceLabel: '${dashboardViewModel.balanceViewModel.fullBalanceLabel}',
fullBalance: balance.fullBalance, fullBalance: balance.fullBalance,
fullFiatBalance: balance.fiatFullBalance, fullFiatBalance: balance.fiatFullBalance,
@ -265,6 +266,7 @@ class BalanceRowWidget extends StatelessWidget {
required this.fullFiatBalance, required this.fullFiatBalance,
required this.currency, required this.currency,
required this.hasAdditionalBalance, required this.hasAdditionalBalance,
required this.hasFullBalance,
super.key, super.key,
}); });
@ -281,6 +283,7 @@ class BalanceRowWidget extends StatelessWidget {
final String fullFiatBalance; final String fullFiatBalance;
final CryptoCurrency currency; final CryptoCurrency currency;
final bool hasAdditionalBalance; final bool hasAdditionalBalance;
final bool hasFullBalance;
// void _showBalanceDescription(BuildContext context) { // void _showBalanceDescription(BuildContext context) {
// showPopUp<void>( // showPopUp<void>(
@ -515,7 +518,7 @@ class BalanceRowWidget extends StatelessWidget {
), ),
], ],
), ),
if (hasAdditionalBalance) if (hasFullBalance)
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [

View file

@ -326,6 +326,10 @@ abstract class BalanceViewModelBase with Store {
@computed @computed
bool get hasAdditionalBalance => _hasAdditionBalanceForWalletType(wallet.type); bool get hasAdditionalBalance => _hasAdditionBalanceForWalletType(wallet.type);
@computed
bool get hasFullBalance =>
wallet.type == WalletType.bitcoin || wallet.type == WalletType.litecoin;
bool _hasAdditionBalanceForWalletType(WalletType type) { bool _hasAdditionBalanceForWalletType(WalletType type) {
switch (type) { switch (type) {
case WalletType.ethereum: case WalletType.ethereum: