From 4ed0e569386d1121d18c40e176a4fb720bdc8efb Mon Sep 17 00:00:00 2001 From: adrianvrj Date: Fri, 4 Oct 2024 12:44:21 -0600 Subject: [PATCH] [feat] navigating using local storage with wallet address --- .../app/app/myfunds/{[useraddr] => }/page.tsx | 26 ++-- .../app/app/myprofile/[useraddr]/page.tsx | 103 ---------------- .../gostarkme-web/app/app/myprofile/page.tsx | 112 ++++++++++++++++++ frontend/gostarkme-web/app/app/page.tsx | 4 +- .../components/modules/myfunds/UserFunds.tsx | 22 +++- .../components/ui/ConnectWalletButton.tsx | 17 +-- frontend/gostarkme-web/package.json | 3 +- 7 files changed, 156 insertions(+), 131 deletions(-) rename frontend/gostarkme-web/app/app/myfunds/{[useraddr] => }/page.tsx (52%) delete mode 100644 frontend/gostarkme-web/app/app/myprofile/[useraddr]/page.tsx create mode 100644 frontend/gostarkme-web/app/app/myprofile/page.tsx diff --git a/frontend/gostarkme-web/app/app/myfunds/[useraddr]/page.tsx b/frontend/gostarkme-web/app/app/myfunds/page.tsx similarity index 52% rename from frontend/gostarkme-web/app/app/myfunds/[useraddr]/page.tsx rename to frontend/gostarkme-web/app/app/myfunds/page.tsx index a65ea8a..79ca7db 100644 --- a/frontend/gostarkme-web/app/app/myfunds/[useraddr]/page.tsx +++ b/frontend/gostarkme-web/app/app/myfunds/page.tsx @@ -1,22 +1,24 @@ -import React from 'react'; +'use client' + import UserFunds from '@/components/modules/myfunds/UserFunds'; import Navbar from '@/components/ui/Navbar'; import Footer from '@/components/ui/Footer'; +import { useState } from 'react'; +import { useEventListener, useLocalStorage } from 'usehooks-ts' -interface MyFundsPageProps { - params: { useraddr: string }; -} +const MyFundsPage = () => { + const [storedAddress, setStoredAddress] = useState(typeof window !== 'undefined' ? localStorage.getItem('walletAddress') : null); -export function generateStaticParams() { - return [{ useraddr: '1' }] -} + const handleWalletChange = () => { + const addr = localStorage.getItem("walletAddress"); + setStoredAddress(addr); + } -const MyFundsPage: React.FC = ({ params }) => { - const { useraddr } = params; + useEventListener("local-storage", handleWalletChange); const navItems = [ - { label: 'My Profile', href: `/app/myprofile/${useraddr}` }, - { label: 'My funds', href: `/app/myfunds/${useraddr}` } + { label: 'My Profile', href: `/app/myprofile` }, + { label: 'My funds', href: `/app/myfunds` } ]; return ( @@ -32,7 +34,7 @@ const MyFundsPage: React.FC = ({ params }) => { }} />
- +