Skip to content

Commit 3a2bf28

Browse files
committed
Fix missing security alerts scene
1 parent df20ab3 commit 3a2bf28

5 files changed

Lines changed: 36 additions & 28 deletions

File tree

src/actions/LoginActions.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import { lstrings } from '../locales/strings'
2525
import type { WalletCreateItem } from '../selectors/getCreateWalletList'
2626
import { config } from '../theme/appConfig'
2727
import type { Dispatch, GetState, ThunkAction } from '../types/reduxTypes'
28-
import type { EdgeAppSceneProps, NavigationBase } from '../types/routerTypes'
28+
import type {
29+
EdgeAppSceneProps,
30+
NavigationBase,
31+
RootSceneProps
32+
} from '../types/routerTypes'
2933
import { currencyCodesToEdgeAssets } from '../util/CurrencyInfoHelpers'
3034
import { logActivity } from '../util/logger'
3135
import { logEvent, trackError } from '../util/tracking'
@@ -52,12 +56,11 @@ const PER_WALLET_TIMEOUT = 5000
5256
const MIN_CREATE_WALLET_TIMEOUT = 20000
5357

5458
export function initializeAccount(
55-
navigation: NavigationBase,
59+
navigation: RootSceneProps<'login'>['navigation'],
5660
account: EdgeAccount
5761
): ThunkAction<Promise<void>> {
5862
return async (dispatch, getState) => {
5963
const { newAccount } = account
60-
const rootNavigation = getRootNavigation(navigation)
6164

6265
// Load all settings upfront so we can navigate immediately after LOGIN
6366
const [syncedSettings, localSettings] = await Promise.all([
@@ -80,15 +83,15 @@ export function initializeAccount(
8083
// Navigate immediately - all settings are now in Redux
8184
if (newAccount) {
8285
await navigateToNewAccountFlow(
83-
rootNavigation,
86+
navigation,
8487
account,
8588
syncedSettings,
8689
referralPromise,
8790
dispatch,
8891
getState
8992
)
9093
} else {
91-
navigateToExistingAccountHome(rootNavigation, referralPromise)
94+
navigateToExistingAccountHome(navigation, referralPromise)
9295
}
9396

9497
performance.mark('loginEnd', { detail: { isNewAccount: newAccount } })
@@ -143,6 +146,9 @@ export function initializeAccount(
143146

144147
// Check for security alerts:
145148
if (hasSecurityAlerts(account)) {
149+
// This is not the normal security alerts scene!
150+
// Since we only have access to the root navigator,
151+
// this scene exists as a peer of the main app:
146152
navigation.push('securityAlerts')
147153
hideSurvey = true
148154
}
@@ -208,7 +214,7 @@ export function initializeAccount(
208214
* Navigate to wallet creation flow for new accounts.
209215
*/
210216
async function navigateToNewAccountFlow(
211-
rootNavigation: NavigationBase,
217+
navigation: RootSceneProps<'login'>['navigation'],
212218
account: EdgeAccount,
213219
syncedSettings: SyncedAccountSettings,
214220
referralPromise: Promise<void>,
@@ -279,7 +285,7 @@ async function navigateToNewAccountFlow(
279285
)
280286
}
281287

282-
rootNavigation.replace('edgeApp', {
288+
navigation.replace('edgeApp', {
283289
screen: 'edgeAppStack',
284290
params: {
285291
screen: 'createWalletSelectCryptoNewAccount',
@@ -296,11 +302,11 @@ async function navigateToNewAccountFlow(
296302
* Navigate to home screen for existing accounts.
297303
*/
298304
function navigateToExistingAccountHome(
299-
rootNavigation: NavigationBase,
305+
navigation: RootSceneProps<'login'>['navigation'],
300306
referralPromise: Promise<void>
301307
): void {
302308
const { defaultScreen } = getDeviceSettings()
303-
rootNavigation.replace('edgeApp', {
309+
navigation.replace('edgeApp', {
304310
screen: 'edgeAppStack',
305311
params: {
306312
screen: 'edgeTabs',

src/components/Main.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,11 @@ export const Main: React.FC = () => {
12801280
return <LoginScene {...props} />
12811281
}}
12821282
</RootStack.Screen>
1283+
1284+
<RootStack.Screen
1285+
name="securityAlerts"
1286+
component={SecurityAlertsScene}
1287+
/>
12831288
</RootStack.Navigator>
12841289
{navigation == null ? null : (
12851290
<DeepLinkingManager navigation={navigation} />

src/components/scenes/LoginScene.tsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ export const LoginScene: React.FC<Props> = props => {
7777
context
7878
.loginWithPIN(YOLO_USERNAME, YOLO_PIN)
7979
.then(async account => {
80-
await dispatch(
81-
initializeAccount(navigation as NavigationBase, account)
82-
)
80+
await dispatch(initializeAccount(navigation, account))
8381
})
8482
.catch((error: unknown) => {
8583
showError(error)
@@ -89,9 +87,7 @@ export const LoginScene: React.FC<Props> = props => {
8987
context
9088
.loginWithPassword(YOLO_USERNAME, YOLO_PASSWORD)
9189
.then(async account => {
92-
await dispatch(
93-
initializeAccount(navigation as NavigationBase, account)
94-
)
90+
await dispatch(initializeAccount(navigation, account))
9591
})
9692
.catch((error: unknown) => {
9793
showError(error)
@@ -110,9 +106,7 @@ export const LoginScene: React.FC<Props> = props => {
110106
useLoginId: true
111107
})
112108
.then(async account => {
113-
await dispatch(
114-
initializeAccount(navigation as NavigationBase, account)
115-
)
109+
await dispatch(initializeAccount(navigation, account))
116110
})
117111
.catch((error: unknown) => {
118112
showError(error)
@@ -144,11 +138,9 @@ export const LoginScene: React.FC<Props> = props => {
144138
: undefined
145139

146140
const handleLogin = useHandler((account: EdgeAccount) => {
147-
dispatch(initializeAccount(navigation as NavigationBase, account)).catch(
148-
(error: unknown) => {
149-
showError(error)
150-
}
151-
)
141+
dispatch(initializeAccount(navigation, account)).catch((error: unknown) => {
142+
showError(error)
143+
})
152144
})
153145

154146
const handleSendLogs = useHandler(() => {

src/components/scenes/SecurityAlertsScene.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import * as React from 'react'
33

44
import { useHandler } from '../../hooks/useHandler'
55
import { useDispatch, useSelector } from '../../types/reactRedux'
6-
import type { EdgeAppSceneProps } from '../../types/routerTypes'
6+
import type { RootSceneProps } from '../../types/routerTypes'
77
import { logEvent } from '../../util/tracking'
88
import { SceneWrapper } from '../common/SceneWrapper'
99

10-
interface Props extends EdgeAppSceneProps<'securityAlerts'> {}
10+
// Danger: This scene is mounted in two places,
11+
// so this could also be `EdgeAppSceneProps<'securityAlerts'>`:
12+
interface Props extends RootSceneProps<'securityAlerts'> {}
1113

1214
export const SecurityAlertsScene: React.FC<Props> = props => {
1315
const { navigation } = props

src/types/routerTypes.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export type RootParamList = {} & {
270270
edgeApp: NavigationCore.NavigatorScreenParams<DrawerParamList> | undefined
271271
gettingStarted: GettingStartedParams
272272
login: LoginParams
273+
securityAlerts: undefined
273274
}
274275

275276
// Upgraded types to comply with the navigation upgrade requirements
@@ -322,6 +323,7 @@ export type WalletsTabSceneProps<Name extends keyof WalletsTabParamList> =
322323
// defined above.
323324
// -------------------------------------------------------------------------
324325

326+
/** @deprecated Use one of the XyzParamList types instead */
325327
export type AppParamList = RootParamList &
326328
DrawerParamList &
327329
EdgeAppStackParamList &
@@ -330,31 +332,32 @@ export type AppParamList = RootParamList &
330332
BuySellTabParamList &
331333
WalletsTabParamList
332334

333-
export type RouteSceneKey = keyof AppParamList
334-
335335
/**
336336
* The of the `navigation` prop passed to each scene,
337337
* but without any scene-specific stuff.
338+
* @deprecated Use one of the `XyzSceneProps<"routeName">['navigation']` types.
338339
*/
339340
export type NavigationBase = NavigationCore.NavigationProp<AppParamList> &
340341
StackActionHelpers<AppParamList>
341342

342343
/**
343344
* The `navigation` prop passed to each scene.
345+
* @deprecated Use one of the `XyzSceneProps<"routeName">['navigation']` types.
344346
*/
345-
346347
export type NavigationProp<RouteName extends keyof AppParamList> =
347348
NavigationCore.NavigationProp<AppParamList, RouteName> &
348349
StackActionHelpers<AppParamList>
349350

350351
/**
351352
* The `route` prop passed to each scene.
353+
* @deprecated Use one of the `XyzSceneProps<"routeName">['route']` types.
352354
*/
353355
export type RouteProp<Name extends keyof AppParamList> =
354356
NavigationCore.RouteProp<AppParamList, Name>
355357

356358
/**
357359
* All the props passed to each scene.
360+
* @deprecated Use one of the `XyzSceneProps<"routeName">` types.
358361
*/
359362
export interface EdgeSceneProps<Name extends keyof AppParamList> {
360363
navigation: NavigationProp<Name>

0 commit comments

Comments
 (0)