Skip to content

Commit d501142

Browse files
committed
feat: added rainbowkit connect wallet button
1 parent 18a9e25 commit d501142

File tree

4 files changed

+39
-79
lines changed

4 files changed

+39
-79
lines changed

.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# Prisma
1313
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
14-
DATABASE_URL="file:./db.sqlite" # unnused now for postgres
14+
# DATABASE_URL="file:./db.sqlite" # unnused now for postgres
1515

1616
# Next Auth
1717
# You can generate a new secret on the command line with:
@@ -26,4 +26,6 @@ POSTGRES_URL_NON_POOLING=
2626
POSTGRES_USER=
2727
POSTGRES_HOST=
2828
POSTGRES_PASSWORD=
29-
POSTGRES_DATABASE=
29+
POSTGRES_DATABASE=
30+
31+
NEXT_PUBLIC_WALLET_CONNECT_ID=

src/components/Topbar.tsx

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from "wagmi";
3838
import { InjectedConnector } from "wagmi/connectors/injected";
3939
import { useEffect, useState } from "react";
40+
import { ConnectButton } from "@rainbow-me/rainbowkit";
4041

4142
interface NavItem {
4243
label: string;
@@ -194,51 +195,7 @@ export default function Topbar() {
194195
spacing={6}
195196
minW={"10rem"}
196197
>
197-
{sessionData ? (
198-
<div className="mb-4 text-center">
199-
<button
200-
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
201-
onClick={onClickSignOut as () => void}
202-
>
203-
Sign Out
204-
</button>
205-
</div>
206-
) : showConnection ? (
207-
<div className="mb-4">
208-
{/* {chain?.unsupported ? (
209-
<button onClick={() => switchNetwork?.()}>
210-
{`Switch to ${polygonMumbai.name}`}
211-
{isLoading &&
212-
pendingChainId === polygonMumbai.id &&
213-
" (switching)"}
214-
</button> */}
215-
{isConnected ? (
216-
<button
217-
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
218-
onClick={onClickSignIn as () => void}
219-
>
220-
Sign In
221-
</button>
222-
) : null}
223-
</div>
224-
) : null}
225-
{showConnection ? (
226-
<div className="text-center">
227-
{address ? (
228-
<p className="mb-4">
229-
<code className="block rounded bg-black/20 p-4 text-white">
230-
{address}
231-
</code>
232-
</p>
233-
) : null}
234-
<Button
235-
className="rounded-full bg-white/10 px-10 py-3 font-semibold text-white no-underline transition hover:bg-white/20"
236-
onClick={() => (!isConnected ? connect() : disconnect())}
237-
>
238-
{!isConnected ? "Connect Wallet" : "Disconnect"}
239-
</Button>
240-
</div>
241-
) : null}
198+
<ConnectButton />
242199
</Stack>
243200
</Flex>
244201

src/env.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const server = z.object({
3030
*/
3131
const client = z.object({
3232
// NEXT_PUBLIC_CLIENTVAR: z.string().min(1),
33+
NEXT_PUBLIC_WALLET_CONNECT_ID: z.string().min(1),
3334
});
3435

3536
/**
@@ -44,9 +45,8 @@ const processEnv = {
4445
NODE_ENV: process.env.NODE_ENV,
4546
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
4647
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
47-
// DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID,
48-
// DISCORD_CLIENT_SECRET: process.env.DISCORD_CLIENT_SECRET,
4948
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
49+
NEXT_PUBLIC_WALLET_CONNECT_ID: process.env.NEXT_PUBLIC_WALLET_CONNECT_ID,
5050
};
5151

5252
// Don't touch the part below

src/pages/_app.tsx

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
// Imports
22
// ========================================================
3+
import React from "react";
4+
35
import { type AppType } from "next/app";
46
import { type Session } from "next-auth";
57
import { SessionProvider } from "next-auth/react";
68
import { api } from "@/utils/api";
9+
710
import "@/styles/globals.css";
11+
12+
import "@rainbow-me/rainbowkit/styles.css";
13+
14+
import { RainbowKitSiweNextAuthProvider } from "@rainbow-me/rainbowkit-siwe-next-auth";
15+
import { getDefaultWallets, RainbowKitProvider } from "@rainbow-me/rainbowkit";
16+
817
// SIWE Integration
918
import { WagmiConfig, createConfig, configureChains } from "wagmi";
1019
import { polygonMumbai } from "wagmi/chains";
1120
import { publicProvider } from "wagmi/providers/public";
1221
import { ChakraProvider } from "@chakra-ui/react";
1322
import { theme } from "@/theme";
14-
import { MetaMaskConnector } from "wagmi/connectors/metaMask";
1523
import { MDXProvider } from "@mdx-js/react";
1624
import Components from "@/components/mdx/Components";
17-
import { InjectedConnector } from "wagmi/connectors/injected";
18-
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
1925
import Layout from "@/components/Layout";
26+
import { env } from "@/env.mjs";
2027

2128
// Config
2229
// ========================================================
@@ -28,27 +35,15 @@ const { chains, publicClient, webSocketPublicClient } = configureChains(
2835
[publicProvider()],
2936
);
3037

31-
/**
32-
* Configure publicProvider and allow for auto wallet connection
33-
*/
34-
const config = createConfig({
38+
const { connectors } = getDefaultWallets({
39+
appName: "D_D Academy",
40+
projectId: env.NEXT_PUBLIC_WALLET_CONNECT_ID,
41+
chains,
42+
});
43+
44+
const wagmiConfig = createConfig({
3545
autoConnect: true,
36-
connectors: [
37-
new MetaMaskConnector({ chains }),
38-
new InjectedConnector({
39-
chains,
40-
options: {
41-
name: "Injected",
42-
shimDisconnect: true,
43-
},
44-
}),
45-
new CoinbaseWalletConnector({
46-
chains,
47-
options: {
48-
appName: "Developer DAO Academy",
49-
},
50-
}),
51-
],
46+
connectors,
5247
publicClient,
5348
webSocketPublicClient,
5449
});
@@ -61,13 +56,19 @@ const MyApp: AppType<{ session: Session | null }> = ({
6156
}) => {
6257
return (
6358
<ChakraProvider theme={theme}>
64-
<WagmiConfig config={config}>
65-
<SessionProvider session={session} refetchInterval={0}>
66-
<MDXProvider components={Components}>
67-
<Layout>
68-
<Component {...pageProps} />
69-
</Layout>
70-
</MDXProvider>
59+
<WagmiConfig config={wagmiConfig}>
60+
<SessionProvider refetchInterval={0} session={session}>
61+
<RainbowKitSiweNextAuthProvider>
62+
<RainbowKitProvider chains={chains}>
63+
<React.StrictMode>
64+
<MDXProvider components={Components}>
65+
<Layout>
66+
<Component {...pageProps} />
67+
</Layout>
68+
</MDXProvider>
69+
</React.StrictMode>
70+
</RainbowKitProvider>
71+
</RainbowKitSiweNextAuthProvider>
7172
</SessionProvider>
7273
</WagmiConfig>
7374
</ChakraProvider>

0 commit comments

Comments
 (0)