@getpara/evm-wallet-connectors 2.0.0-alpha.6 → 2.0.0-alpha.61

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