coin control fixes

This commit is contained in:
Matthew Fosse 2024-07-11 11:49:14 -07:00
parent 4ec9d7b2e1
commit e5e2a8706b
2 changed files with 34 additions and 4 deletions

View file

@ -1170,7 +1170,7 @@ abstract class ElectrumWalletBase
await updateAllUnspents();
if (unspentCoinsInfo.isEmpty) {
unspentCoins.forEach((coin) => _addCoinInfo(coin));
unspentCoins.forEach((coin) => addCoinInfo(coin));
return;
}
@ -1190,7 +1190,7 @@ abstract class ElectrumWalletBase
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
coin.bitcoinAddressRecord.balance += coinInfo.value;
} else {
_addCoinInfo(coin);
addCoinInfo(coin);
}
});
}
@ -1222,7 +1222,7 @@ abstract class ElectrumWalletBase
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
coin.bitcoinAddressRecord.balance += coinInfo.value;
} else {
_addCoinInfo(coin);
addCoinInfo(coin);
}
});
}
@ -1249,7 +1249,7 @@ abstract class ElectrumWalletBase
}
@action
Future<void> _addCoinInfo(BitcoinUnspent coin) async {
Future<void> addCoinInfo(BitcoinUnspent coin) async {
final newInfo = UnspentCoinsInfo(
walletId: id,
hash: coin.hash,

View file

@ -481,6 +481,36 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
unconfirmed += utxo.value.toInt();
}
});
// update unspent balances:
// reset coin balances to 0:
unspentCoins.forEach((coin) {
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
coin.bitcoinAddressRecord.balance = 0;
});
unspentCoins.forEach((coin) {
final coinInfoList = unspentCoinsInfo.values.where(
(element) =>
element.walletId.contains(id) &&
element.hash.contains(coin.hash) &&
element.vout == coin.vout,
);
if (coinInfoList.isNotEmpty) {
final coinInfo = coinInfoList.first;
coin.isFrozen = coinInfo.isFrozen;
coin.isSending = coinInfo.isSending;
coin.note = coinInfo.note;
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
coin.bitcoinAddressRecord.balance += coinInfo.value;
} else {
super.addCoinInfo(coin);
}
});
return ElectrumBalance(confirmed: confirmed, unconfirmed: unconfirmed, frozen: balance.frozen);
}