@getpara/evm-wallet-connectors 2.0.0-dev.0 → 2.0.0-dev.1
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.js
CHANGED
|
@@ -53,7 +53,17 @@ var __async = (__this, __arguments, generator) => {
|
|
|
53
53
|
|
|
54
54
|
// src/providers/EvmExternalWalletContext.tsx
|
|
55
55
|
import { createContext, useCallback, useEffect, useMemo, useRef } from "react";
|
|
56
|
-
import {
|
|
56
|
+
import {
|
|
57
|
+
useAccount,
|
|
58
|
+
useSwitchChain,
|
|
59
|
+
useConnect,
|
|
60
|
+
useDisconnect,
|
|
61
|
+
useEnsName,
|
|
62
|
+
useEnsAvatar,
|
|
63
|
+
useSignMessage,
|
|
64
|
+
useSwitchAccount,
|
|
65
|
+
useConnections
|
|
66
|
+
} from "wagmi";
|
|
57
67
|
|
|
58
68
|
// src/utils/isEIP6963Connector.ts
|
|
59
69
|
var isEIP6963Connector = (wallet) => {
|
|
@@ -117,10 +127,21 @@ var EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
|
|
|
117
127
|
function EvmExternalWalletProvider({
|
|
118
128
|
children,
|
|
119
129
|
onSwitchWallet,
|
|
120
|
-
para
|
|
130
|
+
para,
|
|
131
|
+
walletsWithFullAuth,
|
|
132
|
+
connectedWallet
|
|
121
133
|
}) {
|
|
122
134
|
const { connectAsync, connectors: untypedConnectors } = useConnect();
|
|
123
|
-
const
|
|
135
|
+
const connections = useConnections();
|
|
136
|
+
const {
|
|
137
|
+
address: wagmiAddress,
|
|
138
|
+
isConnecting,
|
|
139
|
+
isReconnecting,
|
|
140
|
+
chainId,
|
|
141
|
+
connector: connectedConnector,
|
|
142
|
+
isConnected
|
|
143
|
+
} = useAccount();
|
|
144
|
+
const { switchAccount: wagmiSwitchAccount } = useSwitchAccount();
|
|
124
145
|
const { chains, switchChainAsync } = useSwitchChain();
|
|
125
146
|
const { disconnectAsync } = useDisconnect();
|
|
126
147
|
const { data: ensName } = useEnsName({ address: wagmiAddress });
|
|
@@ -137,18 +158,43 @@ function EvmExternalWalletProvider({
|
|
|
137
158
|
}
|
|
138
159
|
return storedExternalWallets;
|
|
139
160
|
};
|
|
161
|
+
const switchAccount = useCallback(
|
|
162
|
+
(connectorName) => {
|
|
163
|
+
var _a;
|
|
164
|
+
const connector = (_a = connections.find((c) => c.connector.name === connectorName)) == null ? void 0 : _a.connector;
|
|
165
|
+
if (!connector) {
|
|
166
|
+
console.warn(`connector not found: ${connectorName}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
wagmiSwitchAccount({ connector });
|
|
170
|
+
},
|
|
171
|
+
[connections, wagmiSwitchAccount]
|
|
172
|
+
);
|
|
140
173
|
useEffect(() => {
|
|
141
174
|
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
142
|
-
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet &&
|
|
175
|
+
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
143
176
|
reset();
|
|
144
177
|
}
|
|
145
178
|
}, [isConnecting, isReconnecting, isLocalConnecting, wagmiAddress, connectedConnector]);
|
|
146
179
|
useEffect(() => {
|
|
147
180
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
148
|
-
if (!isLocalConnecting && !isConnecting && !isReconnecting && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === WalletType.EVM && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress) {
|
|
181
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === WalletType.EVM && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
149
182
|
switchWallet(wagmiAddress);
|
|
150
183
|
}
|
|
151
184
|
}, [isLocalConnecting, wagmiAddress, isReconnecting, isConnecting]);
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedConnector && connectedWallet.type === WalletType.EVM && connectedConnector.name !== connectedWallet.name) {
|
|
187
|
+
switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
|
|
188
|
+
}
|
|
189
|
+
}, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && !isConnected && !connectedConnector) {
|
|
192
|
+
if (Object.values(para.wallets).length === 0) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
connectParaEmbedded();
|
|
196
|
+
}
|
|
197
|
+
}, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
|
|
152
198
|
const connectors = untypedConnectors;
|
|
153
199
|
const reset = () => __async(this, null, function* () {
|
|
154
200
|
yield disconnectAsync();
|
|
@@ -203,9 +249,19 @@ function EvmExternalWalletProvider({
|
|
|
203
249
|
}
|
|
204
250
|
return { error };
|
|
205
251
|
});
|
|
206
|
-
const login = (_0) => __async(this, [_0], function* ({
|
|
252
|
+
const login = (_0) => __async(this, [_0], function* ({
|
|
253
|
+
address,
|
|
254
|
+
walletId,
|
|
255
|
+
connectorName
|
|
256
|
+
}) {
|
|
257
|
+
var _a;
|
|
207
258
|
try {
|
|
208
|
-
return yield para.externalWalletLogin({
|
|
259
|
+
return yield para.externalWalletLogin({
|
|
260
|
+
address,
|
|
261
|
+
type: WalletType.EVM,
|
|
262
|
+
provider: connectorName,
|
|
263
|
+
withFullParaAuth: walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes((_a = walletId == null ? void 0 : walletId.toUpperCase()) != null ? _a : "")
|
|
264
|
+
});
|
|
209
265
|
} catch (err) {
|
|
210
266
|
yield disconnectAsync();
|
|
211
267
|
yield para.logout();
|
|
@@ -213,15 +269,24 @@ function EvmExternalWalletProvider({
|
|
|
213
269
|
}
|
|
214
270
|
});
|
|
215
271
|
const switchWallet = (address) => __async(this, null, function* () {
|
|
272
|
+
var _a;
|
|
216
273
|
updateExternalWalletState({ isConnecting: true });
|
|
217
274
|
let error;
|
|
218
275
|
if (!address) {
|
|
219
276
|
yield para.logout();
|
|
220
277
|
} else {
|
|
221
|
-
|
|
222
|
-
yield
|
|
223
|
-
}
|
|
224
|
-
|
|
278
|
+
if (para.isExternalWalletAuth) {
|
|
279
|
+
yield reset();
|
|
280
|
+
} else {
|
|
281
|
+
try {
|
|
282
|
+
yield login({
|
|
283
|
+
address,
|
|
284
|
+
connectorName: connectedConnector == null ? void 0 : connectedConnector.name,
|
|
285
|
+
walletId: (_a = getParaDetails(connectedConnector.id)) == null ? void 0 : _a.id
|
|
286
|
+
});
|
|
287
|
+
} catch (err) {
|
|
288
|
+
error = err;
|
|
289
|
+
}
|
|
225
290
|
}
|
|
226
291
|
}
|
|
227
292
|
onSwitchWallet == null ? void 0 : onSwitchWallet({ address, error });
|
|
@@ -248,7 +313,7 @@ function EvmExternalWalletProvider({
|
|
|
248
313
|
address = (_d = data.accounts) == null ? void 0 : _d[0];
|
|
249
314
|
if (address) {
|
|
250
315
|
try {
|
|
251
|
-
const loginResp = yield login({ address, connectorName: connector.name });
|
|
316
|
+
const loginResp = yield login({ address, connectorName: connector.name, walletId: connector.paraDetails.id });
|
|
252
317
|
userExists = loginResp.userExists;
|
|
253
318
|
isVerified = loginResp.isVerified;
|
|
254
319
|
verificationMessage.current = loginResp.signatureVerificationMessage;
|
|
@@ -322,6 +387,10 @@ function EvmExternalWalletProvider({
|
|
|
322
387
|
getQrUri: getQrUri(connector)
|
|
323
388
|
});
|
|
324
389
|
});
|
|
390
|
+
const getParaDetails = (id) => {
|
|
391
|
+
var _a;
|
|
392
|
+
return (_a = connectors.find((w) => w.id === id)) == null ? void 0 : _a.paraDetails;
|
|
393
|
+
};
|
|
325
394
|
const formattedChains = chains.map((c) => {
|
|
326
395
|
return {
|
|
327
396
|
id: c.id,
|
|
@@ -698,8 +767,14 @@ function isMetaMask(ethereum) {
|
|
|
698
767
|
return true;
|
|
699
768
|
}
|
|
700
769
|
var metaMaskWallet = ({ projectId, walletConnectParameters }) => {
|
|
701
|
-
var _a, _b, _c;
|
|
702
|
-
|
|
770
|
+
var _a, _b, _c, _d;
|
|
771
|
+
let metaMaskTarget = typeof window !== "undefined" ? (_c = (_b = (_a = window.ethereum) == null ? void 0 : _a.providers) == null ? void 0 : _b.find(isMetaMask)) != null ? _c : window.ethereum : void 0;
|
|
772
|
+
const metaMaskInjectedProvider = metaMaskTarget ? metaMaskTarget : getInjectedProvider({ flag: "isMetaMask" });
|
|
773
|
+
const isMetaMaskInjected = !!metaMaskInjectedProvider && metaMaskInjectedProvider.isMetaMask;
|
|
774
|
+
const providerMapTarget = (_d = metaMaskTarget == null ? void 0 : metaMaskTarget.providerMap) == null ? void 0 : _d.get("MetaMask");
|
|
775
|
+
if (providerMapTarget) {
|
|
776
|
+
metaMaskTarget = providerMapTarget;
|
|
777
|
+
}
|
|
703
778
|
const getUri = (uri) => {
|
|
704
779
|
return isAndroid() ? `metamask://wc?uri=${encodeURIComponent(uri)}` : isIOS() ? !isTelegram() ? (
|
|
705
780
|
// currently broken in MetaMask v6.5.0 https://github.com/MetaMask/metamask-mobile/issues/6457
|
|
@@ -717,7 +792,7 @@ var metaMaskWallet = ({ projectId, walletConnectParameters }) => {
|
|
|
717
792
|
downloadUrl: "https://metamask.io/download/",
|
|
718
793
|
getUri,
|
|
719
794
|
createConnector: isMetaMaskInjected ? getInjectedConnector({
|
|
720
|
-
target:
|
|
795
|
+
target: metaMaskTarget
|
|
721
796
|
}) : getWalletConnectConnector({
|
|
722
797
|
projectId,
|
|
723
798
|
walletConnectParameters
|
package/dist/index.js.br
CHANGED
|
Binary file
|
package/dist/index.js.gz
CHANGED
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
import type { CommonChain, CommonWallet } from '@getpara/react-common';
|
|
3
|
-
import ParaWeb from '@getpara/web-sdk';
|
|
2
|
+
import type { CommonChain, CommonWallet, TExternalWallet } from '@getpara/react-common';
|
|
3
|
+
import ParaWeb, { Wallet } from '@getpara/web-sdk';
|
|
4
4
|
export type EvmExternalWalletContextType = {
|
|
5
5
|
wallets: CommonWallet[];
|
|
6
6
|
chains: CommonChain[];
|
|
@@ -32,5 +32,7 @@ export type EvmExternalWalletProviderConfig = {
|
|
|
32
32
|
error?: string;
|
|
33
33
|
}) => void;
|
|
34
34
|
para: ParaWeb;
|
|
35
|
+
walletsWithFullAuth: TExternalWallet[];
|
|
36
|
+
connectedWallet?: Omit<Wallet, 'signer'> | null;
|
|
35
37
|
};
|
|
36
|
-
export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, walletsWithFullAuth, connectedWallet, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,6 +4,10 @@ export declare function hasInjectedProvider({ flag, namespace }: {
|
|
|
4
4
|
flag?: WalletProviderFlags;
|
|
5
5
|
namespace?: string;
|
|
6
6
|
}): boolean;
|
|
7
|
+
export declare function getInjectedProvider({ flag, namespace }: {
|
|
8
|
+
flag?: WalletProviderFlags;
|
|
9
|
+
namespace?: string;
|
|
10
|
+
}): any;
|
|
7
11
|
export declare function getInjectedConnector({ flag, namespace, target, }: {
|
|
8
12
|
flag?: WalletProviderFlags;
|
|
9
13
|
namespace?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/evm-wallet-connectors",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.1",
|
|
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-dev.
|
|
14
|
-
"@getpara/web-sdk": "^2.0.0-dev.
|
|
13
|
+
"@getpara/wagmi-v2-connector": "2.0.0-dev.1",
|
|
14
|
+
"@getpara/web-sdk": "^2.0.0-dev.1",
|
|
15
15
|
"viem": "2.x",
|
|
16
16
|
"wagmi": "2.x",
|
|
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-dev.
|
|
26
|
+
"@getpara/react-common": "^2.0.0-dev.1",
|
|
27
27
|
"@types/react": "^18.0.31",
|
|
28
28
|
"@types/react-dom": "^18.2.7",
|
|
29
29
|
"typescript": "^5.4.3"
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"dist",
|
|
37
37
|
"package.json"
|
|
38
38
|
],
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "426e843bd6084fb2e5f30ab87b02c79fc2f52832"
|
|
40
40
|
}
|