Skip to content

Commit

Permalink
fix: remove registered tokens when changing network settings (#475)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alexruzenhack authored and andreabadesso committed Jun 24, 2024
1 parent a59de91 commit 7c7e2af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sagas/networkSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
types,
reloadWalletRequested,
onExceptionCaptured,
networkSettingsUpdateReady
networkSettingsUpdateReady,
} from '../actions';
import {
NETWORK_MAINNET,
Expand All @@ -23,7 +23,7 @@ import {
STAGE_DEV_PRIVNET,
STAGE_TESTNET,
WALLET_SERVICE_REQUEST_TIMEOUT,
NETWORK_PRIVATENET
NETWORK_PRIVATENET,
} from '../constants';
import {
getFullnodeNetwork,
Expand Down Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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 */

Expand Down

0 comments on commit 7c7e2af

Please sign in to comment.