@getpara/evm-wallet-connectors 2.0.0-dev.3 → 2.0.0-dev.7

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.
@@ -4,7 +4,9 @@ import { TExternalHooks } from './externalHooks.js';
4
4
  export type EvmExternalWalletContextType = ExternalWalletContextType & ChainManagement<number> & BalanceManagement & ConnectParaEmbedded & TExternalHooks & {
5
5
  username?: string;
6
6
  avatar?: string;
7
- } & FarcasterMiniAppManagement;
7
+ } & FarcasterMiniAppManagement & {
8
+ verificationStage: 'verifying' | 'switchingChain';
9
+ };
8
10
  export declare const EvmExternalWalletContext: import("react").Context<EvmExternalWalletContextType>;
9
11
  export type EvmExternalWalletProviderConfig = ExternalWalletProviderConfigBase;
10
12
  export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, walletsWithFullAuth, connectedWallet, includeWalletVerification, connectionOnly, }: 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, 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,
@@ -28,7 +28,10 @@ import {
28
28
  import { isMobile } from "@getpara/web-sdk";
29
29
  import { etherUnits, formatUnits } from "viem";
30
30
  import { externalHooks } from "./externalHooks.js";
31
- const EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
31
+ const EvmExternalWalletContext = createContext(__spreadProps(__spreadValues({}, defaultEvmExternalWallet), {
32
+ farcasterStatus: void 0,
33
+ verificationStage: void 0
34
+ }));
32
35
  function EvmExternalWalletProvider({
33
36
  children,
34
37
  onSwitchWallet,
@@ -62,6 +65,7 @@ function EvmExternalWalletProvider({
62
65
  const connectors = untypedConnectors;
63
66
  const connectionsRef = useRef(connections);
64
67
  const connectorsRef = useRef(connectors);
68
+ const [verificationStage, setVerificationStage] = useState("verifying");
65
69
  const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
66
70
  const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
67
71
  const getStoredExternalWallets = () => {
@@ -75,14 +79,18 @@ function EvmExternalWalletProvider({
75
79
  const switchAccount = useCallback(
76
80
  (connectorName) => {
77
81
  var _a;
78
- const connector = (_a = connections.find((c) => c.connector.name === connectorName)) == null ? void 0 : _a.connector;
82
+ const connector = (_a = connectionsRef.current.find((c) => {
83
+ var _a2;
84
+ const paraDetails = (_a2 = c.connector) == null ? void 0 : _a2.paraDetails;
85
+ return [paraDetails == null ? void 0 : paraDetails.name, paraDetails == null ? void 0 : paraDetails.id, paraDetails == null ? void 0 : paraDetails.internalId].includes(connectorName);
86
+ })) == null ? void 0 : _a.connector;
79
87
  if (!connector) {
80
88
  console.warn(`connector not found: ${connectorName}`);
81
89
  return;
82
90
  }
83
91
  wagmiSwitchAccount({ connector });
84
92
  },
85
- [connections, wagmiSwitchAccount]
93
+ [wagmiSwitchAccount]
86
94
  );
87
95
  const findConnectorAndAccount = (externalWallet) => {
88
96
  var _a;
@@ -90,12 +98,10 @@ function EvmExternalWalletProvider({
90
98
  switch (true) {
91
99
  case !!externalWallet.providerId:
92
100
  {
93
- connector = (_a = connectionsRef.current.find(
94
- (c) => {
95
- var _a2;
96
- return ((_a2 = c.connector.paraDetails) == null ? void 0 : _a2.internalId) === externalWallet.providerId;
97
- }
98
- )) == null ? void 0 : _a.connector;
101
+ connector = (_a = connectionsRef.current.find((c) => {
102
+ var _a2;
103
+ return ((_a2 = c.connector) == null ? void 0 : _a2.name) === externalWallet.providerId;
104
+ })) == null ? void 0 : _a.connector;
99
105
  }
100
106
  break;
101
107
  }
@@ -122,29 +128,52 @@ function EvmExternalWalletProvider({
122
128
  }
123
129
  }, [isLocalConnecting, wagmiAddress, isConnected]);
124
130
  useEffect(() => {
125
- if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedConnector && connectedWallet.type === "EVM" && connectedConnector.name !== connectedWallet.name) {
131
+ var _a;
132
+ 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;
133
+ if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedConnector && connectedWallet.type === "EVM" && connectedConnectorName !== connectedWallet.name) {
126
134
  switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
127
135
  }
128
136
  }, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
129
137
  useEffect(() => {
130
- if (!isLocalConnecting && !isConnecting && !isReconnecting && !isConnected && !connectedConnector) {
131
- if (Object.values(para.wallets).length === 0) {
132
- return;
138
+ const connectPara = () => __async(this, null, function* () {
139
+ if (!isLocalConnecting && !isConnecting && !isReconnecting && !isConnected && !connectedConnector) {
140
+ if (Object.values(para.wallets).length === 0 || !(yield para.isFullyLoggedIn())) {
141
+ return;
142
+ }
143
+ connectParaEmbedded();
133
144
  }
134
- connectParaEmbedded();
135
- }
145
+ });
146
+ connectPara();
136
147
  }, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
137
148
  const reset = () => __async(this, null, function* () {
138
149
  yield disconnectAsync();
139
150
  yield para.logout();
140
151
  });
152
+ const getChainParams = (chainId2) => {
153
+ var _a;
154
+ const chain = chains.find((c) => c.id === chainId2);
155
+ if (!chain) return null;
156
+ return {
157
+ chainId: `0x${chainId2.toString(16)}`,
158
+ chainName: chain.name,
159
+ nativeCurrency: {
160
+ name: chain.nativeCurrency.name,
161
+ symbol: chain.nativeCurrency.symbol,
162
+ decimals: chain.nativeCurrency.decimals
163
+ },
164
+ rpcUrls: [chain.rpcUrls.default.http[0]],
165
+ blockExplorerUrls: ((_a = chain.blockExplorers) == null ? void 0 : _a.default) ? [chain.blockExplorers.default.url] : void 0
166
+ };
167
+ };
141
168
  const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
169
+ var _a, _b, _c, _d, _e, _f, _g, _h;
142
170
  let signOpts = {};
143
171
  if (externalWallet) {
144
172
  signOpts = findConnectorAndAccount(externalWallet);
173
+ yield switchAccount((_a = externalWallet.providerId) != null ? _a : "");
145
174
  }
175
+ const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
146
176
  try {
147
- const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
148
177
  const signature = yield signMessageAsync(__spreadValues({
149
178
  message,
150
179
  account: address
@@ -155,6 +184,29 @@ function EvmExternalWalletProvider({
155
184
  };
156
185
  } catch (e) {
157
186
  console.error("Error signing message:", e);
187
+ console.error("Error signing message:", e.message, e.details);
188
+ if (e.message.includes("Chain not configured") || e.details.includes("Chain not configured")) {
189
+ setVerificationStage("switchingChain");
190
+ const currentChainParams = getChainParams((_c = (_b = chains[0]) == null ? void 0 : _b.id) != null ? _c : chainId);
191
+ if (!currentChainParams) {
192
+ return {
193
+ error: `Chain ${chainId} not found in configuration`
194
+ };
195
+ }
196
+ try {
197
+ yield switchChainAsync({
198
+ addEthereumChainParameter: currentChainParams,
199
+ chainId: (_e = (_d = chains[0]) == null ? void 0 : _d.id) != null ? _e : chainId
200
+ });
201
+ setVerificationStage("verifying");
202
+ return yield signMessage({ message, externalWallet });
203
+ } catch (error) {
204
+ console.error("Error adding chain:", error);
205
+ return {
206
+ error: `Error adding chain. You may need to add ${currentChainParams == null ? void 0 : currentChainParams.chainName} support to ${(_h = (_g = (_f = connectedConnector == null ? void 0 : connectedConnector.paraDetails) == null ? void 0 : _f.name) != null ? _g : connectedConnector == null ? void 0 : connectedConnector.name) != null ? _h : "the wallet"} manually.`
207
+ };
208
+ }
209
+ }
158
210
  switch (e.name) {
159
211
  case "UserRejectedRequestError": {
160
212
  return { error: "Signature request rejected" };
@@ -166,6 +218,7 @@ function EvmExternalWalletProvider({
166
218
  }
167
219
  });
168
220
  const signVerificationMessage = () => __async(this, null, function* () {
221
+ setVerificationStage("verifying");
169
222
  const signature = yield signMessage({ message: verificationMessage.current });
170
223
  return signature;
171
224
  });
@@ -202,6 +255,7 @@ function EvmExternalWalletProvider({
202
255
  refetchEnsAvatar();
203
256
  return yield para.loginExternalWallet({
204
257
  externalWallet: {
258
+ partnerId: para.partnerId,
205
259
  address,
206
260
  type: "EVM",
207
261
  provider,
@@ -268,7 +322,7 @@ function EvmExternalWalletProvider({
268
322
  authState = yield login(__spreadValues({
269
323
  address
270
324
  }, loginInfo));
271
- verificationMessage.current = authState.stage === "verify" ? authState.signatureVerificationMessage : void 0;
325
+ verificationMessage.current = authState.signatureVerificationMessage;
272
326
  } catch (err) {
273
327
  address = void 0;
274
328
  error = err;
@@ -299,25 +353,35 @@ function EvmExternalWalletProvider({
299
353
  const _connector = connector.walletConnectModalConnector && _isMobile ? connector.walletConnectModalConnector : connector;
300
354
  return yield connect(_connector);
301
355
  });
356
+ const findConnector = (providerId) => {
357
+ return connectorsRef.current.find(
358
+ (w) => {
359
+ var _a, _b, _c;
360
+ return [(_a = w == null ? void 0 : w.paraDetails) == null ? void 0 : _a.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);
361
+ }
362
+ );
363
+ };
302
364
  const requestInfo = (providerId) => __async(this, null, function* () {
303
- var _a, _b;
304
- const connector = connectors.find((c) => {
305
- var _a2;
306
- return ((_a2 = c.paraDetails) == null ? void 0 : _a2.internalId) === providerId;
307
- });
308
- if (connector.isAuthorized) isLinkingAccount.current = true;
365
+ var _a, _b, _c;
366
+ const connector = findConnector(providerId);
367
+ isLinkingAccount.current = true;
309
368
  try {
310
369
  const address = yield connectBase(connector);
370
+ const providerId2 = (_b = (_a = wallets.find((w) => {
371
+ var _a2, _b2;
372
+ return (w == null ? void 0 : w.name) === ((_b2 = (_a2 = connector == null ? void 0 : connector.paraDetails) == null ? void 0 : _a2.name) != null ? _b2 : "");
373
+ })) == null ? void 0 : _a.name) != null ? _b : connector == null ? void 0 : connector.name;
311
374
  return {
375
+ partnerId: para.partnerId,
312
376
  address,
313
377
  type: "EVM",
314
- providerId: (_a = connector.paraDetails) == null ? void 0 : _a.internalId,
315
- provider: connector.name,
378
+ providerId: providerId2,
379
+ provider: providerId2,
316
380
  ensName,
317
381
  ensAvatar
318
382
  };
319
383
  } catch (e) {
320
- throw new Error((_b = e == null ? void 0 : e.message) != null ? _b : e);
384
+ throw new Error((_c = e == null ? void 0 : e.message) != null ? _c : e);
321
385
  }
322
386
  });
323
387
  const disconnectBase = (providerId) => __async(this, null, function* () {
@@ -325,13 +389,10 @@ function EvmExternalWalletProvider({
325
389
  if (!providerId) {
326
390
  throw new Error("Provider ID is required to disconnect");
327
391
  }
328
- const connector = connectors.find((c) => {
329
- var _a2;
330
- return ((_a2 = c.paraDetails) == null ? void 0 : _a2.internalId) === providerId;
331
- });
392
+ const connector = findConnector(providerId);
332
393
  isLinkingAccount.current = true;
333
394
  try {
334
- yield connector.disconnect();
395
+ yield connector == null ? void 0 : connector.disconnect();
335
396
  } catch (e) {
336
397
  throw new Error((_a = e == null ? void 0 : e.message) != null ? _a : e);
337
398
  }
@@ -346,32 +407,45 @@ function EvmExternalWalletProvider({
346
407
  }
347
408
  }
348
409
  });
349
- const eip6963ids = connectors.filter((c) => isEIP6963Connector(c)).map((c) => c.id);
410
+ const eip6963Names = connectors.filter((c) => isEIP6963Connector(c)).map((c) => c.name);
350
411
  const dedupedConnectors = connectors.map((c) => {
351
- var _a, _b, _c;
412
+ var _a, _b;
352
413
  if ((_a = c.paraDetails) == null ? void 0 : _a.isWalletConnectModalConnector) {
353
414
  return;
354
415
  }
355
- if (!isEIP6963Connector(c) && eip6963ids.includes((_b = c.paraDetails) == null ? void 0 : _b.rdns)) {
416
+ if (!isEIP6963Connector(c) && eip6963Names.includes(c.name)) {
356
417
  return;
357
418
  }
358
419
  if (isEIP6963Connector(c)) {
359
420
  const paraMetadata = nonEip6963ConnectorsByRdns[c.id];
360
421
  return __spreadProps(__spreadValues({}, c), { paraDetails: paraMetadata });
361
422
  }
362
- if (((_c = c.paraDetails) == null ? void 0 : _c.id) === "WALLETCONNECT" && walletConnectModalConnector) {
423
+ if (((_b = c.paraDetails) == null ? void 0 : _b.internalId) === "WALLETCONNECT" && walletConnectModalConnector) {
363
424
  return __spreadProps(__spreadValues({}, c), { walletConnectModalConnector });
364
425
  }
365
426
  return c;
366
427
  }).filter((c) => !!c);
367
428
  const wallets = dedupedConnectors.map((c) => {
368
- var _a, _b, _c;
429
+ var _a, _b, _c, _d, _e, _f, _g;
369
430
  if (((_a = c.paraDetails) == null ? void 0 : _a.internalId) === "SAFE" && (typeof window === "undefined" || window.parent === window)) {
370
431
  return void 0;
371
432
  }
372
433
  const connector = __spreadValues(__spreadValues({}, c), c.paraDetails);
373
434
  const supportsWalletConnect = connector.type === "walletConnect" || ((_b = connector.paraDetails) == null ? void 0 : _b.internalId) === "WALLETCONNECT" || ((_c = connector.paraDetails) == null ? void 0 : _c.showQrModal);
435
+ const isInjected = !c.paraDetails && eip6963Names.includes(c.name);
436
+ if (isInjected && connectors.some((c2) => {
437
+ var _a2;
438
+ return ((_a2 = c2.paraDetails) == null ? void 0 : _a2.rdns) === c2.id;
439
+ })) {
440
+ return void 0;
441
+ }
374
442
  return __spreadValues(__spreadProps(__spreadValues({}, connector), {
443
+ // Using name here since that's the only common id across the networks
444
+ id: connector.name,
445
+ internalId: (_d = connector.internalId) != null ? _d : connector.name,
446
+ isExtension: (_e = connector.isExtension) != null ? _e : isInjected,
447
+ installed: (_f = connector.installed) != null ? _f : isInjected,
448
+ iconUrl: (_g = connector.iconUrl) != null ? _g : connector.icon,
375
449
  connect: () => connect(connector),
376
450
  connectMobile: (manual) => connectMobile(connector, manual),
377
451
  type: "EVM"
@@ -379,12 +453,11 @@ function EvmExternalWalletProvider({
379
453
  }).filter(Boolean);
380
454
  const getConnectorInfo = (connector) => {
381
455
  const paraDetails = connector.paraDetails;
382
- const providerId = paraDetails == null ? void 0 : paraDetails.internalId;
383
- const withFullParaAuth = walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(providerId);
456
+ const withFullParaAuth = walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(paraDetails == null ? void 0 : paraDetails.internalId);
384
457
  return {
385
458
  type: "EVM",
386
- providerId,
387
- provider: paraDetails == null ? void 0 : paraDetails.name,
459
+ providerId: connector.name,
460
+ provider: connector.name,
388
461
  withFullParaAuth
389
462
  };
390
463
  };
@@ -404,10 +477,10 @@ function EvmExternalWalletProvider({
404
477
  }
405
478
  );
406
479
  if (!connection) {
407
- return void 0;
480
+ return { isPresent: false };
408
481
  }
409
482
  const address = (_a = connection == null ? void 0 : connection.accounts) == null ? void 0 : _a[0];
410
- return address ? { isConnected: true, address } : { isConnected: false };
483
+ return address ? { isPresent: true, isConnected: true, address } : { isPresent: true, isConnected: false };
411
484
  }, [connections]);
412
485
  const connectParaEmbedded = useCallback(() => __async(this, null, function* () {
413
486
  const paraConnectorInstance = connectors.find((c) => c.id === "para");
@@ -445,7 +518,8 @@ function EvmExternalWalletProvider({
445
518
  getWalletBalance,
446
519
  requestInfo,
447
520
  disconnectBase,
448
- farcasterStatus
521
+ farcasterStatus,
522
+ verificationStage
449
523
  }, externalHooks),
450
524
  children
451
525
  }
@@ -2,7 +2,7 @@
2
2
  import "../chunk-MMUBH76A.js";
3
3
  const isEIP6963Connector = (wallet) => {
4
4
  var _a;
5
- return !!(!wallet.isRainbowKitConnector && ((_a = wallet.icon) == null ? void 0 : _a.startsWith("data:image")) && wallet.uid && wallet.name);
5
+ return !!(!wallet.isRainbowKitConnector && ((_a = wallet.icon) == null ? void 0 : _a.trim().startsWith("data:image")) && wallet.uid && wallet.name);
6
6
  };
7
7
  export {
8
8
  isEIP6963Connector
@@ -13,7 +13,7 @@ const backpackWallet = ({ projectId, walletConnectParameters }) => {
13
13
  id: "backpack",
14
14
  internalId: "BACKPACK",
15
15
  name: "Backpack",
16
- rdns: "app.backpack.mobile",
16
+ rdns: "app.backpack",
17
17
  iconUrl: icon,
18
18
  installed: isBackpackInjected,
19
19
  isExtension: true,
@@ -13,7 +13,7 @@ const farcasterWallet = ({ para, createFarcasterConnector }) => {
13
13
  iconUrl: icon,
14
14
  installed: (para == null ? void 0 : para.isReady) && (para == null ? void 0 : para.isFarcasterMiniApp),
15
15
  isExtension: true,
16
- downloadUrl: "https://warpcast.xyz/",
16
+ downloadUrl: "https://farcaster.xyz/",
17
17
  createConnector: (walletDetails) => createConnector((config) => __spreadValues(__spreadValues({}, createFarcasterConnector()(config)), walletDetails))
18
18
  };
19
19
  };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@getpara/evm-wallet-connectors",
3
- "version": "2.0.0-dev.3",
3
+ "version": "2.0.0-dev.7",
4
4
  "dependencies": {
5
5
  "@coinbase/wallet-sdk": "4.3.0",
6
- "@getpara/wagmi-v2-connector": "2.0.0-dev.3",
7
- "@getpara/web-sdk": "2.0.0-dev.3",
6
+ "@getpara/wagmi-v2-connector": "2.0.0-dev.7",
7
+ "@getpara/web-sdk": "2.0.0-dev.7",
8
8
  "zustand": "^4.5.2",
9
9
  "zustand-sync-tabs": "^0.2.2"
10
10
  },
11
11
  "devDependencies": {
12
- "@getpara/react-common": "2.0.0-dev.3",
12
+ "@getpara/react-common": "2.0.0-dev.7",
13
13
  "@tanstack/react-query": "^5.74.0",
14
14
  "@types/react": "^18.0.31",
15
15
  "@types/react-dom": "^18.2.7",
@@ -25,7 +25,7 @@
25
25
  "dist",
26
26
  "package.json"
27
27
  ],
28
- "gitHead": "ffe34f7d8df2dd3c2327ca1f35bcc9764e0a68a2",
28
+ "gitHead": "225cd3693edaab4dac81df7285956d2616e5717f",
29
29
  "main": "dist/index.js",
30
30
  "peerDependencies": {
31
31
  "@farcaster/miniapp-wagmi-connector": "^1.0.0",