This commit is contained in:
Matthew Fosse 2025-01-22 16:37:53 -08:00
parent b254ec90ca
commit 3fd3a095bb
2 changed files with 13 additions and 8 deletions

View file

@ -929,13 +929,13 @@ abstract class ElectrumWalletBase
);
} else {
// Here, lastOutput already is change, return the amount left without the fee to the user's address.
updatedOutputs[updatedOutputs.length - 1] = BitcoinOutput(
updatedOutputs.last = BitcoinOutput(
address: lastOutput.address,
value: BigInt.from(amountLeftForChange),
isSilentPayment: lastOutput.isSilentPayment,
isChange: true,
);
outputs[outputs.length - 1] = BitcoinOutput(
outputs.last = BitcoinOutput(
address: lastOutput.address,
value: BigInt.from(amountLeftForChange),
isSilentPayment: lastOutput.isSilentPayment,
@ -1450,9 +1450,11 @@ abstract class ElectrumWalletBase
return updatedUnspentCoins;
}
Future<void> updateCoins(List<BitcoinUnspent> newUnspentCoins) async {
Future<List<BitcoinUnspent>> updateCoinsWithInfoFromBox(List<BitcoinUnspent> newUnspentCoins) async {
// this function updates and returns unspent coins list (freshly fetched from the server)
// with info from the box, if the box doesn't have info for some of the unspents, it adds them to the box
if (newUnspentCoins.isEmpty) {
return;
return newUnspentCoins;
}
newUnspentCoins.forEach((coin) {
@ -1476,12 +1478,14 @@ abstract class ElectrumWalletBase
addCoinInfo(coin);
}
});
return newUnspentCoins;
}
@action
Future<void> updateUnspentsForAddress(BitcoinAddressRecord address) async {
final newUnspentCoins = await fetchUnspent(address);
await updateCoins(newUnspentCoins ?? []);
unspentCoins = await updateCoinsWithInfoFromBox(newUnspentCoins);
}
@action
@ -1531,6 +1535,7 @@ abstract class ElectrumWalletBase
}
}
// delete unspent coins info entries that don't have a corresponding unspent coin:
Future<void> _refreshUnspentCoinsInfo() async {
try {
final List<dynamic> keys = [];

View file

@ -845,11 +845,11 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
mwebUnspentCoins.add(unspent);
});
// copy coin control attributes to mwebCoins:
await updateCoins(mwebUnspentCoins);
// copy coin control attributes to coinsInfo:
mwebUnspentCoins = await updateCoinsWithInfoFromBox(mwebUnspentCoins);
// get regular ltc unspents (this resets unspentCoins):
await super.updateAllUnspents();
// add the mwebCoins:
// add back the mwebCoins:
unspentCoins.addAll(mwebUnspentCoins);
}