Skip to content

Commit e12aae3

Browse files
committed
fix: improve ux
1 parent e28a805 commit e12aae3

File tree

3 files changed

+18
-48
lines changed

3 files changed

+18
-48
lines changed

pages/index.page.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
import { useRouter } from 'next/router';
21
import { useEffect } from 'react';
3-
import { ROUTES } from 'src/components/primitives/Link';
42

53
import { MainLayout } from '../src/layouts/MainLayout';
64
import { useWeb3Context } from '../src/libs/hooks/useWeb3Context';
5+
import { useRootStore } from '../src/store/root';
6+
import Dashboard from './dashboard.page';
7+
import Markets from './markets.page';
78

89
export default function Home() {
9-
const router = useRouter();
1010
const { currentAccount } = useWeb3Context();
11+
const trackEvent = useRootStore((store) => store.trackEvent);
1112

12-
// Redirect based on wallet connection status
1313
useEffect(() => {
14-
if (currentAccount) {
15-
// If wallet is connected, go to dashboard
16-
router.replace(ROUTES.dashboard);
17-
} else {
18-
// If no wallet connected, go to markets
19-
router.replace(ROUTES.markets);
20-
}
21-
}, [currentAccount, router]);
14+
trackEvent('Page Viewed', {
15+
'Page Name': 'Home',
16+
'Wallet Connected': !!currentAccount,
17+
'Connection Status': currentAccount ? 'Connected' : 'Unconnected',
18+
});
19+
}, [trackEvent, currentAccount]);
2220

23-
// Don't render anything since we're redirecting
24-
return null;
21+
// Show dashboard if wallet is connected, otherwise show markets
22+
return currentAccount ? <Dashboard /> : <Markets />;
2523
}
2624

2725
Home.getLayout = function getLayout(page: React.ReactElement) {

pages/markets.page.tsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { Box, Container } from '@mui/material';
2-
import { useRouter } from 'next/router';
3-
import { ReactNode, useEffect, useRef } from 'react';
4-
import { ROUTES } from 'src/components/primitives/Link';
2+
import { ReactNode, useEffect } from 'react';
53
import { MainLayout } from 'src/layouts/MainLayout';
6-
import { useWeb3Context } from 'src/libs/hooks/useWeb3Context';
74
import { MarketAssetsListContainer } from 'src/modules/markets/MarketAssetsListContainer';
85
import { MarketsTopPanel } from 'src/modules/markets/MarketsTopPanel';
96
import { useRootStore } from 'src/store/root';
@@ -41,32 +38,7 @@ export const MarketContainer = ({ children }: MarketContainerProps) => {
4138
};
4239

4340
export default function Markets() {
44-
const router = useRouter();
45-
const { currentAccount } = useWeb3Context();
4641
const trackEvent = useRootStore((store) => store.trackEvent);
47-
const prevAccountRef = useRef<string | undefined>();
48-
const isInitialMount = useRef(true);
49-
50-
// Redirect to dashboard only when wallet gets connected (not when already connected)
51-
useEffect(() => {
52-
// Skip the initial mount to avoid redirecting when already connected
53-
if (isInitialMount.current) {
54-
isInitialMount.current = false;
55-
prevAccountRef.current = currentAccount;
56-
return;
57-
}
58-
59-
const wasConnected = !!prevAccountRef.current;
60-
const isConnected = !!currentAccount;
61-
62-
// Only redirect if wallet was not connected before but is now connected
63-
if (!wasConnected && isConnected) {
64-
router.replace(ROUTES.dashboard);
65-
}
66-
67-
// Update the ref for next comparison
68-
prevAccountRef.current = currentAccount;
69-
}, [currentAccount, router]);
7042

7143
useEffect(() => {
7244
trackEvent('Page Viewed', {

src/ui-config/menu-items/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ interface Navigation {
1919
}
2020

2121
export const navigation: Navigation[] = [
22-
{
23-
link: ROUTES.markets,
24-
title: t`Markets`,
25-
dataCy: 'menuMarkets',
26-
},
2722
{
2823
link: ROUTES.dashboard,
2924
title: t`Dashboard`,
3025
dataCy: 'menuDashboard',
3126
},
27+
{
28+
link: ROUTES.markets,
29+
title: t`Markets`,
30+
dataCy: 'menuMarkets',
31+
},
3232
{
3333
link: ROUTES.governance,
3434
title: t`Governance`,

0 commit comments

Comments
 (0)