Skip to content

Commit

Permalink
feat: it extends HibridStore cleanStorage to also clean the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruzenhack committed May 24, 2024
1 parent ead5616 commit 2a95261
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 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,13 +23,13 @@ import {
STAGE_DEV_PRIVNET,
STAGE_TESTNET,
WALLET_SERVICE_REQUEST_TIMEOUT,
NETWORK_PRIVATENET
NETWORK_PRIVATENET,
} from '../constants';
import {
getFullnodeNetwork,
getWalletServiceNetwork,
} from './helpers';
import { REGISTERED_TOKENS_KEY, STORE } from '../store';
import { STORE } from '../store';
import { isWalletServiceEnabled } from './wallet';
import { logger } from '../logger';

Expand Down Expand Up @@ -299,8 +299,8 @@ export function* persistNetworkSettings(action) {
return;
}

// Remove registered tokens
STORE.removeItem(REGISTERED_TOKENS_KEY);
// Remove registered tokens only
yield call([wallet.storage, wallet.storage.cleanStorage], false, false, true)
// Stop wallet and clean its storage without clean its access data.
wallet.stop({ cleanStorage: true, cleanAddresses: true });
// This action should clean the tokens history on redux.
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 2a95261

Please sign in to comment.