From 7c7e2afc36764943cffa4cf2ef4a71c2e777142b Mon Sep 17 00:00:00 2001 From: Alex Ruzenhack Date: Tue, 28 May 2024 01:44:06 +0100 Subject: [PATCH] fix: remove registered tokens when changing network settings (#475) * fix: remove registered tokens when changing network settings * feat: it extends HibridStore cleanStorage to also clean the cache * feat: remove cleanStorage and add cleanTokens when calling wallet.stop --- src/sagas/networkSettings.js | 6 +++--- src/store.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/sagas/networkSettings.js b/src/sagas/networkSettings.js index ea02c3ef8..60eeddcbe 100644 --- a/src/sagas/networkSettings.js +++ b/src/sagas/networkSettings.js @@ -12,7 +12,7 @@ import { types, reloadWalletRequested, onExceptionCaptured, - networkSettingsUpdateReady + networkSettingsUpdateReady, } from '../actions'; import { NETWORK_MAINNET, @@ -23,7 +23,7 @@ import { STAGE_DEV_PRIVNET, STAGE_TESTNET, WALLET_SERVICE_REQUEST_TIMEOUT, - NETWORK_PRIVATENET + NETWORK_PRIVATENET, } from '../constants'; import { getFullnodeNetwork, @@ -300,7 +300,7 @@ export function* persistNetworkSettings(action) { } // Stop wallet and clean its storage without clean its access data. - wallet.stop({ cleanStorage: true, cleanAddresses: true }); + wallet.stop({ cleanStorage: true, cleanAddresses: true, cleanTokens: true }); // This action should clean the tokens history on redux. // In addition, the reload also clean the inmemory storage. yield put(reloadWalletRequested()); diff --git a/src/store.js b/src/store.js index 88d6fcb93..9bf8cd037 100644 --- a/src/store.js +++ b/src/store.js @@ -143,6 +143,22 @@ class HybridStore extends MemoryStore { contracts[ncId] = ncValue; STORE.setItem(REGISTERED_NANO_CONTRACTS_KEY, contracts) } + + /** + * Clean the storage. + * @param {boolean} cleanHistory if we should clean the transaction history. + * @param {boolean} cleanAddresses if we should clean the addresses. + * @param {boolean} cleanTokens if we should clean the registered tokens. + * @async + * @returns {Promise} + */ + async cleanStorage(cleanHistory = false, cleanAddresses = false, cleanTokens = false) { + super.cleanStorage(cleanHistory, cleanAddresses, cleanTokens); + if (cleanTokens) { + // Remove from the cache + STORE.removeItem(REGISTERED_TOKENS_KEY); + } + } } /* eslint-enable class-methods-use-this */