@@ -8,12 +8,14 @@ import { api } from "@/utils/api";
88import useUser from "@/hooks/useUser" ;
99import { useUserStore } from "@/lib/zustand/user" ;
1010import useAppWallet from "@/hooks/useAppWallet" ;
11+ import useMultisigWallet from "@/hooks/useMultisigWallet" ;
1112
1213import SessionProvider from "@/components/SessionProvider" ;
1314import { getServerSession } from "next-auth" ;
1415
15- // import MenuWallets from "@/components/common/overall-layout/menus/wallets";
16+ import MenuWallets from "@/components/common/overall-layout/menus/wallets" ;
1617import MenuWallet from "@/components/common/overall-layout/menus/multisig-wallet" ;
18+ import WalletSelector from "@/components/common/overall-layout/wallet-selector" ;
1719import {
1820 WalletDataLoaderWrapper ,
1921 DialogReportWrapper ,
@@ -69,6 +71,7 @@ export default function RootLayout({
6971 const { user, isLoading } = useUser ( ) ;
7072 const router = useRouter ( ) ;
7173 const { appWallet } = useAppWallet ( ) ;
74+ const { multisigWallet } = useMultisigWallet ( ) ;
7275 const { generateNsec } = useNostrChat ( ) ;
7376
7477 const userAddress = useUserStore ( ( state ) => state . userAddress ) ;
@@ -164,6 +167,43 @@ export default function RootLayout({
164167 const walletPageNames = walletPageRoute ? walletPageRoute . split ( "/" ) : [ ] ;
165168 const pageIsPublic = publicRoutes . includes ( router . pathname ) ;
166169 const isLoggedIn = ! ! user ;
170+ const isHomepage = router . pathname === "/" ;
171+
172+ // Keep track of the last visited wallet to show wallet menu even on other pages
173+ const [ lastVisitedWalletId , setLastVisitedWalletId ] = React . useState < string | null > ( null ) ;
174+ const [ lastVisitedWalletName , setLastVisitedWalletName ] = React . useState < string | null > ( null ) ;
175+ const [ lastWalletStakingEnabled , setLastWalletStakingEnabled ] = React . useState < boolean | null > ( null ) ;
176+
177+ React . useEffect ( ( ) => {
178+ const walletId = router . query . wallet as string | undefined ;
179+ if ( walletId && isWalletPath && appWallet && multisigWallet ) {
180+ setLastVisitedWalletId ( walletId ) ;
181+ setLastVisitedWalletName ( appWallet . name ) ;
182+ // Check if staking is enabled for this wallet
183+ try {
184+ const stakingEnabled = multisigWallet . stakingEnabled ( ) ;
185+ setLastWalletStakingEnabled ( stakingEnabled ) ;
186+ } catch ( error ) {
187+ // Don't update state on error - keep the last known value
188+ console . error ( "Error checking staking status:" , error ) ;
189+ }
190+ }
191+ } , [ router . query . wallet , isWalletPath , appWallet , multisigWallet ] ) ;
192+
193+ const clearWalletContext = React . useCallback ( ( ) => {
194+ setLastVisitedWalletId ( null ) ;
195+ setLastVisitedWalletName ( null ) ;
196+ setLastWalletStakingEnabled ( null ) ;
197+ } , [ ] ) ;
198+
199+ // Clear wallet context when navigating to homepage
200+ React . useEffect ( ( ) => {
201+ if ( isHomepage && lastVisitedWalletId ) {
202+ clearWalletContext ( ) ;
203+ }
204+ } , [ isHomepage , lastVisitedWalletId , clearWalletContext ] ) ;
205+
206+ const showWalletMenu = isLoggedIn && ( isWalletPath || ! ! lastVisitedWalletId ) ;
167207
168208 return (
169209 < div className = "flex h-screen w-screen flex-col overflow-hidden" >
@@ -175,11 +215,21 @@ export default function RootLayout({
175215 data-header = "main"
176216 >
177217 < div className = "flex h-14 items-center gap-4 lg:h-16" >
178- { /* Mobile menu button - only in wallet context */ }
179- { isWalletPath && < MobileNavigation isWalletPath = { isWalletPath } /> }
218+ { /* Mobile menu button - hidden only on public homepage (not logged in) */ }
219+ { ( isLoggedIn || ! isHomepage ) && (
220+ < MobileNavigation
221+ showWalletMenu = { showWalletMenu }
222+ isLoggedIn = { isLoggedIn }
223+ walletId = { router . query . wallet as string || lastVisitedWalletId || undefined }
224+ fallbackWalletName = { lastVisitedWalletName }
225+ onClearWallet = { clearWalletContext }
226+ stakingEnabled = { lastWalletStakingEnabled ?? undefined }
227+ isWalletPath = { isWalletPath }
228+ />
229+ ) }
180230
181231 { /* Logo - in fixed-width container matching sidebar width */ }
182- < div className = { `flex items-center md:w-[260px] lg:w-[280px] ${ isWalletPath ? 'flex-1 justify-center md:flex-none md:justify-start' : '' } ` } >
232+ < div className = { `flex items-center md:w-[260px] lg:w-[280px] ${ ( isLoggedIn || ! isHomepage ) ? 'flex-1 justify-center md:flex-none md:justify-start' : '' } ` } >
183233 < Link
184234 href = "/"
185235 className = "flex items-center gap-2 rounded-md px-4 py-2 text-sm transition-all duration-200 hover:bg-gray-100/50 dark:hover:bg-white/5 md:px-4"
@@ -218,13 +268,57 @@ export default function RootLayout({
218268 </ header >
219269
220270 { /* Content area with sidebar + main */ }
221- < div className = { `flex flex-1 overflow-hidden ${ isWalletPath ? '' : '' } ` } >
222- { /* Sidebar for larger screens - only in wallet context */ }
223- { isWalletPath && (
271+ < div className = { `flex flex-1 overflow-hidden` } >
272+ { /* Sidebar for larger screens - hidden only on public homepage (not logged in) */ }
273+ { ( isLoggedIn || ! isHomepage ) && (
224274 < aside className = "hidden w-[260px] border-r border-gray-300/50 bg-muted/40 dark:border-white/[0.03] md:block lg:w-[280px]" >
225275 < div className = "flex h-full max-h-screen flex-col" >
226- < nav className = "flex-1 pt-2" >
227- < MenuWallet />
276+ < nav className = "flex-1 pt-2 overflow-y-auto" >
277+ < div className = "flex flex-col" >
278+ { /* 1. Home Link - only when NOT logged in */ }
279+ { ! isLoggedIn && (
280+ < div className = "px-2 lg:px-4" >
281+ < div className = "space-y-1" >
282+ < Link
283+ href = "/"
284+ className = { `flex w-full items-center gap-3 rounded-md px-3 py-2 text-sm transition-all duration-200 hover:bg-gray-100/50 dark:hover:bg-white/5 ${
285+ router . pathname === "/"
286+ ? "text-white"
287+ : "text-muted-foreground hover:text-foreground"
288+ } `}
289+ >
290+ < svg className = "h-5 w-5" fill = "none" stroke = "currentColor" viewBox = "0 0 24 24" >
291+ < path strokeLinecap = "round" strokeLinejoin = "round" strokeWidth = { 2 } d = "M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
292+ </ svg >
293+ < span > Home</ span >
294+ </ Link >
295+ </ div >
296+ </ div >
297+ ) }
298+
299+ { /* 2. Wallet Selector - only when logged in */ }
300+ { isLoggedIn && (
301+ < WalletSelector
302+ fallbackWalletName = { lastVisitedWalletName }
303+ onClearWallet = { clearWalletContext }
304+ />
305+ ) }
306+
307+ { /* 3. Wallet Menu - shown when wallet is selected */ }
308+ { showWalletMenu && (
309+ < div className = "mt-4" >
310+ < MenuWallet
311+ walletId = { router . query . wallet as string || lastVisitedWalletId || undefined }
312+ stakingEnabled = { isWalletPath ? undefined : ( lastWalletStakingEnabled ?? undefined ) }
313+ />
314+ </ div >
315+ ) }
316+
317+ { /* 4. Resources Menu - always visible */ }
318+ < div className = "mt-4" >
319+ < MenuWallets />
320+ </ div >
321+ </ div >
228322 </ nav >
229323 < div className = "mt-auto p-4" />
230324 </ div >
0 commit comments