balance refresh and total display fixes

This commit is contained in:
julian 2023-03-08 12:48:43 -06:00
parent ea49ed32ab
commit 2b1d438953
2 changed files with 19 additions and 8 deletions

View file

@ -19,7 +19,7 @@ class Balance {
required this.pendingSpendable,
});
Decimal getTotal({bool includeBlocked = false}) => Format.satoshisToAmount(
Decimal getTotal({bool includeBlocked = true}) => Format.satoshisToAmount(
includeBlocked ? total : total - blockedTotal,
coin: coin,
);
@ -39,12 +39,7 @@ class Balance {
coin: coin,
);
String toJsonIgnoreCoin() => jsonEncode({
"total": total,
"spendable": spendable,
"blockedTotal": blockedTotal,
"pendingSpendable": pendingSpendable,
});
String toJsonIgnoreCoin() => jsonEncode(toMap()..remove("coin"));
factory Balance.fromJson(String json, Coin coin) {
final decoded = jsonDecode(json);
@ -56,4 +51,17 @@ class Balance {
pendingSpendable: decoded["pendingSpendable"] as int,
);
}
Map<String, dynamic> toMap() => {
"coin": coin,
"total": total,
"spendable": spendable,
"blockedTotal": blockedTotal,
"pendingSpendable": pendingSpendable,
};
@override
String toString() {
return toMap().toString();
}
}

View file

@ -126,7 +126,10 @@ class BitcoinWallet extends CoinServiceAPI
coin: coin,
db: db,
getChainHeight: () => chainHeight,
refreshedBalanceCallback: updateCachedBalance,
refreshedBalanceCallback: (balance) async {
_balance = balance;
await updateCachedBalance(_balance!);
},
);
initPaynymWalletInterface(
walletId: walletId,