separate mweb balances, pt.2

This commit is contained in:
Matthew Fosse 2024-09-12 13:15:20 -07:00
parent 9dd696a474
commit 6a4327a53b
3 changed files with 67 additions and 29 deletions

View file

@ -319,7 +319,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
lastFewProgresses.add(syncStatus.progress());
if (lastFewProgresses.length < 4) return;
// limit list size to 4:
while(lastFewProgresses.length > 4) {
while (lastFewProgresses.length > 4) {
lastFewProgresses.removeAt(0);
}
// if the progress is the same over the last 40 seconds, restart the sync:
@ -676,12 +676,14 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
int confirmed = balance.confirmed;
int unconfirmed = balance.unconfirmed;
int confirmedMweb = 0;
int unconfirmedMweb = 0;
try {
mwebUtxosBox.values.forEach((utxo) {
if (utxo.height > 0) {
confirmed += utxo.value.toInt();
confirmedMweb += utxo.value.toInt();
} else {
unconfirmed += utxo.value.toInt();
unconfirmedMweb += utxo.value.toInt();
}
});
} catch (_) {}
@ -733,7 +735,13 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
}
}
return ElectrumBalance(confirmed: confirmed, unconfirmed: unconfirmed, frozen: balance.frozen);
return ElectrumBalance(
confirmed: confirmed,
unconfirmed: unconfirmed,
frozen: balance.frozen,
secondConfirmed: confirmedMweb,
secondUnconfirmed: unconfirmedMweb,
);
}
@override

View file

@ -281,10 +281,9 @@ class CryptoBalanceWidget extends StatelessWidget {
secondAvailableBalance: balance.secondAvailableBalance,
secondAvailableFiatBalance: balance.fiatSecondAvailableBalance,
secondAdditionalBalanceLabel:
'${dashboardViewModel.balanceViewModel.additionalBalanceLabel}',
'${dashboardViewModel.balanceViewModel.secondAdditionalBalanceLabel}',
secondAvailableBalanceLabel:
'${dashboardViewModel.balanceViewModel.availableBalanceLabel}',
'${dashboardViewModel.balanceViewModel.secondAvailableBalanceLabel}',
isTestnet: dashboardViewModel.isTestnet,
);
});
@ -792,7 +791,7 @@ class BalanceRowWidget extends StatelessWidget {
children: [
SizedBox(height: 24),
Text(
'${additionalBalanceLabel}',
'${secondAvailableBalanceLabel}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
@ -804,7 +803,7 @@ class BalanceRowWidget extends StatelessWidget {
),
SizedBox(height: 8),
AutoSizeText(
additionalBalance,
secondAvailableBalance,
style: TextStyle(
fontSize: 20,
fontFamily: 'Lato',
@ -818,7 +817,7 @@ class BalanceRowWidget extends StatelessWidget {
SizedBox(height: 4),
if (!isTestnet)
Text(
'${additionalFiatBalance}',
'${secondAvailableFiatBalance}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
@ -836,7 +835,7 @@ class BalanceRowWidget extends StatelessWidget {
children: [
SizedBox(height: 24),
Text(
'${additionalBalanceLabel}',
'${secondAdditionalBalanceLabel}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,
@ -848,7 +847,7 @@ class BalanceRowWidget extends StatelessWidget {
),
SizedBox(height: 8),
AutoSizeText(
additionalBalance,
secondAdditionalBalance,
style: TextStyle(
fontSize: 20,
fontFamily: 'Lato',
@ -862,7 +861,7 @@ class BalanceRowWidget extends StatelessWidget {
SizedBox(height: 4),
if (!isTestnet)
Text(
'${additionalFiatBalance}',
'${secondAdditionalFiatBalance}',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 12,

View file

@ -166,6 +166,26 @@ abstract class BalanceViewModelBase with Store {
}
}
@computed
String get secondAvailableBalanceLabel {
switch (wallet.type) {
case WalletType.litecoin:
return "T: mweb confirmed";
default:
return S.current.confirmed;
}
}
@computed
String get secondAdditionalBalanceLabel {
switch (wallet.type) {
case WalletType.litecoin:
return "T: mweb unconfirmed";
default:
return S.current.unconfirmed;
}
}
@computed
bool get hasMultiBalance => appStore.wallet!.type == WalletType.haven;
@ -215,6 +235,17 @@ abstract class BalanceViewModelBase with Store {
return walletBalance.formattedAdditionalBalance;
}
@computed
String get secondAdditionalBalance {
final walletBalance = _walletBalance;
if (displayMode == BalanceDisplayMode.hiddenBalance) {
return '---';
}
return walletBalance.formattedSecondAdditionalBalance;
}
@computed
String get availableFiatBalance {
final walletBalance = _walletBalance;
@ -317,15 +348,15 @@ abstract class BalanceViewModelBase with Store {
}
@computed
bool get hasAdditionalBalance => _hasAdditionBalanceForWalletType(wallet.type);
bool get hasAdditionalBalance => _hasAdditionalBalanceForWalletType(wallet.type);
@computed
bool get hasSecondAdditionalBalance => _hasSecondAddtionalBalanceForWalletType(wallet.type);
bool get hasSecondAdditionalBalance => _hasSecondAdditionalBalanceForWalletType(wallet.type);
@computed
bool get hasSecondAvailableBalance => _hasSecondAvailableBalanceForWalletType(wallet.type);
bool _hasAdditionBalanceForWalletType(WalletType type) {
bool _hasAdditionalBalanceForWalletType(WalletType type) {
switch (type) {
case WalletType.ethereum:
case WalletType.polygon:
@ -337,22 +368,22 @@ abstract class BalanceViewModelBase with Store {
}
}
bool _hasSecondAddtionalBalanceForWalletType(WalletType type) {
switch (type) {
case WalletType.litecoin:
return true;
default:
return false;
}
bool _hasSecondAdditionalBalanceForWalletType(WalletType type) {
// return _walletBalance.secondAdditional != null && _walletBalance.secondAdditional! != 0;
// if (wallet.type == WalletType.litecoin && settingsStore.mwebEnabled) {
// return true;
// }
// return false;
return true;
}
bool _hasSecondAvailableBalanceForWalletType(WalletType type) {
switch (type) {
case WalletType.litecoin:
return true;
default:
return false;
}
// return _walletBalance.secondAdditional != null && _walletBalance.secondAdditional! != 0;
// if (wallet.type == WalletType.litecoin && settingsStore.mwebEnabled) {
// return true;
// }
// return false;
return true;
}
@computed