@getpara/evm-wallet-connectors 2.0.0-alpha.47 → 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 = () => {
@@ -144,15 +146,31 @@ function EvmExternalWalletProvider({
144
146
  yield disconnectAsync();
145
147
  yield para.logout();
146
148
  });
147
- const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
149
+ const getChainParams = (chainId2) => {
148
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;
149
167
  let signOpts = {};
150
168
  if (externalWallet) {
151
169
  signOpts = findConnectorAndAccount(externalWallet);
152
170
  yield switchAccount((_a = externalWallet.providerId) != null ? _a : "");
153
171
  }
172
+ const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
154
173
  try {
155
- const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
156
174
  const signature = yield signMessageAsync(__spreadValues({
157
175
  message,
158
176
  account: address
@@ -163,6 +181,29 @@ function EvmExternalWalletProvider({
163
181
  };
164
182
  } catch (e) {
165
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
+ }
166
207
  switch (e.name) {
167
208
  case "UserRejectedRequestError": {
168
209
  return { error: "Signature request rejected" };
@@ -174,6 +215,7 @@ function EvmExternalWalletProvider({
174
215
  }
175
216
  });
176
217
  const signVerificationMessage = () => __async(this, null, function* () {
218
+ setVerificationStage("verifying");
177
219
  const signature = yield signMessage({ message: verificationMessage.current });
178
220
  return signature;
179
221
  });
@@ -473,7 +515,8 @@ function EvmExternalWalletProvider({
473
515
  getWalletBalance,
474
516
  requestInfo,
475
517
  disconnectBase,
476
- farcasterStatus
518
+ farcasterStatus,
519
+ verificationStage
477
520
  }, externalHooks),
478
521
  children
479
522
  }
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@getpara/evm-wallet-connectors",
3
- "version": "2.0.0-alpha.47",
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.47",
7
- "@getpara/web-sdk": "2.0.0-alpha.47",
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.47",
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": "c26d1830f6e63b34f33b5c799795c8c7cb00bb5a",
28
+ "gitHead": "bfb7086671a63d7360602908f3140c40959a43f6",
29
29
  "main": "dist/index.js",
30
30
  "peerDependencies": {
31
31
  "@farcaster/miniapp-wagmi-connector": "^1.0.0",