@berachain/wagmi 0.4.2-beta.2 → 0.4.2-beta.4
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.
- package/dist/{BeraWagmi-D_9r9lFE.d.cts → BeraWagmi-DPriTsqn.d.cts} +1 -1
- package/dist/{BeraWagmi-BYoBR8sq.d.ts → BeraWagmi-PCCV3r-u.d.ts} +1 -1
- package/dist/chunk-FMEKPQER.cjs +1 -0
- package/dist/chunk-FPJ6HXP4.mjs +1 -0
- package/dist/chunk-HU7OL27P.mjs +1 -0
- package/dist/chunk-OLYL3V2D.cjs +1 -0
- package/dist/context/index.cjs +1 -1
- package/dist/context/index.d.cts +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/context/lightweight/index.cjs +1 -0
- package/dist/context/lightweight/index.d.cts +27 -0
- package/dist/context/lightweight/index.d.ts +27 -0
- package/dist/context/lightweight/index.mjs +1 -0
- package/dist/hooks/index.cjs +1 -1
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.mjs +1 -1
- package/package.json +1 -1
- package/src/context/BeraWagmi.tsx +18 -147
- package/src/context/BeraWagmiLightWeight.tsx +37 -174
- package/src/context/WagmiProviderLightWeight.tsx +39 -14
- package/src/context/beraWagmiContext.ts +7 -0
- package/src/context/useThirdweb.tsx +21 -158
- package/src/context/useThirdwebLightWeight.tsx +26 -23
- package/dist/chunk-CGJ4MZ4C.mjs +0 -1
- package/dist/chunk-GZLYCTRI.cjs +0 -1
- package/dist/chunk-HSGI3QYR.cjs +0 -1
- package/dist/chunk-RFS3IIRD.mjs +0 -1
- package/dist/context/thirdweb/index.cjs +0 -1
- package/dist/context/thirdweb/index.d.cts +0 -47
- package/dist/context/thirdweb/index.d.ts +0 -47
- package/dist/context/thirdweb/index.mjs +0 -1
- /package/src/context/{thirdweb → lightweight}/index.ts +0 -0
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
type PropsWithChildren,
|
|
4
|
-
useContext,
|
|
5
|
-
useMemo,
|
|
6
|
-
} from "react";
|
|
1
|
+
import { type PropsWithChildren, useMemo } from "react";
|
|
7
2
|
import useSWRImmutable from "swr/immutable";
|
|
8
|
-
import type {
|
|
9
|
-
MultiStepAuthArgsType,
|
|
10
|
-
Profile,
|
|
11
|
-
SingleStepAuthArgsType,
|
|
12
|
-
Wallet,
|
|
13
|
-
} from "thirdweb/wallets";
|
|
14
3
|
import type { Address, Chain } from "viem";
|
|
15
4
|
import { normalize } from "viem/ens";
|
|
16
5
|
import {
|
|
17
|
-
type UseWalletClientReturnType,
|
|
18
6
|
useAccount,
|
|
19
7
|
useDisconnect,
|
|
20
8
|
useEnsAvatar,
|
|
@@ -24,152 +12,40 @@ import {
|
|
|
24
12
|
} from "wagmi";
|
|
25
13
|
|
|
26
14
|
import type { getConfig, ThirdwebConfig } from "../config";
|
|
15
|
+
import type { BeraWagmiApi } from "./BeraWagmi";
|
|
16
|
+
import { BeraWagmiContext } from "./beraWagmiContext";
|
|
27
17
|
import { LightweightAccountProvider } from "./LightweightAccountProvider";
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
export function useBeraWagmi() {
|
|
31
|
-
const context = useContext(BeraWagmiContext);
|
|
32
|
-
if (!context) {
|
|
33
|
-
throw new Error("BeraWagmiContext not found");
|
|
34
|
-
}
|
|
35
|
-
return context;
|
|
36
|
-
}
|
|
37
|
-
export interface BeraWagmiApi {
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated used for prototyping only.
|
|
40
|
-
*/
|
|
41
|
-
DebugConnectButton(): React.ReactNode;
|
|
42
|
-
/**
|
|
43
|
-
* Account connected to berachain dapp. It might include some additional data once embedded wallets are enabled.
|
|
44
|
-
*/
|
|
45
|
-
account:
|
|
46
|
-
| {
|
|
47
|
-
/**
|
|
48
|
-
* Chain ID to which the wallet provider is currently connected to.
|
|
49
|
-
*/
|
|
50
|
-
chainId: number;
|
|
51
|
-
/**
|
|
52
|
-
* Whether the wallet is an embedded wallet.
|
|
53
|
-
*/
|
|
54
|
-
isEmbeddedWallet: boolean;
|
|
55
|
-
connectorName: string | null;
|
|
56
|
-
connectionId: string;
|
|
57
|
-
profiles: Profile[] | undefined;
|
|
58
|
-
/**
|
|
59
|
-
* Wallet to display.
|
|
60
|
-
*
|
|
61
|
-
* This might be manually overridden by the accountOverride prop, thus not being the same as the connected wallet.
|
|
62
|
-
*/
|
|
63
|
-
wallet:
|
|
64
|
-
| {
|
|
65
|
-
address: Address;
|
|
66
|
-
/**
|
|
67
|
-
* ENS name of the wallet.
|
|
68
|
-
*/
|
|
69
|
-
ensName: string | null;
|
|
70
|
-
/**
|
|
71
|
-
* ENS avatar of the wallet.
|
|
72
|
-
*/
|
|
73
|
-
ensAvatar: string | null;
|
|
74
|
-
/**
|
|
75
|
-
* Whether the wallet has 7702 authorization.
|
|
76
|
-
*/
|
|
77
|
-
has7702Authorization: boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Whether the wallet is a contract.
|
|
80
|
-
*/
|
|
81
|
-
isContract: boolean;
|
|
82
|
-
}
|
|
83
|
-
| undefined;
|
|
84
|
-
}
|
|
85
|
-
| undefined;
|
|
86
|
-
isEmbeddedWalletsEnabled: boolean;
|
|
87
|
-
isConnected: boolean;
|
|
88
|
-
isConnecting: boolean;
|
|
89
|
-
flags: {
|
|
90
|
-
disableEip5792: boolean;
|
|
91
|
-
disable5792Upgrade: boolean;
|
|
92
|
-
};
|
|
93
|
-
walletClient: UseWalletClientReturnType["data"];
|
|
94
|
-
openConnectModal(): Promise<void> | void;
|
|
95
|
-
/**
|
|
96
|
-
* Connects a wallet using a specific strategy.
|
|
97
|
-
* For email/phone use MultiStepAuthArgsType (requires preAuthenticate first).
|
|
98
|
-
*/
|
|
99
|
-
connect(
|
|
100
|
-
args: SingleStepAuthArgsType | MultiStepAuthArgsType,
|
|
101
|
-
): Promise<Wallet | null> | undefined;
|
|
102
|
-
/**
|
|
103
|
-
* Sends an OTP to the user's email or phone number.
|
|
104
|
-
* Call this before connect() when using email or phone strategy.
|
|
105
|
-
*/
|
|
106
|
-
preAuthenticate(
|
|
107
|
-
args:
|
|
108
|
-
| { strategy: "email"; email: string }
|
|
109
|
-
| { strategy: "phone"; phoneNumber: string },
|
|
110
|
-
): Promise<void>;
|
|
111
|
-
disconnect(): void;
|
|
112
|
-
/**
|
|
113
|
-
* A callback that is called when a smart account upgrade is rejected.
|
|
114
|
-
*
|
|
115
|
-
* This is used to disable EIP-5792 temporarily.
|
|
116
|
-
*/
|
|
117
|
-
onSmartAccountRejection(): void;
|
|
118
|
-
|
|
119
|
-
defaultChainId: ChainId;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const BeraWagmiContext = createContext<BeraWagmiApi | undefined>(undefined);
|
|
123
|
-
|
|
124
|
-
export enum ChainId {
|
|
125
|
-
MAINNET = 80094,
|
|
126
|
-
BEPOLIA = 80069,
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export type ConnectEvent =
|
|
130
|
-
| { type: "connect"; data: SingleStepAuthArgsType | MultiStepAuthArgsType }
|
|
131
|
-
| { type: "connect_modal" };
|
|
18
|
+
import type { UseThirdwebBaseResult } from "./useThirdwebLightWeight";
|
|
132
19
|
|
|
133
|
-
export interface
|
|
20
|
+
export interface IBeraWagmiProviderBaseProps extends PropsWithChildren {
|
|
134
21
|
config: ReturnType<typeof getConfig>;
|
|
135
|
-
theme?: "dark" | "light" | "auto";
|
|
136
22
|
flags?: {
|
|
137
23
|
disableEip5792?: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* Whether to disable the 5792 upgrade for users that haven't upgraded yet.
|
|
140
|
-
*
|
|
141
|
-
* `atomic.status === "ready"`
|
|
142
|
-
*/
|
|
143
24
|
disable5792Upgrade?: boolean;
|
|
144
|
-
/**
|
|
145
|
-
* A value that mocks the connected wallet address, while transactions are still sent from the connected wallet.
|
|
146
|
-
* It can be used for advanced use cases like sending permissionless transactions (like incentive claims).
|
|
147
|
-
*/
|
|
148
25
|
accountOverride?: Address;
|
|
149
26
|
};
|
|
150
27
|
onSmartAccountRejection?: () => void;
|
|
151
|
-
onConnect?: (event: ConnectEvent) => void;
|
|
152
|
-
onConnectError?: (error: Error) => void;
|
|
153
|
-
chains?: Chain[];
|
|
154
28
|
defaultChain: Chain;
|
|
155
29
|
thirdweb: ThirdwebConfig;
|
|
156
|
-
|
|
30
|
+
/** The thirdweb hook result — lightweight or full. */
|
|
31
|
+
thirdwebResult: UseThirdwebBaseResult;
|
|
32
|
+
/** Provided by the full variant; lightweight stubs these. */
|
|
33
|
+
openConnectModal?: BeraWagmiApi["openConnectModal"];
|
|
34
|
+
DebugConnectButton?: BeraWagmiApi["DebugConnectButton"];
|
|
157
35
|
}
|
|
158
36
|
|
|
159
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Base provider that wires up the BeraWagmiContext.
|
|
39
|
+
* Both the lightweight and full WagmiProviders render this.
|
|
40
|
+
*/
|
|
41
|
+
export function BeraWagmiProviderBase({
|
|
160
42
|
children,
|
|
161
43
|
config,
|
|
162
44
|
flags: { disableEip5792, disable5792Upgrade, accountOverride } = {},
|
|
163
|
-
theme,
|
|
164
45
|
onSmartAccountRejection,
|
|
165
|
-
chains = [],
|
|
166
46
|
defaultChain,
|
|
167
47
|
thirdweb,
|
|
168
|
-
|
|
169
|
-
onConnect,
|
|
170
|
-
onConnectError,
|
|
171
|
-
}: IBeraWagmiProviderProps) {
|
|
172
|
-
const {
|
|
48
|
+
thirdwebResult: {
|
|
173
49
|
wallet,
|
|
174
50
|
connect,
|
|
175
51
|
connectionId,
|
|
@@ -179,25 +55,17 @@ export function BeraWagmiProvider({
|
|
|
179
55
|
profiles,
|
|
180
56
|
preAuthenticate,
|
|
181
57
|
isConnecting,
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
publicJsonRpcUrl,
|
|
188
|
-
onConnect,
|
|
189
|
-
onConnectError,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const { address: connectedAddress, chainId } = useAccount(); // wagmi
|
|
58
|
+
},
|
|
59
|
+
openConnectModal,
|
|
60
|
+
DebugConnectButton,
|
|
61
|
+
}: IBeraWagmiProviderBaseProps) {
|
|
62
|
+
const { address: connectedAddress, chainId } = useAccount();
|
|
193
63
|
|
|
194
64
|
const { disconnect: disconnectWagmi } = useDisconnect();
|
|
195
65
|
const publicClient = usePublicClient();
|
|
196
66
|
|
|
197
67
|
const address = useMemo<Address | undefined>(() => {
|
|
198
|
-
// no address anyway if no connected address
|
|
199
68
|
if (!connectedAddress || !wallet) return undefined;
|
|
200
|
-
|
|
201
69
|
return accountOverride ?? connectedAddress;
|
|
202
70
|
}, [accountOverride, connectedAddress, wallet]);
|
|
203
71
|
|
|
@@ -219,18 +87,14 @@ export function BeraWagmiProvider({
|
|
|
219
87
|
},
|
|
220
88
|
);
|
|
221
89
|
const [isContract, has7702Authorization] = useMemo(() => {
|
|
222
|
-
if (!code)
|
|
223
|
-
// if no code, it's not a contract or has 7702 authorization
|
|
224
|
-
return [false, false];
|
|
90
|
+
if (!code) return [false, false];
|
|
225
91
|
|
|
226
92
|
const has7702Authorization = code.startsWith("0xef01");
|
|
227
93
|
|
|
228
94
|
if (has7702Authorization) {
|
|
229
|
-
// if has 7702 authorization, it's not a contract
|
|
230
95
|
return [false, true];
|
|
231
96
|
}
|
|
232
97
|
|
|
233
|
-
// if doesn't have 7702 authorization but has code, it's a contract
|
|
234
98
|
return [true, false];
|
|
235
99
|
}, [code]);
|
|
236
100
|
|
|
@@ -238,11 +102,10 @@ export function BeraWagmiProvider({
|
|
|
238
102
|
|
|
239
103
|
const normalizedEns = useMemo(() => {
|
|
240
104
|
try {
|
|
241
|
-
// some characters might throw an error when normalizing
|
|
242
|
-
// for instance `_` throws an error (e.g. `bera_boy`)
|
|
243
105
|
return ens ? normalize(ens) : undefined;
|
|
244
106
|
} catch {
|
|
245
|
-
//
|
|
107
|
+
// some characters might throw an error when normalizing
|
|
108
|
+
// for instance `_` throws an error (e.g. `bera_boy`)
|
|
246
109
|
// @see https://berachain-dapps.sentry.io/issues/6949741717/?alert_rule_id=16379160&alert_type=issue¬ification_uuid=b01366a6-78b0-4348-a3c1-5f76ced1d539&project=4509842561630209
|
|
247
110
|
}
|
|
248
111
|
}, [ens]);
|
|
@@ -265,13 +128,12 @@ export function BeraWagmiProvider({
|
|
|
265
128
|
},
|
|
266
129
|
isEmbeddedWalletsEnabled: thirdweb.embeddedWallets ?? true,
|
|
267
130
|
isConnecting,
|
|
268
|
-
isConnected:
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
},
|
|
131
|
+
isConnected: !!address && !!walletClient,
|
|
132
|
+
DebugConnectButton:
|
|
133
|
+
DebugConnectButton ??
|
|
134
|
+
(() => {
|
|
135
|
+
return null;
|
|
136
|
+
}),
|
|
275
137
|
account:
|
|
276
138
|
wallet && chainId && address
|
|
277
139
|
? {
|
|
@@ -290,16 +152,17 @@ export function BeraWagmiProvider({
|
|
|
290
152
|
}
|
|
291
153
|
: undefined,
|
|
292
154
|
connect,
|
|
293
|
-
openConnectModal
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
155
|
+
openConnectModal:
|
|
156
|
+
openConnectModal ??
|
|
157
|
+
(() => {
|
|
158
|
+
throw new Error(
|
|
159
|
+
"openConnectModal is not available in lightweight mode. Use @berachain/wagmi/context instead.",
|
|
160
|
+
);
|
|
161
|
+
}),
|
|
298
162
|
disconnect: () => {
|
|
299
163
|
disconnectWagmi();
|
|
300
164
|
disconnectProvider();
|
|
301
165
|
},
|
|
302
|
-
// chains,
|
|
303
166
|
defaultChainId: defaultChain.id,
|
|
304
167
|
}}
|
|
305
168
|
>
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
3
4
|
import { useMemo } from "react";
|
|
4
5
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
6
|
import { ThirdwebProvider } from "thirdweb/react";
|
|
6
|
-
import type { Chain, Transport } from "viem";
|
|
7
|
+
import type { Address, Chain, Transport } from "viem";
|
|
7
8
|
import { WagmiProvider as WagmiProviderBase } from "wagmi";
|
|
8
9
|
|
|
10
|
+
import type { ThirdwebConfig } from "../config";
|
|
9
11
|
import { getConfig } from "../config/defaultWagmiConfig";
|
|
10
|
-
import {
|
|
12
|
+
import type { ConnectEvent } from "./BeraWagmi";
|
|
13
|
+
import { BeraWagmiProviderBase } from "./BeraWagmiLightWeight";
|
|
14
|
+
import { useThirdwebLightWeight } from "./useThirdwebLightWeight";
|
|
11
15
|
|
|
12
|
-
type
|
|
13
|
-
IBeraWagmiProviderProps,
|
|
14
|
-
"config" | "defaultChain"
|
|
15
|
-
> & {
|
|
16
|
+
type WagmiProviderLightWeightProps = PropsWithChildren<{
|
|
16
17
|
transports?: Record<number, Transport>;
|
|
17
18
|
defaultChain: Chain;
|
|
18
|
-
|
|
19
|
+
chains?: Chain[];
|
|
20
|
+
thirdweb: ThirdwebConfig;
|
|
21
|
+
flags?: {
|
|
22
|
+
disableEip5792?: boolean;
|
|
23
|
+
disable5792Upgrade?: boolean;
|
|
24
|
+
accountOverride?: Address;
|
|
25
|
+
};
|
|
26
|
+
onSmartAccountRejection?: () => void;
|
|
27
|
+
onConnect?: (event: ConnectEvent) => void;
|
|
28
|
+
onConnectError?: (error: Error) => void;
|
|
29
|
+
publicJsonRpcUrl?: string;
|
|
30
|
+
}>;
|
|
19
31
|
|
|
20
32
|
const queryClient = new QueryClient();
|
|
21
33
|
|
|
@@ -24,9 +36,12 @@ export function WagmiProvider({
|
|
|
24
36
|
defaultChain,
|
|
25
37
|
chains,
|
|
26
38
|
thirdweb,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
children,
|
|
40
|
+
onConnect,
|
|
41
|
+
onConnectError,
|
|
42
|
+
publicJsonRpcUrl,
|
|
43
|
+
...baseProps
|
|
44
|
+
}: WagmiProviderLightWeightProps) {
|
|
30
45
|
const config = useMemo(() => {
|
|
31
46
|
return getConfig({
|
|
32
47
|
thirdweb,
|
|
@@ -36,6 +51,14 @@ export function WagmiProvider({
|
|
|
36
51
|
});
|
|
37
52
|
}, [defaultChain, thirdweb, transports, chains]);
|
|
38
53
|
|
|
54
|
+
const thirdwebResult = useThirdwebLightWeight({
|
|
55
|
+
config,
|
|
56
|
+
chain: defaultChain,
|
|
57
|
+
publicJsonRpcUrl,
|
|
58
|
+
onConnect,
|
|
59
|
+
onConnectError,
|
|
60
|
+
});
|
|
61
|
+
|
|
39
62
|
return (
|
|
40
63
|
<ThirdwebProvider>
|
|
41
64
|
<WagmiProviderBase
|
|
@@ -44,13 +67,15 @@ export function WagmiProvider({
|
|
|
44
67
|
reconnectOnMount={false}
|
|
45
68
|
>
|
|
46
69
|
<QueryClientProvider client={queryClient}>
|
|
47
|
-
<
|
|
48
|
-
{...
|
|
70
|
+
<BeraWagmiProviderBase
|
|
71
|
+
{...baseProps}
|
|
49
72
|
thirdweb={thirdweb}
|
|
50
|
-
chains={chains}
|
|
51
73
|
defaultChain={defaultChain}
|
|
52
74
|
config={config}
|
|
53
|
-
|
|
75
|
+
thirdwebResult={thirdwebResult}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</BeraWagmiProviderBase>
|
|
54
79
|
</QueryClientProvider>
|
|
55
80
|
</WagmiProviderBase>
|
|
56
81
|
</ThirdwebProvider>
|
|
@@ -1,29 +1,16 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import type { ConnectionOptions } from "@thirdweb-dev/wagmi-adapter";
|
|
3
1
|
import { defineChain } from "thirdweb";
|
|
4
2
|
import {
|
|
5
3
|
ConnectButton,
|
|
6
|
-
useActiveAccount,
|
|
7
|
-
useActiveWallet,
|
|
8
|
-
useAutoConnect,
|
|
9
|
-
useProfiles,
|
|
10
|
-
useConnect as useTwConnect,
|
|
11
4
|
useConnectModal as useTwConnectModal,
|
|
12
|
-
useDisconnect as useTwDisconnect,
|
|
13
|
-
useWalletInfo,
|
|
14
5
|
} from "thirdweb/react";
|
|
15
|
-
import type {
|
|
16
|
-
Account,
|
|
17
|
-
AutoConnectProps,
|
|
18
|
-
Profile,
|
|
19
|
-
Wallet,
|
|
20
|
-
} from "thirdweb/wallets";
|
|
21
|
-
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
22
6
|
import type { Chain } from "viem";
|
|
23
|
-
import { useConnect } from "wagmi";
|
|
24
7
|
|
|
25
|
-
import type { getConfig
|
|
8
|
+
import type { getConfig } from "../config";
|
|
26
9
|
import type { BeraWagmiApi, ConnectEvent } from "./BeraWagmi";
|
|
10
|
+
import {
|
|
11
|
+
type UseThirdwebBaseResult,
|
|
12
|
+
useThirdwebLightWeight,
|
|
13
|
+
} from "./useThirdwebLightWeight";
|
|
27
14
|
|
|
28
15
|
export function useThirdweb({
|
|
29
16
|
config,
|
|
@@ -32,7 +19,7 @@ export function useThirdweb({
|
|
|
32
19
|
chain,
|
|
33
20
|
onConnect,
|
|
34
21
|
onConnectError,
|
|
35
|
-
publicJsonRpcUrl
|
|
22
|
+
publicJsonRpcUrl,
|
|
36
23
|
}: {
|
|
37
24
|
onConnect?: (event: ConnectEvent) => void;
|
|
38
25
|
onConnectError?: (error: Error) => void;
|
|
@@ -41,142 +28,32 @@ export function useThirdweb({
|
|
|
41
28
|
chains?: Chain[];
|
|
42
29
|
publicJsonRpcUrl?: string;
|
|
43
30
|
chain: Chain;
|
|
44
|
-
}):
|
|
45
|
-
BeraWagmiApi,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
> & {
|
|
53
|
-
connectionId: string;
|
|
54
|
-
connectorName: string | null;
|
|
55
|
-
isEmbeddedWallet: boolean;
|
|
56
|
-
wallet: Account | undefined;
|
|
57
|
-
profiles: Profile[] | undefined;
|
|
58
|
-
} {
|
|
59
|
-
const { connectors, connect: wagmiConnect } = useConnect();
|
|
60
|
-
|
|
61
|
-
const activeWallet = useActiveWallet();
|
|
62
|
-
const activeAccount = useActiveAccount(); // thirdweb
|
|
63
|
-
const { disconnect: disconnectThirdweb } = useTwDisconnect();
|
|
64
|
-
const { data: walletInfo } = useWalletInfo(activeWallet?.id);
|
|
65
|
-
const { connect: twConnect } = useTwConnect();
|
|
66
|
-
|
|
67
|
-
const { data: profiles } = useProfiles({ client: config.client });
|
|
68
|
-
|
|
69
|
-
const thirdwebChain = useMemo(
|
|
70
|
-
() =>
|
|
71
|
-
defineChain({
|
|
72
|
-
id: chain.id,
|
|
73
|
-
blockExplorers: chain.blockExplorers,
|
|
74
|
-
blockTime: chain.blockTime,
|
|
75
|
-
ensTlds: chain.ensTlds,
|
|
76
|
-
testnet: chain.testnet,
|
|
77
|
-
contracts: chain.contracts,
|
|
78
|
-
nativeCurrency: chain.nativeCurrency,
|
|
79
|
-
name: chain.name,
|
|
80
|
-
rpcUrls: {
|
|
81
|
-
default: {
|
|
82
|
-
http: [publicJsonRpcUrl],
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
}),
|
|
86
|
-
[publicJsonRpcUrl, chain],
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const connectOptions = {
|
|
90
|
-
client: config.client,
|
|
91
|
-
chain: thirdwebChain,
|
|
92
|
-
wallets: config.wallets,
|
|
93
|
-
} as const satisfies AutoConnectProps;
|
|
94
|
-
|
|
95
|
-
async function syncConnectedWallet(wallet: Wallet) {
|
|
96
|
-
// console.debug("syncConnectedWallet", wallet);
|
|
97
|
-
// now "connect" the wagmi connector
|
|
98
|
-
const twConnector = connectors.find((c) => c.id === "in-app-wallet");
|
|
99
|
-
|
|
100
|
-
if (twConnector) {
|
|
101
|
-
const options: ConnectionOptions = {
|
|
102
|
-
withCapabilities: true,
|
|
103
|
-
wallet,
|
|
104
|
-
} as const;
|
|
105
|
-
|
|
106
|
-
wagmiConnect({
|
|
107
|
-
connector: twConnector,
|
|
108
|
-
chainId: chain.id,
|
|
109
|
-
...options,
|
|
110
|
-
});
|
|
111
|
-
} else {
|
|
112
|
-
// captureException is not available here since we don't have shared-ui
|
|
113
|
-
// however this happens only if wagmi is misconfigured
|
|
114
|
-
console.error("no tw connector found");
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const { isLoading: isAutoConnecting } = useAutoConnect({
|
|
119
|
-
...connectOptions,
|
|
120
|
-
onConnect: syncConnectedWallet,
|
|
31
|
+
}): UseThirdwebBaseResult &
|
|
32
|
+
Pick<BeraWagmiApi, "openConnectModal" | "DebugConnectButton"> {
|
|
33
|
+
const base = useThirdwebLightWeight({
|
|
34
|
+
config,
|
|
35
|
+
chain,
|
|
36
|
+
onConnect,
|
|
37
|
+
onConnectError,
|
|
38
|
+
publicJsonRpcUrl,
|
|
121
39
|
});
|
|
122
40
|
|
|
123
|
-
const connectionId = useMemo(() => {
|
|
124
|
-
// this might not be available in some environments
|
|
125
|
-
if ("randomUUID" in crypto) {
|
|
126
|
-
return crypto.randomUUID();
|
|
127
|
-
}
|
|
128
|
-
return Math.random().toString(36).substring(2, 15);
|
|
129
|
-
}, [activeWallet?.id, activeAccount?.address]);
|
|
130
|
-
|
|
131
41
|
const { connect: twConnectModal } = useTwConnectModal();
|
|
132
42
|
|
|
133
43
|
return {
|
|
134
|
-
|
|
135
|
-
if (!config.hasEmbeddedWallets) {
|
|
136
|
-
console.error(
|
|
137
|
-
"useBeraWagmi.connect: this function is not available if embedded wallets are disabled",
|
|
138
|
-
);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
return twConnect(async () => {
|
|
142
|
-
// this must be called inside twConnect or it won't work for social login wallets
|
|
143
|
-
const wallet = config.wallets.find(
|
|
144
|
-
(w) => w.id === "inApp",
|
|
145
|
-
) as InAppWallet;
|
|
146
|
-
|
|
147
|
-
if (!wallet) {
|
|
148
|
-
console.error("useBeraWagmi.connect: no inApp wallet found");
|
|
149
|
-
throw new Error("no inApp wallet found");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return wallet
|
|
153
|
-
.connect({
|
|
154
|
-
...connectOptions,
|
|
155
|
-
...args,
|
|
156
|
-
})
|
|
157
|
-
.then(async () => {
|
|
158
|
-
onConnect?.({ type: "connect", data: args });
|
|
159
|
-
await syncConnectedWallet(wallet);
|
|
160
|
-
return wallet;
|
|
161
|
-
})
|
|
162
|
-
.catch((e) => {
|
|
163
|
-
onConnectError?.(e);
|
|
164
|
-
throw e;
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
},
|
|
44
|
+
...base,
|
|
168
45
|
async openConnectModal() {
|
|
169
46
|
try {
|
|
170
47
|
const wallet = await twConnectModal({
|
|
171
|
-
...connectOptions,
|
|
48
|
+
...base.connectOptions,
|
|
172
49
|
wallets: config.wallets,
|
|
173
50
|
theme: theme === "auto" ? undefined : theme,
|
|
174
51
|
size: "compact",
|
|
175
52
|
chains: [
|
|
176
|
-
thirdwebChain,
|
|
53
|
+
base.thirdwebChain,
|
|
177
54
|
...chains
|
|
178
55
|
// avoid duplicates
|
|
179
|
-
.filter((c) => c.id !== thirdwebChain.id)
|
|
56
|
+
.filter((c) => c.id !== base.thirdwebChain.id)
|
|
180
57
|
.map((c) =>
|
|
181
58
|
defineChain({
|
|
182
59
|
id: c.id,
|
|
@@ -186,34 +63,20 @@ export function useThirdweb({
|
|
|
186
63
|
}); // opens the connect modal
|
|
187
64
|
|
|
188
65
|
onConnect?.({ type: "connect_modal" });
|
|
189
|
-
await syncConnectedWallet(wallet);
|
|
66
|
+
await base.syncConnectedWallet(wallet);
|
|
190
67
|
} catch (e) {
|
|
191
68
|
onConnectError?.(e as Error);
|
|
192
69
|
throw e;
|
|
193
70
|
}
|
|
194
71
|
},
|
|
195
|
-
disconnect() {
|
|
196
|
-
if (activeWallet) {
|
|
197
|
-
disconnectThirdweb(activeWallet);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
isConnecting: isAutoConnecting,
|
|
201
|
-
connectionId,
|
|
202
|
-
connectorName: walletInfo?.name ?? null,
|
|
203
|
-
isEmbeddedWallet: walletInfo?.id === "inApp",
|
|
204
|
-
wallet: activeAccount,
|
|
205
|
-
profiles,
|
|
206
|
-
preAuthenticate(args) {
|
|
207
|
-
return preAuthenticate({ ...args, client: config.client });
|
|
208
|
-
},
|
|
209
72
|
DebugConnectButton() {
|
|
210
73
|
return (
|
|
211
74
|
<ConnectButton
|
|
212
|
-
{...connectOptions}
|
|
75
|
+
{...base.connectOptions}
|
|
213
76
|
connectModal={{
|
|
214
77
|
size: "compact",
|
|
215
78
|
}}
|
|
216
|
-
onConnect={(wallet) => syncConnectedWallet(wallet)}
|
|
79
|
+
onConnect={(wallet) => base.syncConnectedWallet(wallet)}
|
|
217
80
|
/>
|
|
218
81
|
);
|
|
219
82
|
},
|