Skip to content

Commit

Permalink
try to fix some session namespace & whitelabel stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Jan 12, 2023
1 parent 93a0762 commit 474fb77
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 45 deletions.
21 changes: 0 additions & 21 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -468,27 +468,6 @@
if (torusTheme) {
theme = torusTheme.split('-')[0]
}
if (storageAvailable('sessionStorage')) {
const torusWhiteLabel = sessionStorage.getItem('torus-white-label')
if (torusWhiteLabel !== null) {
try {
const whiteLabelData = JSON.parse(torusWhiteLabel)
if (whiteLabelData.theme) {
theme = whiteLabelData.theme.isDark ? 'dark' : 'light'
if (whiteLabelData.theme.colors && whiteLabelData.theme.colors.torusBrand1) {
const redirectSpinner = document.querySelector('#skeleton-redirect-spinner')
const redirectSpinnerHead = document.querySelector('#skeleton-redirect-spinner .head')
const redirectSpinnerMask = document.querySelector('#skeleton-redirect-spinner .mask')
redirectSpinner.style.backgroundColor = whiteLabelData.theme.colors.torusBrand1
redirectSpinner.style.background = `conic-gradient(transparent, ${whiteLabelData.theme.colors.torusBrand1})`
redirectSpinnerHead.style.backgroundColor = whiteLabelData.theme.colors.torusBrand1
}
}
} catch (error) {
console.error(error)
}
}
}
}

if (theme === 'dark') document.querySelector('body').style.backgroundColor = '#24252A'
Expand Down
16 changes: 1 addition & 15 deletions src/controllers/PreferencesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,14 @@ class PreferencesController extends SafeEventEmitter {
customNfts,
customNetworks,
} = user.data || {}
let whiteLabelLocale

// White Label override
if (config.sessionStorageAvailable) {
let torusWhiteLabel = sessionStorage.getItem('torus-white-label')
if (torusWhiteLabel) {
try {
torusWhiteLabel = JSON.parse(torusWhiteLabel)
whiteLabelLocale = torusWhiteLabel.defaultLanguage
} catch (error) {
log.error(error)
}
}
}

this.updateStore(
{
contacts,
theme,
crashReport: Boolean(enable_crash_reporter),
selectedCurrency: defaultCurrency,
locale: whiteLabelLocale || locale || getUserLanguage(),
locale: locale || getUserLanguage(),
permissions,
accountType: account_type || ACCOUNT_TYPE.NORMAL,
defaultPublicAddress: default_public_address || public_address,
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/Auth/OpenLoginHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import log from 'loglevel'
import config from '../../config'
import { ACCOUNT_TYPE } from '../../utils/enums'
import { get, post, put } from '../../utils/httpHelpers'
import { generateAddressFromPrivateKey, generateTorusAuthHeaders, getIFrameOriginObject } from '../../utils/utils'
import { generateAddressFromPrivateKey, generateTorusAuthHeaders, getIFrameOriginObject, storageUtils } from '../../utils/utils'

const getOpenloginWhitelabel = (whiteLabel = {}) => {
const whiteLabelOpenLogin = {}
Expand Down Expand Up @@ -70,6 +70,7 @@ class OpenLoginHandler {
network: config.torusNetwork,
no3PC: true,
_sessionNamespace: sessionNamespace || namespace,
storageKey: storageUtils.storageType,
})
}

Expand Down
1 change: 1 addition & 0 deletions src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default {
}
}
statusStream.write({ loggedIn: false })
sessionStorage.removeItem('torus-white-label')
resetStore(accountTracker.store, accountTrackerHandler)
resetStore(txController.store, transactionControllerHandler)
resetStore(assetController.store, assetControllerHandler)
Expand Down
7 changes: 2 additions & 5 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,11 @@ export default {
state.embedState = { ...state.embedState, buttonSize: payload || 56 }
},
async setWhiteLabel(state, payload) {
if (!payload && config.sessionStorageAvailable) {
if (!payload) {
state.whiteLabel = {
isActive: false,
}
localThemeSet(THEME_LIGHT_BLUE_NAME, state)
sessionStorage.removeItem('torus-white-label')
return
}
state.whiteLabel = {
Expand All @@ -192,7 +191,7 @@ export default {
}
localThemeSet(undefined, state)
// Set locale here from defaultLanguage
if (config.sessionStorageAvailable && payload) {
if (payload) {
// Checks if whitelabel defaultLanguage is supported
const selectedLocale = LOCALES.find((localeInner) => localeInner.value === payload.defaultLanguage)
if (selectedLocale) {
Expand All @@ -205,8 +204,6 @@ export default {
i18n.mergeLocaleMessage(key, payload.customTranslations[key])
})
}

sessionStorage.setItem('torus-white-label', JSON.stringify(payload))
}
},
setOAuthModalStatus(state, payload) {
Expand Down
5 changes: 2 additions & 3 deletions src/torus.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Web3 from 'web3'
import config from './config'
import TorusController from './controllers/TorusController'
import setupMultiplex from './controllers/utils/setupMultiplex'
import { getDefaultNetwork, getIFrameOrigin, getIFrameOriginObject, isMain } from './utils/utils'
import { getDefaultNetwork, getIFrameOrigin, isMain, storageUtils } from './utils/utils'
// import store from './store'
let storeReference
let deferredDispatch = []
Expand Down Expand Up @@ -39,8 +39,7 @@ const torus = {
let sessionData

if (config.localStorageAvailable) {
const storage = !isMain ? (config.isCustomLogin === null ? window.sessionStorage : window.localStorage) : window.localStorage
const storageKey = config.isCustomLogin === true ? `torus_app_${getIFrameOriginObject().hostname}` : 'torus-app'
const { storage, storageKey } = storageUtils
sessionData = storage.getItem(storageKey)
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ export const getIFrameOriginObject = () => {

export const storageUtils = {
storage: !isMain ? (config.isCustomLogin === null ? window.sessionStorage : window.localStorage) : window.localStorage,
storageType: !isMain ? (config.isCustomLogin === null ? 'session' : 'local') : 'local',
storageKey: config.isCustomLogin === true ? `torus_app_${config.namespace || getIFrameOriginObject().hostname}` : 'torus-app',
openloginStoreKey: config.isCustomLogin === true ? `openlogin_store_${config.namespace || getIFrameOriginObject().hostname}` : 'openlogin_store',
}
Expand Down

0 comments on commit 474fb77

Please sign in to comment.