Skip to content

Commit a3fa5e6

Browse files
committed
add warning login modal
1 parent b2b79c2 commit a3fa5e6

4 files changed

Lines changed: 73 additions & 1 deletion

File tree

turnkey/src/app/layout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ReactQueryProvider } from "@/features/react-query";
22
import { TurnkeyProvider } from "@turnkey/sdk-react";
33
import type { Metadata } from "next";
44
import "./globals.css";
5+
import { WarningDialogProvider } from "@/features/warning-dialog";
56

67
export const dynamic = "force-dynamic";
78

@@ -25,7 +26,9 @@ export default function RootLayout({
2526
defaultOrganizationId: process.env.PUBLIC_TURNKEY_ORGANIZATION_ID!,
2627
}}
2728
>
28-
<ReactQueryProvider>{children}</ReactQueryProvider>
29+
<ReactQueryProvider>
30+
<WarningDialogProvider>{children}</WarningDialogProvider>
31+
</ReactQueryProvider>
2932
</TurnkeyProvider>
3033
</body>
3134
</html>

turnkey/src/app/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { OneBalanceAccountRequired } from "@/features/onebalance-account/onebala
66
import { Swap } from "@/features/swap/swap-ui";
77
import { TransactionHistory } from "@/features/transaction-history/transaction-history-ui";
88
import { Transfer } from "@/features/transfer/transfer-ui";
9+
import { ClientOnly } from "@/features/ui/client-only";
910
import { Header } from "@/features/ui/header";
1011
import { Login } from "@/features/ui/login";
12+
import { WarningDialog } from "@/features/warning-dialog";
1113
import * as Tabs from "@radix-ui/react-tabs";
1214
import { Toaster } from "sonner";
1315

@@ -52,6 +54,9 @@ export default function Home() {
5254
</main>
5355
</Tabs.Root>
5456
<Toaster />
57+
<ClientOnly>
58+
<WarningDialog />
59+
</ClientOnly>
5560
</EnvironmentProvider>
5661
);
5762
}

turnkey/src/features/turnkey/use-turnkey-login.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { usePersistedBTCWallet } from "../onebalance-account/use-persisted-btc-w
44
import { useMutation } from "@tanstack/react-query";
55
import { useTurnkey } from "@turnkey/sdk-react";
66
import { queryClient } from "../react-query";
7+
import { useContext, useState } from "react";
8+
import { WarningDialogContext } from "../warning-dialog";
79

810
export const useTurnkeyLogin = () => {
911
const { passkeyClient } = useTurnkey();
12+
const { setIsWarningModalOpen } = useContext(WarningDialogContext);
1013
const {
1114
evm: [previousEvmOrgId, setEvmOrgId],
1215
btc: [, setBtcOrgId],
@@ -30,6 +33,7 @@ export const useTurnkeyLogin = () => {
3033
setBtcOrgId("null");
3134
}
3235
toast.dismiss();
36+
setIsWarningModalOpen(true);
3337
},
3438
});
3539

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
"use client";
2+
import {
3+
Dialog,
4+
DialogClose,
5+
DialogContent,
6+
DialogDescription,
7+
DialogFooter,
8+
DialogHeader,
9+
DialogTitle,
10+
DialogTrigger,
11+
} from "@/components/ui/dialog";
12+
import { createContext, PropsWithChildren, useContext, useState } from "react";
13+
14+
export const WarningDialogContext = createContext<{
15+
isWarningModalOpen: boolean;
16+
setIsWarningModalOpen: (open: boolean) => void;
17+
}>(null!);
18+
19+
export const WarningDialogProvider = ({ children }: PropsWithChildren) => {
20+
const [isWarningModalOpen, setIsWarningModalOpen] = useState(false);
21+
22+
return (
23+
<WarningDialogContext.Provider
24+
value={{ isWarningModalOpen, setIsWarningModalOpen }}
25+
>
26+
{children}
27+
</WarningDialogContext.Provider>
28+
);
29+
};
30+
31+
export const WarningDialog = () => {
32+
const { isWarningModalOpen, setIsWarningModalOpen } =
33+
useContext(WarningDialogContext);
34+
35+
return (
36+
<Dialog open={isWarningModalOpen} onOpenChange={setIsWarningModalOpen}>
37+
<DialogTrigger />
38+
39+
<DialogContent>
40+
<DialogHeader>
41+
<DialogTitle>Warning</DialogTitle>
42+
43+
<DialogDescription className="text-base flex flex-col gap-2 pt-4">
44+
<span>
45+
This is a demo app, please use with care and do not deposit more
46+
than $500.
47+
</span>
48+
<span>Transactions are capped at $500.</span>
49+
</DialogDescription>
50+
</DialogHeader>
51+
52+
<DialogFooter>
53+
<DialogClose className="h-14 px-10 text-base bg-brand-orange rounded-full text-black">
54+
I understand
55+
</DialogClose>
56+
</DialogFooter>
57+
</DialogContent>
58+
</Dialog>
59+
);
60+
};

0 commit comments

Comments
 (0)