mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Cw 830 coin control getting cleared (#1825)
* init commit * add select all button * localisation all coins * fix isSending and isFrozen state updates * fix: clean up electrum UTXOs * ui fixes * address the review comments[skip ci] * remove onPopInvoked[skip ci] --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
4ca50b5e63
commit
9cd69c4ba3
40 changed files with 402 additions and 125 deletions
|
@ -106,6 +106,15 @@ class BitcoinWalletService extends WalletService<
|
|||
final walletInfo = walletInfoSource.values
|
||||
.firstWhereOrNull((info) => info.id == WalletBase.idFor(wallet, getType()))!;
|
||||
await walletInfoSource.delete(walletInfo.key);
|
||||
|
||||
final unspentCoinsToDelete = unspentCoinsInfoSource.values.where(
|
||||
(unspentCoin) => unspentCoin.walletId == walletInfo.id).toList();
|
||||
|
||||
final keysToDelete = unspentCoinsToDelete.map((unspentCoin) => unspentCoin.key).toList();
|
||||
|
||||
if (keysToDelete.isNotEmpty) {
|
||||
await unspentCoinsInfoSource.deleteAll(keysToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -304,6 +304,7 @@ abstract class ElectrumWalletBase
|
|||
Future<void> init() async {
|
||||
await walletAddresses.init();
|
||||
await transactionHistory.init();
|
||||
await cleanUpDuplicateUnspentCoins();
|
||||
await save();
|
||||
|
||||
_autoSaveTimer =
|
||||
|
@ -1379,10 +1380,11 @@ abstract class ElectrumWalletBase
|
|||
}));
|
||||
|
||||
unspentCoins = updatedUnspentCoins;
|
||||
|
||||
final currentWalletUnspentCoins = unspentCoinsInfo.values.where((element) => element.walletId == id);
|
||||
|
||||
if (unspentCoinsInfo.length != updatedUnspentCoins.length) {
|
||||
if (currentWalletUnspentCoins.length != updatedUnspentCoins.length) {
|
||||
unspentCoins.forEach((coin) => addCoinInfo(coin));
|
||||
return;
|
||||
}
|
||||
|
||||
await updateCoins(unspentCoins);
|
||||
|
@ -1408,6 +1410,7 @@ abstract class ElectrumWalletBase
|
|||
coin.isFrozen = coinInfo.isFrozen;
|
||||
coin.isSending = coinInfo.isSending;
|
||||
coin.note = coinInfo.note;
|
||||
|
||||
if (coin.bitcoinAddressRecord is! BitcoinSilentPaymentAddressRecord)
|
||||
coin.bitcoinAddressRecord.balance += coinInfo.value;
|
||||
} else {
|
||||
|
@ -1445,20 +1448,27 @@ abstract class ElectrumWalletBase
|
|||
|
||||
@action
|
||||
Future<void> addCoinInfo(BitcoinUnspent coin) async {
|
||||
final newInfo = UnspentCoinsInfo(
|
||||
walletId: id,
|
||||
hash: coin.hash,
|
||||
isFrozen: coin.isFrozen,
|
||||
isSending: coin.isSending,
|
||||
noteRaw: coin.note,
|
||||
address: coin.bitcoinAddressRecord.address,
|
||||
value: coin.value,
|
||||
vout: coin.vout,
|
||||
isChange: coin.isChange,
|
||||
isSilentPayment: coin is BitcoinSilentPaymentsUnspent,
|
||||
);
|
||||
|
||||
await unspentCoinsInfo.add(newInfo);
|
||||
// Check if the coin is already in the unspentCoinsInfo for the wallet
|
||||
final existingCoinInfo = unspentCoinsInfo.values.firstWhereOrNull(
|
||||
(element) => element.walletId == walletInfo.id && element == coin);
|
||||
|
||||
if (existingCoinInfo == null) {
|
||||
final newInfo = UnspentCoinsInfo(
|
||||
walletId: id,
|
||||
hash: coin.hash,
|
||||
isFrozen: coin.isFrozen,
|
||||
isSending: coin.isSending,
|
||||
noteRaw: coin.note,
|
||||
address: coin.bitcoinAddressRecord.address,
|
||||
value: coin.value,
|
||||
vout: coin.vout,
|
||||
isChange: coin.isChange,
|
||||
isSilentPayment: coin is BitcoinSilentPaymentsUnspent,
|
||||
);
|
||||
|
||||
await unspentCoinsInfo.add(newInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _refreshUnspentCoinsInfo() async {
|
||||
|
@ -1486,6 +1496,23 @@ abstract class ElectrumWalletBase
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> cleanUpDuplicateUnspentCoins() async {
|
||||
final currentWalletUnspentCoins = unspentCoinsInfo.values.where((element) => element.walletId == id);
|
||||
final Map<String, UnspentCoinsInfo> uniqueUnspentCoins = {};
|
||||
final List<dynamic> duplicateKeys = [];
|
||||
|
||||
for (final unspentCoin in currentWalletUnspentCoins) {
|
||||
final key = '${unspentCoin.hash}:${unspentCoin.vout}';
|
||||
if (!uniqueUnspentCoins.containsKey(key)) {
|
||||
uniqueUnspentCoins[key] = unspentCoin;
|
||||
} else {
|
||||
duplicateKeys.add(unspentCoin.key);
|
||||
}
|
||||
}
|
||||
|
||||
if (duplicateKeys.isNotEmpty) await unspentCoinsInfo.deleteAll(duplicateKeys);
|
||||
}
|
||||
|
||||
int transactionVSize(String transactionHex) => BtcTransaction.fromRaw(transactionHex).getVSize();
|
||||
|
||||
Future<String?> canReplaceByFee(ElectrumTransactionInfo tx) async {
|
||||
|
|
|
@ -126,6 +126,15 @@ class LitecoinWalletService extends WalletService<
|
|||
mwebdLogs.deleteSync();
|
||||
}
|
||||
}
|
||||
|
||||
final unspentCoinsToDelete = unspentCoinsInfoSource.values.where(
|
||||
(unspentCoin) => unspentCoin.walletId == walletInfo.id).toList();
|
||||
|
||||
final keysToDelete = unspentCoinsToDelete.map((unspentCoin) => unspentCoin.key).toList();
|
||||
|
||||
if (keysToDelete.isNotEmpty) {
|
||||
await unspentCoinsInfoSource.deleteAll(keysToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue