Skip to content

Commit 5883c00

Browse files
committed
chore: fix navigation bugs
1 parent e96be31 commit 5883c00

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

‎apps/wallet/src/ui/app/components/NavigationStackProvider.tsx‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,34 @@ function getRootDepth({ pathname, search }: { pathname: string; search: string }
2020
return null;
2121
}
2222

23+
function getHistoryIndex(): number {
24+
return window.history.state?.idx ?? 0;
25+
}
26+
2327
export function NavigationStackProvider({ children }: { children: ReactNode }) {
2428
const location = useLocation();
2529
const navigationType = useNavigationType();
26-
const [depth, setDepth] = useState(() => getRootDepth(location) ?? 2);
30+
const initialRootDepth = getRootDepth(location);
31+
const [depth, setDepth] = useState(() => initialRootDepth ?? Math.min(2, getHistoryIndex()));
2732
const lastLocationKey = useRef(location.key);
28-
const isDepthUnknown = useRef(getRootDepth(location) === null);
33+
const minPopDepth = useRef(initialRootDepth === null ? 2 : 1);
2934

3035
useEffect(() => {
3136
if (lastLocationKey.current === location.key) return;
3237
lastLocationKey.current = location.key;
3338

3439
const rootDepth = getRootDepth(location);
3540
if (rootDepth !== null) {
36-
isDepthUnknown.current = false;
41+
minPopDepth.current = 1;
3742
setDepth(rootDepth);
38-
} else if (navigationType === 'PUSH') {
39-
setDepth((prev) => prev + 1);
43+
return;
44+
}
45+
46+
const maxDepth = getHistoryIndex();
47+
if (navigationType === 'PUSH') {
48+
setDepth((prev) => Math.min(maxDepth, prev + 1));
4049
} else if (navigationType === 'POP') {
41-
const minDepth = isDepthUnknown.current ? 2 : 1;
42-
setDepth((prev) => Math.max(minDepth, prev - 1));
50+
setDepth((prev) => Math.min(maxDepth, Math.max(minPopDepth.current, prev - 1)));
4351
}
4452
// oxlint-disable-next-line react-hooks/exhaustive-deps
4553
}, [location.key, navigationType]);

‎apps/wallet/src/ui/app/pages/accounts/CreateNewPasskey.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ export function CreateNewPasskey() {
8080
];
8181

8282
return (
83-
<PageTemplate
84-
title="Create Passkey Account"
85-
isTitleCentered
86-
onBack={() => navigate('/accounts/import-existing', { replace: true })}
87-
>
83+
<PageTemplate title="Create Passkey Account" isTitleCentered>
8884
<Form
8985
className="flex h-full flex-col justify-between"
9086
form={form}

‎apps/wallet/src/ui/app/pages/accounts/ImportPasskeyPage.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ import { z } from 'zod';
1818
import { useBackgroundClient } from '../../hooks';
1919

2020
export function ImportPasskeyPage() {
21-
const navigate = useNavigate();
2221
const [searchParams] = useSearchParams();
2322
const accountID = searchParams.get('accountID') || '';
2423
useBootstrapSourceFlow();
2524

2625
return (
27-
<PageTemplate
28-
title="Import Passkey Account"
29-
isTitleCentered
30-
onBack={() => navigate('/accounts/import-existing', { replace: true })}
31-
>
26+
<PageTemplate title="Import Passkey Account" isTitleCentered>
3227
{accountID ? (
3328
<NicknameSetContent accountID={accountID} />
3429
) : (

0 commit comments

Comments
 (0)