@getpara/evm-wallet-connectors 2.0.0-alpha.46 → 2.0.0-alpha.48

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,
@@ -29,7 +29,8 @@ import { isMobile } from "@getpara/web-sdk";
29
29
  import { etherUnits, formatUnits } from "viem";
30
30
  import { externalHooks } from "./externalHooks.js";
31
31
  const EvmExternalWalletContext = createContext(__spreadProps(__spreadValues({}, defaultEvmExternalWallet), {
32
- farcasterStatus: void 0
32
+ farcasterStatus: void 0,
33
+ verificationStage: void 0
33
34
  }));
34
35
  function EvmExternalWalletProvider({
35
36
  children,
@@ -64,6 +65,7 @@ function EvmExternalWalletProvider({
64
65
  const connectors = untypedConnectors;
65
66
  const connectionsRef = useRef(connections);
66
67
  const connectorsRef = useRef(connectors);
68
+ const [verificationStage, setVerificationStage] = useState("verifying");
67
69
  const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
68
70
  const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
69
71
  const getStoredExternalWallets = () => {
@@ -126,7 +128,9 @@ function EvmExternalWalletProvider({
126
128
  }
127
129
  }, [isLocalConnecting, wagmiAddress, isConnected]);
128
130
  useEffect(() => {
129
- 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) {
130
134
  switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
131
135
  }
132
136
  }, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
@@ -142,15 +146,31 @@ function EvmExternalWalletProvider({
142
146
  yield disconnectAsync();
143
147
  yield para.logout();
144
148
  });
145
- const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
149
+ const getChainParams = (chainId2) => {
146
150
  var _a;
151
+ const chain = chains.find((c) => c.id === chainId2);
152
+ if (!chain) return null;
153
+ return {
154
+ chainId: `0x${chainId2.toString(16)}`,
155
+ chainName: chain.name,
156
+ nativeCurrency: {
157
+ name: chain.nativeCurrency.name,
158
+ symbol: chain.nativeCurrency.symbol,
159
+ decimals: chain.nativeCurrency.decimals
160
+ },
161
+ rpcUrls: [chain.rpcUrls.default.http[0]],
162
+ blockExplorerUrls: ((_a = chain.blockExplorers) == null ? void 0 : _a.default) ? [chain.blockExplorers.default.url] : void 0
163
+ };
164
+ };
165
+ const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
166
+ var _a, _b, _c, _d, _e, _f, _g, _h;
147
167
  let signOpts = {};
148
168
  if (externalWallet) {
149
169
  signOpts = findConnectorAndAccount(externalWallet);
150
170
  yield switchAccount((_a = externalWallet.providerId) != null ? _a : "");
151
171
  }
172
+ const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
152
173
  try {
153
- const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
154
174
  const signature = yield signMessageAsync(__spreadValues({
155
175
  message,
156
176
  account: address
@@ -161,6 +181,29 @@ function EvmExternalWalletProvider({
161
181
  };
162
182
  } catch (e) {
163
183
  console.error("Error signing message:", e);
184
+ console.error("Error signing message:", e.message, e.details);
185
+ if (e.message.includes("Chain not configured") || e.details.includes("Chain not configured")) {
186
+ setVerificationStage("switchingChain");
187
+ const currentChainParams = getChainParams((_c = (_b = chains[0]) == null ? void 0 : _b.id) != null ? _c : chainId);
188
+ if (!currentChainParams) {
189
+ return {
190
+ error: `Chain ${chainId} not found in configuration`
191
+ };
192
+ }
193
+ try {
194
+ yield switchChainAsync({
195
+ addEthereumChainParameter: currentChainParams,
196
+ chainId: (_e = (_d = chains[0]) == null ? void 0 : _d.id) != null ? _e : chainId
197
+ });
198
+ setVerificationStage("verifying");
199
+ return yield signMessage({ message, externalWallet });
200
+ } catch (error) {
201
+ console.error("Error adding chain:", error);
202
+ return {
203
+ 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.`
204
+ };
205
+ }
206
+ }
164
207
  switch (e.name) {
165
208
  case "UserRejectedRequestError": {
166
209
  return { error: "Signature request rejected" };
@@ -172,6 +215,7 @@ function EvmExternalWalletProvider({
172
215
  }
173
216
  });
174
217
  const signVerificationMessage = () => __async(this, null, function* () {
218
+ setVerificationStage("verifying");
175
219
  const signature = yield signMessage({ message: verificationMessage.current });
176
220
  return signature;
177
221
  });
@@ -471,7 +515,8 @@ function EvmExternalWalletProvider({
471
515
  getWalletBalance,
472
516
  requestInfo,
473
517
  disconnectBase,
474
- farcasterStatus
518
+ farcasterStatus,
519
+ verificationStage
475
520
  }, externalHooks),
476
521
  children
477
522
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@getpara/evm-wallet-connectors",
3
- "version": "2.0.0-alpha.46",
3
+ "version": "2.0.0-alpha.48",
4
4
  "dependencies": {
5
5
  "@coinbase/wallet-sdk": "4.3.0",
6
- "@getpara/wagmi-v2-connector": "2.0.0-alpha.46",
7
- "@getpara/web-sdk": "2.0.0-alpha.46",
6
+ "@getpara/wagmi-v2-connector": "2.0.0-alpha.48",
7
+ "@getpara/web-sdk": "2.0.0-alpha.48",
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-alpha.46",
12
+ "@getpara/react-common": "2.0.0-alpha.48",
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": "29c553622c2e33503e5ff52d4c64725ffc15922a",
28
+ "gitHead": "bfb7086671a63d7360602908f3140c40959a43f6",
29
29
  "main": "dist/index.js",
30
30
  "peerDependencies": {
31
31
  "@farcaster/miniapp-wagmi-connector": "^1.0.0",