Skip to content

Commit d68edca

Browse files
committed
refactor(556x): Fix nested Route issues and Storybook compatibility for UnlockPage
1 parent 33daab7 commit d68edca

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

ui/pages/routes/routes.component.tsx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,13 @@ export default function Routes() {
618618
<Route path={ONBOARDING_ROUTE} component={OnboardingFlow} />
619619
{/** @ts-expect-error TODO: Replace `component` prop with `element` once `react-router` is upgraded to v6 */}
620620
<Route path={LOCK_ROUTE} component={Lock} exact />
621-
<Route path={UNLOCK_ROUTE} exact>
621+
<Route
622+
path={UNLOCK_ROUTE}
623+
// v5 Route supports exact with render props, but TS types don't recognize it
624+
// Using spread operator with type assertion to bypass incorrect type definitions
625+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
626+
{...({ exact: true } as any)}
627+
>
622628
{(props: RouteComponentProps) => {
623629
const { history: v5History, location: v5Location } = props;
624630
const navigate = createV5CompatNavigate(v5History);
@@ -666,15 +672,12 @@ export default function Routes() {
666672
keyringId?: string;
667673
}>;
668674
return (
669-
<Authenticated
670-
path={`${REVEAL_SEED_ROUTE}/:keyringId?`}
671-
component={() => (
672-
<RevealSeedConfirmationComponent
673-
navigate={navigate}
674-
keyringId={match.params.keyringId}
675-
/>
676-
)}
677-
/>
675+
<AuthenticatedV5Compat>
676+
<RevealSeedConfirmationComponent
677+
navigate={navigate}
678+
keyringId={match.params.keyringId}
679+
/>
680+
</AuthenticatedV5Compat>
678681
);
679682
}}
680683
</Route>
@@ -870,15 +873,12 @@ export default function Routes() {
870873
params: { chainId: string; protocolId: string };
871874
}>;
872875
return (
873-
<Authenticated
874-
path={`${DEFI_ROUTE}/:chainId/:protocolId`}
875-
component={() => (
876-
<DeFiPageComponent
877-
navigate={navigate}
878-
params={match.params}
879-
/>
880-
)}
881-
/>
876+
<AuthenticatedV5Compat>
877+
<DeFiPageComponent
878+
navigate={navigate}
879+
params={match.params}
880+
/>
881+
</AuthenticatedV5Compat>
882882
);
883883
}}
884884
</Route>
@@ -1121,7 +1121,12 @@ export default function Routes() {
11211121
{renderRoutes()}
11221122
</Box>
11231123
{isUnlocked ? <Alerts history={history} /> : null}
1124-
<ToastMaster location={location} />
1124+
{React.createElement(
1125+
ToastMaster as React.ComponentType<{
1126+
location: RouteComponentProps['location'];
1127+
}>,
1128+
{ location },
1129+
)}
11251130
</div>
11261131
);
11271132
}

ui/pages/unlock-page/README.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Story, Canvas, ArgsTable } from '@storybook/addon-docs';
22

3-
import UnlockPage from '.';
3+
import UnlockPage from './unlock-page.component';
44

55
# Unlock Page
66

@@ -14,7 +14,7 @@ Portal page for user to auth the access of their account
1414

1515
| Name | Description |
1616
| -------------------------- | -------------------------------------------------------------------------- |
17-
| `history` | History router for redirect after action `object` |
17+
| `navigate` | Navigate function for redirect after action `object` |
1818
| `isUnlocked` | If isUnlocked is true will redirect to most recent route in history `bool` |
1919
| `onRestore` | onClick handler for "Forgot password?" link `func` |
2020
| `onSubmit` | onSumbit handler when form is submitted `func` |

ui/pages/unlock-page/unlock-page.container.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,7 @@ const UnlockPageWithNavState = (props) => {
112112
return <UnlockPageConnected {...props} navState={navState} />;
113113
};
114114

115+
// Export the connected component for Storybook/testing
116+
export { UnlockPageConnected };
117+
115118
export default UnlockPageWithNavState;

ui/pages/unlock-page/unlock-page.stories.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { createBrowserHistory } from 'history';
21
import React from 'react';
32
import README from './README.mdx';
43
import UnlockPage from './unlock-page.component';
@@ -13,7 +12,8 @@ export default {
1312
},
1413
},
1514
argTypes: {
16-
history: { control: 'object' },
15+
navigate: { control: 'object' },
16+
location: { control: 'object' },
1717
isUnlocked: { control: 'boolean' },
1818
onRestore: { action: 'onRestore' },
1919
onSubmit: { action: 'onSubmit' },
@@ -22,8 +22,9 @@ export default {
2222
};
2323

2424
export const DefaultStory = (args) => {
25-
const history = createBrowserHistory();
26-
return <UnlockPage {...args} history={history} />;
25+
const navigate = (path) => console.log('Navigate to:', path);
26+
const location = { pathname: '/unlock', search: '', state: null };
27+
return <UnlockPage {...args} navigate={navigate} location={location} />;
2728
};
2829

2930
DefaultStory.storyName = 'Default';

0 commit comments

Comments
 (0)