@getpara/evm-wallet-connectors 2.0.0-alpha.19 → 2.0.0-alpha.21
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 -3
- package/dist/index.js +5 -1
- package/dist/providers/EvmExternalWalletContext.d.ts +20 -36
- package/dist/providers/EvmExternalWalletContext.js +125 -48
- package/dist/providers/ParaEvmContext.d.ts +2 -1
- package/dist/providers/ParaEvmContext.js +6 -2
- package/dist/providers/createParaWagmiConfig.d.ts +10 -0
- package/dist/providers/createParaWagmiConfig.js +62 -0
- package/dist/stores/wagmiConfigStore.d.ts +11 -0
- package/dist/utils/resolveWalletList.d.ts +3 -0
- package/dist/utils/resolveWalletList.js +16 -0
- package/dist/wallets/connectors/backpack/backpack.js +1 -0
- package/dist/wallets/connectors/coinbase/coinbase.js +1 -0
- package/dist/wallets/connectors/haha/haha.js +1 -0
- package/dist/wallets/connectors/metaMask/metaMask.js +1 -0
- package/dist/wallets/connectors/okx/okx.js +1 -0
- package/dist/wallets/connectors/rabby/rabby.js +1 -0
- package/dist/wallets/connectors/rainbow/rainbow.js +1 -0
- package/dist/wallets/connectors/safe/safe.js +1 -0
- package/dist/wallets/connectors/walletConnect/walletConnect.js +1 -0
- package/dist/wallets/connectors/zerion/zerion.js +1 -0
- package/dist/wallets/connectorsForWallets.js +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
export { createParaWagmiConfig } from './providers/createParaWagmiConfig.js';
|
|
1
2
|
export { EvmExternalWalletContext } from './providers/EvmExternalWalletContext.js';
|
|
2
|
-
export type
|
|
3
|
+
export { type EvmExternalWalletContextType, defaultEvmExternalWallet } from './providers/EvmExternalWalletContext.js';
|
|
3
4
|
export { ParaEvmProvider } from './providers/ParaEvmContext.js';
|
|
4
5
|
export type { ParaEvmProviderProps, ParaEvmProviderConfig, ParaWagmiProviderProps } from './providers/ParaEvmContext.js';
|
|
5
|
-
export * from './wallets/connectors/index.js';
|
|
6
|
-
export type { WalletList } from './types/Wallet.js';
|
|
7
6
|
export { getWagmiConfig } from './stores/wagmiConfigStore.js';
|
|
7
|
+
export type { WalletList } from './types/Wallet.js';
|
|
8
|
+
export * from './wallets/connectors/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import "./chunk-MMUBH76A.js";
|
|
3
|
+
import { createParaWagmiConfig } from "./providers/createParaWagmiConfig.js";
|
|
3
4
|
import { EvmExternalWalletContext } from "./providers/EvmExternalWalletContext.js";
|
|
5
|
+
import { defaultEvmExternalWallet } from "./providers/EvmExternalWalletContext.js";
|
|
4
6
|
import { ParaEvmProvider } from "./providers/ParaEvmContext.js";
|
|
5
|
-
export * from "./wallets/connectors/index.js";
|
|
6
7
|
import { getWagmiConfig } from "./stores/wagmiConfigStore.js";
|
|
8
|
+
export * from "./wallets/connectors/index.js";
|
|
7
9
|
export {
|
|
8
10
|
EvmExternalWalletContext,
|
|
9
11
|
ParaEvmProvider,
|
|
12
|
+
createParaWagmiConfig,
|
|
13
|
+
defaultEvmExternalWallet,
|
|
10
14
|
getWagmiConfig
|
|
11
15
|
};
|
|
@@ -1,42 +1,26 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
4
|
-
export
|
|
5
|
-
wallets:
|
|
6
|
-
chains:
|
|
7
|
-
chainId
|
|
2
|
+
import type { BalanceManagement, ChainManagement, ConnectParaEmbedded, ExternalWalletContextType, ExternalWalletProviderConfigBase } from '@getpara/react-common';
|
|
3
|
+
import { ExternalWalletInfo } from '@getpara/web-sdk';
|
|
4
|
+
export declare const defaultEvmExternalWallet: {
|
|
5
|
+
wallets: any[];
|
|
6
|
+
chains: any[];
|
|
7
|
+
chainId: any;
|
|
8
|
+
username: any;
|
|
9
|
+
avatar: any;
|
|
10
|
+
balance: any;
|
|
11
|
+
disconnect: () => Promise<void>;
|
|
12
|
+
switchChain: () => Promise<void>;
|
|
13
|
+
connectParaEmbedded: () => Promise<{}>;
|
|
14
|
+
signMessage: () => Promise<{}>;
|
|
15
|
+
signVerificationMessage: () => Promise<{}>;
|
|
16
|
+
getWalletBalance: () => Promise<any>;
|
|
17
|
+
requestInfo: () => Promise<ExternalWalletInfo>;
|
|
18
|
+
disconnectBase: () => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export type EvmExternalWalletContextType = ExternalWalletContextType & ChainManagement<number> & BalanceManagement & ConnectParaEmbedded & {
|
|
8
21
|
username?: string;
|
|
9
22
|
avatar?: string;
|
|
10
|
-
balance?: string;
|
|
11
|
-
disconnect: () => Promise<void>;
|
|
12
|
-
switchChain: (chainId: number) => Promise<{
|
|
13
|
-
error?: string[];
|
|
14
|
-
}>;
|
|
15
|
-
connectParaEmbedded: () => Promise<{
|
|
16
|
-
result?: unknown;
|
|
17
|
-
error?: string;
|
|
18
|
-
}>;
|
|
19
|
-
signMessage: (message: string) => Promise<{
|
|
20
|
-
signature?: string;
|
|
21
|
-
error?: string;
|
|
22
|
-
}>;
|
|
23
|
-
signVerificationMessage: () => Promise<{
|
|
24
|
-
address?: string;
|
|
25
|
-
signature?: string;
|
|
26
|
-
error?: string;
|
|
27
|
-
}>;
|
|
28
|
-
getWalletBalance: () => Promise<string | undefined>;
|
|
29
23
|
};
|
|
30
24
|
export declare const EvmExternalWalletContext: import("react").Context<EvmExternalWalletContextType>;
|
|
31
|
-
export type EvmExternalWalletProviderConfig =
|
|
32
|
-
onSwitchWallet?: (args: {
|
|
33
|
-
address?: string;
|
|
34
|
-
error?: string;
|
|
35
|
-
}) => void;
|
|
36
|
-
para: ParaWeb;
|
|
37
|
-
walletsWithFullAuth: TExternalWallet[];
|
|
38
|
-
includeWalletVerification?: boolean;
|
|
39
|
-
connectionOnly?: boolean;
|
|
40
|
-
connectedWallet?: Omit<Wallet, 'signer'> | null;
|
|
41
|
-
};
|
|
25
|
+
export type EvmExternalWalletProviderConfig = ExternalWalletProviderConfigBase;
|
|
42
26
|
export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, walletsWithFullAuth, connectedWallet, includeWalletVerification, connectionOnly, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -32,11 +32,13 @@ const defaultEvmExternalWallet = {
|
|
|
32
32
|
avatar: void 0,
|
|
33
33
|
balance: void 0,
|
|
34
34
|
disconnect: () => Promise.resolve(),
|
|
35
|
-
switchChain: () => Promise.resolve(
|
|
35
|
+
switchChain: () => Promise.resolve(),
|
|
36
36
|
connectParaEmbedded: () => Promise.resolve({}),
|
|
37
37
|
signMessage: () => Promise.resolve({}),
|
|
38
38
|
signVerificationMessage: () => Promise.resolve({}),
|
|
39
|
-
getWalletBalance: () => Promise.resolve(void 0)
|
|
39
|
+
getWalletBalance: () => Promise.resolve(void 0),
|
|
40
|
+
requestInfo: () => Promise.resolve({}),
|
|
41
|
+
disconnectBase: () => Promise.resolve()
|
|
40
42
|
};
|
|
41
43
|
const EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
|
|
42
44
|
function EvmExternalWalletProvider({
|
|
@@ -66,8 +68,12 @@ function EvmExternalWalletProvider({
|
|
|
66
68
|
name: normalize(ensName)
|
|
67
69
|
});
|
|
68
70
|
const { signMessageAsync } = useSignMessage();
|
|
71
|
+
const isLinkingAccount = useRef(false);
|
|
69
72
|
const verificationMessage = useRef();
|
|
70
73
|
const { refetch: getBalance } = useBalance({ address: wagmiAddress });
|
|
74
|
+
const connectors = untypedConnectors;
|
|
75
|
+
const connectionsRef = useRef(connections);
|
|
76
|
+
const connectorsRef = useRef(connectors);
|
|
71
77
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
72
78
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
73
79
|
const getStoredExternalWallets = () => {
|
|
@@ -90,6 +96,23 @@ function EvmExternalWalletProvider({
|
|
|
90
96
|
},
|
|
91
97
|
[connections, wagmiSwitchAccount]
|
|
92
98
|
);
|
|
99
|
+
const findConnectorAndAccount = (externalWallet) => {
|
|
100
|
+
var _a;
|
|
101
|
+
let connector;
|
|
102
|
+
switch (true) {
|
|
103
|
+
case !!externalWallet.providerId:
|
|
104
|
+
{
|
|
105
|
+
connector = (_a = connectionsRef.current.find(
|
|
106
|
+
(c) => {
|
|
107
|
+
var _a2;
|
|
108
|
+
return ((_a2 = c.connector.paraDetails) == null ? void 0 : _a2.internalId) === externalWallet.providerId;
|
|
109
|
+
}
|
|
110
|
+
)) == null ? void 0 : _a.connector;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
return { connector, account: externalWallet.address };
|
|
115
|
+
};
|
|
93
116
|
const getWalletBalance = useCallback(
|
|
94
117
|
// Format from wei to eth
|
|
95
118
|
() => __async(this, null, function* () {
|
|
@@ -100,13 +123,13 @@ function EvmExternalWalletProvider({
|
|
|
100
123
|
);
|
|
101
124
|
useEffect(() => {
|
|
102
125
|
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
103
|
-
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
126
|
+
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para" && !isLinkingAccount.current) {
|
|
104
127
|
reset();
|
|
105
128
|
}
|
|
106
129
|
}, [isConnecting, isReconnecting, isLocalConnecting, wagmiAddress, connectedConnector]);
|
|
107
130
|
useEffect(() => {
|
|
108
131
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
109
|
-
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") {
|
|
132
|
+
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" && !isLinkingAccount.current) {
|
|
110
133
|
switchWallet(wagmiAddress);
|
|
111
134
|
}
|
|
112
135
|
}, [isLocalConnecting, wagmiAddress, isReconnecting, isConnecting]);
|
|
@@ -123,22 +146,27 @@ function EvmExternalWalletProvider({
|
|
|
123
146
|
connectParaEmbedded();
|
|
124
147
|
}
|
|
125
148
|
}, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
|
|
126
|
-
const connectors = untypedConnectors;
|
|
127
149
|
const reset = () => __async(this, null, function* () {
|
|
128
150
|
yield disconnectAsync();
|
|
129
151
|
yield para.logout();
|
|
130
152
|
});
|
|
131
|
-
const signMessage = (
|
|
153
|
+
const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
|
|
154
|
+
let signOpts = {};
|
|
155
|
+
if (externalWallet) {
|
|
156
|
+
signOpts = findConnectorAndAccount(externalWallet);
|
|
157
|
+
}
|
|
132
158
|
try {
|
|
133
|
-
const
|
|
159
|
+
const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
|
|
160
|
+
const signature = yield signMessageAsync(__spreadValues({
|
|
134
161
|
message,
|
|
135
|
-
account:
|
|
136
|
-
});
|
|
162
|
+
account: address
|
|
163
|
+
}, signOpts));
|
|
137
164
|
return {
|
|
138
|
-
address
|
|
165
|
+
address,
|
|
139
166
|
signature
|
|
140
167
|
};
|
|
141
168
|
} catch (e) {
|
|
169
|
+
console.error("Error signing message:", e);
|
|
142
170
|
switch (e.name) {
|
|
143
171
|
case "UserRejectedRequestError": {
|
|
144
172
|
return { error: "Signature request rejected" };
|
|
@@ -150,7 +178,7 @@ function EvmExternalWalletProvider({
|
|
|
150
178
|
}
|
|
151
179
|
});
|
|
152
180
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
153
|
-
const signature = yield signMessage(verificationMessage.current);
|
|
181
|
+
const signature = yield signMessage({ message: verificationMessage.current });
|
|
154
182
|
return signature;
|
|
155
183
|
});
|
|
156
184
|
const switchChain = (chainId2) => __async(this, null, function* () {
|
|
@@ -180,12 +208,7 @@ function EvmExternalWalletProvider({
|
|
|
180
208
|
}
|
|
181
209
|
return { error };
|
|
182
210
|
});
|
|
183
|
-
const login = (_0) => __async(this, [_0], function* ({
|
|
184
|
-
address,
|
|
185
|
-
walletId,
|
|
186
|
-
connectorName
|
|
187
|
-
}) {
|
|
188
|
-
var _a;
|
|
211
|
+
const login = (_0) => __async(this, [_0], function* ({ address, withFullParaAuth = false, providerId, provider }) {
|
|
189
212
|
try {
|
|
190
213
|
refetchEnsName();
|
|
191
214
|
refetchEnsAvatar();
|
|
@@ -193,8 +216,9 @@ function EvmExternalWalletProvider({
|
|
|
193
216
|
externalWallet: {
|
|
194
217
|
address,
|
|
195
218
|
type: "EVM",
|
|
196
|
-
provider
|
|
197
|
-
|
|
219
|
+
provider,
|
|
220
|
+
providerId,
|
|
221
|
+
withFullParaAuth,
|
|
198
222
|
ensName,
|
|
199
223
|
ensAvatar,
|
|
200
224
|
isConnectionOnly: connectionOnly,
|
|
@@ -208,7 +232,6 @@ function EvmExternalWalletProvider({
|
|
|
208
232
|
}
|
|
209
233
|
});
|
|
210
234
|
const switchWallet = (address) => __async(this, null, function* () {
|
|
211
|
-
var _a;
|
|
212
235
|
updateExternalWalletState({ isConnecting: true });
|
|
213
236
|
let error;
|
|
214
237
|
if (!address) {
|
|
@@ -218,11 +241,10 @@ function EvmExternalWalletProvider({
|
|
|
218
241
|
yield reset();
|
|
219
242
|
} else {
|
|
220
243
|
try {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
});
|
|
244
|
+
const loginInfo = getConnectorInfo(connectedConnector);
|
|
245
|
+
yield login(__spreadValues({
|
|
246
|
+
address
|
|
247
|
+
}, loginInfo));
|
|
226
248
|
} catch (err) {
|
|
227
249
|
error = err;
|
|
228
250
|
}
|
|
@@ -231,31 +253,33 @@ function EvmExternalWalletProvider({
|
|
|
231
253
|
onSwitchWallet == null ? void 0 : onSwitchWallet({ address, error });
|
|
232
254
|
updateExternalWalletState({ isConnecting: false });
|
|
233
255
|
});
|
|
234
|
-
const
|
|
256
|
+
const connectBase = (connector) => __async(this, null, function* () {
|
|
235
257
|
var _a, _b, _c, _d;
|
|
258
|
+
const walletChainId = yield connector.getChainId();
|
|
259
|
+
const data = yield connectAsync({
|
|
260
|
+
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
261
|
+
chainId: (_c = (_a = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _a.id) != null ? _c : (
|
|
262
|
+
// Fall back to the first chain provided.
|
|
263
|
+
(_b = chains[0]) == null ? void 0 : _b.id
|
|
264
|
+
),
|
|
265
|
+
connector
|
|
266
|
+
});
|
|
267
|
+
return (_d = data.accounts) == null ? void 0 : _d[0];
|
|
268
|
+
});
|
|
269
|
+
const connect = (connector) => __async(this, null, function* () {
|
|
236
270
|
updateExternalWalletState({ isConnecting: true });
|
|
237
271
|
yield disconnectAsync();
|
|
238
|
-
const walletChainId = yield connector.getChainId();
|
|
239
272
|
let authState;
|
|
240
273
|
let address;
|
|
241
274
|
let error;
|
|
242
275
|
try {
|
|
243
|
-
|
|
244
|
-
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
245
|
-
chainId: (_c = (_a = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _a.id) != null ? _c : (
|
|
246
|
-
// Fall back to the first chain provided.
|
|
247
|
-
(_b = chains[0]) == null ? void 0 : _b.id
|
|
248
|
-
),
|
|
249
|
-
connector
|
|
250
|
-
});
|
|
251
|
-
address = (_d = data.accounts) == null ? void 0 : _d[0];
|
|
276
|
+
address = yield connectBase(connector);
|
|
252
277
|
if (address) {
|
|
253
278
|
try {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
279
|
+
const loginInfo = getConnectorInfo(connector);
|
|
280
|
+
authState = yield login(__spreadValues({
|
|
281
|
+
address
|
|
282
|
+
}, loginInfo));
|
|
259
283
|
verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
|
|
260
284
|
} catch (err) {
|
|
261
285
|
address = void 0;
|
|
@@ -269,7 +293,7 @@ function EvmExternalWalletProvider({
|
|
|
269
293
|
break;
|
|
270
294
|
}
|
|
271
295
|
case "ResourceUnavailableRpcError": {
|
|
272
|
-
`${connector.name} not detected`;
|
|
296
|
+
error = `${connector.name} not detected`;
|
|
273
297
|
break;
|
|
274
298
|
}
|
|
275
299
|
default: {
|
|
@@ -290,6 +314,43 @@ function EvmExternalWalletProvider({
|
|
|
290
314
|
var _a;
|
|
291
315
|
return getWalletConnectUri(connector, (_a = connector.paraDetails) == null ? void 0 : _a.getUri);
|
|
292
316
|
};
|
|
317
|
+
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
318
|
+
var _a, _b;
|
|
319
|
+
const connector = connectors.find((c) => {
|
|
320
|
+
var _a2;
|
|
321
|
+
return ((_a2 = c.paraDetails) == null ? void 0 : _a2.internalId) === providerId;
|
|
322
|
+
});
|
|
323
|
+
if (connector.isAuthorized) isLinkingAccount.current = true;
|
|
324
|
+
try {
|
|
325
|
+
const address = yield connectBase(connector);
|
|
326
|
+
return {
|
|
327
|
+
address,
|
|
328
|
+
type: "EVM",
|
|
329
|
+
providerId: (_a = connector.paraDetails) == null ? void 0 : _a.internalId,
|
|
330
|
+
provider: connector.name,
|
|
331
|
+
ensName,
|
|
332
|
+
ensAvatar
|
|
333
|
+
};
|
|
334
|
+
} catch (e) {
|
|
335
|
+
throw new Error((_b = e == null ? void 0 : e.message) != null ? _b : e);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
const disconnectBase = (providerId) => __async(this, null, function* () {
|
|
339
|
+
var _a;
|
|
340
|
+
if (!providerId) {
|
|
341
|
+
throw new Error("Provider ID is required to disconnect");
|
|
342
|
+
}
|
|
343
|
+
const connector = connectors.find((c) => {
|
|
344
|
+
var _a2;
|
|
345
|
+
return ((_a2 = c.paraDetails) == null ? void 0 : _a2.internalId) === providerId;
|
|
346
|
+
});
|
|
347
|
+
isLinkingAccount.current = true;
|
|
348
|
+
try {
|
|
349
|
+
yield connector.disconnect();
|
|
350
|
+
} catch (e) {
|
|
351
|
+
throw new Error((_a = e == null ? void 0 : e.message) != null ? _a : e);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
293
354
|
const nonEip6963ConnectorsByRdns = {};
|
|
294
355
|
let walletConnectModalConnector;
|
|
295
356
|
connectors.filter((c) => !isEIP6963Connector(c)).forEach((c) => {
|
|
@@ -313,7 +374,7 @@ function EvmExternalWalletProvider({
|
|
|
313
374
|
const paraMetadata = nonEip6963ConnectorsByRdns[c.id];
|
|
314
375
|
return __spreadProps(__spreadValues({}, c), { paraDetails: paraMetadata });
|
|
315
376
|
}
|
|
316
|
-
if (((_c = c.paraDetails) == null ? void 0 : _c.id) === "
|
|
377
|
+
if (((_c = c.paraDetails) == null ? void 0 : _c.id) === "WALLETCONNECT" && walletConnectModalConnector) {
|
|
317
378
|
return __spreadProps(__spreadValues({}, c), { walletConnectModalConnector });
|
|
318
379
|
}
|
|
319
380
|
return c;
|
|
@@ -327,9 +388,16 @@ function EvmExternalWalletProvider({
|
|
|
327
388
|
getQrUri: getQrUri(connector)
|
|
328
389
|
});
|
|
329
390
|
});
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
391
|
+
const getConnectorInfo = (connector) => {
|
|
392
|
+
const paraDetails = connector.paraDetails;
|
|
393
|
+
const providerId = paraDetails == null ? void 0 : paraDetails.internalId;
|
|
394
|
+
const withFullParaAuth = walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(providerId);
|
|
395
|
+
return {
|
|
396
|
+
type: "EVM",
|
|
397
|
+
providerId,
|
|
398
|
+
provider: paraDetails == null ? void 0 : paraDetails.name,
|
|
399
|
+
withFullParaAuth
|
|
400
|
+
};
|
|
333
401
|
};
|
|
334
402
|
const formattedChains = chains.map((c) => {
|
|
335
403
|
return {
|
|
@@ -351,6 +419,12 @@ function EvmExternalWalletProvider({
|
|
|
351
419
|
return { error };
|
|
352
420
|
}
|
|
353
421
|
}), [connectors]);
|
|
422
|
+
useEffect(() => {
|
|
423
|
+
connectionsRef.current = connections;
|
|
424
|
+
}, [connections]);
|
|
425
|
+
useEffect(() => {
|
|
426
|
+
connectorsRef.current = connectors;
|
|
427
|
+
}, [connectors]);
|
|
354
428
|
return /* @__PURE__ */ jsx(
|
|
355
429
|
EvmExternalWalletContext.Provider,
|
|
356
430
|
{
|
|
@@ -365,7 +439,9 @@ function EvmExternalWalletProvider({
|
|
|
365
439
|
connectParaEmbedded,
|
|
366
440
|
signMessage,
|
|
367
441
|
signVerificationMessage,
|
|
368
|
-
getWalletBalance
|
|
442
|
+
getWalletBalance,
|
|
443
|
+
requestInfo,
|
|
444
|
+
disconnectBase
|
|
369
445
|
},
|
|
370
446
|
children
|
|
371
447
|
}
|
|
@@ -373,5 +449,6 @@ function EvmExternalWalletProvider({
|
|
|
373
449
|
}
|
|
374
450
|
export {
|
|
375
451
|
EvmExternalWalletContext,
|
|
376
|
-
EvmExternalWalletProvider
|
|
452
|
+
EvmExternalWalletProvider,
|
|
453
|
+
defaultEvmExternalWallet
|
|
377
454
|
};
|
|
@@ -4,12 +4,13 @@ import { WalletList } from '../types/Wallet.js';
|
|
|
4
4
|
import { Chain, Transport } from 'viem';
|
|
5
5
|
import { EvmExternalWalletProviderConfig } from './EvmExternalWalletContext.js';
|
|
6
6
|
import { InjectedParameters } from 'wagmi/connectors';
|
|
7
|
+
import { TExternalWallet } from '@getpara/react-common';
|
|
7
8
|
export interface ParaEvmProviderConfig<chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>> extends Omit<CreateConfigParameters<chains, transports>, 'connectors'> {
|
|
8
9
|
appName: string;
|
|
9
10
|
appDescription?: string;
|
|
10
11
|
appUrl?: string;
|
|
11
12
|
appIcon?: string;
|
|
12
|
-
wallets?: WalletList;
|
|
13
|
+
wallets?: WalletList | TExternalWallet[];
|
|
13
14
|
projectId: string;
|
|
14
15
|
paraConnectorOptions?: InjectedParameters;
|
|
15
16
|
}
|
|
@@ -12,7 +12,8 @@ import { http } from "viem";
|
|
|
12
12
|
import { computeWalletConnectMetaData } from "../utils/computeWalletConnectMetaData.js";
|
|
13
13
|
import { EvmExternalWalletProvider } from "./EvmExternalWalletContext.js";
|
|
14
14
|
import { paraConnector } from "@getpara/wagmi-v2-connector";
|
|
15
|
-
import { setWagmiConfig } from "../stores/wagmiConfigStore.js";
|
|
15
|
+
import { setWagmiConfig, getWagmiConfig } from "../stores/wagmiConfigStore.js";
|
|
16
|
+
import { resolveWalletList } from "../utils/resolveWalletList.js";
|
|
16
17
|
const createDefaultTransports = (chains) => {
|
|
17
18
|
const transportsObject = chains.reduce((acc, chain) => {
|
|
18
19
|
const key = chain.id;
|
|
@@ -59,8 +60,11 @@ function ParaEvmProvider({
|
|
|
59
60
|
});
|
|
60
61
|
}, [para]);
|
|
61
62
|
const config = useMemo(() => {
|
|
63
|
+
const existing = getWagmiConfig();
|
|
64
|
+
if (existing) return existing;
|
|
62
65
|
const wcMetadata = computeWalletConnectMetaData({ appName, appDescription, appUrl, appIcon });
|
|
63
|
-
const
|
|
66
|
+
const walletFactories = resolveWalletList(wallets);
|
|
67
|
+
const baseConnectors = connectorsForWallets(walletFactories, {
|
|
64
68
|
projectId,
|
|
65
69
|
appName,
|
|
66
70
|
appDescription,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Chain, Transport } from 'viem';
|
|
2
|
+
import type { ParaEvmProviderConfig } from './ParaEvmContext.js';
|
|
3
|
+
import ParaWeb from '@getpara/web-sdk';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Wagmi configuration for the Para EVM provider.
|
|
6
|
+
* @param para - The ParaWeb instance to use.
|
|
7
|
+
* @param cfg - The configuration options for the Para EVM provider.
|
|
8
|
+
* @returns The created Wagmi configuration.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createParaWagmiConfig<const chains extends readonly [Chain, ...Chain[]], transports extends Record<chains[number]['id'], Transport>>(para: ParaWeb, cfg: ParaEvmProviderConfig<chains, transports>): import("wagmi").Config<chains, transports, readonly import("wagmi").CreateConnectorFn[]>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__objRest,
|
|
4
|
+
__spreadProps,
|
|
5
|
+
__spreadValues
|
|
6
|
+
} from "../chunk-MMUBH76A.js";
|
|
7
|
+
import { createConfig } from "wagmi";
|
|
8
|
+
import { connectorsForWallets } from "../wallets/connectorsForWallets.js";
|
|
9
|
+
import { computeWalletConnectMetaData } from "../utils/computeWalletConnectMetaData.js";
|
|
10
|
+
import { paraConnector } from "@getpara/wagmi-v2-connector";
|
|
11
|
+
import { setWagmiConfig } from "../stores/wagmiConfigStore.js";
|
|
12
|
+
import { resolveWalletList } from "../utils/resolveWalletList.js";
|
|
13
|
+
function createParaWagmiConfig(para, cfg) {
|
|
14
|
+
const _a = cfg, {
|
|
15
|
+
projectId,
|
|
16
|
+
appName,
|
|
17
|
+
appDescription,
|
|
18
|
+
appIcon,
|
|
19
|
+
appUrl,
|
|
20
|
+
wallets,
|
|
21
|
+
chains,
|
|
22
|
+
transports,
|
|
23
|
+
paraConnectorOptions
|
|
24
|
+
} = _a, wagmiParams = __objRest(_a, [
|
|
25
|
+
"projectId",
|
|
26
|
+
"appName",
|
|
27
|
+
"appDescription",
|
|
28
|
+
"appIcon",
|
|
29
|
+
"appUrl",
|
|
30
|
+
"wallets",
|
|
31
|
+
"chains",
|
|
32
|
+
"transports",
|
|
33
|
+
"paraConnectorOptions"
|
|
34
|
+
]);
|
|
35
|
+
const wcMetadata = computeWalletConnectMetaData({ appName, appDescription, appUrl, appIcon });
|
|
36
|
+
const walletFactories = resolveWalletList(wallets);
|
|
37
|
+
const baseConnectors = connectorsForWallets(walletFactories, {
|
|
38
|
+
projectId,
|
|
39
|
+
appName,
|
|
40
|
+
appDescription,
|
|
41
|
+
appUrl,
|
|
42
|
+
appIcon,
|
|
43
|
+
walletConnectParameters: { metadata: wcMetadata }
|
|
44
|
+
});
|
|
45
|
+
const paraConn = paraConnector({
|
|
46
|
+
para,
|
|
47
|
+
chains: [...chains],
|
|
48
|
+
disableModal: true,
|
|
49
|
+
appName,
|
|
50
|
+
options: paraConnectorOptions != null ? paraConnectorOptions : {}
|
|
51
|
+
});
|
|
52
|
+
const created = createConfig(__spreadProps(__spreadValues({}, wagmiParams), {
|
|
53
|
+
chains,
|
|
54
|
+
transports,
|
|
55
|
+
connectors: [...baseConnectors, paraConn]
|
|
56
|
+
}));
|
|
57
|
+
setWagmiConfig(created);
|
|
58
|
+
return created;
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
createParaWagmiConfig
|
|
62
|
+
};
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import type { Config } from 'wagmi';
|
|
2
|
+
/**
|
|
3
|
+
* Sets the Wagmi configuration in the global store.
|
|
4
|
+
*
|
|
5
|
+
* @param config - The Wagmi configuration object to be stored
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*/
|
|
2
8
|
export declare const setWagmiConfig: (config: Config) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the current Wagmi configuration from the global store.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Config | null} - The current Wagmi configuration or null if not set
|
|
13
|
+
*/
|
|
3
14
|
export declare const getWagmiConfig: () => Config;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../chunk-MMUBH76A.js";
|
|
3
|
+
import { allWallets } from "../wallets/connectors/index.js";
|
|
4
|
+
function resolveWalletList(wallets) {
|
|
5
|
+
if (!wallets || !wallets.length) return [];
|
|
6
|
+
if (typeof wallets[0] === "function") return wallets;
|
|
7
|
+
const ids = wallets;
|
|
8
|
+
const resolved = allWallets.filter((createWalletFn) => {
|
|
9
|
+
const meta = createWalletFn({ projectId: "", appName: "" });
|
|
10
|
+
return ids.includes(meta.id.toUpperCase());
|
|
11
|
+
});
|
|
12
|
+
return resolved;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
resolveWalletList
|
|
16
|
+
};
|
|
@@ -51,7 +51,7 @@ const connectorsForWallets = (walletList, { projectId, walletConnectParameters,
|
|
|
51
51
|
}), additionalParaParams ? additionalParaParams : {}))
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
|
-
const isWalletConnectConnector = walletMeta.
|
|
54
|
+
const isWalletConnectConnector = walletMeta.internalId === "WALLETCONNECT";
|
|
55
55
|
if (isWalletConnectConnector && createConnector) {
|
|
56
56
|
connectors.push(
|
|
57
57
|
createConnector(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/evm-wallet-connectors",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@coinbase/wallet-sdk": "4.3.0",
|
|
13
|
-
"@getpara/wagmi-v2-connector": "2.0.0-alpha.
|
|
14
|
-
"@getpara/web-sdk": "2.0.0-alpha.
|
|
13
|
+
"@getpara/wagmi-v2-connector": "2.0.0-alpha.21",
|
|
14
|
+
"@getpara/web-sdk": "2.0.0-alpha.21",
|
|
15
15
|
"viem": "^2.24.2",
|
|
16
16
|
"wagmi": "^2.14.16",
|
|
17
17
|
"zustand": "^4.5.2",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "vitest run --coverage"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@getpara/react-common": "2.0.0-alpha.
|
|
26
|
+
"@getpara/react-common": "2.0.0-alpha.21",
|
|
27
27
|
"@tanstack/react-query": ">=5.0.0",
|
|
28
28
|
"@types/react": "^18.0.31",
|
|
29
29
|
"@types/react-dom": "^18.2.7",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dist",
|
|
40
40
|
"package.json"
|
|
41
41
|
],
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "03daa3537312bc52e0640225c8abdbf8047c15da"
|
|
43
43
|
}
|