Skip to content

Commit

Permalink
chore(suite): migration of eth transactions and accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Apr 5, 2023
1 parent 53c72b7 commit ddd24ef
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/suite/src/storage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Storage changelog

## 35

- saved ethereum network type txs are removed to be fetched again and obtain internal transfers and token transfer contract and standard

## 34

- added `coinjoinDebugSettings`
Expand Down
2 changes: 1 addition & 1 deletion packages/suite/src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { migrate } from './migrations';

import type { SuiteDBSchema } from './definitions';

const VERSION = 34; // don't forget to add migration and CHANGELOG when changing versions!
const VERSION = 35; // don't forget to add migration and CHANGELOG when changing versions!

/**
* If the object stores don't already exist then creates them.
Expand Down
38 changes: 38 additions & 0 deletions packages/suite/src/storage/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,42 @@ export const migrate: OnUpgradeFunc<SuiteDBSchema> = async (
if (oldVersion < 34) {
db.createObjectStore('coinjoinDebugSettings');
}

if (oldVersion < 35) {
// remove ethereum network transactions
let txsCursor = await transaction.objectStore('txs').openCursor();

const accountsToUpdate = ['eth', 'etc', 'trop', 'tgor'];

while (txsCursor) {
const tx = txsCursor.value as DBWalletAccountTransactionCompatible;

if (accountsToUpdate.includes(tx.tx.symbol)) {
// eslint-disable-next-line no-await-in-loop
await txsCursor.delete();
} else {
tx.tx.internalTransfers = [];
// eslint-disable-next-line no-await-in-loop
await txsCursor.update(tx);
}
// eslint-disable-next-line no-await-in-loop
txsCursor = await txsCursor.continue();
}

// force to fetch ethereum network transactions again
let accountsCursor = await transaction.objectStore('accounts').openCursor();

while (accountsCursor) {
const account = accountsCursor.value;

if (accountsToUpdate.includes(account.symbol)) {
account.history = { total: 0, unconfirmed: 0, tokens: 0 };
// eslint-disable-next-line no-await-in-loop
await accountsCursor.update(account);
}

// eslint-disable-next-line no-await-in-loop
accountsCursor = await accountsCursor.continue();
}
}
};

0 comments on commit ddd24ef

Please sign in to comment.