From 5b86cb853f942e25813cb66d0d926b1ccd23d8d9 Mon Sep 17 00:00:00 2001 From: Alfredo Bonilla Date: Thu, 20 Feb 2025 19:20:31 -0600 Subject: [PATCH] feat: fix wallet connection --- .../features/WalletConnectionCheck.tsx | 55 +++++++++++++++++++ apps/web/src/app/layout.tsx | 5 +- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 apps/web/src/app/_components/features/WalletConnectionCheck.tsx diff --git a/apps/web/src/app/_components/features/WalletConnectionCheck.tsx b/apps/web/src/app/_components/features/WalletConnectionCheck.tsx new file mode 100644 index 0000000..d2a51f3 --- /dev/null +++ b/apps/web/src/app/_components/features/WalletConnectionCheck.tsx @@ -0,0 +1,55 @@ +"use client"; + +import { useAccount } from "@starknet-react/core"; +import { useSession } from "next-auth/react"; +import { useEffect, useState } from "react"; +import { toast } from "react-hot-toast"; +import { useTranslation } from "react-i18next"; +import WalletConnectFlow from "./WalletConnectFlow"; + +interface WalletConnectionCheckProps { + children: React.ReactNode; +} + +export default function WalletConnectionCheck({ + children, +}: WalletConnectionCheckProps) { + const { data: session, status } = useSession(); + const { address } = useAccount(); + const [showConnectPrompt, setShowConnectPrompt] = useState(false); + const { t } = useTranslation(); + + useEffect(() => { + // Only show the connect prompt if there's a session but no wallet + // and we're not in a loading state + if (status === "authenticated" && session && !address) { + setShowConnectPrompt(true); + toast.error(t("please_connect_wallet")); + } else { + setShowConnectPrompt(false); + } + }, [session, address, status, t]); + + // Don't show prompt during loading/transitioning states + if (status === "loading") { + return children; + } + + if (showConnectPrompt) { + return ( +
+
+

+ {t("connect_wallet")} +

+

+ {t("connect_wallet_description")} +

+ +
+
+ ); + } + + return children; +} diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx index f6bfda8..e6ebd03 100644 --- a/apps/web/src/app/layout.tsx +++ b/apps/web/src/app/layout.tsx @@ -9,6 +9,7 @@ import { SessionProvider } from "next-auth/react"; import i18n from "~/i18n"; import StarknetProvider from "~/providers/starknet"; import { TRPCReactProvider } from "~/trpc/react"; +import WalletConnectionCheck from "./_components/features/WalletConnectionCheck"; export default function RootLayout({ children, @@ -33,7 +34,9 @@ export default function RootLayout({ -
{children}
+ +
{children}
+