Skip to content

Commit

Permalink
chore(cache): add type to cache and slice (#6222)
Browse files Browse the repository at this point in the history
  • Loading branch information
mperdomo-bc committed Jan 8, 2024
1 parent e6e9daa commit a7e2647
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const determineAuthenticationFlow = function* (
yield put(actions.auth.setMagicLinkInfo(authMagicLink))
yield put(
actions.auth.setProductAuthMetadata({
platform: platformType as PlatformTypes,
platform: platformType,
product: ProductAuthOptions.EXCHANGE,
redirect,
sessionIdMobile
Expand All @@ -157,7 +157,7 @@ export const determineAuthenticationFlow = function* (
// store data in the cache and update form values to be used to submit login
yield put(actions.cache.emailStored(walletData?.email))
yield put(actions.cache.guidStored(walletData?.guid))
yield put(actions.cache.mobileConnectedStored(walletData?.is_mobile_setup))
yield put(actions.cache.mobileConnectedStored(!!walletData?.is_mobile_setup))
yield put(actions.cache.hasCloudBackup(walletData?.has_cloud_backup))
yield put(actions.form.change(LOGIN_FORM, 'emailToken', walletData?.email_code))
yield put(actions.form.change(LOGIN_FORM, 'guid', walletData?.guid))
Expand Down
32 changes: 17 additions & 15 deletions packages/blockchain-wallet-v4-frontend/src/data/cache/slice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit'

const initialState = {
import { CacheType } from './types'

const initialState: CacheType = {
announcements: {},
channelChannelId: undefined,
channelPhonePubkey: undefined,
Expand All @@ -15,7 +17,7 @@ const initialState = {
lastUnusedAmounts: {},
mobileConnected: undefined,
noActionRequiredSweep: undefined,
unifiedAccount: undefined
unifiedAccount: false
}

const cacheSlice = createSlice({
Expand All @@ -30,43 +32,43 @@ const cacheSlice = createSlice({

state.announcements[id] = { ...state.announcements[id], collapsed }
},
channelChannelIdCreated: (state, action) => {
channelChannelIdCreated: (state, action: PayloadAction<CacheType['channelChannelId']>) => {
state.channelChannelId = action.payload
},
channelPhoneConnected: (state, action) => {
channelPhoneConnected: (state, action: PayloadAction<CacheType['channelPhonePubkey']>) => {
state.channelPhonePubkey = action.payload
},
channelPrivKeyCreated: (state, action) => {
channelPrivKeyCreated: (state, action: PayloadAction<CacheType['channelPrivKey']>) => {
state.channelPrivKey = action.payload
},
disconnectChannelPhone: (state) => {
state.channelPhonePubkey = undefined
},
emailStored: (state, action) => {
emailStored: (state, action: PayloadAction<CacheType['lastEmail']>) => {
state.lastEmail = action.payload
},
exchangeEmail: (state, action) => {
exchangeEmail: (state, action: PayloadAction<CacheType['exchangeEmail']>) => {
state.exchangeEmail = action.payload
},
exchangeWalletGuid: (state, action) => {
exchangeWalletGuid: (state, action: PayloadAction<CacheType['exchangeWalletGuid']>) => {
state.exchangeWalletGuid = action.payload
},
guidEntered: (state, action) => {
guidEntered: (state, action: PayloadAction<CacheType['lastGuid']>) => {
state.lastGuid = action.payload
},
guidStored: (state, action) => {
guidStored: (state, action: PayloadAction<CacheType['guidStored']>) => {
state.guidStored = action.payload
},
hasCloudBackup: (state, action) => {
hasCloudBackup: (state, action: PayloadAction<CacheType['hasCloudBackup']>) => {
state.hasCloudBackup = action.payload
},
lastLogoutTimestamp: (state, action) => {
lastLogoutTimestamp: (state, action: PayloadAction<CacheType['lastLogoutTimestamp']>) => {
state.lastLogoutTimestamp = action.payload
},
mobileConnectedStored: (state, action) => {
mobileConnectedStored: (state, action: PayloadAction<CacheType['mobileConnected']>) => {
state.mobileConnected = action.payload
},
noActionRequiredSweep: (state, action) => {
noActionRequiredSweep: (state, action: PayloadAction<CacheType['noActionRequiredSweep']>) => {
state.noActionRequiredSweep = action.payload
},
removeExchangeLogin: (state) => {
Expand Down Expand Up @@ -103,7 +105,7 @@ const cacheSlice = createSlice({
setLastUnusedAmount: (state, action: PayloadAction<{ amount: string; pair: string }>) => {
state.lastUnusedAmounts[action.payload.pair] = action.payload.amount
},
setUnifiedAccount: (state, action) => {
setUnifiedAccount: (state, action: PayloadAction<CacheType['unifiedAccount']>) => {
state.unifiedAccount = action.payload
}
}
Expand Down
23 changes: 23 additions & 0 deletions packages/blockchain-wallet-v4-frontend/src/data/cache/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type CacheType = {
announcements: Announcement
channelChannelId: string | undefined
channelPhonePubkey: string | undefined
channelPrivKey: string | undefined
exchangeEmail: string | undefined
exchangeWalletGuid: string | undefined
guidStored: string | undefined
hasCloudBackup: boolean | undefined
lastEmail: string | undefined
lastGuid: string | undefined
lastLogoutTimestamp: number | undefined
lastUnusedAmounts: UnusedAmmounts
mobileConnected: boolean | undefined
noActionRequiredSweep: ActionSweep | undefined
unifiedAccount: boolean | undefined
}

type Announcement = { [keyof: string]: { collapsed?: boolean; dismissed: boolean } }

type UnusedAmmounts = { [keyof: string]: string }

type ActionSweep = { guid: string; seen: boolean }
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default ({ api, coreSagas, networks }) => {
// TODO: use new world deeplinking once merged
const defineExchangeSettingsGoal = function* (search) {
const params = new URLSearchParams(search)
const guid = params.get('guid')
const guid = params.get('guid') ?? undefined
const settingsChange = params.get('change')
const email = decodeURIComponent(params.get('email') as string)
yield put(actions.cache.removeStoredLogin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ class Login extends PureComponent<InjectedFormProps<{}, Props> & Props> {
case LoginSteps.VERIFY_MAGIC_LINK:
return <VerifyMagicLink {...loginProps} />
case LoginSteps.SOFI_SUCCESS:
return <SofiSuccess {...loginProps} />

return <SofiSuccess />
case LoginSteps.ENTER_EMAIL_GUID:
default:
return product === ProductAuthOptions.EXCHANGE ? (
Expand Down

0 comments on commit a7e2647

Please sign in to comment.