@getpara/evm-wallet-connectors 2.0.0-alpha.7 → 2.0.0-alpha.71
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/README.md +20 -0
- package/dist/connectors/walletConnect.d.ts +63 -0
- package/dist/connectors/walletConnect.js +366 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -1
- package/dist/providers/EvmExternalWalletContext.d.ts +7 -35
- package/dist/providers/EvmExternalWalletContext.js +280 -86
- package/dist/providers/ParaEvmContext.d.ts +2 -1
- package/dist/providers/ParaEvmContext.js +49 -7
- package/dist/providers/createParaWagmiConfig.d.ts +10 -0
- package/dist/providers/createParaWagmiConfig.js +65 -0
- package/dist/providers/externalHooks.d.ts +7 -0
- package/dist/providers/externalHooks.js +7 -0
- package/dist/stores/wagmiConfigStore.d.ts +14 -0
- package/dist/stores/wagmiConfigStore.js +16 -0
- package/dist/types/Wallet.d.ts +5 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/utils/getWalletConnectConnector.js +1 -1
- package/dist/utils/getWalletConnectUri.d.ts +1 -1
- package/dist/utils/getWalletConnectUri.js +20 -14
- package/dist/utils/isEIP6963Connector.js +1 -1
- package/dist/utils/resolveWalletList.d.ts +3 -0
- package/dist/utils/resolveWalletList.js +16 -0
- package/dist/wallets/connectors/backpack/backpack.d.ts +3 -0
- package/dist/wallets/connectors/backpack/backpack.js +31 -0
- package/dist/wallets/connectors/backpack/backpackIcon.d.ts +1 -0
- package/dist/wallets/connectors/backpack/backpackIcon.js +6 -0
- package/dist/wallets/connectors/coinbase/coinbase.js +1 -0
- package/dist/wallets/connectors/farcaster/farcaster.d.ts +2 -0
- package/dist/wallets/connectors/farcaster/farcaster.js +22 -0
- package/dist/wallets/connectors/farcaster/farcasterIcon.d.ts +1 -0
- package/dist/wallets/connectors/farcaster/farcasterIcon.js +6 -0
- package/dist/wallets/connectors/haha/haha.d.ts +3 -0
- package/dist/wallets/connectors/haha/haha.js +31 -0
- package/dist/wallets/connectors/haha/hahaIcon.d.ts +1 -0
- package/dist/wallets/connectors/haha/hahaIcon.js +6 -0
- package/dist/wallets/connectors/index.d.ts +7 -1
- package/dist/wallets/connectors/index.js +18 -1
- package/dist/wallets/connectors/metaMask/metaMask.js +8 -4
- package/dist/wallets/connectors/metaMask/metaMaskIcon.d.ts +1 -1
- package/dist/wallets/connectors/metaMask/metaMaskIcon.js +1 -1
- package/dist/wallets/connectors/okx/okx.d.ts +3 -0
- package/dist/wallets/connectors/okx/okx.js +32 -0
- package/dist/wallets/connectors/okx/okxIcon.d.ts +1 -0
- package/dist/wallets/connectors/okx/okxIcon.js +6 -0
- package/dist/wallets/connectors/phantom/phantom.d.ts +3 -0
- package/dist/wallets/connectors/phantom/phantom.js +31 -0
- package/dist/wallets/connectors/phantom/phantomIcon.d.ts +1 -0
- package/dist/wallets/connectors/phantom/phantomIcon.js +6 -0
- package/dist/wallets/connectors/rabby/rabby.js +1 -0
- package/dist/wallets/connectors/rainbow/rainbow.js +8 -1
- package/dist/wallets/connectors/safe/safe.js +1 -0
- package/dist/wallets/connectors/valora/valora.d.ts +3 -0
- package/dist/wallets/connectors/valora/valora.js +29 -0
- package/dist/wallets/connectors/valora/valoraIcon.d.ts +1 -0
- package/dist/wallets/connectors/valora/valoraIcon.js +6 -0
- package/dist/wallets/connectors/walletConnect/walletConnect.js +1 -0
- package/dist/wallets/connectors/zerion/zerion.js +5 -1
- package/dist/wallets/connectorsForWallets.d.ts +4 -1
- package/dist/wallets/connectorsForWallets.js +14 -3
- package/package.json +34 -26
|
@@ -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, useCallback, useEffect, useMemo, useRef } from "react";
|
|
8
|
+
import { createContext, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
9
9
|
import {
|
|
10
10
|
useAccount,
|
|
11
11
|
useSwitchChain,
|
|
@@ -19,32 +19,28 @@ import {
|
|
|
19
19
|
useBalance
|
|
20
20
|
} from "wagmi";
|
|
21
21
|
import { isEIP6963Connector } from "../utils/isEIP6963Connector.js";
|
|
22
|
-
import {
|
|
22
|
+
import { emitWalletConnectUri } from "../utils/getWalletConnectUri.js";
|
|
23
23
|
import { normalize } from "viem/ens";
|
|
24
24
|
import { useExternalWalletStore } from "../stores/useStore.js";
|
|
25
|
+
import {
|
|
26
|
+
defaultEvmExternalWallet,
|
|
27
|
+
openMobileUrl
|
|
28
|
+
} from "@getpara/react-common";
|
|
25
29
|
import { isMobile } from "@getpara/web-sdk";
|
|
26
30
|
import { etherUnits, formatUnits } from "viem";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
avatar: void 0,
|
|
33
|
-
balance: void 0,
|
|
34
|
-
disconnect: () => Promise.resolve(),
|
|
35
|
-
switchChain: () => Promise.resolve({}),
|
|
36
|
-
connectParaEmbedded: () => Promise.resolve({}),
|
|
37
|
-
signMessage: () => Promise.resolve({}),
|
|
38
|
-
signVerificationMessage: () => Promise.resolve({}),
|
|
39
|
-
getWalletBalance: () => Promise.resolve(void 0)
|
|
40
|
-
};
|
|
41
|
-
const EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
|
|
31
|
+
import { externalHooks } from "./externalHooks.js";
|
|
32
|
+
const EvmExternalWalletContext = createContext(__spreadProps(__spreadValues({}, defaultEvmExternalWallet), {
|
|
33
|
+
farcasterStatus: void 0,
|
|
34
|
+
verificationStage: void 0
|
|
35
|
+
}));
|
|
42
36
|
function EvmExternalWalletProvider({
|
|
43
37
|
children,
|
|
44
38
|
onSwitchWallet,
|
|
45
39
|
para,
|
|
46
40
|
walletsWithFullAuth,
|
|
47
|
-
connectedWallet
|
|
41
|
+
connectedWallet: connectedWalletProp,
|
|
42
|
+
includeWalletVerification,
|
|
43
|
+
connectionOnly
|
|
48
44
|
}) {
|
|
49
45
|
const { connectAsync, connectors: untypedConnectors } = useConnect();
|
|
50
46
|
const connections = useConnections();
|
|
@@ -58,14 +54,20 @@ function EvmExternalWalletProvider({
|
|
|
58
54
|
} = useAccount();
|
|
59
55
|
const { switchAccount: wagmiSwitchAccount } = useSwitchAccount();
|
|
60
56
|
const { chains, switchChainAsync } = useSwitchChain();
|
|
61
|
-
const { disconnectAsync } = useDisconnect();
|
|
57
|
+
const { disconnectAsync, status: disconnectStatus } = useDisconnect();
|
|
62
58
|
const { data: ensName, refetch: refetchEnsName } = useEnsName({ address: wagmiAddress });
|
|
63
59
|
const { data: ensAvatar, refetch: refetchEnsAvatar } = useEnsAvatar({
|
|
64
60
|
name: normalize(ensName)
|
|
65
61
|
});
|
|
66
62
|
const { signMessageAsync } = useSignMessage();
|
|
63
|
+
const connectedWallet = connectedWalletProp ? para.findWallet(connectedWalletProp.id, connectedWalletProp.type) : null;
|
|
64
|
+
const disconnectTypeRef = useRef();
|
|
67
65
|
const verificationMessage = useRef();
|
|
68
66
|
const { refetch: getBalance } = useBalance({ address: wagmiAddress });
|
|
67
|
+
const connectors = untypedConnectors;
|
|
68
|
+
const connectionsRef = useRef(connections);
|
|
69
|
+
const connectorsRef = useRef(connectors);
|
|
70
|
+
const [verificationStage, setVerificationStage] = useState("verifying");
|
|
69
71
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
70
72
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
71
73
|
const getStoredExternalWallets = () => {
|
|
@@ -79,15 +81,34 @@ function EvmExternalWalletProvider({
|
|
|
79
81
|
const switchAccount = useCallback(
|
|
80
82
|
(connectorName) => {
|
|
81
83
|
var _a;
|
|
82
|
-
const connector = (_a =
|
|
84
|
+
const connector = (_a = connectionsRef.current.find((c) => {
|
|
85
|
+
var _a2;
|
|
86
|
+
const paraDetails = (_a2 = c.connector) == null ? void 0 : _a2.paraDetails;
|
|
87
|
+
return [paraDetails == null ? void 0 : paraDetails.name, paraDetails == null ? void 0 : paraDetails.id, paraDetails == null ? void 0 : paraDetails.internalId].includes(connectorName);
|
|
88
|
+
})) == null ? void 0 : _a.connector;
|
|
83
89
|
if (!connector) {
|
|
84
90
|
console.warn(`connector not found: ${connectorName}`);
|
|
85
91
|
return;
|
|
86
92
|
}
|
|
87
93
|
wagmiSwitchAccount({ connector });
|
|
88
94
|
},
|
|
89
|
-
[
|
|
95
|
+
[wagmiSwitchAccount]
|
|
90
96
|
);
|
|
97
|
+
const findConnectorAndAccount = (externalWallet) => {
|
|
98
|
+
var _a;
|
|
99
|
+
let connector;
|
|
100
|
+
switch (true) {
|
|
101
|
+
case !!externalWallet.providerId:
|
|
102
|
+
{
|
|
103
|
+
connector = (_a = connectionsRef.current.find((c) => {
|
|
104
|
+
var _a2;
|
|
105
|
+
return ((_a2 = c.connector) == null ? void 0 : _a2.name) === externalWallet.providerId;
|
|
106
|
+
})) == null ? void 0 : _a.connector;
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return { connector, account: externalWallet.address };
|
|
111
|
+
};
|
|
91
112
|
const getWalletBalance = useCallback(
|
|
92
113
|
// Format from wei to eth
|
|
93
114
|
() => __async(this, null, function* () {
|
|
@@ -98,45 +119,109 @@ function EvmExternalWalletProvider({
|
|
|
98
119
|
);
|
|
99
120
|
useEffect(() => {
|
|
100
121
|
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
101
|
-
if (
|
|
122
|
+
if ((connectedConnector == null ? void 0 : connectedConnector.id) === "para") {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && !disconnectTypeRef.current && para.isReady && !para.isFarcasterMiniApp) {
|
|
102
126
|
reset();
|
|
103
127
|
}
|
|
104
|
-
}, [
|
|
128
|
+
}, [isConnected, isLocalConnecting, wagmiAddress, connectedConnector, para.isReady, para.isFarcasterMiniApp]);
|
|
105
129
|
useEffect(() => {
|
|
106
130
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
107
|
-
if (!isLocalConnecting &&
|
|
131
|
+
if (!isLocalConnecting && isConnected && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === "EVM" && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para" && !disconnectTypeRef.current) {
|
|
108
132
|
switchWallet(wagmiAddress);
|
|
109
133
|
}
|
|
110
|
-
}, [isLocalConnecting, wagmiAddress,
|
|
134
|
+
}, [isLocalConnecting, wagmiAddress, isConnected]);
|
|
111
135
|
useEffect(() => {
|
|
112
|
-
|
|
136
|
+
var _a;
|
|
137
|
+
const connectedConnectorName = (connectedConnector == null ? void 0 : connectedConnector.name) === "WalletConnect" ? (_a = connectedConnector == null ? void 0 : connectedConnector.paraDetails) == null ? void 0 : _a.name : connectedConnector == null ? void 0 : connectedConnector.name;
|
|
138
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedConnector && connectedWallet.type === "EVM" && connectedConnectorName !== connectedWallet.name) {
|
|
113
139
|
switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
|
|
114
140
|
}
|
|
115
141
|
}, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
|
|
116
142
|
useEffect(() => {
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
|
|
143
|
+
const connectPara = () => __async(this, null, function* () {
|
|
144
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && !isConnected && !connectedConnector) {
|
|
145
|
+
if (Object.values(para.wallets).length === 0 || !(yield para.isFullyLoggedIn())) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
connectParaEmbedded();
|
|
120
149
|
}
|
|
121
|
-
|
|
122
|
-
|
|
150
|
+
});
|
|
151
|
+
connectPara();
|
|
123
152
|
}, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
|
|
124
|
-
const connectors = untypedConnectors;
|
|
125
153
|
const reset = () => __async(this, null, function* () {
|
|
126
154
|
yield disconnectAsync();
|
|
127
155
|
yield para.logout();
|
|
128
156
|
});
|
|
129
|
-
const
|
|
157
|
+
const getChainParams = (chainId2) => {
|
|
158
|
+
var _a;
|
|
159
|
+
const chain = chains.find((c) => c.id === chainId2);
|
|
160
|
+
if (!chain) return null;
|
|
161
|
+
return {
|
|
162
|
+
chainId: `0x${chainId2.toString(16)}`,
|
|
163
|
+
chainName: chain.name,
|
|
164
|
+
nativeCurrency: {
|
|
165
|
+
name: chain.nativeCurrency.name,
|
|
166
|
+
symbol: chain.nativeCurrency.symbol,
|
|
167
|
+
decimals: chain.nativeCurrency.decimals
|
|
168
|
+
},
|
|
169
|
+
rpcUrls: [chain.rpcUrls.default.http[0]],
|
|
170
|
+
blockExplorerUrls: ((_a = chain.blockExplorers) == null ? void 0 : _a.default) ? [chain.blockExplorers.default.url] : void 0
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
|
|
174
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
175
|
+
let signOpts = {};
|
|
176
|
+
const connector = findConnector(
|
|
177
|
+
externalWallet ? externalWallet.providerId : getConnectorInfo(connectedConnector).providerId
|
|
178
|
+
);
|
|
179
|
+
const signUri = isMobile() && connector.type === "walletConnect" ? (_a = connector.paraDetails) == null ? void 0 : _a.deeplinkUri : void 0;
|
|
180
|
+
const openApp = () => {
|
|
181
|
+
if (signUri) {
|
|
182
|
+
openMobileUrl(signUri);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
openApp();
|
|
186
|
+
if (externalWallet) {
|
|
187
|
+
signOpts = findConnectorAndAccount(externalWallet);
|
|
188
|
+
yield switchAccount((_b = externalWallet.providerId) != null ? _b : "");
|
|
189
|
+
}
|
|
190
|
+
const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
|
|
130
191
|
try {
|
|
131
|
-
const signature = yield signMessageAsync({
|
|
192
|
+
const signature = yield signMessageAsync(__spreadValues({
|
|
132
193
|
message,
|
|
133
|
-
account:
|
|
134
|
-
});
|
|
194
|
+
account: address
|
|
195
|
+
}, signOpts));
|
|
135
196
|
return {
|
|
136
|
-
address
|
|
197
|
+
address,
|
|
137
198
|
signature
|
|
138
199
|
};
|
|
139
200
|
} catch (e) {
|
|
201
|
+
console.error("Error signing message:", e);
|
|
202
|
+
console.error("Error signing message:", e.message, e.details);
|
|
203
|
+
if (e.message.includes("Chain not configured") || e.details.includes("Chain not configured")) {
|
|
204
|
+
setVerificationStage("switchingChain");
|
|
205
|
+
const currentChainParams = getChainParams((_d = (_c = chains[0]) == null ? void 0 : _c.id) != null ? _d : chainId);
|
|
206
|
+
if (!currentChainParams) {
|
|
207
|
+
return {
|
|
208
|
+
error: `Chain ${chainId} not found in configuration`
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
yield switchChainAsync({
|
|
213
|
+
addEthereumChainParameter: currentChainParams,
|
|
214
|
+
chainId: (_f = (_e = chains[0]) == null ? void 0 : _e.id) != null ? _f : chainId
|
|
215
|
+
});
|
|
216
|
+
setVerificationStage("verifying");
|
|
217
|
+
return yield signMessage({ message, externalWallet });
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error("Error adding chain:", error);
|
|
220
|
+
return {
|
|
221
|
+
error: `Error adding chain. You may need to add ${currentChainParams == null ? void 0 : currentChainParams.chainName} support to ${(_i = (_h = (_g = connectedConnector == null ? void 0 : connectedConnector.paraDetails) == null ? void 0 : _g.name) != null ? _h : connectedConnector == null ? void 0 : connectedConnector.name) != null ? _i : "the wallet"} manually.`
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
140
225
|
switch (e.name) {
|
|
141
226
|
case "UserRejectedRequestError": {
|
|
142
227
|
return { error: "Signature request rejected" };
|
|
@@ -148,7 +233,8 @@ function EvmExternalWalletProvider({
|
|
|
148
233
|
}
|
|
149
234
|
});
|
|
150
235
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
151
|
-
|
|
236
|
+
setVerificationStage("verifying");
|
|
237
|
+
const signature = yield signMessage({ message: verificationMessage.current });
|
|
152
238
|
return signature;
|
|
153
239
|
});
|
|
154
240
|
const switchChain = (chainId2) => __async(this, null, function* () {
|
|
@@ -178,47 +264,47 @@ function EvmExternalWalletProvider({
|
|
|
178
264
|
}
|
|
179
265
|
return { error };
|
|
180
266
|
});
|
|
181
|
-
const login = (_0) => __async(this, [_0], function* ({
|
|
182
|
-
|
|
183
|
-
walletId,
|
|
184
|
-
connectorName
|
|
185
|
-
}) {
|
|
186
|
-
var _a;
|
|
267
|
+
const login = (_0) => __async(this, [_0], function* ({ address, withFullParaAuth = false, providerId, provider }) {
|
|
268
|
+
var _a, _b, _c;
|
|
187
269
|
try {
|
|
188
270
|
refetchEnsName();
|
|
189
271
|
refetchEnsAvatar();
|
|
190
272
|
return yield para.loginExternalWallet({
|
|
191
273
|
externalWallet: {
|
|
274
|
+
partnerId: para.partnerId,
|
|
192
275
|
address,
|
|
193
276
|
type: "EVM",
|
|
194
|
-
provider
|
|
195
|
-
|
|
277
|
+
provider,
|
|
278
|
+
providerId,
|
|
279
|
+
withFullParaAuth,
|
|
196
280
|
ensName,
|
|
197
|
-
ensAvatar
|
|
198
|
-
|
|
281
|
+
ensAvatar,
|
|
282
|
+
isConnectionOnly: connectionOnly,
|
|
283
|
+
withVerification: includeWalletVerification
|
|
284
|
+
},
|
|
285
|
+
uri: window == null ? void 0 : window.location.origin,
|
|
286
|
+
chainId: (_c = (_b = (_a = chains[0]) == null ? void 0 : _a.id) != null ? _b : chainId) == null ? void 0 : _c.toString()
|
|
199
287
|
});
|
|
200
|
-
} catch (
|
|
288
|
+
} catch (e) {
|
|
201
289
|
yield disconnectAsync();
|
|
202
290
|
yield para.logout();
|
|
203
291
|
throw "Error logging you in. Please try again.";
|
|
204
292
|
}
|
|
205
293
|
});
|
|
206
294
|
const switchWallet = (address) => __async(this, null, function* () {
|
|
207
|
-
var _a;
|
|
208
295
|
updateExternalWalletState({ isConnecting: true });
|
|
209
296
|
let error;
|
|
210
297
|
if (!address) {
|
|
211
298
|
yield para.logout();
|
|
212
299
|
} else {
|
|
213
|
-
if (para.isExternalWalletAuth) {
|
|
300
|
+
if (para.isExternalWalletAuth || para.isExternalWalletWithVerification) {
|
|
214
301
|
yield reset();
|
|
215
302
|
} else {
|
|
216
303
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
304
|
+
const loginInfo = getConnectorInfo(connectedConnector);
|
|
305
|
+
yield login(__spreadValues({
|
|
306
|
+
address
|
|
307
|
+
}, loginInfo));
|
|
222
308
|
} catch (err) {
|
|
223
309
|
error = err;
|
|
224
310
|
}
|
|
@@ -227,28 +313,37 @@ function EvmExternalWalletProvider({
|
|
|
227
313
|
onSwitchWallet == null ? void 0 : onSwitchWallet({ address, error });
|
|
228
314
|
updateExternalWalletState({ isConnecting: false });
|
|
229
315
|
});
|
|
316
|
+
const connectBase = (connector) => __async(this, null, function* () {
|
|
317
|
+
var _a, _b, _c, _d, _e, _f;
|
|
318
|
+
if (connector.type === "walletConnect" || ((_a = connector.paraDetails) == null ? void 0 : _a.internalId) === "WALLETCONNECT" || ((_b = connector.paraDetails) == null ? void 0 : _b.showQrModal)) {
|
|
319
|
+
yield emitWalletConnectUri(connector, connector.getUri);
|
|
320
|
+
}
|
|
321
|
+
const walletChainId = yield connector.getChainId();
|
|
322
|
+
const data = yield connectAsync({
|
|
323
|
+
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
324
|
+
chainId: (_e = (_c = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _c.id) != null ? _e : (
|
|
325
|
+
// Fall back to the first chain provided.
|
|
326
|
+
(_d = chains[0]) == null ? void 0 : _d.id
|
|
327
|
+
),
|
|
328
|
+
connector
|
|
329
|
+
});
|
|
330
|
+
return (_f = data.accounts) == null ? void 0 : _f[0];
|
|
331
|
+
});
|
|
230
332
|
const connect = (connector) => __async(this, null, function* () {
|
|
231
|
-
var _a, _b, _c, _d;
|
|
232
333
|
updateExternalWalletState({ isConnecting: true });
|
|
233
334
|
yield disconnectAsync();
|
|
234
|
-
const walletChainId = yield connector.getChainId();
|
|
235
335
|
let authState;
|
|
236
336
|
let address;
|
|
237
337
|
let error;
|
|
238
338
|
try {
|
|
239
|
-
|
|
240
|
-
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
241
|
-
chainId: (_c = (_a = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _a.id) != null ? _c : (
|
|
242
|
-
// Fall back to the first chain provided.
|
|
243
|
-
(_b = chains[0]) == null ? void 0 : _b.id
|
|
244
|
-
),
|
|
245
|
-
connector
|
|
246
|
-
});
|
|
247
|
-
address = (_d = data.accounts) == null ? void 0 : _d[0];
|
|
339
|
+
address = yield connectBase(connector);
|
|
248
340
|
if (address) {
|
|
249
341
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
342
|
+
const loginInfo = getConnectorInfo(connector);
|
|
343
|
+
authState = yield login(__spreadValues({
|
|
344
|
+
address
|
|
345
|
+
}, loginInfo));
|
|
346
|
+
verificationMessage.current = authState.signatureVerificationMessage;
|
|
252
347
|
} catch (err) {
|
|
253
348
|
address = void 0;
|
|
254
349
|
error = err;
|
|
@@ -261,10 +356,11 @@ function EvmExternalWalletProvider({
|
|
|
261
356
|
break;
|
|
262
357
|
}
|
|
263
358
|
case "ResourceUnavailableRpcError": {
|
|
264
|
-
`${connector.name} not detected`;
|
|
359
|
+
error = `${connector.name} not detected`;
|
|
265
360
|
break;
|
|
266
361
|
}
|
|
267
362
|
default: {
|
|
363
|
+
console.error("Wagmi connection error:", e.message);
|
|
268
364
|
error = "An unknown error occurred";
|
|
269
365
|
break;
|
|
270
366
|
}
|
|
@@ -278,10 +374,61 @@ function EvmExternalWalletProvider({
|
|
|
278
374
|
const _connector = connector.walletConnectModalConnector && _isMobile ? connector.walletConnectModalConnector : connector;
|
|
279
375
|
return yield connect(_connector);
|
|
280
376
|
});
|
|
281
|
-
const
|
|
377
|
+
const findConnector = (providerId) => {
|
|
282
378
|
var _a;
|
|
283
|
-
|
|
379
|
+
const connector = connectorsRef.current.find(
|
|
380
|
+
(w) => {
|
|
381
|
+
var _a2, _b, _c;
|
|
382
|
+
return [(_a2 = w == null ? void 0 : w.paraDetails) == null ? void 0 : _a2.name, (_b = w == null ? void 0 : w.paraDetails) == null ? void 0 : _b.id, (_c = w == null ? void 0 : w.paraDetails) == null ? void 0 : _c.internalId].includes(providerId);
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
return connector ? __spreadProps(__spreadValues({}, connector), { getUri: (_a = connector.paraDetails) == null ? void 0 : _a.getUri }) : void 0;
|
|
284
386
|
};
|
|
387
|
+
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
388
|
+
var _a, _b, _c, _d;
|
|
389
|
+
const connector = findConnector(providerId);
|
|
390
|
+
disconnectTypeRef.current = "ACCOUNT_LINKING";
|
|
391
|
+
try {
|
|
392
|
+
let address;
|
|
393
|
+
if (connector.connected && ((_a = connector.accounts) == null ? void 0 : _a[0])) {
|
|
394
|
+
address = connector.accounts[0];
|
|
395
|
+
} else {
|
|
396
|
+
address = yield connectBase(connector);
|
|
397
|
+
}
|
|
398
|
+
const providerId2 = (_c = (_b = wallets.find((w) => {
|
|
399
|
+
var _a2, _b2;
|
|
400
|
+
return (w == null ? void 0 : w.name) === ((_b2 = (_a2 = connector == null ? void 0 : connector.paraDetails) == null ? void 0 : _a2.name) != null ? _b2 : "");
|
|
401
|
+
})) == null ? void 0 : _b.name) != null ? _c : connector == null ? void 0 : connector.name;
|
|
402
|
+
return {
|
|
403
|
+
partnerId: para.partnerId,
|
|
404
|
+
address,
|
|
405
|
+
type: "EVM",
|
|
406
|
+
providerId: providerId2,
|
|
407
|
+
provider: providerId2,
|
|
408
|
+
ensName,
|
|
409
|
+
ensAvatar
|
|
410
|
+
};
|
|
411
|
+
} catch (e) {
|
|
412
|
+
throw new Error((_d = e == null ? void 0 : e.message) != null ? _d : e);
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
const disconnectBase = (_0, ..._1) => __async(this, [_0, ..._1], function* (providerId, { disconnectType } = {}) {
|
|
416
|
+
var _a;
|
|
417
|
+
if (!providerId) {
|
|
418
|
+
throw new Error("Provider ID is required to disconnect");
|
|
419
|
+
}
|
|
420
|
+
const connector = findConnector(providerId);
|
|
421
|
+
if (disconnectType) {
|
|
422
|
+
disconnectTypeRef.current = disconnectType;
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
yield connector == null ? void 0 : connector.disconnect();
|
|
426
|
+
} catch (e) {
|
|
427
|
+
throw new Error((_a = e == null ? void 0 : e.message) != null ? _a : e);
|
|
428
|
+
} finally {
|
|
429
|
+
disconnectTypeRef.current = void 0;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
285
432
|
const nonEip6963ConnectorsByRdns = {};
|
|
286
433
|
let walletConnectModalConnector;
|
|
287
434
|
connectors.filter((c) => !isEIP6963Connector(c)).forEach((c) => {
|
|
@@ -292,36 +439,58 @@ function EvmExternalWalletProvider({
|
|
|
292
439
|
}
|
|
293
440
|
}
|
|
294
441
|
});
|
|
295
|
-
const
|
|
442
|
+
const eip6963Names = connectors.filter((c) => isEIP6963Connector(c)).map((c) => c.name);
|
|
296
443
|
const dedupedConnectors = connectors.map((c) => {
|
|
297
|
-
var _a, _b
|
|
444
|
+
var _a, _b;
|
|
298
445
|
if ((_a = c.paraDetails) == null ? void 0 : _a.isWalletConnectModalConnector) {
|
|
299
446
|
return;
|
|
300
447
|
}
|
|
301
|
-
if (!isEIP6963Connector(c) &&
|
|
448
|
+
if (!isEIP6963Connector(c) && eip6963Names.includes(c.name)) {
|
|
302
449
|
return;
|
|
303
450
|
}
|
|
304
451
|
if (isEIP6963Connector(c)) {
|
|
305
452
|
const paraMetadata = nonEip6963ConnectorsByRdns[c.id];
|
|
306
453
|
return __spreadProps(__spreadValues({}, c), { paraDetails: paraMetadata });
|
|
307
454
|
}
|
|
308
|
-
if (((
|
|
455
|
+
if (((_b = c.paraDetails) == null ? void 0 : _b.internalId) === "WALLETCONNECT" && walletConnectModalConnector) {
|
|
309
456
|
return __spreadProps(__spreadValues({}, c), { walletConnectModalConnector });
|
|
310
457
|
}
|
|
311
458
|
return c;
|
|
312
459
|
}).filter((c) => !!c);
|
|
313
460
|
const wallets = dedupedConnectors.map((c) => {
|
|
461
|
+
var _a, _b, _c, _d, _e;
|
|
462
|
+
if (((_a = c.paraDetails) == null ? void 0 : _a.internalId) === "SAFE" && (typeof window === "undefined" || window.parent === window)) {
|
|
463
|
+
return void 0;
|
|
464
|
+
}
|
|
314
465
|
const connector = __spreadValues(__spreadValues({}, c), c.paraDetails);
|
|
466
|
+
const isInjected = !c.paraDetails && eip6963Names.includes(c.name);
|
|
467
|
+
if (isInjected && connectors.some((c2) => {
|
|
468
|
+
var _a2;
|
|
469
|
+
return ((_a2 = c2.paraDetails) == null ? void 0 : _a2.rdns) === c2.id;
|
|
470
|
+
})) {
|
|
471
|
+
return void 0;
|
|
472
|
+
}
|
|
315
473
|
return __spreadProps(__spreadValues({}, connector), {
|
|
474
|
+
// Using name here since that's the only common id across the networks
|
|
475
|
+
id: connector.name,
|
|
476
|
+
internalId: (_b = connector.internalId) != null ? _b : connector.name,
|
|
477
|
+
isExtension: (_c = connector.isExtension) != null ? _c : isInjected,
|
|
478
|
+
installed: (_d = connector.installed) != null ? _d : isInjected,
|
|
479
|
+
iconUrl: (_e = connector.iconUrl) != null ? _e : connector.icon,
|
|
316
480
|
connect: () => connect(connector),
|
|
317
|
-
connectMobile: (
|
|
318
|
-
type: "EVM"
|
|
319
|
-
getQrUri: getQrUri(connector)
|
|
481
|
+
connectMobile: (manual) => connectMobile(connector, manual),
|
|
482
|
+
type: "EVM"
|
|
320
483
|
});
|
|
321
|
-
});
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
484
|
+
}).filter(Boolean);
|
|
485
|
+
const getConnectorInfo = (connector) => {
|
|
486
|
+
const paraDetails = connector.paraDetails;
|
|
487
|
+
const withFullParaAuth = walletsWithFullAuth === "ALL" || (walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(paraDetails == null ? void 0 : paraDetails.internalId));
|
|
488
|
+
return {
|
|
489
|
+
type: "EVM",
|
|
490
|
+
providerId: connector.name,
|
|
491
|
+
provider: connector.name,
|
|
492
|
+
withFullParaAuth
|
|
493
|
+
};
|
|
325
494
|
};
|
|
326
495
|
const formattedChains = chains.map((c) => {
|
|
327
496
|
return {
|
|
@@ -330,6 +499,20 @@ function EvmExternalWalletProvider({
|
|
|
330
499
|
};
|
|
331
500
|
});
|
|
332
501
|
const username = useMemo(() => ensName != null ? ensName : wagmiAddress, [ensName, wagmiAddress]);
|
|
502
|
+
const farcasterStatus = useMemo(() => {
|
|
503
|
+
var _a;
|
|
504
|
+
const connection = connections.find(
|
|
505
|
+
(c) => {
|
|
506
|
+
var _a2;
|
|
507
|
+
return ((_a2 = c.connector.paraDetails) == null ? void 0 : _a2.internalId) === "FARCASTER";
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
if (!connection) {
|
|
511
|
+
return { isPresent: false };
|
|
512
|
+
}
|
|
513
|
+
const address = (_a = connection == null ? void 0 : connection.accounts) == null ? void 0 : _a[0];
|
|
514
|
+
return address ? { isPresent: true, isConnected: true, address } : { isPresent: true, isConnected: false };
|
|
515
|
+
}, [connections]);
|
|
333
516
|
const connectParaEmbedded = useCallback(() => __async(this, null, function* () {
|
|
334
517
|
const paraConnectorInstance = connectors.find((c) => c.id === "para");
|
|
335
518
|
if (!paraConnectorInstance) {
|
|
@@ -343,22 +526,33 @@ function EvmExternalWalletProvider({
|
|
|
343
526
|
return { error };
|
|
344
527
|
}
|
|
345
528
|
}), [connectors]);
|
|
529
|
+
useEffect(() => {
|
|
530
|
+
connectionsRef.current = connections;
|
|
531
|
+
}, [connections]);
|
|
532
|
+
useEffect(() => {
|
|
533
|
+
connectorsRef.current = connectors;
|
|
534
|
+
}, [connectors]);
|
|
346
535
|
return /* @__PURE__ */ jsx(
|
|
347
536
|
EvmExternalWalletContext.Provider,
|
|
348
537
|
{
|
|
349
|
-
value: {
|
|
538
|
+
value: __spreadValues({
|
|
350
539
|
wallets,
|
|
351
540
|
chains: formattedChains,
|
|
352
541
|
chainId,
|
|
353
542
|
username,
|
|
354
543
|
avatar: ensAvatar,
|
|
355
544
|
disconnect: disconnectAsync,
|
|
545
|
+
disconnectStatus,
|
|
356
546
|
switchChain,
|
|
357
547
|
connectParaEmbedded,
|
|
358
548
|
signMessage,
|
|
359
549
|
signVerificationMessage,
|
|
360
|
-
getWalletBalance
|
|
361
|
-
|
|
550
|
+
getWalletBalance,
|
|
551
|
+
requestInfo,
|
|
552
|
+
disconnectBase,
|
|
553
|
+
farcasterStatus,
|
|
554
|
+
verificationStage
|
|
555
|
+
}, externalHooks),
|
|
362
556
|
children
|
|
363
557
|
}
|
|
364
558
|
);
|
|
@@ -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
|
}
|