Skip to content

Commit fdcb67d

Browse files
Dhruv-2003aashutoshrathi
andauthoredMay 28, 2024
feat: Web3Provider changes for resolving build bug (#19)
* fix: Walletconnect web3modal added * fix: web3modal deps fixed with bun.lockb * feat: Converted Web3Provider to Web3ModalProvider * fix: don't use walletConnect * feat: Created a connectWallet component * fix: don't use WC and use hooks --------- Co-authored-by: Aashutosh Rathi <[email protected]>
1 parent 20e9c17 commit fdcb67d

File tree

7 files changed

+397
-163
lines changed

7 files changed

+397
-163
lines changed
 

‎.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ tsconfig.tsbuildinfo
66
tsconfig.*.tsbuildinfo
77
vocs.config.ts.timestamp-*
88
.vercel
9-
.vocs
9+
.vocs
10+
11+
bun.lockb
12+

‎docs/components/AccessPassFlow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { useEffect, useState } from "react";
22
import { sepolia } from "viem/chains";
33
import { useAccount, useReadContracts } from "wagmi";
44
import { nftRegistryContract } from "../constants";
5-
import { ConnectWallet } from "./ConnectWallet";
65
import { MintNFT } from "./MintNFT";
76
import { NFTMinted } from "./NFTMinted";
87
import { NotApprovedToMint } from "./NotApprovedToMint";
98
import { queryClient } from "./Web3Provider";
9+
import { ConnectWallet } from "./ConnectWallet";
1010

1111
export const AccessPassFlow = () => {
1212
const { address, isConnected, chainId } = useAccount();

‎docs/components/ConnectWallet.tsx

Lines changed: 11 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,16 @@
1-
import { ConnectButton } from "@rainbow-me/rainbowkit";
1+
import { useWeb3Modal } from "@web3modal/wagmi/react";
22

33
export const ConnectWallet = () => {
4+
const { open } = useWeb3Modal();
45
return (
5-
<ConnectButton.Custom>
6-
{({
7-
account,
8-
chain,
9-
openAccountModal,
10-
openChainModal,
11-
openConnectModal,
12-
authenticationStatus,
13-
mounted,
14-
}) => {
15-
const ready = mounted && authenticationStatus !== "loading";
16-
const connected =
17-
ready &&
18-
account &&
19-
chain &&
20-
(!authenticationStatus || authenticationStatus === "authenticated");
21-
return (
22-
<div
23-
{...(!ready && {
24-
"aria-hidden": true,
25-
style: {
26-
opacity: 0,
27-
pointerEvents: "none",
28-
userSelect: "none",
29-
},
30-
})}
31-
>
32-
{(() => {
33-
if (!connected) {
34-
return (
35-
<div className="flex items-center justify-center">
36-
<button
37-
onClick={openConnectModal}
38-
type="button"
39-
className="bg-teal-primary w-44 h-9 px-4 rounded-lg ring-2 ring-teal-primary/25 text-black font-jetbrains font-bold"
40-
>
41-
Connect Wallet
42-
</button>
43-
</div>
44-
);
45-
}
46-
if (chain.unsupported) {
47-
return (
48-
<div className="flex items-center justify-center">
49-
<button
50-
onClick={openChainModal}
51-
type="button"
52-
className="bg-error-med w-44 h-9 px-4 rounded-lg ring-2 ring-error-med/25 text-black font-jetbrains font-bold"
53-
>
54-
Switch Network
55-
</button>
56-
</div>
57-
);
58-
}
59-
})()}
60-
</div>
61-
);
62-
}}
63-
</ConnectButton.Custom>
6+
<div className="flex items-center justify-center">
7+
<button
8+
onClick={() => open()}
9+
type="button"
10+
className="cursor-pointer bg-teal-primary w-44 h-9 px-4 rounded-lg ring-2 ring-teal-primary/25 text-black font-jetbrains font-bold"
11+
>
12+
Connect Wallet
13+
</button>
14+
</div>
6415
);
6516
};

‎docs/components/SignupForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { keccak256, toBytes } from "viem";
55
import { sepolia } from "viem/chains";
66
import { useAccount, useSignTypedData } from "wagmi";
77
import { getLocalStorageItem, updateLocalStorageItem } from "../utils";
8-
import { ConnectWallet } from "./ConnectWallet";
98
import { Field } from "./Field";
9+
import { ConnectWallet } from "./ConnectWallet";
1010

1111
const hashFormData = (formData: Record<string, any>) => {
1212
return keccak256(toBytes(JSON.stringify(formData)));

‎docs/components/Web3Provider.tsx

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import {
2-
RainbowKitProvider,
3-
darkTheme,
4-
getDefaultConfig,
5-
} from "@rainbow-me/rainbowkit";
6-
import "@rainbow-me/rainbowkit/styles.css";
1+
import { createWeb3Modal } from "@web3modal/wagmi/react";
2+
73
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
8-
import { WagmiProvider } from "wagmi";
4+
import { WagmiProvider, createConfig, http } from "wagmi";
95
import { sepolia } from "wagmi/chains";
6+
import { injected } from "wagmi/connectors";
107
import { walletConnectProjectId } from "../constants";
118

12-
// This is faster than using the default RPC
9+
// 0. Setup queryClient
10+
export const queryClient = new QueryClient();
11+
12+
export const projectId = walletConnectProjectId;
13+
1314
const sepoliaEuRPC = {
1415
...sepolia,
1516
rpcUrls: {
@@ -19,33 +20,26 @@ const sepoliaEuRPC = {
1920
},
2021
};
2122

22-
const config = getDefaultConfig({
23-
appName: "Stackr Docs",
24-
projectId: walletConnectProjectId,
23+
const config = createConfig({
2524
chains: [sepoliaEuRPC],
25+
transports: {
26+
[sepoliaEuRPC.id]: http(),
27+
},
28+
connectors: [injected({ shimDisconnect: true })],
2629
ssr: true,
2730
});
2831

29-
export const queryClient = new QueryClient();
32+
createWeb3Modal({
33+
wagmiConfig: config,
34+
projectId,
35+
});
3036

3137
export const Web3Provider: React.FC<{ children: React.ReactNode }> = ({
3238
children,
3339
}) => {
3440
return (
3541
<WagmiProvider config={config}>
36-
<QueryClientProvider client={queryClient}>
37-
<RainbowKitProvider
38-
theme={darkTheme({
39-
accentColor: "#00CECE",
40-
accentColorForeground: "black",
41-
borderRadius: "small",
42-
fontStack: "system",
43-
overlayBlur: "small",
44-
})}
45-
>
46-
{children}
47-
</RainbowKitProvider>
48-
</QueryClientProvider>
42+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
4943
</WagmiProvider>
5044
);
5145
};

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"preview": "vocs preview"
99
},
1010
"dependencies": {
11-
"@rainbow-me/rainbowkit": "^2.0.2",
1211
"@tanstack/react-query": "^5.28.9",
1312
"@types/react": "latest",
13+
"@web3modal/wagmi": "^4.2.2",
1414
"mdx-mermaid": "^2.0.0",
1515
"mermaid": "^10.9.0",
1616
"react": "latest",

0 commit comments

Comments
 (0)
Please sign in to comment.