add delete address labels and tx notes functionality (isar notes unimplemented atm)

This commit is contained in:
julian 2023-02-03 18:17:39 -06:00
parent eb42493e4d
commit 74ca8e1e07
2 changed files with 44 additions and 10 deletions

View file

@ -257,30 +257,62 @@ class MainDB {
// transactions
for (int i = 0; i < transactionCount; i += paginateLimit) {
final txns = await getTransactions(walletId)
final txnIds = await getTransactions(walletId)
.offset(i)
.limit(paginateLimit)
.idProperty()
.findAll();
await isar.transactions
.deleteAll(txns.map((e) => e.id).toList(growable: false));
await isar.transactions.deleteAll(txnIds);
}
// addresses
for (int i = 0; i < addressCount; i += paginateLimit) {
final addresses = await getAddresses(walletId)
final addressIds = await getAddresses(walletId)
.offset(i)
.limit(paginateLimit)
.idProperty()
.findAll();
await isar.addresses
.deleteAll(addresses.map((e) => e.id).toList(growable: false));
await isar.addresses.deleteAll(addressIds);
}
// utxos
for (int i = 0; i < utxoCount; i += paginateLimit) {
final utxos =
await getUTXOs(walletId).offset(i).limit(paginateLimit).findAll();
await isar.utxos
.deleteAll(utxos.map((e) => e.id).toList(growable: false));
final utxoIds = await getUTXOs(walletId)
.offset(i)
.limit(paginateLimit)
.idProperty()
.findAll();
await isar.utxos.deleteAll(utxoIds);
}
});
}
Future<void> deleteAddressLabels(String walletId) async {
final addressLabelCount = await getAddressLabels(walletId).count();
await isar.writeTxn(() async {
const paginateLimit = 50;
for (int i = 0; i < addressLabelCount; i += paginateLimit) {
final labelIds = await getAddressLabels(walletId)
.offset(i)
.limit(paginateLimit)
.idProperty()
.findAll();
await isar.addressLabels.deleteAll(labelIds);
}
});
}
Future<void> deleteTransactionNotes(String walletId) async {
final noteCount = await getTransactionNotes(walletId).count();
await isar.writeTxn(() async {
const paginateLimit = 50;
for (int i = 0; i < noteCount; i += paginateLimit) {
final labelIds = await getTransactionNotes(walletId)
.offset(i)
.limit(paginateLimit)
.idProperty()
.findAll();
await isar.transactionNotes.deleteAll(labelIds);
}
});
}

View file

@ -388,6 +388,8 @@ class WalletsService extends ChangeNotifier {
// delete wallet data in main db
await MainDB.instance.deleteWalletBlockchainData(walletId);
await MainDB.instance.deleteAddressLabels(walletId);
await MainDB.instance.deleteTransactionNotes(walletId);
// box data may currently still be read/written to if wallet was refreshing
// when delete was requested so instead of deleting now we mark the wallet