From d573085971c02c47b0132929d4de8a6eb656dd2c Mon Sep 17 00:00:00 2001 From: Alex Ruzenhack Date: Mon, 22 Apr 2024 18:42:43 +0100 Subject: [PATCH 1/2] fix: useWalletService by forcefully disabling it when wallet service URL is empty --- src/sagas/wallet.js | 53 +++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/sagas/wallet.js b/src/sagas/wallet.js index c275e7382..21f068c7e 100644 --- a/src/sagas/wallet.js +++ b/src/sagas/wallet.js @@ -122,7 +122,17 @@ export function* isWalletServiceEnabled() { yield call(() => AsyncStorage.removeItem(IGNORE_WS_TOGGLE_FLAG)); } - const walletServiceEnabled = yield call(checkForFeatureFlag, WALLET_SERVICE_FEATURE_TOGGLE); + let walletServiceEnabled = yield call(checkForFeatureFlag, WALLET_SERVICE_FEATURE_TOGGLE); + + // At this point the networkSettings already have 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 + // doesn't intend to use the Wallet Service. Therefore, we need to force + // a disable on it. + walletServiceEnabled = false; + yield put(setUseWalletService(false)); + } return walletServiceEnabled; } @@ -133,26 +143,7 @@ export function* startWallet(action) { pin, } = action.payload; - const uniqueDeviceId = getUniqueId(); - const useWalletService = yield call(isWalletServiceEnabled); - const usePushNotification = yield call(isPushNotificationEnabled); - - 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) => { - dispatch = _dispatch; - }); - + // As this is a core setting for the wallet, it should be loaded first. // Network settings either from store or redux state let networkSettings; // Custom network settings are persisted in the app storage @@ -174,6 +165,26 @@ export function* startWallet(action) { networkSettings = yield select(getNetworkSettings); } + const uniqueDeviceId = getUniqueId(); + const useWalletService = yield call(isWalletServiceEnabled); + const usePushNotification = yield call(isPushNotificationEnabled); + + 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) => { + dispatch = _dispatch; + }); + let wallet; if (useWalletService && !isEmpty(networkSettings.walletServiceUrl)) { const network = new Network(networkSettings.network); From f8103a71253759318732960cc1ce5f4babc94594 Mon Sep 17 00:00:00 2001 From: Alex Ruzenhack Date: Tue, 23 Apr 2024 13:47:03 +0100 Subject: [PATCH 2/2] refactor: clean tx history and metadata first on wallet start --- src/sagas/wallet.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sagas/wallet.js b/src/sagas/wallet.js index 21f068c7e..05c20b0f0 100644 --- a/src/sagas/wallet.js +++ b/src/sagas/wallet.js @@ -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 @@ -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; @@ -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) => {