Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove registered tokens when changing network settings #475

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is needed to also clean the app's AsyncStorage managed by the HybridStore.

super.cleanStorage(cleanHistory, cleanAddresses, cleanTokens);
if (cleanTokens) {
// Remove from the cache
STORE.removeItem(REGISTERED_TOKENS_KEY);
}
}
}
/* eslint-enable class-methods-use-this */

Expand Down
Loading