From 2b1d438953695c802df21e6fbe6a105f66d88799 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 8 Mar 2023 12:48:43 -0600 Subject: [PATCH] balance refresh and total display fixes --- lib/models/balance.dart | 22 +++++++++++++------ .../coins/bitcoin/bitcoin_wallet.dart | 5 ++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/models/balance.dart b/lib/models/balance.dart index 90ef24570..0589ac90d 100644 --- a/lib/models/balance.dart +++ b/lib/models/balance.dart @@ -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 toMap() => { + "coin": coin, + "total": total, + "spendable": spendable, + "blockedTotal": blockedTotal, + "pendingSpendable": pendingSpendable, + }; + + @override + String toString() { + return toMap().toString(); + } } diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index e2ea91cb1..555b64b2d 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -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,