forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppShell.tsx
More file actions
78 lines (70 loc) · 2.6 KB
/
Copy pathAppShell.tsx
File metadata and controls
78 lines (70 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use client";
import ConnectWalletButton from "@/components/ConnectWalletButton/ConnectWalletButton";
import Footer from "@/components/Footer/Footer";
import Navbar from "@/components/Navbar/Navbar";
import NetworkMismatchBanner from "@/components/NetworkMismatchBanner/NetworkMismatchBanner";
import RpcUnreachableBanner from "@/components/RpcUnreachableBanner/RpcUnreachableBanner";
import ContextProvider from "@/context";
import {
OwnConnectButtonProvider,
useHasOwnConnectButton,
} from "@/context/OwnConnectButtonContext";
import { useStellarWallet } from "@/context/StellarWalletContext";
import { Box } from "@chakra-ui/react";
import { usePathname } from "next/navigation";
// Routes where the page itself always renders an inline Connect Wallet button
// in the disconnected state — no dynamic condition, just pathname matching.
// Dynamic routes (/farm/[poolId]) are handled via OwnConnectButtonContext
// because the inline CTA there is conditional (only inside the deposit modal).
const STATIC_OWN_CONNECT_ROUTES = ["/history"];
function LayoutWrapper({ children }: { children: React.ReactNode }) {
const { isConnected } = useStellarWallet();
const pathname = usePathname();
// Pages signal a dynamic own-CTA via context (e.g. /farm, /farm/[poolId]).
const hasContextCTA = useHasOwnConnectButton();
// /history always renders its own inline button; no context needed.
const hasStaticCTA = STATIC_OWN_CONNECT_ROUTES.includes(pathname ?? "");
const hasOwnConnectButton = hasContextCTA || hasStaticCTA;
return (
<Box
display="flex"
flexDirection="column"
minH="100vh"
bg="app.bg"
color="app.text"
>
<Navbar />
<RpcUnreachableBanner />
<NetworkMismatchBanner />
{isConnected ? (
<>
<Box as="main" flex={1}>{children}</Box>
<Footer />
</>
) : (
<>
<Box
as="main"
flex={1}
pb={{ base: hasOwnConnectButton ? 0 : "88px", md: 0 }}
>
{children}
</Box>
{!hasOwnConnectButton && <ConnectWalletButton />}
</>
)}
</Box>
);
}
export default function AppShell({ children }: { children: React.ReactNode }) {
return (
<ContextProvider>
{/* OwnConnectButtonProvider must be inside ContextProvider so the
wallet context is available to children, but it wraps LayoutWrapper
so pages can signal upward before the floating button is rendered. */}
<OwnConnectButtonProvider>
<LayoutWrapper>{children}</LayoutWrapper>
</OwnConnectButtonProvider>
</ContextProvider>
);
}