@berachain/wagmi 0.2.0-beta.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{BeraWagmi-4czj_EN4.d.ts → BeraWagmi-8ToIEnAn.d.ts} +18 -19
  2. package/dist/{BeraWagmi-Cgyr2tEA.d.cts → BeraWagmi-DqUsx-wd.d.cts} +18 -19
  3. package/dist/chunk-3MA6ZB64.cjs +1 -0
  4. package/dist/chunk-3VNWHDTQ.cjs +1 -0
  5. package/dist/chunk-HH2ZYQRJ.mjs +1 -0
  6. package/dist/chunk-YYGDSOWD.mjs +1 -0
  7. package/dist/config/index.cjs +1 -1
  8. package/dist/config/index.d.cts +13 -18
  9. package/dist/config/index.d.ts +13 -18
  10. package/dist/config/index.mjs +1 -1
  11. package/dist/context/index.cjs +1 -1
  12. package/dist/context/index.d.cts +8 -6
  13. package/dist/context/index.d.ts +8 -6
  14. package/dist/context/index.mjs +1 -1
  15. package/dist/core/thirdweb/index.cjs +1 -0
  16. package/dist/core/thirdweb/index.d.cts +74 -0
  17. package/dist/core/thirdweb/index.d.ts +74 -0
  18. package/dist/core/thirdweb/index.mjs +1 -0
  19. package/dist/hooks/index.cjs +1 -1
  20. package/dist/hooks/index.d.cts +23 -4
  21. package/dist/hooks/index.d.ts +23 -4
  22. package/dist/hooks/index.mjs +1 -1
  23. package/package.json +12 -8
  24. package/src/config/defaultWagmiConfig.ts +23 -142
  25. package/src/context/BeraWagmi.tsx +39 -104
  26. package/src/context/LightweightAccountProvider.tsx +9 -2
  27. package/src/context/WagmiProvider.tsx +30 -17
  28. package/src/context/useThirdweb.tsx +29 -23
  29. package/src/core/thirdweb/index.ts +61 -0
  30. package/src/hooks/index.ts +3 -1
  31. package/src/hooks/useBeraWallet.ts +2 -1
  32. package/src/hooks/useCapabilities.ts +34 -0
  33. package/dist/chunk-24VBIB22.cjs +0 -1
  34. package/dist/chunk-CPC3I7WV.cjs +0 -1
  35. package/dist/chunk-YGBWE4UM.mjs +0 -1
  36. package/dist/chunk-ZKXXJYGS.mjs +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@berachain/wagmi",
3
- "version": "0.2.0-beta.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -21,6 +21,12 @@
21
21
  "import": "./dist/*/index.mjs",
22
22
  "require": "./dist/*/index.cjs",
23
23
  "default": "./dist/*/index.mjs"
24
+ },
25
+ "./*/thirdweb": {
26
+ "types": "./dist/*/thirdweb/index.d.ts",
27
+ "import": "./dist/*/thirdweb/index.mjs",
28
+ "require": "./dist/*/thirdweb/index.cjs",
29
+ "default": "./dist/*/thirdweb/index.mjs"
24
30
  }
25
31
  },
26
32
  "typesVersions": {
@@ -34,25 +40,23 @@
34
40
  "author": "Berachain",
35
41
  "license": "MIT",
36
42
  "dependencies": {
37
- "@react-native-async-storage/async-storage": "2.2.0",
38
- "@tanstack/react-query": "5.59.0",
39
43
  "@thirdweb-dev/wagmi-adapter": "0.2.204",
40
44
  "@wagmi/core": "2.22.1",
41
- "porto": "0.2.23",
42
45
  "swr": "2.3.3",
43
- "thirdweb": "5.118.0",
44
- "@berachain/config": "0.0.7"
46
+ "thirdweb": "5.118.2"
45
47
  },
46
48
  "devDependencies": {
47
49
  "@types/node": "24.1.0",
48
50
  "@types/react": "19.1.8",
49
51
  "tsup": "8.4.0",
50
- "viem": "2.41.2",
51
- "wagmi": "2.19.5"
52
+ "viem": "2.45.0",
53
+ "wagmi": "2.19.5",
54
+ "@berachain/config": "0.1.0"
52
55
  },
53
56
  "peerDependencies": {
54
57
  "react": "^19.1",
55
58
  "react-dom": "^19.1",
59
+ "@tanstack/react-query": "^5.59.0",
56
60
  "viem": "^2.41.2",
57
61
  "wagmi": "^2.19.5"
58
62
  },
@@ -7,125 +7,36 @@ import {
7
7
  inAppWallet,
8
8
  } from "thirdweb/wallets";
9
9
  import type { Chain, Transport } from "viem";
10
- import {
11
- arbitrum,
12
- avalanche,
13
- base,
14
- berachain,
15
- berachainBepolia,
16
- bsc,
17
- mainnet,
18
- optimism,
19
- polygon,
20
- } from "viem/chains";
21
- import {
22
- type Config,
23
- createConfig,
24
- createStorage,
25
- fallback,
26
- http,
27
- } from "wagmi";
28
-
29
- import {
30
- alchemyJsonRpcUrl,
31
- appConfig,
32
- chainId,
33
- jsonRpcUrl,
34
- privateRcpUrl,
35
- publicJsonRpcUrl,
36
- } from "@berachain/config/internal";
10
+ import { type Config, createConfig, createStorage } from "wagmi";
37
11
 
38
- /**
39
- * Using default viem chain definition since it also includes ens and other metadata
40
- */
41
- export const chain: Chain =
42
- chainId === berachain.id ? berachain : berachainBepolia;
43
-
44
- export const defaultBeraNetworkConfig: NetworkConfig = {
45
- chain: chain,
46
- };
47
-
48
- export interface NetworkConfig {
49
- chain: Chain;
12
+ export interface ThirdwebConfig {
13
+ sponsorGas?: boolean;
14
+ embeddedWallets?: boolean;
15
+ clientId: string;
50
16
  }
51
- const hasMulticall = !!chain.contracts?.multicall3;
52
17
 
53
- /**
54
- * Exporting this is helpful for the multi-chain zap, to get the list of chains that we want to support.
55
- */
56
- export const externalChains: Chain[] = [
57
- mainnet,
58
- polygon,
59
- optimism,
60
- base,
61
- bsc,
62
- arbitrum,
63
- avalanche,
64
- ] as const;
65
-
66
- export const chainIdToName: Record<Chain["id"], string> = [
67
- ...externalChains,
68
- berachain,
69
- berachainBepolia,
70
- ].reduce(
71
- (acc, chain) => {
72
- acc[chain.id] = chain.name;
73
- return acc;
74
- },
75
- {} as Record<Chain["id"], string>,
76
- );
77
-
78
- /**
79
- * Thirdweb RPC URLs have a rate limit of 3 RPS.
80
- * http() uses default viem transport which varies based on the chain definition.
81
- *
82
- * Quicknode RPC URLs are CORS restricted to *.berachain.com, *.berachain-staging.com. They have a 100rpm rate limit.
83
- */
84
- const externalTransports: Record<Chain["id"], (string | undefined)[]> = {
85
- [mainnet.id]: [
86
- "https://1.rpc.thirdweb.com/",
87
- "https://ultra-sleek-pond.quiknode.pro/08ab7832de196248b7ba7dcffad268c9b3747f48/",
88
- ],
89
- [polygon.id]: [
90
- "https://137.rpc.thirdweb.com/",
91
- "https://sleek-thrilling-orb.matic.quiknode.pro/592d9950044bf173c232f5ecf79a2725c43f517b/",
92
- ],
93
- [optimism.id]: [
94
- "https://10.rpc.thirdweb.com/",
95
- "https://blue-neat-liquid.optimism.quiknode.pro/26ca3fe255f687652124050450faada988023979/",
96
- ],
97
- [base.id]: [
98
- "https://8453.rpc.thirdweb.com/",
99
- "https://soft-empty-sailboat.base-mainnet.quiknode.pro/bb9300074b062c5e0a1e93e0a8ebd53501c32fe7/",
100
- ],
101
- [bsc.id]: [
102
- "https://56.rpc.thirdweb.com/",
103
- "https://chaotic-floral-brook.bsc.quiknode.pro/6f0e5a9791285c6b59f2a6a907a62ec9d581d7bd/",
104
- ],
105
- [avalanche.id]: [
106
- "https://43114.rpc.thirdweb.com/",
107
- "https://shy-special-mansion.avalanche-mainnet.quiknode.pro/efa880845032c2ef4049637d779d2ae58acf0f65/ext/bc/C/rpc/",
108
- ],
109
- [arbitrum.id]: [
110
- "https://42161.rpc.thirdweb.com/",
111
- "https://fluent-broken-violet.arbitrum-mainnet.quiknode.pro/445b20e9ed10e22fffee6498a40c4f83f83f4ec7/",
112
- ],
113
- };
18
+ export interface BeraWagmiConfig {
19
+ thirdweb: ThirdwebConfig;
20
+ transports?: Record<number, Transport>;
21
+ chains?: Chain[];
22
+ defaultChain: Chain;
23
+ }
114
24
 
115
25
  export function getConfig({
116
- sponsorGas,
117
- enableEmbeddedWallets,
118
- }: {
119
- sponsorGas?: boolean;
120
- enableEmbeddedWallets: boolean;
121
- }) {
26
+ thirdweb,
27
+ transports = {},
28
+ defaultChain: chain,
29
+ chains = [],
30
+ }: BeraWagmiConfig) {
122
31
  const thirdwebClient = createThirdwebClient({
123
- clientId: appConfig.apiKeys.public.thirdweb,
32
+ clientId: thirdweb.clientId,
124
33
  });
125
34
 
35
+ const hasMulticall = !!chain.contracts?.multicall3;
36
+
126
37
  const executionMode = {
127
38
  mode: "EIP7702",
128
- sponsorGas,
39
+ sponsorGas: thirdweb.sponsorGas,
129
40
  } as const satisfies NonNullable<InAppWalletCreationOptions>["executionMode"];
130
41
 
131
42
  const thirdwebWallet: ReturnType<typeof inAppWallet> = inAppWallet({
@@ -142,11 +53,11 @@ export function getConfig({
142
53
  ].filter((w, index, self) => self.findIndex((t) => t.id === w.id) === index);
143
54
 
144
55
  return {
145
- wallets: enableEmbeddedWallets ? [thirdwebWallet, ...wallets] : wallets,
56
+ wallets: thirdweb.embeddedWallets ? [thirdwebWallet, ...wallets] : wallets,
146
57
  executionMode,
147
58
  client: thirdwebClient,
148
59
  wagmi: createConfig({
149
- chains: [defaultBeraNetworkConfig.chain, ...externalChains],
60
+ chains: [chain, ...chains],
150
61
  // recommended by wagmi docs https://wagmi.sh/react/guides/ssr#ssr
151
62
  ssr: true,
152
63
  connectors: [
@@ -172,37 +83,7 @@ export function getConfig({
172
83
  }
173
84
  : undefined,
174
85
  },
175
- transports: {
176
- [defaultBeraNetworkConfig.chain.id]: fallback(
177
- [privateRcpUrl, jsonRpcUrl, alchemyJsonRpcUrl, publicJsonRpcUrl]
178
- .filter((i) => i)
179
- .map((url) =>
180
- http(url, {
181
- batch: {
182
- wait: 35,
183
- },
184
- }),
185
- ),
186
- ),
187
- ...Object.entries(externalTransports).reduce<
188
- Record<Chain["id"], Transport>
189
- >((acc, [chainId, urls]) => {
190
- acc[Number(chainId) as Chain["id"]] = fallback(
191
- [
192
- ...urls,
193
- // undefined for default rpc
194
- undefined,
195
- ].map((url) =>
196
- http(url, {
197
- batch: {
198
- wait: 15,
199
- },
200
- }),
201
- ),
202
- );
203
- return acc;
204
- }, {}),
205
- },
86
+ transports,
206
87
  }) as Config,
207
88
  };
208
89
  }
@@ -1,36 +1,21 @@
1
1
  import {
2
2
  createContext,
3
3
  type PropsWithChildren,
4
- useCallback,
5
4
  useContext,
6
5
  useMemo,
7
6
  } from "react";
8
7
  import useSWRImmutable from "swr/immutable";
9
- import type { Address, Chain, GetCapabilitiesReturnType } from "viem";
10
- import {
11
- arbitrum,
12
- avalanche,
13
- base,
14
- bsc,
15
- mainnet,
16
- optimism,
17
- polygon,
18
- } from "viem/chains";
8
+ import type { Address, Chain } from "viem";
19
9
  import { normalize } from "viem/ens";
20
10
  import {
21
11
  type UseWalletClientReturnType,
22
12
  useAccount,
23
- useCapabilities,
24
13
  useDisconnect,
25
14
  usePublicClient,
26
15
  useWalletClient,
27
16
  } from "wagmi";
28
17
 
29
- import { defaultChainId } from "@berachain/config/internal";
30
- import type { EdgeConfigSchema } from "@berachain/config/internal/edge-config";
31
- import { isFlagEnabled } from "@berachain/config/internal/edge-config";
32
-
33
- import type { getConfig } from "~/config";
18
+ import type { getConfig, ThirdwebConfig } from "~/config";
34
19
  import { useEnsAvatar, useEnsName } from "../hooks";
35
20
  import { LightweightAccountProvider } from "./LightweightAccountProvider";
36
21
  import { useThirdweb } from "./useThirdweb";
@@ -61,18 +46,7 @@ export interface BeraWagmiApi {
61
46
  */
62
47
  isEmbeddedWallet: boolean;
63
48
  connectorName: string | null;
64
- flags: {
65
- getSupportsAtomic: (chainId: number) => boolean;
66
- };
67
- /**
68
- * Wallet provider capabilities for the current account.
69
- *
70
- * Status can be:
71
- * - supported: User has enabled the feature.
72
- * - ready: The wallet provider is ready to use the feature.
73
- * - unsupported: The wallet provider does not support the feature.
74
- */
75
- capabilities: GetCapabilitiesReturnType | undefined;
49
+ connectionId: string;
76
50
  /**
77
51
  * Wallet to display.
78
52
  *
@@ -105,6 +79,10 @@ export interface BeraWagmiApi {
105
79
  isEmbeddedWalletsEnabled: boolean;
106
80
  isConnected: boolean;
107
81
  isConnecting: boolean;
82
+ flags: {
83
+ disableEip5792: boolean;
84
+ disable5792Upgrade: boolean;
85
+ };
108
86
  walletClient: UseWalletClientReturnType["data"];
109
87
  connectWallet: () => Promise<void> | void;
110
88
  disconnect(): void;
@@ -117,15 +95,20 @@ export interface BeraWagmiApi {
117
95
  /**
118
96
  * List of external chains that are whitelisted for that app.
119
97
  */
120
- externalChainList: Chain[];
98
+ chains: Chain[];
99
+ defaultChainId: ChainId;
121
100
  }
122
101
 
123
102
  const BeraWagmiContext = createContext<BeraWagmiApi | undefined>(undefined);
124
103
 
104
+ export enum ChainId {
105
+ MAINNET = 80094,
106
+ BEPOLIA = 80069,
107
+ }
108
+
125
109
  export interface IBeraWagmiProviderProps extends PropsWithChildren {
126
110
  config: ReturnType<typeof getConfig>;
127
111
  theme?: "dark" | "light" | "auto";
128
- isEmbeddedWalletsEnabled: boolean;
129
112
  disableEip5792: boolean;
130
113
  /**
131
114
  * Whether to disable the 5792 upgrade for users that haven't upgraded yet.
@@ -135,63 +118,31 @@ export interface IBeraWagmiProviderProps extends PropsWithChildren {
135
118
  disable5792Upgrade?: boolean;
136
119
  accountOverride?: Address;
137
120
  onSmartAccountRejection?: () => void;
138
- edgeConfigChainList: EdgeConfigSchema["wagmi"]["externalChainList"];
139
121
  /**
140
122
  * Event triggered when a wallet is connected manually.
141
123
  *
142
124
  * This is not triggered when a wallet connect automatically after a refresh.
143
125
  */
144
126
  onConnectedWallet?: () => void;
145
- }
146
-
147
- /**
148
- * This are the chains that have been approved by the Bera team to be used in the BeraHub,
149
- * for multi chain zapping.
150
- */
151
- const externalApprovedChains = [
152
- mainnet,
153
- polygon,
154
- optimism,
155
- base,
156
- bsc,
157
- avalanche,
158
- arbitrum,
159
- ];
160
-
161
- /**
162
- * The chain is selected
163
- * - if it's part of the pre-approved array
164
- * - if it's not present in the edge config
165
- * - if it's present and it is enabled on this env, branch & app
166
- */
167
- function getExternalChainList({
168
- externalChainList,
169
- }: {
170
- externalChainList: EdgeConfigSchema["wagmi"]["externalChainList"];
171
- }): Chain[] {
172
- return externalApprovedChains.filter((aChain): boolean => {
173
- const extChain = externalChainList?.find((c) => c.chainId === aChain.id);
174
- return !extChain || isFlagEnabled(extChain.enabled);
175
- });
127
+ chains: Chain[];
128
+ defaultChain: Chain;
129
+ thirdweb: ThirdwebConfig;
130
+ publicJsonRpcUrl: string;
176
131
  }
177
132
 
178
133
  export function BeraWagmiProvider({
179
134
  children,
180
135
  config,
181
- isEmbeddedWalletsEnabled,
182
136
  disableEip5792,
183
137
  disable5792Upgrade,
184
138
  theme,
185
139
  accountOverride,
186
140
  onSmartAccountRejection,
187
- edgeConfigChainList,
141
+ chains,
142
+ defaultChain,
143
+ thirdweb,
144
+ publicJsonRpcUrl,
188
145
  }: IBeraWagmiProviderProps) {
189
- const externalChainList = useMemo(() => {
190
- return getExternalChainList({
191
- externalChainList: edgeConfigChainList,
192
- });
193
- }, [edgeConfigChainList]);
194
-
195
146
  const {
196
147
  wallet,
197
148
  connect,
@@ -204,7 +155,9 @@ export function BeraWagmiProvider({
204
155
  } = useThirdweb({
205
156
  config,
206
157
  theme,
207
- extenalChains: externalChainList,
158
+ chains,
159
+ chain: defaultChain,
160
+ publicJsonRpcUrl,
208
161
  });
209
162
 
210
163
  const { address: connectedAddress, chainId } = useAccount(); // wagmi
@@ -219,32 +172,9 @@ export function BeraWagmiProvider({
219
172
  return accountOverride ?? connectedAddress;
220
173
  }, [accountOverride, connectedAddress, wallet]);
221
174
 
222
- const { data: capabilities } = useCapabilities({
223
- account: connectedAddress,
224
- // This is needed to avoid cache issues with the capabilities when switching wallets
225
- scopeKey: connectionId,
226
- query: {
227
- retry: 3,
228
- },
229
- // chainId: defaultChainId,
230
- });
231
- const getSupportsAtomic = useCallback(
232
- (targetChainId: number) => {
233
- if (disableEip5792) return false;
234
- if (!capabilities) return false;
235
-
236
- return (
237
- capabilities?.[targetChainId]?.atomic?.status === "supported" ||
238
- (!disable5792Upgrade &&
239
- capabilities?.[targetChainId]?.atomic?.status === "ready")
240
- );
241
- },
242
- [capabilities, disableEip5792, disable5792Upgrade],
243
- );
244
-
245
175
  const { data: ens } = useEnsName({
246
176
  config: config.wagmi,
247
- chainId: defaultChainId,
177
+ chainId: defaultChain.id,
248
178
  address,
249
179
  });
250
180
 
@@ -295,11 +225,15 @@ export function BeraWagmiProvider({
295
225
  return (
296
226
  <BeraWagmiContext.Provider
297
227
  value={{
228
+ flags: {
229
+ disableEip5792,
230
+ disable5792Upgrade: !!disable5792Upgrade,
231
+ },
298
232
  walletClient,
299
233
  onSmartAccountRejection: () => {
300
234
  onSmartAccountRejection?.();
301
235
  },
302
- isEmbeddedWalletsEnabled,
236
+ isEmbeddedWalletsEnabled: thirdweb.embeddedWallets ?? true,
303
237
  isConnecting,
304
238
  isConnected:
305
239
  !!address &&
@@ -309,16 +243,13 @@ export function BeraWagmiProvider({
309
243
  account:
310
244
  wallet && chainId && address
311
245
  ? {
246
+ connectionId,
312
247
  chainId,
313
248
  connectorName,
314
249
  isEmbeddedWallet,
315
- capabilities,
316
- flags: {
317
- getSupportsAtomic,
318
- },
319
250
  wallet: {
320
251
  address,
321
- ensName: ens ?? null,
252
+ ensName: ens?.replace(".bera", ".🐻⛓️") ?? null,
322
253
  ensAvatar: avatar.data ?? null,
323
254
  has7702Authorization,
324
255
  isContract,
@@ -333,10 +264,14 @@ export function BeraWagmiProvider({
333
264
  disconnectWagmi();
334
265
  disconnectProvider();
335
266
  },
336
- externalChainList,
267
+ chains,
268
+ defaultChainId: defaultChain.id,
337
269
  }}
338
270
  >
339
- <LightweightAccountProvider address={address}>
271
+ <LightweightAccountProvider
272
+ address={address}
273
+ defaultChainId={defaultChain.id}
274
+ >
340
275
  {children}
341
276
  </LightweightAccountProvider>
342
277
  </BeraWagmiContext.Provider>
@@ -1,9 +1,12 @@
1
1
  import { createContext, type PropsWithChildren } from "react";
2
2
  import type { Address } from "viem";
3
3
 
4
+ import type { ChainId } from "./BeraWagmi";
5
+
4
6
  export const LightweightAccountContext = createContext<
5
7
  | {
6
8
  address: Address | undefined;
9
+ defaultChainId: ChainId;
7
10
  }
8
11
  | undefined
9
12
  >(undefined);
@@ -16,9 +19,13 @@ export const LightweightAccountContext = createContext<
16
19
  export function LightweightAccountProvider({
17
20
  children,
18
21
  address,
19
- }: PropsWithChildren<{ address: Address | undefined }>) {
22
+ defaultChainId,
23
+ }: PropsWithChildren<{
24
+ address: Address | undefined;
25
+ defaultChainId: ChainId;
26
+ }>) {
20
27
  return (
21
- <LightweightAccountContext.Provider value={{ address }}>
28
+ <LightweightAccountContext.Provider value={{ address, defaultChainId }}>
22
29
  {children}
23
30
  </LightweightAccountContext.Provider>
24
31
  );
@@ -2,33 +2,40 @@
2
2
 
3
3
  import { useMemo } from "react";
4
4
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
- import { Porto } from "porto";
6
5
  import { ThirdwebProvider } from "thirdweb/react";
6
+ import type { Chain, Transport } from "viem";
7
7
  import { WagmiProvider as WagmiProviderBase } from "wagmi";
8
8
 
9
9
  import { getConfig } from "~/config/defaultWagmiConfig";
10
10
  import { BeraWagmiProvider, type IBeraWagmiProviderProps } from "./BeraWagmi";
11
11
 
12
- const queryClient = new QueryClient();
12
+ type WagmiProviderProps = Omit<
13
+ IBeraWagmiProviderProps,
14
+ "config" | "defaultChain"
15
+ > & {
16
+ transports?: Record<number, Transport>;
17
+ defaultChain: Chain;
18
+ chains?: Chain[];
19
+ };
13
20
 
14
- // Initialize Porto to inject it into Dynamic via EIP-6963
15
- Porto.create();
21
+ const queryClient = new QueryClient();
16
22
 
17
23
  export function WagmiProvider({
18
- sponsorGas,
24
+ transports,
25
+ defaultChain,
26
+ chains,
27
+ thirdweb,
19
28
  ...beraWagmiProps
20
- }: Omit<IBeraWagmiProviderProps, "config"> & {
21
- sponsorGas?: boolean;
22
- }) {
29
+ }: WagmiProviderProps) {
23
30
  // useMemo to make sure this is initialized only once
24
- const config = useMemo(
25
- () =>
26
- getConfig({
27
- sponsorGas,
28
- enableEmbeddedWallets: beraWagmiProps.isEmbeddedWalletsEnabled,
29
- }),
30
- [],
31
- );
31
+ const config = useMemo(() => {
32
+ return getConfig({
33
+ thirdweb,
34
+ transports,
35
+ defaultChain,
36
+ chains,
37
+ });
38
+ }, [defaultChain, thirdweb, transports, chains]);
32
39
 
33
40
  return (
34
41
  <ThirdwebProvider>
@@ -38,7 +45,13 @@ export function WagmiProvider({
38
45
  reconnectOnMount={false}
39
46
  >
40
47
  <QueryClientProvider client={queryClient}>
41
- <BeraWagmiProvider {...beraWagmiProps} config={config} />
48
+ <BeraWagmiProvider
49
+ {...beraWagmiProps}
50
+ thirdweb={thirdweb}
51
+ chains={chains}
52
+ defaultChain={defaultChain}
53
+ config={config}
54
+ />
42
55
  </QueryClientProvider>
43
56
  </WagmiProviderBase>
44
57
  </ThirdwebProvider>
@@ -14,35 +14,21 @@ import type { Account, AutoConnectProps, Wallet } from "thirdweb/wallets";
14
14
  import type { Chain } from "viem";
15
15
  import { useConnect } from "wagmi";
16
16
 
17
- import { defaultChainId, publicJsonRpcUrl } from "@berachain/config/internal";
18
-
19
- import { chain, type getConfig } from "~/config";
17
+ import type { getConfig } from "~/config";
20
18
  import type { UseWalletProviderReturnType } from "./types";
21
19
 
22
- const thirdwebChain = defineChain({
23
- id: chain.id,
24
- blockExplorers: chain.blockExplorers,
25
- blockTime: chain.blockTime,
26
- ensTlds: chain.ensTlds,
27
- testnet: chain.testnet,
28
- contracts: chain.contracts,
29
- nativeCurrency: chain.nativeCurrency,
30
- name: chain.name,
31
- rpcUrls: {
32
- default: {
33
- http: [publicJsonRpcUrl],
34
- },
35
- },
36
- });
37
-
38
20
  export function useThirdweb({
39
21
  config,
40
22
  theme,
41
- extenalChains,
23
+ chains,
24
+ chain,
25
+ publicJsonRpcUrl,
42
26
  }: {
43
27
  config: ReturnType<typeof getConfig>;
44
28
  theme: "light" | "dark" | "auto" | undefined;
45
- extenalChains: Chain[];
29
+ chains: Chain[];
30
+ publicJsonRpcUrl: string;
31
+ chain: Chain;
46
32
  }): UseWalletProviderReturnType<Account> {
47
33
  const { connectors, connect: wagmiConnect } = useConnect();
48
34
 
@@ -51,6 +37,26 @@ export function useThirdweb({
51
37
  const { disconnect: disconnectThirdweb } = useTwDisconnect();
52
38
  const { data: walletInfo } = useWalletInfo(activeWallet?.id);
53
39
 
40
+ const thirdwebChain = useMemo(
41
+ () =>
42
+ defineChain({
43
+ id: chain.id,
44
+ blockExplorers: chain.blockExplorers,
45
+ blockTime: chain.blockTime,
46
+ ensTlds: chain.ensTlds,
47
+ testnet: chain.testnet,
48
+ contracts: chain.contracts,
49
+ nativeCurrency: chain.nativeCurrency,
50
+ name: chain.name,
51
+ rpcUrls: {
52
+ default: {
53
+ http: [publicJsonRpcUrl],
54
+ },
55
+ },
56
+ }),
57
+ [publicJsonRpcUrl, chain],
58
+ );
59
+
54
60
  const connectOptions = {
55
61
  client: config.client,
56
62
  chain: thirdwebChain,
@@ -70,7 +76,7 @@ export function useThirdweb({
70
76
 
71
77
  wagmiConnect({
72
78
  connector: twConnector,
73
- chainId: defaultChainId,
79
+ chainId: chain.id,
74
80
  ...options,
75
81
  });
76
82
  } else {
@@ -100,7 +106,7 @@ export function useThirdweb({
100
106
  size: "compact",
101
107
  chains: [
102
108
  thirdwebChain,
103
- ...extenalChains.map((c) =>
109
+ ...chains.map((c) =>
104
110
  defineChain({
105
111
  id: c.id,
106
112
  }),