@getpara/evm-wallet-connectors 2.0.0-alpha.5 → 2.0.0-alpha.50
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.d.ts +4 -2
- package/dist/index.js +5 -1
- package/dist/providers/EvmExternalWalletContext.d.ts +7 -35
- package/dist/providers/EvmExternalWalletContext.js +238 -79
- package/dist/providers/ParaEvmContext.d.ts +2 -1
- package/dist/providers/ParaEvmContext.js +49 -7
- package/dist/providers/createParaWagmiConfig.d.ts +10 -0
- package/dist/providers/createParaWagmiConfig.js +65 -0
- package/dist/providers/externalHooks.d.ts +7 -0
- package/dist/providers/externalHooks.js +7 -0
- package/dist/stores/wagmiConfigStore.d.ts +14 -0
- package/dist/stores/wagmiConfigStore.js +16 -0
- package/dist/types/Wallet.d.ts +3 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/utils/getWalletConnectUri.js +14 -11
- package/dist/utils/isEIP6963Connector.js +1 -1
- package/dist/utils/resolveWalletList.d.ts +3 -0
- package/dist/utils/resolveWalletList.js +16 -0
- package/dist/wallets/connectors/backpack/backpack.d.ts +3 -0
- package/dist/wallets/connectors/backpack/backpack.js +31 -0
- package/dist/wallets/connectors/backpack/backpackIcon.d.ts +1 -0
- package/dist/wallets/connectors/backpack/backpackIcon.js +6 -0
- package/dist/wallets/connectors/coinbase/coinbase.js +1 -0
- package/dist/wallets/connectors/farcaster/farcaster.d.ts +2 -0
- package/dist/wallets/connectors/farcaster/farcaster.js +22 -0
- package/dist/wallets/connectors/farcaster/farcasterIcon.d.ts +1 -0
- package/dist/wallets/connectors/farcaster/farcasterIcon.js +6 -0
- package/dist/wallets/connectors/haha/haha.d.ts +3 -0
- package/dist/wallets/connectors/haha/haha.js +31 -0
- package/dist/wallets/connectors/haha/hahaIcon.d.ts +1 -0
- package/dist/wallets/connectors/haha/hahaIcon.js +6 -0
- package/dist/wallets/connectors/index.d.ts +7 -1
- package/dist/wallets/connectors/index.js +18 -1
- package/dist/wallets/connectors/metaMask/metaMask.js +1 -0
- package/dist/wallets/connectors/metaMask/metaMaskIcon.d.ts +1 -1
- package/dist/wallets/connectors/metaMask/metaMaskIcon.js +1 -1
- package/dist/wallets/connectors/okx/okx.d.ts +3 -0
- package/dist/wallets/connectors/okx/okx.js +32 -0
- package/dist/wallets/connectors/okx/okxIcon.d.ts +1 -0
- package/dist/wallets/connectors/okx/okxIcon.js +6 -0
- package/dist/wallets/connectors/phantom/phantom.d.ts +3 -0
- package/dist/wallets/connectors/phantom/phantom.js +31 -0
- package/dist/wallets/connectors/phantom/phantomIcon.d.ts +1 -0
- package/dist/wallets/connectors/phantom/phantomIcon.js +6 -0
- package/dist/wallets/connectors/rabby/rabby.js +1 -0
- package/dist/wallets/connectors/rainbow/rainbow.js +1 -0
- package/dist/wallets/connectors/safe/safe.js +1 -0
- package/dist/wallets/connectors/valora/valora.d.ts +3 -0
- package/dist/wallets/connectors/valora/valora.js +29 -0
- package/dist/wallets/connectors/valora/valoraIcon.d.ts +1 -0
- package/dist/wallets/connectors/valora/valoraIcon.js +6 -0
- package/dist/wallets/connectors/walletConnect/walletConnect.js +1 -0
- package/dist/wallets/connectors/zerion/zerion.js +1 -0
- package/dist/wallets/connectorsForWallets.d.ts +4 -1
- package/dist/wallets/connectorsForWallets.js +14 -3
- 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
|
|
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
|
|
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
|
|
3
|
-
import
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
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, 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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,
|
|
41
|
+
includeWalletVerification,
|
|
42
|
+
connectionOnly
|
|
48
43
|
}) {
|
|
49
44
|
const { connectAsync, connectors: untypedConnectors } = useConnect();
|
|
50
45
|
const connections = useConnections();
|
|
@@ -64,8 +59,13 @@ function EvmExternalWalletProvider({
|
|
|
64
59
|
name: normalize(ensName)
|
|
65
60
|
});
|
|
66
61
|
const { signMessageAsync } = useSignMessage();
|
|
62
|
+
const isLinkingAccount = useRef(false);
|
|
67
63
|
const verificationMessage = useRef();
|
|
68
64
|
const { refetch: getBalance } = useBalance({ address: wagmiAddress });
|
|
65
|
+
const connectors = untypedConnectors;
|
|
66
|
+
const connectionsRef = useRef(connections);
|
|
67
|
+
const connectorsRef = useRef(connectors);
|
|
68
|
+
const [verificationStage, setVerificationStage] = useState("verifying");
|
|
69
69
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
70
70
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
71
71
|
const getStoredExternalWallets = () => {
|
|
@@ -79,15 +79,34 @@ function EvmExternalWalletProvider({
|
|
|
79
79
|
const switchAccount = useCallback(
|
|
80
80
|
(connectorName) => {
|
|
81
81
|
var _a;
|
|
82
|
-
const connector = (_a =
|
|
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;
|
|
83
87
|
if (!connector) {
|
|
84
88
|
console.warn(`connector not found: ${connectorName}`);
|
|
85
89
|
return;
|
|
86
90
|
}
|
|
87
91
|
wagmiSwitchAccount({ connector });
|
|
88
92
|
},
|
|
89
|
-
[
|
|
93
|
+
[wagmiSwitchAccount]
|
|
90
94
|
);
|
|
95
|
+
const findConnectorAndAccount = (externalWallet) => {
|
|
96
|
+
var _a;
|
|
97
|
+
let connector;
|
|
98
|
+
switch (true) {
|
|
99
|
+
case !!externalWallet.providerId:
|
|
100
|
+
{
|
|
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;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return { connector, account: externalWallet.address };
|
|
109
|
+
};
|
|
91
110
|
const getWalletBalance = useCallback(
|
|
92
111
|
// Format from wei to eth
|
|
93
112
|
() => __async(this, null, function* () {
|
|
@@ -98,18 +117,20 @@ function EvmExternalWalletProvider({
|
|
|
98
117
|
);
|
|
99
118
|
useEffect(() => {
|
|
100
119
|
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
101
|
-
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para") {
|
|
120
|
+
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para" && !isLinkingAccount.current && para.isReady && !para.isFarcasterMiniApp) {
|
|
102
121
|
reset();
|
|
103
122
|
}
|
|
104
|
-
}, [
|
|
123
|
+
}, [isConnected, isLocalConnecting, wagmiAddress, connectedConnector, para.isReady, para.isFarcasterMiniApp]);
|
|
105
124
|
useEffect(() => {
|
|
106
125
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
107
|
-
if (!isLocalConnecting &&
|
|
126
|
+
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
127
|
switchWallet(wagmiAddress);
|
|
109
128
|
}
|
|
110
|
-
}, [isLocalConnecting, wagmiAddress,
|
|
129
|
+
}, [isLocalConnecting, wagmiAddress, isConnected]);
|
|
111
130
|
useEffect(() => {
|
|
112
|
-
|
|
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) {
|
|
113
134
|
switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
|
|
114
135
|
}
|
|
115
136
|
}, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
|
|
@@ -121,22 +142,68 @@ function EvmExternalWalletProvider({
|
|
|
121
142
|
connectParaEmbedded();
|
|
122
143
|
}
|
|
123
144
|
}, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
|
|
124
|
-
const connectors = untypedConnectors;
|
|
125
145
|
const reset = () => __async(this, null, function* () {
|
|
126
146
|
yield disconnectAsync();
|
|
127
147
|
yield para.logout();
|
|
128
148
|
});
|
|
129
|
-
const
|
|
149
|
+
const getChainParams = (chainId2) => {
|
|
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;
|
|
167
|
+
let signOpts = {};
|
|
168
|
+
if (externalWallet) {
|
|
169
|
+
signOpts = findConnectorAndAccount(externalWallet);
|
|
170
|
+
yield switchAccount((_a = externalWallet.providerId) != null ? _a : "");
|
|
171
|
+
}
|
|
172
|
+
const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
|
|
130
173
|
try {
|
|
131
|
-
const signature = yield signMessageAsync({
|
|
174
|
+
const signature = yield signMessageAsync(__spreadValues({
|
|
132
175
|
message,
|
|
133
|
-
account:
|
|
134
|
-
});
|
|
176
|
+
account: address
|
|
177
|
+
}, signOpts));
|
|
135
178
|
return {
|
|
136
|
-
address
|
|
179
|
+
address,
|
|
137
180
|
signature
|
|
138
181
|
};
|
|
139
182
|
} catch (e) {
|
|
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
|
+
}
|
|
140
207
|
switch (e.name) {
|
|
141
208
|
case "UserRejectedRequestError": {
|
|
142
209
|
return { error: "Signature request rejected" };
|
|
@@ -148,7 +215,8 @@ function EvmExternalWalletProvider({
|
|
|
148
215
|
}
|
|
149
216
|
});
|
|
150
217
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
151
|
-
|
|
218
|
+
setVerificationStage("verifying");
|
|
219
|
+
const signature = yield signMessage({ message: verificationMessage.current });
|
|
152
220
|
return signature;
|
|
153
221
|
});
|
|
154
222
|
const switchChain = (chainId2) => __async(this, null, function* () {
|
|
@@ -178,23 +246,22 @@ function EvmExternalWalletProvider({
|
|
|
178
246
|
}
|
|
179
247
|
return { error };
|
|
180
248
|
});
|
|
181
|
-
const login = (_0) => __async(this, [_0], function* ({
|
|
182
|
-
address,
|
|
183
|
-
walletId,
|
|
184
|
-
connectorName
|
|
185
|
-
}) {
|
|
186
|
-
var _a;
|
|
249
|
+
const login = (_0) => __async(this, [_0], function* ({ address, withFullParaAuth = false, providerId, provider }) {
|
|
187
250
|
try {
|
|
188
251
|
refetchEnsName();
|
|
189
252
|
refetchEnsAvatar();
|
|
190
253
|
return yield para.loginExternalWallet({
|
|
191
254
|
externalWallet: {
|
|
255
|
+
partnerId: para.partnerId,
|
|
192
256
|
address,
|
|
193
257
|
type: "EVM",
|
|
194
|
-
provider
|
|
195
|
-
|
|
258
|
+
provider,
|
|
259
|
+
providerId,
|
|
260
|
+
withFullParaAuth,
|
|
196
261
|
ensName,
|
|
197
|
-
ensAvatar
|
|
262
|
+
ensAvatar,
|
|
263
|
+
isConnectionOnly: connectionOnly,
|
|
264
|
+
withVerification: includeWalletVerification
|
|
198
265
|
}
|
|
199
266
|
});
|
|
200
267
|
} catch (err) {
|
|
@@ -204,21 +271,19 @@ function EvmExternalWalletProvider({
|
|
|
204
271
|
}
|
|
205
272
|
});
|
|
206
273
|
const switchWallet = (address) => __async(this, null, function* () {
|
|
207
|
-
var _a;
|
|
208
274
|
updateExternalWalletState({ isConnecting: true });
|
|
209
275
|
let error;
|
|
210
276
|
if (!address) {
|
|
211
277
|
yield para.logout();
|
|
212
278
|
} else {
|
|
213
|
-
if (para.isExternalWalletAuth) {
|
|
279
|
+
if (para.isExternalWalletAuth || para.isExternalWalletWithVerification) {
|
|
214
280
|
yield reset();
|
|
215
281
|
} else {
|
|
216
282
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
283
|
+
const loginInfo = getConnectorInfo(connectedConnector);
|
|
284
|
+
yield login(__spreadValues({
|
|
285
|
+
address
|
|
286
|
+
}, loginInfo));
|
|
222
287
|
} catch (err) {
|
|
223
288
|
error = err;
|
|
224
289
|
}
|
|
@@ -227,28 +292,34 @@ function EvmExternalWalletProvider({
|
|
|
227
292
|
onSwitchWallet == null ? void 0 : onSwitchWallet({ address, error });
|
|
228
293
|
updateExternalWalletState({ isConnecting: false });
|
|
229
294
|
});
|
|
230
|
-
const
|
|
295
|
+
const connectBase = (connector) => __async(this, null, function* () {
|
|
231
296
|
var _a, _b, _c, _d;
|
|
297
|
+
const walletChainId = yield connector.getChainId();
|
|
298
|
+
const data = yield connectAsync({
|
|
299
|
+
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
300
|
+
chainId: (_c = (_a = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _a.id) != null ? _c : (
|
|
301
|
+
// Fall back to the first chain provided.
|
|
302
|
+
(_b = chains[0]) == null ? void 0 : _b.id
|
|
303
|
+
),
|
|
304
|
+
connector
|
|
305
|
+
});
|
|
306
|
+
return (_d = data.accounts) == null ? void 0 : _d[0];
|
|
307
|
+
});
|
|
308
|
+
const connect = (connector) => __async(this, null, function* () {
|
|
232
309
|
updateExternalWalletState({ isConnecting: true });
|
|
233
310
|
yield disconnectAsync();
|
|
234
|
-
const walletChainId = yield connector.getChainId();
|
|
235
311
|
let authState;
|
|
236
312
|
let address;
|
|
237
313
|
let error;
|
|
238
314
|
try {
|
|
239
|
-
|
|
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];
|
|
315
|
+
address = yield connectBase(connector);
|
|
248
316
|
if (address) {
|
|
249
317
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
318
|
+
const loginInfo = getConnectorInfo(connector);
|
|
319
|
+
authState = yield login(__spreadValues({
|
|
320
|
+
address
|
|
321
|
+
}, loginInfo));
|
|
322
|
+
verificationMessage.current = authState.signatureVerificationMessage;
|
|
252
323
|
} catch (err) {
|
|
253
324
|
address = void 0;
|
|
254
325
|
error = err;
|
|
@@ -261,10 +332,11 @@ function EvmExternalWalletProvider({
|
|
|
261
332
|
break;
|
|
262
333
|
}
|
|
263
334
|
case "ResourceUnavailableRpcError": {
|
|
264
|
-
`${connector.name} not detected`;
|
|
335
|
+
error = `${connector.name} not detected`;
|
|
265
336
|
break;
|
|
266
337
|
}
|
|
267
338
|
default: {
|
|
339
|
+
console.error("Wagmi connection error:", e.message);
|
|
268
340
|
error = "An unknown error occurred";
|
|
269
341
|
break;
|
|
270
342
|
}
|
|
@@ -278,10 +350,50 @@ function EvmExternalWalletProvider({
|
|
|
278
350
|
const _connector = connector.walletConnectModalConnector && _isMobile ? connector.walletConnectModalConnector : connector;
|
|
279
351
|
return yield connect(_connector);
|
|
280
352
|
});
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
353
|
+
const findConnector = (providerId) => {
|
|
354
|
+
return connectorsRef.current.find(
|
|
355
|
+
(w) => {
|
|
356
|
+
var _a, _b, _c;
|
|
357
|
+
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);
|
|
358
|
+
}
|
|
359
|
+
);
|
|
284
360
|
};
|
|
361
|
+
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
362
|
+
var _a, _b, _c;
|
|
363
|
+
const connector = findConnector(providerId);
|
|
364
|
+
isLinkingAccount.current = true;
|
|
365
|
+
try {
|
|
366
|
+
const address = yield connectBase(connector);
|
|
367
|
+
const providerId2 = (_b = (_a = wallets.find((w) => {
|
|
368
|
+
var _a2, _b2;
|
|
369
|
+
return (w == null ? void 0 : w.name) === ((_b2 = (_a2 = connector == null ? void 0 : connector.paraDetails) == null ? void 0 : _a2.name) != null ? _b2 : "");
|
|
370
|
+
})) == null ? void 0 : _a.name) != null ? _b : connector == null ? void 0 : connector.name;
|
|
371
|
+
return {
|
|
372
|
+
partnerId: para.partnerId,
|
|
373
|
+
address,
|
|
374
|
+
type: "EVM",
|
|
375
|
+
providerId: providerId2,
|
|
376
|
+
provider: providerId2,
|
|
377
|
+
ensName,
|
|
378
|
+
ensAvatar
|
|
379
|
+
};
|
|
380
|
+
} catch (e) {
|
|
381
|
+
throw new Error((_c = e == null ? void 0 : e.message) != null ? _c : e);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
const disconnectBase = (providerId) => __async(this, null, function* () {
|
|
385
|
+
var _a;
|
|
386
|
+
if (!providerId) {
|
|
387
|
+
throw new Error("Provider ID is required to disconnect");
|
|
388
|
+
}
|
|
389
|
+
const connector = findConnector(providerId);
|
|
390
|
+
isLinkingAccount.current = true;
|
|
391
|
+
try {
|
|
392
|
+
yield connector == null ? void 0 : connector.disconnect();
|
|
393
|
+
} catch (e) {
|
|
394
|
+
throw new Error((_a = e == null ? void 0 : e.message) != null ? _a : e);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
285
397
|
const nonEip6963ConnectorsByRdns = {};
|
|
286
398
|
let walletConnectModalConnector;
|
|
287
399
|
connectors.filter((c) => !isEIP6963Connector(c)).forEach((c) => {
|
|
@@ -292,36 +404,59 @@ function EvmExternalWalletProvider({
|
|
|
292
404
|
}
|
|
293
405
|
}
|
|
294
406
|
});
|
|
295
|
-
const
|
|
407
|
+
const eip6963Names = connectors.filter((c) => isEIP6963Connector(c)).map((c) => c.name);
|
|
296
408
|
const dedupedConnectors = connectors.map((c) => {
|
|
297
|
-
var _a, _b
|
|
409
|
+
var _a, _b;
|
|
298
410
|
if ((_a = c.paraDetails) == null ? void 0 : _a.isWalletConnectModalConnector) {
|
|
299
411
|
return;
|
|
300
412
|
}
|
|
301
|
-
if (!isEIP6963Connector(c) &&
|
|
413
|
+
if (!isEIP6963Connector(c) && eip6963Names.includes(c.name)) {
|
|
302
414
|
return;
|
|
303
415
|
}
|
|
304
416
|
if (isEIP6963Connector(c)) {
|
|
305
417
|
const paraMetadata = nonEip6963ConnectorsByRdns[c.id];
|
|
306
418
|
return __spreadProps(__spreadValues({}, c), { paraDetails: paraMetadata });
|
|
307
419
|
}
|
|
308
|
-
if (((
|
|
420
|
+
if (((_b = c.paraDetails) == null ? void 0 : _b.internalId) === "WALLETCONNECT" && walletConnectModalConnector) {
|
|
309
421
|
return __spreadProps(__spreadValues({}, c), { walletConnectModalConnector });
|
|
310
422
|
}
|
|
311
423
|
return c;
|
|
312
424
|
}).filter((c) => !!c);
|
|
313
425
|
const wallets = dedupedConnectors.map((c) => {
|
|
426
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
427
|
+
if (((_a = c.paraDetails) == null ? void 0 : _a.internalId) === "SAFE" && (typeof window === "undefined" || window.parent === window)) {
|
|
428
|
+
return void 0;
|
|
429
|
+
}
|
|
314
430
|
const connector = __spreadValues(__spreadValues({}, c), c.paraDetails);
|
|
315
|
-
|
|
431
|
+
const supportsWalletConnect = connector.type === "walletConnect" || ((_b = connector.paraDetails) == null ? void 0 : _b.internalId) === "WALLETCONNECT" || ((_c = connector.paraDetails) == null ? void 0 : _c.showQrModal);
|
|
432
|
+
const isInjected = !c.paraDetails && eip6963Names.includes(c.name);
|
|
433
|
+
if (isInjected && connectors.some((c2) => {
|
|
434
|
+
var _a2;
|
|
435
|
+
return ((_a2 = c2.paraDetails) == null ? void 0 : _a2.rdns) === c2.id;
|
|
436
|
+
})) {
|
|
437
|
+
return void 0;
|
|
438
|
+
}
|
|
439
|
+
return __spreadValues(__spreadProps(__spreadValues({}, connector), {
|
|
440
|
+
// Using name here since that's the only common id across the networks
|
|
441
|
+
id: connector.name,
|
|
442
|
+
internalId: (_d = connector.internalId) != null ? _d : connector.name,
|
|
443
|
+
isExtension: (_e = connector.isExtension) != null ? _e : isInjected,
|
|
444
|
+
installed: (_f = connector.installed) != null ? _f : isInjected,
|
|
445
|
+
iconUrl: (_g = connector.iconUrl) != null ? _g : connector.icon,
|
|
316
446
|
connect: () => connect(connector),
|
|
317
|
-
connectMobile: (
|
|
447
|
+
connectMobile: (manual) => connectMobile(connector, manual),
|
|
448
|
+
type: "EVM"
|
|
449
|
+
}), supportsWalletConnect && { getQrUri: () => getWalletConnectUri(connector, connector.getUri) });
|
|
450
|
+
}).filter(Boolean);
|
|
451
|
+
const getConnectorInfo = (connector) => {
|
|
452
|
+
const paraDetails = connector.paraDetails;
|
|
453
|
+
const withFullParaAuth = walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(paraDetails == null ? void 0 : paraDetails.internalId);
|
|
454
|
+
return {
|
|
318
455
|
type: "EVM",
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
var _a;
|
|
324
|
-
return (_a = connectors.find((w) => w.id === id)) == null ? void 0 : _a.paraDetails;
|
|
456
|
+
providerId: connector.name,
|
|
457
|
+
provider: connector.name,
|
|
458
|
+
withFullParaAuth
|
|
459
|
+
};
|
|
325
460
|
};
|
|
326
461
|
const formattedChains = chains.map((c) => {
|
|
327
462
|
return {
|
|
@@ -330,6 +465,20 @@ function EvmExternalWalletProvider({
|
|
|
330
465
|
};
|
|
331
466
|
});
|
|
332
467
|
const username = useMemo(() => ensName != null ? ensName : wagmiAddress, [ensName, wagmiAddress]);
|
|
468
|
+
const farcasterStatus = useMemo(() => {
|
|
469
|
+
var _a;
|
|
470
|
+
const connection = connections.find(
|
|
471
|
+
(c) => {
|
|
472
|
+
var _a2;
|
|
473
|
+
return ((_a2 = c.connector.paraDetails) == null ? void 0 : _a2.internalId) === "FARCASTER";
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
if (!connection) {
|
|
477
|
+
return { isPresent: false };
|
|
478
|
+
}
|
|
479
|
+
const address = (_a = connection == null ? void 0 : connection.accounts) == null ? void 0 : _a[0];
|
|
480
|
+
return address ? { isPresent: true, isConnected: true, address } : { isPresent: true, isConnected: false };
|
|
481
|
+
}, [connections]);
|
|
333
482
|
const connectParaEmbedded = useCallback(() => __async(this, null, function* () {
|
|
334
483
|
const paraConnectorInstance = connectors.find((c) => c.id === "para");
|
|
335
484
|
if (!paraConnectorInstance) {
|
|
@@ -343,10 +492,16 @@ function EvmExternalWalletProvider({
|
|
|
343
492
|
return { error };
|
|
344
493
|
}
|
|
345
494
|
}), [connectors]);
|
|
495
|
+
useEffect(() => {
|
|
496
|
+
connectionsRef.current = connections;
|
|
497
|
+
}, [connections]);
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
connectorsRef.current = connectors;
|
|
500
|
+
}, [connectors]);
|
|
346
501
|
return /* @__PURE__ */ jsx(
|
|
347
502
|
EvmExternalWalletContext.Provider,
|
|
348
503
|
{
|
|
349
|
-
value: {
|
|
504
|
+
value: __spreadValues({
|
|
350
505
|
wallets,
|
|
351
506
|
chains: formattedChains,
|
|
352
507
|
chainId,
|
|
@@ -357,8 +512,12 @@ function EvmExternalWalletProvider({
|
|
|
357
512
|
connectParaEmbedded,
|
|
358
513
|
signMessage,
|
|
359
514
|
signVerificationMessage,
|
|
360
|
-
getWalletBalance
|
|
361
|
-
|
|
515
|
+
getWalletBalance,
|
|
516
|
+
requestInfo,
|
|
517
|
+
disconnectBase,
|
|
518
|
+
farcasterStatus,
|
|
519
|
+
verificationStage
|
|
520
|
+
}, externalHooks),
|
|
362
521
|
children
|
|
363
522
|
}
|
|
364
523
|
);
|
|
@@ -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
|
}
|