Skip to content

Commit aefe212

Browse files
committed
add zklogin
1 parent 03e1c50 commit aefe212

File tree

7 files changed

+86
-43
lines changed

7 files changed

+86
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ next-env.d.ts
4242

4343
package-lock.json
4444
bun.lock
45+
opencode.json
46+
ENOKI_INTEGRATION.md

app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Metadata } from "next";
22
import { Anton, Inter } from "next/font/google";
3-
import { SuiProviders } from "@/components/SuiProviders";
3+
import { EnokiProviders } from "@/components/providers/EnokiProviders";
44
import "./globals.css";
55
import "@mysten/dapp-kit/dist/index.css";
66

@@ -57,7 +57,7 @@ export default function RootLayout({
5757
className={`${anton.variable} ${inter.variable} antialiased`}
5858
suppressHydrationWarning
5959
>
60-
<SuiProviders>{children}</SuiProviders>
60+
<EnokiProviders>{children}</EnokiProviders>
6161
</body>
6262
</html>
6363
);

components/SuiProviders.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

components/WalletConnectButton.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ import { ConnectButton, useCurrentAccount } from "@mysten/dapp-kit";
55
export function WalletConnectButton() {
66
const account = useCurrentAccount();
77

8-
// Format địa chỉ: 0x1234...5678
8+
// Format address: 0x1234...5678
99
const formatAddress = (address: string) => {
1010
return `${address.slice(0, 6)}...${address.slice(-4)}`;
1111
};
1212

1313
return (
14-
<ConnectButton
15-
connectText="Launch App"
16-
className="sui-wallet-button"
17-
>
14+
<ConnectButton connectText="Launch App" className="sui-wallet-button">
1815
{account && (
19-
<div className="bg-black dark:bg-white text-white dark:text-black px-5 py-2 rounded-full font-bold text-sm uppercase hover:scale-105 transition-transform flex items-center gap-2">
20-
<span className="material-icons text-base">account_balance_wallet</span>
16+
<div className="bg-black dark:bg-white text-white dark:text-black px-5 rounded-full font-bold text-sm uppercase hover:scale-105 transition-transform flex items-center gap-2">
17+
<span className="material-icons text-base">
18+
account_balance_wallet
19+
</span>
2120
<span>{formatAddress(account.address)}</span>
2221
</div>
2322
)}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use client";
2+
3+
import { ReactNode, useEffect } from "react";
4+
import {
5+
createNetworkConfig,
6+
SuiClientProvider,
7+
WalletProvider,
8+
useSuiClientContext,
9+
} from "@mysten/dapp-kit";
10+
import { getFullnodeUrl } from "@mysten/sui/client";
11+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
12+
import { isEnokiNetwork, registerEnokiWallets } from "@mysten/enoki";
13+
import { enokiConfig } from "@/config/enoki";
14+
import "@mysten/dapp-kit/dist/index.css";
15+
16+
const { networkConfig } = createNetworkConfig({
17+
testnet: { url: getFullnodeUrl("testnet") },
18+
mainnet: { url: getFullnodeUrl("mainnet") },
19+
});
20+
21+
const queryClient = new QueryClient({
22+
defaultOptions: {
23+
queries: {
24+
refetchOnWindowFocus: false,
25+
retry: false,
26+
},
27+
},
28+
});
29+
30+
function RegisterEnokiWallets() {
31+
const { client, network } = useSuiClientContext();
32+
33+
useEffect(() => {
34+
if (!isEnokiNetwork(network)) return;
35+
36+
const redirectUrl =
37+
typeof window !== "undefined"
38+
? `${window.location.origin}`
39+
: "http://localhost:3000";
40+
41+
const { unregister } = registerEnokiWallets({
42+
apiKey: enokiConfig.apiKey,
43+
providers: {
44+
google: {
45+
clientId: enokiConfig.googleClientId,
46+
redirectUrl,
47+
},
48+
},
49+
client,
50+
network,
51+
});
52+
53+
return unregister;
54+
}, [client, network]);
55+
56+
return null;
57+
}
58+
59+
export function EnokiProviders({ children }: { children: ReactNode }) {
60+
return (
61+
<QueryClientProvider client={queryClient}>
62+
<SuiClientProvider networks={networkConfig} defaultNetwork="testnet">
63+
<RegisterEnokiWallets />
64+
<WalletProvider autoConnect={true}>{children}</WalletProvider>
65+
</SuiClientProvider>
66+
</QueryClientProvider>
67+
);
68+
}

config/enoki.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const enokiConfig = {
2+
apiKey: process.env.NEXT_PUBLIC_ENOKI_API_KEY!,
3+
googleClientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID!,
4+
network: (process.env.NEXT_PUBLIC_SUI_NETWORK || "testnet") as "mainnet" | "testnet",
5+
rpcUrl: process.env.NEXT_PUBLIC_SUI_RPC_URL!,
6+
};

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
},
1111
"dependencies": {
1212
"@mysten/dapp-kit": "^0.20.0",
13+
"@mysten/enoki": "^0.13.0",
1314
"@mysten/sui": "^1.45.2",
1415
"@tanstack/react-query": "^5.90.18",
16+
"jwt-decode": "^4.0.0",
1517
"next": "16.1.3",
1618
"react": "19.2.3",
1719
"react-dom": "19.2.3"

0 commit comments

Comments
 (0)