mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 15:06:04 +00:00
this should maybe be refactored, pt.1
This commit is contained in:
parent
ec25c2bad5
commit
9dd696a474
4 changed files with 214 additions and 24 deletions
|
@ -7,7 +7,14 @@ class ElectrumBalance extends Balance {
|
||||||
required this.confirmed,
|
required this.confirmed,
|
||||||
required this.unconfirmed,
|
required this.unconfirmed,
|
||||||
required this.frozen,
|
required this.frozen,
|
||||||
}) : super(confirmed, unconfirmed);
|
this.secondConfirmed,
|
||||||
|
this.secondUnconfirmed,
|
||||||
|
}) : super(
|
||||||
|
confirmed,
|
||||||
|
unconfirmed,
|
||||||
|
secondAvailable: secondConfirmed,
|
||||||
|
secondAdditional: secondUnconfirmed,
|
||||||
|
);
|
||||||
|
|
||||||
static ElectrumBalance? fromJSON(String? jsonSource) {
|
static ElectrumBalance? fromJSON(String? jsonSource) {
|
||||||
if (jsonSource == null) {
|
if (jsonSource == null) {
|
||||||
|
@ -25,6 +32,8 @@ class ElectrumBalance extends Balance {
|
||||||
int confirmed;
|
int confirmed;
|
||||||
int unconfirmed;
|
int unconfirmed;
|
||||||
final int frozen;
|
final int frozen;
|
||||||
|
int? secondConfirmed;
|
||||||
|
int? secondUnconfirmed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
String get formattedAvailableBalance => bitcoinAmountToString(amount: confirmed - frozen);
|
||||||
|
@ -38,6 +47,17 @@ class ElectrumBalance extends Balance {
|
||||||
return frozenFormatted == '0.0' ? '' : frozenFormatted;
|
return frozenFormatted == '0.0' ? '' : frozenFormatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
String toJSON() =>
|
@override
|
||||||
json.encode({'confirmed': confirmed, 'unconfirmed': unconfirmed, 'frozen': frozen});
|
String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed ?? 0);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get formattedSecondAdditionalBalance => bitcoinAmountToString(amount: secondUnconfirmed ?? 0);
|
||||||
|
|
||||||
|
String toJSON() => json.encode({
|
||||||
|
'confirmed': confirmed,
|
||||||
|
'unconfirmed': unconfirmed,
|
||||||
|
'frozen': frozen,
|
||||||
|
'secondConfirmed': secondConfirmed,
|
||||||
|
'secondUnconfirmed': secondUnconfirmed
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
abstract class Balance {
|
abstract class Balance {
|
||||||
const Balance(this.available, this.additional);
|
const Balance(this.available, this.additional, {this.secondAvailable, this.secondAdditional});
|
||||||
|
|
||||||
final int available;
|
final int available;
|
||||||
|
|
||||||
final int additional;
|
final int additional;
|
||||||
|
|
||||||
|
final int? secondAvailable;
|
||||||
|
final int? secondAdditional;
|
||||||
|
|
||||||
String get formattedAvailableBalance;
|
String get formattedAvailableBalance;
|
||||||
|
|
||||||
String get formattedAdditionalBalance;
|
String get formattedAdditionalBalance;
|
||||||
|
|
||||||
String get formattedUnAvailableBalance => '';
|
String get formattedUnAvailableBalance => '';
|
||||||
|
String get formattedSecondAvailableBalance => '';
|
||||||
|
String get formattedSecondAdditionalBalance => '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,8 +151,7 @@ class CryptoBalanceWidget extends StatelessWidget {
|
||||||
title: "Invalid wownero bindings",
|
title: "Invalid wownero bindings",
|
||||||
subTitle: dashboardViewModel.getWowneroError.toString(),
|
subTitle: dashboardViewModel.getWowneroError.toString(),
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
)
|
));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return Container();
|
return Container();
|
||||||
},
|
},
|
||||||
|
@ -273,6 +272,19 @@ class CryptoBalanceWidget extends StatelessWidget {
|
||||||
currency: balance.asset,
|
currency: balance.asset,
|
||||||
hasAdditionalBalance:
|
hasAdditionalBalance:
|
||||||
dashboardViewModel.balanceViewModel.hasAdditionalBalance,
|
dashboardViewModel.balanceViewModel.hasAdditionalBalance,
|
||||||
|
hasSecondAdditionalBalance:
|
||||||
|
dashboardViewModel.balanceViewModel.hasSecondAdditionalBalance,
|
||||||
|
hasSecondAvailableBalance:
|
||||||
|
dashboardViewModel.balanceViewModel.hasSecondAvailableBalance,
|
||||||
|
secondAdditionalBalance: balance.secondAdditionalBalance,
|
||||||
|
secondAdditionalFiatBalance: balance.fiatSecondAdditionalBalance,
|
||||||
|
secondAvailableBalance: balance.secondAvailableBalance,
|
||||||
|
secondAvailableFiatBalance: balance.fiatSecondAvailableBalance,
|
||||||
|
secondAdditionalBalanceLabel:
|
||||||
|
'${dashboardViewModel.balanceViewModel.additionalBalanceLabel}',
|
||||||
|
secondAvailableBalanceLabel:
|
||||||
|
'${dashboardViewModel.balanceViewModel.availableBalanceLabel}',
|
||||||
|
|
||||||
isTestnet: dashboardViewModel.isTestnet,
|
isTestnet: dashboardViewModel.isTestnet,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -290,12 +302,11 @@ class CryptoBalanceWidget extends StatelessWidget {
|
||||||
child: DashBoardRoundedCardWidget(
|
child: DashBoardRoundedCardWidget(
|
||||||
customBorder: 30,
|
customBorder: 30,
|
||||||
title: "This wallet has encountered an issue",
|
title: "This wallet has encountered an issue",
|
||||||
subTitle: "Here are the things that you should note:\n - "
|
subTitle: "Here are the things that you should note:\n - " +
|
||||||
+dashboardViewModel.isMoneroWalletBrokenReasons.join("\n - ")
|
dashboardViewModel.isMoneroWalletBrokenReasons.join("\n - ") +
|
||||||
+"\n\nPlease restart your wallet and if it doesn't help contact our support.",
|
"\n\nPlease restart your wallet and if it doesn't help contact our support.",
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
)
|
))
|
||||||
)
|
|
||||||
],
|
],
|
||||||
if (dashboardViewModel.showSilentPaymentsCard) ...[
|
if (dashboardViewModel.showSilentPaymentsCard) ...[
|
||||||
SizedBox(height: 10),
|
SizedBox(height: 10),
|
||||||
|
@ -494,10 +505,18 @@ class BalanceRowWidget extends StatelessWidget {
|
||||||
required this.additionalBalanceLabel,
|
required this.additionalBalanceLabel,
|
||||||
required this.additionalBalance,
|
required this.additionalBalance,
|
||||||
required this.additionalFiatBalance,
|
required this.additionalFiatBalance,
|
||||||
|
required this.secondAvailableBalanceLabel,
|
||||||
|
required this.secondAvailableBalance,
|
||||||
|
required this.secondAvailableFiatBalance,
|
||||||
|
required this.secondAdditionalBalanceLabel,
|
||||||
|
required this.secondAdditionalBalance,
|
||||||
|
required this.secondAdditionalFiatBalance,
|
||||||
required this.frozenBalance,
|
required this.frozenBalance,
|
||||||
required this.frozenFiatBalance,
|
required this.frozenFiatBalance,
|
||||||
required this.currency,
|
required this.currency,
|
||||||
required this.hasAdditionalBalance,
|
required this.hasAdditionalBalance,
|
||||||
|
required this.hasSecondAvailableBalance,
|
||||||
|
required this.hasSecondAdditionalBalance,
|
||||||
required this.isTestnet,
|
required this.isTestnet,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -508,10 +527,18 @@ class BalanceRowWidget extends StatelessWidget {
|
||||||
final String additionalBalanceLabel;
|
final String additionalBalanceLabel;
|
||||||
final String additionalBalance;
|
final String additionalBalance;
|
||||||
final String additionalFiatBalance;
|
final String additionalFiatBalance;
|
||||||
|
final String secondAvailableBalanceLabel;
|
||||||
|
final String secondAvailableBalance;
|
||||||
|
final String secondAvailableFiatBalance;
|
||||||
|
final String secondAdditionalBalanceLabel;
|
||||||
|
final String secondAdditionalBalance;
|
||||||
|
final String secondAdditionalFiatBalance;
|
||||||
final String frozenBalance;
|
final String frozenBalance;
|
||||||
final String frozenFiatBalance;
|
final String frozenFiatBalance;
|
||||||
final CryptoCurrency currency;
|
final CryptoCurrency currency;
|
||||||
final bool hasAdditionalBalance;
|
final bool hasAdditionalBalance;
|
||||||
|
final bool hasSecondAvailableBalance;
|
||||||
|
final bool hasSecondAdditionalBalance;
|
||||||
final bool isTestnet;
|
final bool isTestnet;
|
||||||
|
|
||||||
// void _showBalanceDescription(BuildContext context) {
|
// void _showBalanceDescription(BuildContext context) {
|
||||||
|
@ -759,6 +786,94 @@ class BalanceRowWidget extends StatelessWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (hasSecondAvailableBalance)
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 24),
|
||||||
|
Text(
|
||||||
|
'${additionalBalanceLabel}',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: 'Lato',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Theme.of(context).extension<BalancePageTheme>()!.labelTextColor,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
AutoSizeText(
|
||||||
|
additionalBalance,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontFamily: 'Lato',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Theme.of(context).extension<BalancePageTheme>()!.assetTitleColor,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
SizedBox(height: 4),
|
||||||
|
if (!isTestnet)
|
||||||
|
Text(
|
||||||
|
'${additionalFiatBalance}',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: 'Lato',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Theme.of(context).extension<BalancePageTheme>()!.textColor,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (hasSecondAdditionalBalance)
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 24),
|
||||||
|
Text(
|
||||||
|
'${additionalBalanceLabel}',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: 'Lato',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Theme.of(context).extension<BalancePageTheme>()!.labelTextColor,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8),
|
||||||
|
AutoSizeText(
|
||||||
|
additionalBalance,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 20,
|
||||||
|
fontFamily: 'Lato',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Theme.of(context).extension<BalancePageTheme>()!.assetTitleColor,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
SizedBox(height: 4),
|
||||||
|
if (!isTestnet)
|
||||||
|
Text(
|
||||||
|
'${additionalFiatBalance}',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: 'Lato',
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
color: Theme.of(context).extension<BalancePageTheme>()!.textColor,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -21,10 +21,14 @@ class BalanceRecord {
|
||||||
const BalanceRecord(
|
const BalanceRecord(
|
||||||
{required this.availableBalance,
|
{required this.availableBalance,
|
||||||
required this.additionalBalance,
|
required this.additionalBalance,
|
||||||
|
required this.secondAvailableBalance,
|
||||||
|
required this.secondAdditionalBalance,
|
||||||
required this.frozenBalance,
|
required this.frozenBalance,
|
||||||
required this.fiatAvailableBalance,
|
required this.fiatAvailableBalance,
|
||||||
required this.fiatAdditionalBalance,
|
required this.fiatAdditionalBalance,
|
||||||
required this.fiatFrozenBalance,
|
required this.fiatFrozenBalance,
|
||||||
|
required this.fiatSecondAvailableBalance,
|
||||||
|
required this.fiatSecondAdditionalBalance,
|
||||||
required this.asset,
|
required this.asset,
|
||||||
required this.formattedAssetTitle});
|
required this.formattedAssetTitle});
|
||||||
final String fiatAdditionalBalance;
|
final String fiatAdditionalBalance;
|
||||||
|
@ -33,6 +37,10 @@ class BalanceRecord {
|
||||||
final String additionalBalance;
|
final String additionalBalance;
|
||||||
final String availableBalance;
|
final String availableBalance;
|
||||||
final String frozenBalance;
|
final String frozenBalance;
|
||||||
|
final String secondAvailableBalance;
|
||||||
|
final String secondAdditionalBalance;
|
||||||
|
final String fiatSecondAdditionalBalance;
|
||||||
|
final String fiatSecondAvailableBalance;
|
||||||
final CryptoCurrency asset;
|
final CryptoCurrency asset;
|
||||||
final String formattedAssetTitle;
|
final String formattedAssetTitle;
|
||||||
}
|
}
|
||||||
|
@ -243,9 +251,13 @@ abstract class BalanceViewModelBase with Store {
|
||||||
availableBalance: '---',
|
availableBalance: '---',
|
||||||
additionalBalance: '---',
|
additionalBalance: '---',
|
||||||
frozenBalance: '---',
|
frozenBalance: '---',
|
||||||
|
secondAvailableBalance: '---',
|
||||||
|
secondAdditionalBalance: '---',
|
||||||
fiatAdditionalBalance: isFiatDisabled ? '' : '---',
|
fiatAdditionalBalance: isFiatDisabled ? '' : '---',
|
||||||
fiatAvailableBalance: isFiatDisabled ? '' : '---',
|
fiatAvailableBalance: isFiatDisabled ? '' : '---',
|
||||||
fiatFrozenBalance: isFiatDisabled ? '' : '---',
|
fiatFrozenBalance: isFiatDisabled ? '' : '---',
|
||||||
|
fiatSecondAvailableBalance: isFiatDisabled ? '' : '---',
|
||||||
|
fiatSecondAdditionalBalance: isFiatDisabled ? '' : '---',
|
||||||
asset: key,
|
asset: key,
|
||||||
formattedAssetTitle: _formatterAsset(key)));
|
formattedAssetTitle: _formatterAsset(key)));
|
||||||
}
|
}
|
||||||
|
@ -274,15 +286,31 @@ abstract class BalanceViewModelBase with Store {
|
||||||
' ' +
|
' ' +
|
||||||
_getFiatBalance(price: price, cryptoAmount: getFormattedFrozenBalance(value)));
|
_getFiatBalance(price: price, cryptoAmount: getFormattedFrozenBalance(value)));
|
||||||
|
|
||||||
|
final secondAdditionalFiatBalance = isFiatDisabled
|
||||||
|
? ''
|
||||||
|
: (fiatCurrency.toString() +
|
||||||
|
' ' +
|
||||||
|
_getFiatBalance(price: price, cryptoAmount: value.formattedSecondAdditionalBalance));
|
||||||
|
|
||||||
|
final secondAvailableFiatBalance = isFiatDisabled
|
||||||
|
? ''
|
||||||
|
: (fiatCurrency.toString() +
|
||||||
|
' ' +
|
||||||
|
_getFiatBalance(price: price, cryptoAmount: value.formattedSecondAvailableBalance));
|
||||||
|
|
||||||
return MapEntry(
|
return MapEntry(
|
||||||
key,
|
key,
|
||||||
BalanceRecord(
|
BalanceRecord(
|
||||||
availableBalance: value.formattedAvailableBalance,
|
availableBalance: value.formattedAvailableBalance,
|
||||||
additionalBalance: value.formattedAdditionalBalance,
|
additionalBalance: value.formattedAdditionalBalance,
|
||||||
frozenBalance: getFormattedFrozenBalance(value),
|
frozenBalance: getFormattedFrozenBalance(value),
|
||||||
|
secondAvailableBalance: value.formattedSecondAvailableBalance,
|
||||||
|
secondAdditionalBalance: value.formattedSecondAdditionalBalance,
|
||||||
fiatAdditionalBalance: additionalFiatBalance,
|
fiatAdditionalBalance: additionalFiatBalance,
|
||||||
fiatAvailableBalance: availableFiatBalance,
|
fiatAvailableBalance: availableFiatBalance,
|
||||||
fiatFrozenBalance: frozenFiatBalance,
|
fiatFrozenBalance: frozenFiatBalance,
|
||||||
|
fiatSecondAvailableBalance: secondAvailableFiatBalance,
|
||||||
|
fiatSecondAdditionalBalance: secondAdditionalFiatBalance,
|
||||||
asset: key,
|
asset: key,
|
||||||
formattedAssetTitle: _formatterAsset(key)));
|
formattedAssetTitle: _formatterAsset(key)));
|
||||||
});
|
});
|
||||||
|
@ -291,6 +319,12 @@ abstract class BalanceViewModelBase with Store {
|
||||||
@computed
|
@computed
|
||||||
bool get hasAdditionalBalance => _hasAdditionBalanceForWalletType(wallet.type);
|
bool get hasAdditionalBalance => _hasAdditionBalanceForWalletType(wallet.type);
|
||||||
|
|
||||||
|
@computed
|
||||||
|
bool get hasSecondAdditionalBalance => _hasSecondAddtionalBalanceForWalletType(wallet.type);
|
||||||
|
|
||||||
|
@computed
|
||||||
|
bool get hasSecondAvailableBalance => _hasSecondAvailableBalanceForWalletType(wallet.type);
|
||||||
|
|
||||||
bool _hasAdditionBalanceForWalletType(WalletType type) {
|
bool _hasAdditionBalanceForWalletType(WalletType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WalletType.ethereum:
|
case WalletType.ethereum:
|
||||||
|
@ -303,6 +337,24 @@ abstract class BalanceViewModelBase with Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _hasSecondAddtionalBalanceForWalletType(WalletType type) {
|
||||||
|
switch (type) {
|
||||||
|
case WalletType.litecoin:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _hasSecondAvailableBalanceForWalletType(WalletType type) {
|
||||||
|
switch (type) {
|
||||||
|
case WalletType.litecoin:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
List<BalanceRecord> get formattedBalances {
|
List<BalanceRecord> get formattedBalances {
|
||||||
final balance = balances.values.toList();
|
final balance = balances.values.toList();
|
||||||
|
|
Loading…
Reference in a new issue