diff --git a/package.json b/package.json index be7b62a8..074ff02f 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "decimal.js": "^10.2.1", "formik": "^2.2.9", "google-protobuf": "^3.15.8", - "ldk": "^0.5.4", + "ldk": "^0.5.8", "lodash.debounce": "^4.0.8", "lottie-web": "^5.7.8", "marina-provider": "^1.7.2", diff --git a/src/application/redux/reducers/index.ts b/src/application/redux/reducers/index.ts index 723c60e9..1d4a885f 100644 --- a/src/application/redux/reducers/index.ts +++ b/src/application/redux/reducers/index.ts @@ -107,7 +107,7 @@ const marinaReducer = combineReducers({ reducer: walletReducer, key: 'wallet', blacklist: ['deepRestorer', 'updaterLoaders'], - version: 4, + version: 5, migrate: walletMigrate, }), taxi: persist({ diff --git a/src/domain/migrations.ts b/src/domain/migrations.ts index 7a3b4421..22e44fff 100644 --- a/src/domain/migrations.ts +++ b/src/domain/migrations.ts @@ -9,8 +9,11 @@ import type { MasterBlindingKey } from './master-blinding-key'; import type { MasterXPub } from './master-extended-pub'; import type { WalletState } from './wallet'; +// v5 only erases the current transactions state for all accounts during migration +export type WalletPersistedStateV5 = WalletState & Partial; + // v4 is a fixed version of v3 about covenantTemplate field in CustomAccountData -export type WalletPersistedStateV4 = WalletState & Partial; +export type WalletPersistedStateV4 = WalletPersistedStateV5; export type WalletPersistedStateV3 = WalletPersistedStateV4; type keysAddedInV3 = 'encryptedMnemonic' | 'accounts'; @@ -30,6 +33,10 @@ type deletedInV2 = { export type WalletPersistedStateV1 = Omit & deletedInV2; export const walletMigrations = { + 5: (state: WalletPersistedStateV4): WalletPersistedStateV5 => ({ + ...state, + unspentsAndTransactions: removeTransactions(state.unspentsAndTransactions), + }), 4: (state: WalletPersistedStateV3) => ({ ...state, accounts: accountsFieldRenameV4(state.accounts), @@ -78,5 +85,20 @@ function accountsFieldRenameV4( } return renamed; } + +function removeTransactions( + utxosAndTxs: WalletPersistedStateV4['unspentsAndTransactions'] +): WalletPersistedStateV5['unspentsAndTransactions'] { + const result: WalletPersistedStateV5['unspentsAndTransactions'] = {}; + for (const [accountID, utxosTxsByNetwork] of Object.entries(utxosAndTxs)) { + result[accountID] = { + liquid: { ...utxosTxsByNetwork.liquid, transactions: {} }, + testnet: { ...utxosTxsByNetwork.testnet, transactions: {} }, + regtest: { ...utxosTxsByNetwork.regtest, transactions: {} }, + }; + } + return result; +} + // `as any` is needed (redux-persist doesn't support generic types in createMigrate func) export const walletMigrate = createMigrate(walletMigrations as any); diff --git a/yarn.lock b/yarn.lock index ccefe939..17d28797 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6553,10 +6553,10 @@ ldk@^0.5.2: slip77 "^0.2.0" tslib "^2.3.1" -ldk@^0.5.4: - version "0.5.4" - resolved "https://registry.yarnpkg.com/ldk/-/ldk-0.5.4.tgz#20240f318a5f047d2023adec02f1eae466278042" - integrity sha512-55f6Xd79L0WyRoMdhF1Ebk3efO9Nslcr0Z68ViAZvGF4j3Yo54yQQESgWa7PMHw5RSRxe0pKHQbF3nPmpmGURA== +ldk@^0.5.8: + version "0.5.8" + resolved "https://registry.yarnpkg.com/ldk/-/ldk-0.5.8.tgz#c9ee3af9397843cb166689789e39d4e9c0d25f67" + integrity sha512-IMsMKRxFNFhgM1SaqaCI84ABVTV9nd3AzXMP1zeX5ByD/R5lnWhzy9xrz8xxPsf1kSCEBs/N0uA1twSXQznuVw== dependencies: axios "^0.21.1" bip32 "^3.0.1"