Skip to content

Commit

Permalink
refactor: clean tx history and metadata first on wallet start
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruzenhack committed Apr 23, 2024
1 parent d573085 commit f8103a7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/sagas/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function* isWalletServiceEnabled() {

let walletServiceEnabled = yield call(checkForFeatureFlag, WALLET_SERVICE_FEATURE_TOGGLE);

// At this point the networkSettings already have been set by startWallet.
// At this point, the networkSettings have already been set by startWallet.
const networkSettings = yield select(getNetworkSettings);
if (walletServiceEnabled && isEmpty(networkSettings.walletServiceUrl)) {
// In case of an empty value for walletServiceUrl, it means the user
Expand All @@ -143,6 +143,13 @@ export function* startWallet(action) {
pin,
} = action.payload;

// clean memory storage and metadata before starting the wallet.
// This should be cleaned when stopping the wallet,
// but the wallet may be closed unexpectedly
const storage = STORE.getStorage();
yield call([storage.store, storage.store.cleanMetadata]); // clean metadata on memory
yield call([storage, storage.cleanStorage], true); // clean transaction history

// As this is a core setting for the wallet, it should be loaded first.
// Network settings either from store or redux state
let networkSettings;
Expand Down Expand Up @@ -172,13 +179,6 @@ export function* startWallet(action) {
yield put(setUseWalletService(useWalletService));
yield put(setAvailablePushNotification(usePushNotification));

// clean storage and metadata before starting the wallet
// this should be cleaned when stopping the wallet,
// but the wallet may be closed unexpectedly
const storage = STORE.getStorage();
yield storage.store.cleanMetadata();
yield storage.cleanStorage(true);

// This is a work-around so we can dispatch actions from inside callbacks.
let dispatch;
yield put((_dispatch) => {
Expand Down

0 comments on commit f8103a7

Please sign in to comment.