fix: incorrect balance in send card (#2158)

* fix: incorrect balance in send card * fix: ensure that all unique Unspent are used in calculation

cyan committed Apr 4, 2025 at 12:56 UTC fd16a099ea03c47f9d2bd640376a1db49536bfa4
2 files changed +8 -5
cw_core/lib/unspent_transaction_output.dart
+5
@@ -21,4 +21,9 @@ class Unspent with UnspentComparable {
21
22 bool get isP2wpkh =>
23 address.startsWith('bc') || address.startsWith('tb') || address.startsWith('ltc');
24 +
25 + @override
26 + String toString() {
27 + return 'Unspent(address: $address, hash: $hash, value: $value, vout: $vout, keyImage: $keyImage, isSending: $isSending, isFrozen: $isFrozen, isChange: $isChange, note: $note)';
28 + }
29 }
lib/view_model/unspent_coins/unspent_coins_list_view_model.dart
+3 -5
@@ -156,8 +156,8 @@ abstract class UnspentCoinsListViewModelBase with Store {
156 await _updateUnspents();
157 Set<String> seen = {};
158 for (final item in _getSpecificUnspents(overrideCoinTypeToSpendFrom)) {
159 - if (seen.contains(item.hash)) continue;
160 - seen.add(item.hash);
159 + if (seen.contains(item.toString())) continue;
160 + seen.add(item.toString());
161 if (item.isFrozen || !item.isSending) continue;
162 total += item.value;
163 }
@@ -166,8 +166,6 @@ abstract class UnspentCoinsListViewModelBase with Store {
166
167 @action
168 void _updateUnspentCoinsInfo() {
169 - items.clear();
170 -
169 final unspents = _getUnspents()
170 .map((elem) {
171 try {
@@ -201,7 +199,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
199 .toList();
200
201 unspents.sort((a, b) => b.value.compareTo(a.value));
204 -
202 + items.clear();
203 items.addAll(unspents);
204 }
205