@getpara/evm-wallet-connectors 1.12.0 → 2.0.0-alpha.5
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/index.d.ts +4 -1
- package/dist/index.js +1 -2
- package/dist/providers/EvmExternalWalletContext.d.ts +20 -25
- package/dist/providers/EvmExternalWalletContext.js +113 -81
- package/dist/providers/ParaEvmContext.d.ts +10 -11
- package/dist/providers/ParaEvmContext.js +30 -64
- package/dist/types/Wallet.d.ts +1 -1
- package/dist/utils/getWalletConnectConnector.d.ts +1 -1
- package/dist/utils/getWalletConnectConnector.js +1 -3
- package/dist/wallets/connectors/index.d.ts +1 -0
- package/dist/wallets/connectors/index.js +10 -0
- package/dist/wallets/connectors/metaMask/metaMask.js +1 -1
- package/dist/wallets/connectors/rainbow/rainbow.js +1 -1
- package/dist/wallets/connectors/zerion/zerion.js +1 -1
- package/dist/wallets/connectorsForWallets.js +2 -2
- package/package.json +11 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { EvmExternalWalletContext } from './providers/EvmExternalWalletContext.js';
|
|
2
|
+
export type { EvmExternalWalletContextType } from './providers/EvmExternalWalletContext.js';
|
|
2
3
|
export { ParaEvmProvider } from './providers/ParaEvmContext.js';
|
|
4
|
+
export type { ParaEvmProviderProps, ParaEvmProviderConfig, ParaWagmiProviderProps } from './providers/ParaEvmContext.js';
|
|
3
5
|
export * from './wallets/connectors/index.js';
|
|
6
|
+
export type { WalletList } from './types/Wallet.js';
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "./chunk-MMUBH76A.js";
|
|
3
|
-
import {
|
|
3
|
+
import { EvmExternalWalletContext } from "./providers/EvmExternalWalletContext.js";
|
|
4
4
|
import { ParaEvmProvider } from "./providers/ParaEvmContext.js";
|
|
5
5
|
export * from "./wallets/connectors/index.js";
|
|
6
6
|
export {
|
|
7
7
|
EvmExternalWalletContext,
|
|
8
|
-
EvmExternalWalletProvider,
|
|
9
8
|
ParaEvmProvider
|
|
10
9
|
};
|
|
@@ -1,28 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
chains: any[];
|
|
6
|
-
chainId: any;
|
|
7
|
-
username: any;
|
|
8
|
-
avatar: any;
|
|
9
|
-
balance: any;
|
|
10
|
-
disconnect: () => Promise<void>;
|
|
11
|
-
switchChain: () => Promise<{}>;
|
|
12
|
-
signMessage: () => Promise<{}>;
|
|
13
|
-
signVerificationMessage: () => Promise<{}>;
|
|
14
|
-
};
|
|
15
|
-
export declare const EvmExternalWalletContext: import("react").Context<{
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import type { CommonChain, CommonWallet, TExternalWallet } from '@getpara/react-common';
|
|
3
|
+
import ParaWeb, { Wallet } from '@getpara/web-sdk';
|
|
4
|
+
export type EvmExternalWalletContextType = {
|
|
16
5
|
wallets: CommonWallet[];
|
|
17
6
|
chains: CommonChain[];
|
|
18
|
-
chainId
|
|
19
|
-
username
|
|
7
|
+
chainId?: number;
|
|
8
|
+
username?: string;
|
|
20
9
|
avatar?: string;
|
|
21
10
|
balance?: string;
|
|
22
11
|
disconnect: () => Promise<void>;
|
|
23
12
|
switchChain: (chainId: number) => Promise<{
|
|
24
13
|
error?: string[];
|
|
25
14
|
}>;
|
|
15
|
+
connectParaEmbedded: () => Promise<{
|
|
16
|
+
result?: unknown;
|
|
17
|
+
error?: string;
|
|
18
|
+
}>;
|
|
26
19
|
signMessage: (message: string) => Promise<{
|
|
27
20
|
signature?: string;
|
|
28
21
|
error?: string;
|
|
@@ -32,14 +25,16 @@ export declare const EvmExternalWalletContext: import("react").Context<{
|
|
|
32
25
|
signature?: string;
|
|
33
26
|
error?: string;
|
|
34
27
|
}>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
onSwitchWallet
|
|
28
|
+
getWalletBalance: () => Promise<string | undefined>;
|
|
29
|
+
};
|
|
30
|
+
export declare const EvmExternalWalletContext: import("react").Context<EvmExternalWalletContextType>;
|
|
31
|
+
export type EvmExternalWalletProviderConfig = {
|
|
32
|
+
onSwitchWallet?: (args: {
|
|
40
33
|
address?: string;
|
|
41
34
|
error?: string;
|
|
42
35
|
}) => void;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
para: ParaWeb;
|
|
37
|
+
walletsWithFullAuth: TExternalWallet[];
|
|
38
|
+
connectedWallet?: Omit<Wallet, 'signer'> | null;
|
|
39
|
+
};
|
|
40
|
+
export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, walletsWithFullAuth, connectedWallet, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
__spreadValues
|
|
6
6
|
} from "../chunk-MMUBH76A.js";
|
|
7
7
|
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import { createContext, useEffect, useMemo, useRef } from "react";
|
|
8
|
+
import { createContext, useCallback, useEffect, useMemo, useRef } from "react";
|
|
9
9
|
import {
|
|
10
10
|
useAccount,
|
|
11
11
|
useSwitchChain,
|
|
@@ -13,21 +13,16 @@ import {
|
|
|
13
13
|
useDisconnect,
|
|
14
14
|
useEnsName,
|
|
15
15
|
useEnsAvatar,
|
|
16
|
+
useSignMessage,
|
|
16
17
|
useSwitchAccount,
|
|
17
18
|
useConnections,
|
|
18
|
-
useSignMessage,
|
|
19
19
|
useBalance
|
|
20
20
|
} from "wagmi";
|
|
21
21
|
import { isEIP6963Connector } from "../utils/isEIP6963Connector.js";
|
|
22
22
|
import { getWalletConnectUri } from "../utils/getWalletConnectUri.js";
|
|
23
|
-
import {
|
|
24
|
-
isMobile,
|
|
25
|
-
useExternalWalletProviderStore,
|
|
26
|
-
useWalletState,
|
|
27
|
-
WalletType
|
|
28
|
-
} from "@getpara/react-sdk";
|
|
29
23
|
import { normalize } from "viem/ens";
|
|
30
24
|
import { useExternalWalletStore } from "../stores/useStore.js";
|
|
25
|
+
import { isMobile } from "@getpara/web-sdk";
|
|
31
26
|
import { etherUnits, formatUnits } from "viem";
|
|
32
27
|
const defaultEvmExternalWallet = {
|
|
33
28
|
wallets: [],
|
|
@@ -38,26 +33,41 @@ const defaultEvmExternalWallet = {
|
|
|
38
33
|
balance: void 0,
|
|
39
34
|
disconnect: () => Promise.resolve(),
|
|
40
35
|
switchChain: () => Promise.resolve({}),
|
|
36
|
+
connectParaEmbedded: () => Promise.resolve({}),
|
|
41
37
|
signMessage: () => Promise.resolve({}),
|
|
42
|
-
signVerificationMessage: () => Promise.resolve({})
|
|
38
|
+
signVerificationMessage: () => Promise.resolve({}),
|
|
39
|
+
getWalletBalance: () => Promise.resolve(void 0)
|
|
43
40
|
};
|
|
44
41
|
const EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
|
|
45
|
-
function EvmExternalWalletProvider({
|
|
42
|
+
function EvmExternalWalletProvider({
|
|
43
|
+
children,
|
|
44
|
+
onSwitchWallet,
|
|
45
|
+
para,
|
|
46
|
+
walletsWithFullAuth,
|
|
47
|
+
connectedWallet
|
|
48
|
+
}) {
|
|
46
49
|
const { connectAsync, connectors: untypedConnectors } = useConnect();
|
|
47
50
|
const connections = useConnections();
|
|
48
|
-
const {
|
|
51
|
+
const {
|
|
52
|
+
address: wagmiAddress,
|
|
53
|
+
isConnecting,
|
|
54
|
+
isReconnecting,
|
|
55
|
+
chainId,
|
|
56
|
+
connector: connectedConnector,
|
|
57
|
+
isConnected
|
|
58
|
+
} = useAccount();
|
|
59
|
+
const { switchAccount: wagmiSwitchAccount } = useSwitchAccount();
|
|
49
60
|
const { chains, switchChainAsync } = useSwitchChain();
|
|
50
61
|
const { disconnectAsync } = useDisconnect();
|
|
51
|
-
const { switchAccountAsync } = useSwitchAccount();
|
|
52
|
-
const { signMessageAsync } = useSignMessage();
|
|
53
62
|
const { data: ensName, refetch: refetchEnsName } = useEnsName({ address: wagmiAddress });
|
|
54
|
-
const { data: ensAvatar, refetch: refetchEnsAvatar } = useEnsAvatar({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const {
|
|
63
|
+
const { data: ensAvatar, refetch: refetchEnsAvatar } = useEnsAvatar({
|
|
64
|
+
name: normalize(ensName)
|
|
65
|
+
});
|
|
66
|
+
const { signMessageAsync } = useSignMessage();
|
|
67
|
+
const verificationMessage = useRef();
|
|
68
|
+
const { refetch: getBalance } = useBalance({ address: wagmiAddress });
|
|
58
69
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
59
70
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
60
|
-
const verificationMessage = useRef();
|
|
61
71
|
const getStoredExternalWallets = () => {
|
|
62
72
|
const storedExternalWalletsString = localStorage.getItem("@CAPSULE/externalWallets");
|
|
63
73
|
let storedExternalWallets = {};
|
|
@@ -66,10 +76,25 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
66
76
|
}
|
|
67
77
|
return storedExternalWallets;
|
|
68
78
|
};
|
|
69
|
-
const
|
|
79
|
+
const switchAccount = useCallback(
|
|
80
|
+
(connectorName) => {
|
|
81
|
+
var _a;
|
|
82
|
+
const connector = (_a = connections.find((c) => c.connector.name === connectorName)) == null ? void 0 : _a.connector;
|
|
83
|
+
if (!connector) {
|
|
84
|
+
console.warn(`connector not found: ${connectorName}`);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
wagmiSwitchAccount({ connector });
|
|
88
|
+
},
|
|
89
|
+
[connections, wagmiSwitchAccount]
|
|
90
|
+
);
|
|
91
|
+
const getWalletBalance = useCallback(
|
|
70
92
|
// Format from wei to eth
|
|
71
|
-
() =>
|
|
72
|
-
|
|
93
|
+
() => __async(this, null, function* () {
|
|
94
|
+
const { data: balance } = yield getBalance();
|
|
95
|
+
return balance ? formatUnits(balance.value, etherUnits.wei) : void 0;
|
|
96
|
+
}),
|
|
97
|
+
[chainId, wagmiAddress, getBalance]
|
|
73
98
|
);
|
|
74
99
|
useEffect(() => {
|
|
75
100
|
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
@@ -79,16 +104,23 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
79
104
|
}, [isConnecting, isReconnecting, isLocalConnecting, wagmiAddress, connectedConnector]);
|
|
80
105
|
useEffect(() => {
|
|
81
106
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
82
|
-
if (!isLocalConnecting && !isConnecting && !isReconnecting && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) ===
|
|
107
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === "EVM" && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
83
108
|
switchWallet(wagmiAddress);
|
|
84
109
|
}
|
|
85
110
|
}, [isLocalConnecting, wagmiAddress, isReconnecting, isConnecting]);
|
|
86
111
|
useEffect(() => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
switchAccount(wallet.isExternal ? wallet.name : "Para");
|
|
112
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedConnector && connectedWallet.type === "EVM" && connectedConnector.name !== connectedWallet.name) {
|
|
113
|
+
switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
|
|
90
114
|
}
|
|
91
|
-
}, [
|
|
115
|
+
}, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && !isConnected && !connectedConnector) {
|
|
118
|
+
if (Object.values(para.wallets).length === 0) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
connectParaEmbedded();
|
|
122
|
+
}
|
|
123
|
+
}, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
|
|
92
124
|
const connectors = untypedConnectors;
|
|
93
125
|
const reset = () => __async(this, null, function* () {
|
|
94
126
|
yield disconnectAsync();
|
|
@@ -96,8 +128,14 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
96
128
|
});
|
|
97
129
|
const signMessage = (message) => __async(this, null, function* () {
|
|
98
130
|
try {
|
|
99
|
-
const signature = yield signMessageAsync({
|
|
100
|
-
|
|
131
|
+
const signature = yield signMessageAsync({
|
|
132
|
+
message,
|
|
133
|
+
account: wagmiAddress
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
address: wagmiAddress,
|
|
137
|
+
signature
|
|
138
|
+
};
|
|
101
139
|
} catch (e) {
|
|
102
140
|
switch (e.name) {
|
|
103
141
|
case "UserRejectedRequestError": {
|
|
@@ -113,14 +151,6 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
113
151
|
const signature = yield signMessage(verificationMessage.current);
|
|
114
152
|
return signature;
|
|
115
153
|
});
|
|
116
|
-
const switchAccount = (connectorName) => __async(this, null, function* () {
|
|
117
|
-
var _a;
|
|
118
|
-
const connector = (_a = connections.find((c) => c.connector.name === connectorName)) == null ? void 0 : _a.connector;
|
|
119
|
-
if (!connector) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
yield switchAccountAsync({ connector });
|
|
123
|
-
});
|
|
124
154
|
const switchChain = (chainId2) => __async(this, null, function* () {
|
|
125
155
|
var _a, _b, _c;
|
|
126
156
|
let error;
|
|
@@ -157,11 +187,15 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
157
187
|
try {
|
|
158
188
|
refetchEnsName();
|
|
159
189
|
refetchEnsAvatar();
|
|
160
|
-
return yield para.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
190
|
+
return yield para.loginExternalWallet({
|
|
191
|
+
externalWallet: {
|
|
192
|
+
address,
|
|
193
|
+
type: "EVM",
|
|
194
|
+
provider: connectorName,
|
|
195
|
+
withFullParaAuth: walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes((_a = walletId == null ? void 0 : walletId.toUpperCase()) != null ? _a : ""),
|
|
196
|
+
ensName,
|
|
197
|
+
ensAvatar
|
|
198
|
+
}
|
|
165
199
|
});
|
|
166
200
|
} catch (err) {
|
|
167
201
|
yield disconnectAsync();
|
|
@@ -190,7 +224,7 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
190
224
|
}
|
|
191
225
|
}
|
|
192
226
|
}
|
|
193
|
-
onSwitchWallet({ address, error });
|
|
227
|
+
onSwitchWallet == null ? void 0 : onSwitchWallet({ address, error });
|
|
194
228
|
updateExternalWalletState({ isConnecting: false });
|
|
195
229
|
});
|
|
196
230
|
const connect = (connector) => __async(this, null, function* () {
|
|
@@ -198,10 +232,9 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
198
232
|
updateExternalWalletState({ isConnecting: true });
|
|
199
233
|
yield disconnectAsync();
|
|
200
234
|
const walletChainId = yield connector.getChainId();
|
|
235
|
+
let authState;
|
|
201
236
|
let address;
|
|
202
237
|
let error;
|
|
203
|
-
let userExists = false;
|
|
204
|
-
let isVerified = false;
|
|
205
238
|
try {
|
|
206
239
|
const data = yield connectAsync({
|
|
207
240
|
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
@@ -214,10 +247,8 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
214
247
|
address = (_d = data.accounts) == null ? void 0 : _d[0];
|
|
215
248
|
if (address) {
|
|
216
249
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
isVerified = loginResp.isVerified;
|
|
220
|
-
verificationMessage.current = loginResp.signatureVerificationMessage;
|
|
250
|
+
authState = yield login({ address, connectorName: connector.name, walletId: connector.paraDetails.id });
|
|
251
|
+
verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
|
|
221
252
|
} catch (err) {
|
|
222
253
|
address = void 0;
|
|
223
254
|
error = err;
|
|
@@ -240,7 +271,7 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
240
271
|
}
|
|
241
272
|
}
|
|
242
273
|
updateExternalWalletState({ isConnecting: false });
|
|
243
|
-
return { address,
|
|
274
|
+
return { address, authState, error };
|
|
244
275
|
});
|
|
245
276
|
const connectMobile = (connector, isManualWalletConnect) => __async(this, null, function* () {
|
|
246
277
|
const _isMobile = isManualWalletConnect !== void 0 ? isManualWalletConnect : isMobile();
|
|
@@ -283,8 +314,8 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
283
314
|
const connector = __spreadValues(__spreadValues({}, c), c.paraDetails);
|
|
284
315
|
return __spreadProps(__spreadValues({}, connector), {
|
|
285
316
|
connect: () => connect(connector),
|
|
286
|
-
connectMobile: (
|
|
287
|
-
type:
|
|
317
|
+
connectMobile: (isManualWalletConnect) => connectMobile(connector, isManualWalletConnect),
|
|
318
|
+
type: "EVM",
|
|
288
319
|
getQrUri: getQrUri(connector)
|
|
289
320
|
});
|
|
290
321
|
});
|
|
@@ -293,45 +324,46 @@ function EvmExternalWalletProvider({ children, para, onSwitchWallet }) {
|
|
|
293
324
|
return (_a = connectors.find((w) => w.id === id)) == null ? void 0 : _a.paraDetails;
|
|
294
325
|
};
|
|
295
326
|
const formattedChains = chains.map((c) => {
|
|
296
|
-
return {
|
|
327
|
+
return {
|
|
328
|
+
id: c.id,
|
|
329
|
+
name: c.name
|
|
330
|
+
};
|
|
297
331
|
});
|
|
298
332
|
const username = useMemo(() => ensName != null ? ensName : wagmiAddress, [ensName, wagmiAddress]);
|
|
299
|
-
const
|
|
333
|
+
const connectParaEmbedded = useCallback(() => __async(this, null, function* () {
|
|
334
|
+
const paraConnectorInstance = connectors.find((c) => c.id === "para");
|
|
335
|
+
if (!paraConnectorInstance) {
|
|
336
|
+
return { error: "No para connector instance" };
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const result = yield connectAsync({ connector: paraConnectorInstance });
|
|
340
|
+
return { result };
|
|
341
|
+
} catch (err) {
|
|
342
|
+
const error = err instanceof Error ? err.message : "Unknown error";
|
|
343
|
+
return { error };
|
|
344
|
+
}
|
|
345
|
+
}), [connectors]);
|
|
300
346
|
return /* @__PURE__ */ jsx(
|
|
301
347
|
EvmExternalWalletContext.Provider,
|
|
302
348
|
{
|
|
303
|
-
value:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
[
|
|
317
|
-
wallets,
|
|
318
|
-
formattedChains,
|
|
319
|
-
chainId,
|
|
320
|
-
username,
|
|
321
|
-
ensAvatar,
|
|
322
|
-
balance,
|
|
323
|
-
disconnect,
|
|
324
|
-
switchChain,
|
|
325
|
-
signMessage,
|
|
326
|
-
signVerificationMessage
|
|
327
|
-
]
|
|
328
|
-
),
|
|
349
|
+
value: {
|
|
350
|
+
wallets,
|
|
351
|
+
chains: formattedChains,
|
|
352
|
+
chainId,
|
|
353
|
+
username,
|
|
354
|
+
avatar: ensAvatar,
|
|
355
|
+
disconnect: disconnectAsync,
|
|
356
|
+
switchChain,
|
|
357
|
+
connectParaEmbedded,
|
|
358
|
+
signMessage,
|
|
359
|
+
signVerificationMessage,
|
|
360
|
+
getWalletBalance
|
|
361
|
+
},
|
|
329
362
|
children
|
|
330
363
|
}
|
|
331
364
|
);
|
|
332
365
|
}
|
|
333
366
|
export {
|
|
334
367
|
EvmExternalWalletContext,
|
|
335
|
-
EvmExternalWalletProvider
|
|
336
|
-
defaultEvmExternalWallet
|
|
368
|
+
EvmExternalWalletProvider
|
|
337
369
|
};
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { CreateConfigParameters, WagmiProviderProps } from 'wagmi';
|
|
3
3
|
import { WalletList } from '../types/Wallet.js';
|
|
4
4
|
import { Chain, Transport } from 'viem';
|
|
5
|
-
import
|
|
5
|
+
import { EvmExternalWalletProviderConfig } from './EvmExternalWalletContext.js';
|
|
6
6
|
import { InjectedParameters } from 'wagmi/connectors';
|
|
7
|
-
interface
|
|
7
|
+
export interface ParaEvmProviderConfig<chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>> extends Omit<CreateConfigParameters<chains, transports>, 'connectors'> {
|
|
8
8
|
appName: string;
|
|
9
9
|
appDescription?: string;
|
|
10
10
|
appUrl?: string;
|
|
11
11
|
appIcon?: string;
|
|
12
12
|
wallets?: WalletList;
|
|
13
13
|
projectId: string;
|
|
14
|
-
|
|
15
|
-
paraDisableModal?: boolean;
|
|
16
|
-
paraOptions?: InjectedParameters;
|
|
14
|
+
paraConnectorOptions?: InjectedParameters;
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config:
|
|
16
|
+
export type ParaWagmiProviderProps = Omit<WagmiProviderProps, 'config'>;
|
|
17
|
+
export interface ParaEvmProviderProps<chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>> {
|
|
18
|
+
config: ParaEvmProviderConfig<chains, transports>;
|
|
19
|
+
internalConfig: EvmExternalWalletProviderConfig;
|
|
20
|
+
wagmiProviderProps?: ParaWagmiProviderProps;
|
|
21
21
|
}
|
|
22
|
-
export declare function ParaEvmProvider<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>>({ children, config: _config,
|
|
23
|
-
export {};
|
|
22
|
+
export declare function ParaEvmProvider<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>>({ children, internalConfig, config: _config, wagmiProviderProps, }: ParaEvmProviderProps<chains, transports> & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
-
__async,
|
|
4
3
|
__objRest,
|
|
5
4
|
__spreadProps,
|
|
6
5
|
__spreadValues
|
|
7
6
|
} from "../chunk-MMUBH76A.js";
|
|
8
7
|
import { jsx } from "react/jsx-runtime";
|
|
9
|
-
import {
|
|
8
|
+
import { useMemo } from "react";
|
|
10
9
|
import { createConfig, WagmiProvider } from "wagmi";
|
|
11
10
|
import { connectorsForWallets } from "../wallets/connectorsForWallets.js";
|
|
12
11
|
import { http } from "viem";
|
|
13
12
|
import { computeWalletConnectMetaData } from "../utils/computeWalletConnectMetaData.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { connect } from "wagmi/actions";
|
|
17
|
-
import { paraConnector } from "@getpara/wagmi-v2-integration";
|
|
13
|
+
import { EvmExternalWalletProvider } from "./EvmExternalWalletContext.js";
|
|
14
|
+
import { paraConnector } from "@getpara/wagmi-v2-connector";
|
|
18
15
|
const createDefaultTransports = (chains) => {
|
|
19
16
|
const transportsObject = chains.reduce((acc, chain) => {
|
|
20
17
|
const key = chain.id;
|
|
@@ -23,14 +20,14 @@ const createDefaultTransports = (chains) => {
|
|
|
23
20
|
}, {});
|
|
24
21
|
return transportsObject;
|
|
25
22
|
};
|
|
26
|
-
function ParaEvmProvider(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const para =
|
|
33
|
-
const
|
|
23
|
+
function ParaEvmProvider({
|
|
24
|
+
children,
|
|
25
|
+
internalConfig,
|
|
26
|
+
config: _config,
|
|
27
|
+
wagmiProviderProps
|
|
28
|
+
}) {
|
|
29
|
+
const para = internalConfig.para;
|
|
30
|
+
const _a = _config, {
|
|
34
31
|
projectId,
|
|
35
32
|
appName,
|
|
36
33
|
appDescription,
|
|
@@ -39,9 +36,8 @@ function ParaEvmProvider(_a) {
|
|
|
39
36
|
wallets,
|
|
40
37
|
chains,
|
|
41
38
|
transports,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} = _b2, wagmiConfigParams = __objRest(_b2, [
|
|
39
|
+
paraConnectorOptions
|
|
40
|
+
} = _a, wagmiConfigParams = __objRest(_a, [
|
|
45
41
|
"projectId",
|
|
46
42
|
"appName",
|
|
47
43
|
"appDescription",
|
|
@@ -50,18 +46,19 @@ function ParaEvmProvider(_a) {
|
|
|
50
46
|
"wallets",
|
|
51
47
|
"chains",
|
|
52
48
|
"transports",
|
|
53
|
-
"
|
|
54
|
-
"paraOptions"
|
|
49
|
+
"paraConnectorOptions"
|
|
55
50
|
]);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
const paraConnectorInstance = useMemo(() => {
|
|
52
|
+
return paraConnector({
|
|
53
|
+
para,
|
|
54
|
+
chains: [...chains],
|
|
55
|
+
disableModal: true,
|
|
56
|
+
appName,
|
|
57
|
+
options: paraConnectorOptions != null ? paraConnectorOptions : {}
|
|
58
|
+
});
|
|
59
|
+
}, [para]);
|
|
60
|
+
const config = useMemo(() => {
|
|
61
|
+
const wcMetadata = computeWalletConnectMetaData({ appName, appDescription, appUrl, appIcon });
|
|
65
62
|
const baseConnectors = connectorsForWallets(wallets, {
|
|
66
63
|
projectId,
|
|
67
64
|
appName,
|
|
@@ -70,45 +67,14 @@ function ParaEvmProvider(_a) {
|
|
|
70
67
|
appIcon,
|
|
71
68
|
walletConnectParameters: { metadata: wcMetadata }
|
|
72
69
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const config = useMemo(
|
|
76
|
-
() => createConfig(__spreadProps(__spreadValues({}, wagmiConfigParams), {
|
|
70
|
+
const allConnectors = [...baseConnectors, paraConnectorInstance];
|
|
71
|
+
return createConfig(__spreadProps(__spreadValues({}, wagmiConfigParams), {
|
|
77
72
|
chains,
|
|
78
73
|
transports: transports || createDefaultTransports(chains),
|
|
79
74
|
connectors: allConnectors
|
|
80
|
-
}))
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
const connectParaEvmWallet = useCallback(() => __async(this, null, function* () {
|
|
84
|
-
if (!paraConnectorInstance) {
|
|
85
|
-
return { error: "No para connector instance" };
|
|
86
|
-
}
|
|
87
|
-
try {
|
|
88
|
-
const result = yield connect(config, { connector: paraConnectorInstance });
|
|
89
|
-
return { result };
|
|
90
|
-
} catch (err) {
|
|
91
|
-
const error = err instanceof Error ? err.message : "Unknown error";
|
|
92
|
-
return { error };
|
|
93
|
-
}
|
|
94
|
-
}), [paraConnectorInstance, config, connect]);
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
if (!evmContext || !EvmProvider) {
|
|
97
|
-
updateExternalWalletProviderState({
|
|
98
|
-
EvmProvider: EvmExternalWalletProvider,
|
|
99
|
-
evmContext: EvmExternalWalletContext
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, []);
|
|
103
|
-
useEffect(() => {
|
|
104
|
-
updateExternalWalletProviderState({
|
|
105
|
-
connectParaEvmWallet: paraConnectorInstance ? connectParaEvmWallet : void 0
|
|
106
|
-
});
|
|
107
|
-
}, [paraConnectorInstance]);
|
|
108
|
-
if (!evmContext || !EvmProvider) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
return /* @__PURE__ */ jsx(WagmiProvider, __spreadProps(__spreadValues({ config }, wagmiProviderProps), { children }));
|
|
75
|
+
}));
|
|
76
|
+
}, [wallets, paraConnectorInstance]);
|
|
77
|
+
return /* @__PURE__ */ jsx(WagmiProvider, __spreadProps(__spreadValues({ config }, wagmiProviderProps), { children: /* @__PURE__ */ jsx(EvmExternalWalletProvider, __spreadProps(__spreadValues({}, internalConfig), { children })) }));
|
|
112
78
|
}
|
|
113
79
|
export {
|
|
114
80
|
ParaEvmProvider
|
package/dist/types/Wallet.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Connector, CreateConnectorFn } from 'wagmi';
|
|
|
2
2
|
import { WalletConnectParameters } from 'wagmi/connectors';
|
|
3
3
|
import { CoinbaseWalletOptions } from '../wallets/connectors/coinbase/coinbase.js';
|
|
4
4
|
import { WalletConnectWalletOptions } from '../wallets/connectors/walletConnect/walletConnect.js';
|
|
5
|
-
import { WalletMetadata } from '@getpara/react-
|
|
5
|
+
import { type WalletMetadata } from '@getpara/react-common';
|
|
6
6
|
export type Wallet = {
|
|
7
7
|
createConnector?: (walletDetails: WalletDetailsParams) => CreateConnectorFn;
|
|
8
8
|
createMobileConnector?: (walletDetails: WalletDetailsParams) => CreateConnectorFn;
|
|
@@ -3,5 +3,5 @@ interface GetWalletConnectConnectorParams {
|
|
|
3
3
|
projectId: string;
|
|
4
4
|
walletConnectParameters?: ParaWalletConnectParameters;
|
|
5
5
|
}
|
|
6
|
-
export declare function getWalletConnectConnector({ projectId, walletConnectParameters, }: GetWalletConnectConnectorParams): CreateConnector;
|
|
6
|
+
export declare function getWalletConnectConnector({ projectId, walletConnectParameters, }: GetWalletConnectConnectorParams): CreateConnector | undefined;
|
|
7
7
|
export {};
|
|
@@ -48,9 +48,7 @@ function getWalletConnectConnector({
|
|
|
48
48
|
walletConnectParameters
|
|
49
49
|
}) {
|
|
50
50
|
if (!projectId || projectId === "") {
|
|
51
|
-
|
|
52
|
-
"No projectId found. Every dApp must now provide a WalletConnect Cloud projectId to enable WalletConnect v2. Sign up for your free key at https://cloud.walletconnect.com/sign-in"
|
|
53
|
-
);
|
|
51
|
+
return;
|
|
54
52
|
}
|
|
55
53
|
return (walletDetails) => createWalletConnectConnector({
|
|
56
54
|
projectId,
|
|
@@ -6,3 +6,4 @@ import { zerionWallet } from './zerion/zerion.js';
|
|
|
6
6
|
import { rabbyWallet } from './rabby/rabby.js';
|
|
7
7
|
import { safeWallet } from './safe/safe.js';
|
|
8
8
|
export { metaMaskWallet, rainbowWallet, walletConnectWallet, coinbaseWallet, zerionWallet, rabbyWallet, safeWallet };
|
|
9
|
+
export declare const allWallets: ((({ appName, appIcon }: import("./coinbase/coinbase.js").CoinbaseWalletOptions) => import("../../types/Wallet.js").Wallet) | (({ projectId, options }: import("./walletConnect/walletConnect.js").WalletConnectWalletOptions) => import("../../types/Wallet.js").Wallet) | (({ projectId, walletConnectParameters }: import("./metaMask/metaMask.js").MetaMaskWalletOptions) => import("../../types/Wallet.js").Wallet))[];
|
|
@@ -7,7 +7,17 @@ import { coinbaseWallet } from "./coinbase/coinbase.js";
|
|
|
7
7
|
import { zerionWallet } from "./zerion/zerion.js";
|
|
8
8
|
import { rabbyWallet } from "./rabby/rabby.js";
|
|
9
9
|
import { safeWallet } from "./safe/safe.js";
|
|
10
|
+
const allWallets = [
|
|
11
|
+
metaMaskWallet,
|
|
12
|
+
rainbowWallet,
|
|
13
|
+
walletConnectWallet,
|
|
14
|
+
coinbaseWallet,
|
|
15
|
+
zerionWallet,
|
|
16
|
+
rabbyWallet,
|
|
17
|
+
safeWallet
|
|
18
|
+
];
|
|
10
19
|
export {
|
|
20
|
+
allWallets,
|
|
11
21
|
coinbaseWallet,
|
|
12
22
|
metaMaskWallet,
|
|
13
23
|
rabbyWallet,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../../../chunk-MMUBH76A.js";
|
|
3
|
-
import { isAndroid, isIOS, isTelegram } from "@getpara/
|
|
3
|
+
import { isAndroid, isIOS, isTelegram } from "@getpara/web-sdk";
|
|
4
4
|
import { getInjectedConnector, getInjectedProvider } from "../../../utils/getInjectedConnector.js";
|
|
5
5
|
import { getWalletConnectConnector } from "../../../utils/getWalletConnectConnector.js";
|
|
6
6
|
import { icon } from "./metaMaskIcon.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../../../chunk-MMUBH76A.js";
|
|
3
|
-
import { isAndroid, isIOS, isTelegram } from "@getpara/
|
|
3
|
+
import { isAndroid, isIOS, isTelegram } from "@getpara/web-sdk";
|
|
4
4
|
import { getInjectedConnector, hasInjectedProvider } from "../../../utils/getInjectedConnector.js";
|
|
5
5
|
import { getWalletConnectConnector } from "../../../utils/getWalletConnectConnector.js";
|
|
6
6
|
import { icon } from "./rainbowIcon.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "../../../chunk-MMUBH76A.js";
|
|
3
|
-
import { isIOS, isTelegram } from "@getpara/
|
|
3
|
+
import { isIOS, isTelegram } from "@getpara/web-sdk";
|
|
4
4
|
import { getInjectedConnector, hasInjectedProvider } from "../../../utils/getInjectedConnector.js";
|
|
5
5
|
import { getWalletConnectConnector } from "../../../utils/getWalletConnectConnector.js";
|
|
6
6
|
import { icon } from "./zerionIcon.js";
|
|
@@ -9,7 +9,7 @@ import { computeWalletConnectMetaData } from "../utils/computeWalletConnectMetaD
|
|
|
9
9
|
import { omitUndefinedValues } from "../utils/omitUndefinedValues.js";
|
|
10
10
|
const connectorsForWallets = (walletList, { projectId, walletConnectParameters, appName, appDescription, appUrl, appIcon }) => {
|
|
11
11
|
if (!walletList.length) {
|
|
12
|
-
|
|
12
|
+
return [];
|
|
13
13
|
}
|
|
14
14
|
let index = -1;
|
|
15
15
|
const connectors = [];
|
|
@@ -52,7 +52,7 @@ const connectorsForWallets = (walletList, { projectId, walletConnectParameters,
|
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
const isWalletConnectConnector = walletMeta.id === "walletConnect";
|
|
55
|
-
if (isWalletConnectConnector) {
|
|
55
|
+
if (isWalletConnectConnector && createConnector) {
|
|
56
56
|
connectors.push(
|
|
57
57
|
createConnector(
|
|
58
58
|
walletMetaData({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/evm-wallet-connectors",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@coinbase/wallet-sdk": "4.3.0",
|
|
13
|
-
"@getpara/
|
|
14
|
-
"@getpara/
|
|
13
|
+
"@getpara/wagmi-v2-connector": "2.0.0-alpha.5",
|
|
14
|
+
"@getpara/web-sdk": "2.0.0-alpha.5",
|
|
15
|
+
"viem": "^2.24.2",
|
|
16
|
+
"wagmi": "^2.14.16",
|
|
15
17
|
"zustand": "^4.5.2",
|
|
16
18
|
"zustand-sync-tabs": "^0.2.2"
|
|
17
19
|
},
|
|
@@ -21,21 +23,21 @@
|
|
|
21
23
|
"test": "vitest run --coverage"
|
|
22
24
|
},
|
|
23
25
|
"devDependencies": {
|
|
26
|
+
"@getpara/react-common": "2.0.0-alpha.5",
|
|
27
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
24
28
|
"@types/react": "^18.0.31",
|
|
25
29
|
"@types/react-dom": "^18.2.7",
|
|
26
30
|
"typescript": "^5.4.3",
|
|
27
|
-
"viem": "
|
|
28
|
-
"wagmi": "
|
|
31
|
+
"viem": "2.x",
|
|
32
|
+
"wagmi": "2.x"
|
|
29
33
|
},
|
|
30
34
|
"peerDependencies": {
|
|
31
35
|
"react": ">=18",
|
|
32
|
-
"react-dom": ">=18"
|
|
33
|
-
"viem": "2.x",
|
|
34
|
-
"wagmi": "2.x"
|
|
36
|
+
"react-dom": ">=18"
|
|
35
37
|
},
|
|
36
38
|
"files": [
|
|
37
39
|
"dist",
|
|
38
40
|
"package.json"
|
|
39
41
|
],
|
|
40
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3ecfca088f24489f2e8fa5493d0f4459b08880e1"
|
|
41
43
|
}
|