mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 20:09:24 +00:00
c9a6abeea4
* fix: Confirm widget is still mounted * feat: Modify balance display to include full balance * fix: Modifying balance * chore: Feature cleanup * fix: Add frozen balance into consideration when taking available balance and add field to make full balance display only on bitcoin and litecoin wallets * fix: Adjust balance card to display correct available and unavailable balance, unavailable balance should only be displayed when there is one WIP * fix: Cleanup balance page and balance page view_model * chore: Revert formatting * fix: Remove full balance * fix: Remove full balance * fix: Remove full balance * chore: Rever formating [skip ci] * feat: Finalize display only available and unavailable balance * fix: Modify the way balance is displayed, activate frozen balance with label, remove unavailable/additional balance for bitcoin wallet type * fix: Issues coming from syncing with main * fix: Modify additional balance label * fix: Monero and Wownero balances display bug * fix: Resolve merge conflicts * feat: Activate CPFP for BTC, LTC and BCH, also fix issues with frozen balance display * - minor fix - remove unused functions * Fix conflicts --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> Co-authored-by: tuxsudo <tuxsudo@tux.pizza>
70 lines
2.1 KiB
Dart
70 lines
2.1 KiB
Dart
import 'dart:convert';
|
|
import 'package:cw_bitcoin/bitcoin_amount_format.dart';
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
class ElectrumBalance extends Balance {
|
|
ElectrumBalance({
|
|
required this.confirmed,
|
|
required this.unconfirmed,
|
|
required this.frozen,
|
|
this.secondConfirmed = 0,
|
|
this.secondUnconfirmed = 0,
|
|
}) : super(
|
|
confirmed,
|
|
unconfirmed,
|
|
secondAvailable: secondConfirmed,
|
|
secondAdditional: secondUnconfirmed,
|
|
);
|
|
|
|
static ElectrumBalance? fromJSON(String? jsonSource) {
|
|
if (jsonSource == null) {
|
|
return null;
|
|
}
|
|
|
|
final decoded = json.decode(jsonSource) as Map;
|
|
|
|
return ElectrumBalance(
|
|
confirmed: decoded['confirmed'] as int? ?? 0,
|
|
unconfirmed: decoded['unconfirmed'] as int? ?? 0,
|
|
frozen: decoded['frozen'] as int? ?? 0,
|
|
secondConfirmed: decoded['secondConfirmed'] as int? ?? 0,
|
|
secondUnconfirmed: decoded['secondUnconfirmed'] as int? ?? 0,
|
|
);
|
|
}
|
|
|
|
int confirmed;
|
|
int unconfirmed;
|
|
final int frozen;
|
|
int secondConfirmed = 0;
|
|
int secondUnconfirmed = 0;
|
|
|
|
@override
|
|
String get formattedAvailableBalance => bitcoinAmountToString(amount: ((confirmed + unconfirmed) - frozen) );
|
|
|
|
@override
|
|
String get formattedAdditionalBalance => bitcoinAmountToString(amount: unconfirmed);
|
|
|
|
@override
|
|
String get formattedUnAvailableBalance {
|
|
final frozenFormatted = bitcoinAmountToString(amount: frozen);
|
|
return frozenFormatted == '0.0' ? '' : frozenFormatted;
|
|
}
|
|
|
|
@override
|
|
String get formattedSecondAvailableBalance => bitcoinAmountToString(amount: secondConfirmed);
|
|
|
|
@override
|
|
String get formattedSecondAdditionalBalance => bitcoinAmountToString(amount: secondUnconfirmed);
|
|
|
|
@override
|
|
String get formattedFullAvailableBalance =>
|
|
bitcoinAmountToString(amount: (confirmed + unconfirmed) + secondConfirmed - frozen);
|
|
|
|
String toJSON() => json.encode({
|
|
'confirmed': confirmed,
|
|
'unconfirmed': unconfirmed,
|
|
'frozen': frozen,
|
|
'secondConfirmed': secondConfirmed,
|
|
'secondUnconfirmed': secondUnconfirmed
|
|
});
|
|
}
|