From 91a3e2f31240566b0003c3bb2565b9c47e0ba5e0 Mon Sep 17 00:00:00 2001 From: Naveed Elahi Date: Thu, 5 Oct 2023 15:44:22 +0800 Subject: [PATCH 1/2] fix missing token due to mismatched case of addr --- src/controllers/PreferencesController.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/controllers/PreferencesController.js b/src/controllers/PreferencesController.js index 5cbfcb699..df6b39bae 100644 --- a/src/controllers/PreferencesController.js +++ b/src/controllers/PreferencesController.js @@ -24,7 +24,17 @@ import { } from '../utils/enums' import { notifyUser } from '../utils/notifications' import { setSentryEnabled } from '../utils/sentry' -import { formatDate, formatPastTx, formatTime, getEthTxStatus, getIFrameOrigin, getUserLanguage, isMain, waitForMs } from '../utils/utils' +import { + formatDate, + formatPastTx, + formatTime, + getEthTxStatus, + getIFrameOrigin, + getUserLanguage, + isMain, + toChecksumAddressByChainId, + waitForMs, +} from '../utils/utils' import { ObservableStore } from './utils/ObservableStore' import { isErrorObject, prettyPrintData } from './utils/permissionUtils' @@ -311,8 +321,10 @@ class PreferencesController extends SafeEventEmitter { const selectedAddress = address || this.store.getState().selectedAddress const currentState = this.state(selectedAddress) || cloneDeep(DEFAULT_ACCOUNT_STATE) const mergedState = deepmerge(currentState, newPartialState, { arrayMerge: overwriteMerge }) + const chainId = this.network.getCurrentChainId() + const checksumAddress = toChecksumAddressByChainId(selectedAddress, chainId) this.store.updateState({ - [selectedAddress]: mergedState, + [checksumAddress]: mergedState, }) return mergedState } @@ -784,7 +796,7 @@ class PreferencesController extends SafeEventEmitter { normalizedAddChainParams(id, addChainParams) { /** * addChainParams interface - * + * * interface AddEthereumChainParameter { chainId: string; // A 0x-prefixed hexadecimal string chainName: string; From 9963a07900ded6a4f2e1e7991b9397cf799a8bb6 Mon Sep 17 00:00:00 2001 From: Naveed Elahi Date: Fri, 6 Oct 2023 17:59:08 +0800 Subject: [PATCH 2/2] transform user api response to correct address case --- src/controllers/PreferencesController.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/controllers/PreferencesController.js b/src/controllers/PreferencesController.js index df6b39bae..d3b247ae8 100644 --- a/src/controllers/PreferencesController.js +++ b/src/controllers/PreferencesController.js @@ -227,6 +227,11 @@ class PreferencesController extends SafeEventEmitter { customNetworks, } = user.data || {} + // transform addresses that were saved as lowercase in our db + const chainId = this.network.getCurrentChainId() + const publicAddress = toChecksumAddressByChainId(public_address, chainId) + const defaultPublicAddress = toChecksumAddressByChainId(default_public_address) || publicAddress + this.updateStore( { contacts, @@ -236,11 +241,11 @@ class PreferencesController extends SafeEventEmitter { locale: locale || getUserLanguage(), permissions, accountType: account_type || ACCOUNT_TYPE.NORMAL, - defaultPublicAddress: default_public_address || public_address, + defaultPublicAddress, customTokens, customNfts, }, - public_address + publicAddress ) // update network controller with all the custom network updates. @@ -321,10 +326,8 @@ class PreferencesController extends SafeEventEmitter { const selectedAddress = address || this.store.getState().selectedAddress const currentState = this.state(selectedAddress) || cloneDeep(DEFAULT_ACCOUNT_STATE) const mergedState = deepmerge(currentState, newPartialState, { arrayMerge: overwriteMerge }) - const chainId = this.network.getCurrentChainId() - const checksumAddress = toChecksumAddressByChainId(selectedAddress, chainId) this.store.updateState({ - [checksumAddress]: mergedState, + [selectedAddress]: mergedState, }) return mergedState }