Skip to content

Commit

Permalink
chore(sso): typing errors fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Han committed Sep 29, 2021
1 parent 3df6162 commit f653388
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function isAuthenticated(state: RootState): AuthStateType['isAuthenticate
}

export function getRegistering(state: RootState): AuthStateType['registering'] {
return state.auth.isAuthenticated
return state.auth.registering
}

export function getFirstLogin(state: RootState): AuthStateType['firstLogin'] {
Expand All @@ -22,11 +22,11 @@ export function getAuthType(state: RootState): AuthStateType['auth_type'] {
return state.auth.auth_type
}

export function getDesignedProduct(state: RootState): AuthStateType['designatedProduct'] {
return state.auth.designedProduct
export function getDesignatedProduct(state: RootState): AuthStateType['designatedProduct'] {
return state.auth.designatedProduct
}

export function getSecuredChannelLogin(state: RootState): AuthStateType['secureChannelLogin'] {
export function getSecureChannelLogin(state: RootState): AuthStateType['secureChannelLogin'] {
return state.auth.secureChannelLogin
}

Expand Down
55 changes: 36 additions & 19 deletions packages/blockchain-wallet-v4-frontend/src/data/auth/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'

import { Remote } from '@core'

import { AccountUnificationFlows, AuthStateType, ProductAuthOptions } from './types'
import {
AccountUnificationFlows,
AuthStateType,
LoginFailureType,
LoginSuccessType,
MetadataRestoreType,
ProductAuthOptions,
RegisteringFailureType,
RegisteringSuccessType,
RestoringType,
SecureChannelLoginType
} from './types'

const initialState: AuthStateType = {
accountUnificationFlow: undefined,
Expand Down Expand Up @@ -58,14 +69,14 @@ const authSlice = createSlice({
login: (state, action) => {
state.isLoggingIn = true
},
loginFailure: (state, action) => {
loginFailure: (state, action: PayloadAction<LoginFailureType>) => {
state.login = Remote.Failure(action.payload)
},
loginLoading: (state) => {
state.login = Remote.Loading
},
loginRoutine: (state, action) => {},
loginSuccess: (state, action) => {
loginSuccess: (state, action: PayloadAction<LoginSuccessType>) => {
state.login = Remote.Success(action.payload)
},
mobileLogin: (state, action) => {},
Expand All @@ -77,13 +88,13 @@ const authSlice = createSlice({
},
pingManifestFile: () => {},
register: (state, action) => {},
registerFailure: (state, action) => {
registerFailure: (state, action: PayloadAction<RegisteringFailureType>) => {
state.registering = Remote.Failure(action.payload)
},
registerLoading: (state) => {
state.registering = Remote.Loading
},
registerSuccess: (state, action) => {
registerSuccess: (state, action: PayloadAction<RegisteringSuccessType>) => {
state.registering = Remote.Success(action.payload)
},
resendSmsCode: (state, action) => {},
Expand All @@ -94,22 +105,22 @@ const authSlice = createSlice({
restore: (state, action) => {},
restoreFailure: () => {},
restoreFromMetadata: (state, action) => {},
restoreFromMetadataFailure: (state, action) => {
restoreFromMetadataFailure: (state, action: PayloadAction<{ e: unknown }>) => {
state.metadataRestore = Remote.Failure(action.payload)
},
restoreFromMetadataLoading: (state) => {
state.metadataRestore = Remote.Loading
},
restoreFromMetadataSuccess: (state, action) => {
restoreFromMetadataSuccess: (state, action: PayloadAction<MetadataRestoreType>) => {
state.metadataRestore = Remote.Success(action.payload)
},
restoreLoading: (state) => {
state.restoring = Remote.Loading
},
restoreSuccess: (state, action) => {
restoreSuccess: (state, action: PayloadAction<RestoringType>) => {
state.restoring = Remote.Success(action.payload)
},
secureChannelLoginFailure: (state, action) => {
secureChannelLoginFailure: (state, action: PayloadAction<string>) => {
state.secureChannelLogin = Remote.Failure(action.payload)
},
secureChannelLoginLoading: (state) => {
Expand All @@ -118,7 +129,7 @@ const authSlice = createSlice({
secureChannelLoginNotAsked: (state) => {
state.secureChannelLogin = Remote.NotAsked
},
secureChannelLoginSuccess: (state, action) => {
secureChannelLoginSuccess: (state, action: PayloadAction<SecureChannelLoginType>) => {
state.secureChannelLogin = Remote.Success(action.payload)
},
setAccountUnificationFlowType: (state, action: PayloadAction<AccountUnificationFlows>) => {
Expand All @@ -127,7 +138,13 @@ const authSlice = createSlice({
setAuthType: (state, action) => {
state.auth_type = action.payload
},
setDesignatedProductMetadata: (state, action) => {
setDesignatedProductMetadata: (
state,
action: PayloadAction<{
designatedProduct: string | null
designatedProductRedirect: AuthStateType['designatedProductRedirect'] | null
}>
) => {
const { designatedProduct, designatedProductRedirect } = action.payload
// TODO: update to check for explorer when applicable
if (designatedProduct && designatedProduct.toUpperCase() === ProductAuthOptions.WALLET) {
Expand All @@ -142,28 +159,28 @@ const authSlice = createSlice({
state.designatedProductRedirect = designatedProductRedirect
}
},
setFirstLogin: (state, action) => {
setFirstLogin: (state, action: PayloadAction<AuthStateType['firstLogin']>) => {
state.firstLogin = action.payload
},
setKycResetStatus: (state, action) => {
setKycResetStatus: (state, action: PayloadAction<AuthStateType['kycReset']>) => {
state.kycReset = action.payload
},
setMagicLinkInfo: (state, action) => {
setMagicLinkInfo: (state, action: PayloadAction<AuthStateType['magicLinkData']>) => {
state.magicLinkData = action.payload
},
setManifestFile: (state, action) => {
setManifestFile: (state, action: PayloadAction<AuthStateType['manifestFile']>) => {
state.manifestFile = action.payload
},
setRegisterEmail: (state, action) => {
setRegisterEmail: (state, action: PayloadAction<AuthStateType['registerEmail']>) => {
state.registerEmail = action.payload
},
setResetAccount: (state, action) => {
setResetAccount: (state, action: PayloadAction<AuthStateType['resetAccount']>) => {
state.resetAccount = action.payload
},
setResetLogin: (state, action) => {
setResetLogin: (state, action: PayloadAction<AuthStateType['resetAccount']>) => {
state.resetAccount = action.payload
},
setUserGeoLocation: (state, action) => {
setUserGeoLocation: (state, action: PayloadAction<AuthStateType['userGeoData']>) => {
state.userGeoData = action.payload
},
signupDetailsEntered: (state, action) => {},
Expand Down
85 changes: 20 additions & 65 deletions packages/blockchain-wallet-v4-frontend/src/data/auth/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { actions } from './slice'
import { RemoteDataType } from '@core/types'

export enum ProductAuthOptions {
EXCHANGE = 'EXCHANGE',
Expand Down Expand Up @@ -115,6 +115,20 @@ export type LoginErrorType =
}
| string

export type LoginSuccessType = {}

export type LoginFailureType = string | boolean | undefined

export type MetadataRestoreType = any

export type RegisteringFailureType = undefined

export type RegisteringSuccessType = undefined

export type RestoringType = undefined

export type SecureChannelLoginType = undefined

export type AuthStateType = {
accountUnificationFlow?: AccountUnificationFlows
auth_type: number
Expand All @@ -124,74 +138,15 @@ export type AuthStateType = {
isAuthenticated: boolean
isLoggingIn: boolean
kycReset?: boolean
// TODO: make this type more specific
login: any
login: RemoteDataType<LoginFailureType, LoginSuccessType>
magicLinkData?: WalletDataFromMagicLink
manifestFile: any
metadataRestore: any
metadataRestore: RemoteDataType<string, MetadataRestoreType>
mobileLoginStarted: boolean
registerEmail?: string
registering: any
registering: RemoteDataType<RegisteringFailureType, RegisteringSuccessType>
resetAccount: boolean
restoring: any
secureChannelLogin: any
restoring: RemoteDataType<string, RestoringType>
secureChannelLogin: RemoteDataType<string, SecureChannelLoginType>
userGeoData: any
}
// actions

interface LoginFailureActionType {
payload: {
err?: string
}
type: typeof actions.loginFailure.type
}
interface InitializeLoginSuccessActionType {
type: typeof actions.initializeLoginSuccess.type
}

interface InitializeLoginLoadingActionType {
type: typeof actions.initializeLoginLoading.type
}

interface InitializeLoginFailureActionType {
type: typeof actions.initializeLoginFailure.type
}

interface LoginRouteSagaActionType {
payload: {
email?: string
firstLogin?: boolean
mobileLogin?: boolean
}
type: typeof actions.loginRoutine.type
}

interface TriggerWalletMagicLinkSuccessActionType {
type: typeof actions.triggerWalletMagicLinkSuccess.type
}

interface TriggerWalletMagicLinkLoadingActionType {
type: typeof actions.triggerWalletMagicLinkLoading.type
}

interface TriggerWalletMagicLinkFailureActionType {
type: typeof actions.triggerWalletMagicLinkFailure
}

interface SetMagicLinkInfoActionType {
payload: {
magicLinkInfo: WalletDataFromMagicLink
}
type: typeof actions.setMagicLinkInfo.type
}

export type AuthActionTypes =
| LoginFailureActionType
| LoginRouteSagaActionType
| InitializeLoginFailureActionType
| InitializeLoginLoadingActionType
| InitializeLoginSuccessActionType
| SetMagicLinkInfoActionType
| TriggerWalletMagicLinkFailureActionType
| TriggerWalletMagicLinkLoadingActionType
| TriggerWalletMagicLinkSuccessActionType

0 comments on commit f653388

Please sign in to comment.