@getpara/evm-wallet-connectors 2.0.0-fc.2 → 2.0.0
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/README.md +20 -0
- package/dist/connectors/walletConnect.d.ts +63 -0
- package/dist/connectors/walletConnect.js +366 -0
- package/dist/providers/EvmExternalWalletContext.d.ts +4 -2
- package/dist/providers/EvmExternalWalletContext.js +169 -63
- package/dist/providers/ParaEvmContext.js +45 -41
- package/dist/types/Wallet.d.ts +2 -1
- package/dist/utils/getWalletConnectConnector.js +1 -1
- package/dist/utils/getWalletConnectUri.d.ts +1 -1
- package/dist/utils/getWalletConnectUri.js +12 -9
- package/dist/utils/isEIP6963Connector.js +1 -1
- package/dist/wallets/connectors/backpack/backpack.js +1 -1
- package/dist/wallets/connectors/farcaster/farcaster.js +1 -1
- package/dist/wallets/connectors/metaMask/metaMask.js +7 -4
- package/dist/wallets/connectors/rainbow/rainbow.js +7 -1
- package/dist/wallets/connectors/zerion/zerion.js +4 -1
- package/package.json +7 -6
package/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
https://www.npmjs.com/package/@getpara/evm-wallet-connectors
|
|
2
|
+
|
|
3
|
+
The package is used with Para's React SDK Lite to enable external EVM wallet connections. Para automatically manages the Wagmi provider internally when you configure external wallet support.
|
|
4
|
+
|
|
5
|
+
###Key Features
|
|
6
|
+
|
|
7
|
+
- Wagmi Integration: Powered by Wagmi, the popular React hooks library for Ethereum
|
|
8
|
+
- Automatic Setup: Para handles all Wagmi provider configuration internally
|
|
9
|
+
- Unified Configuration: Configure chains and settings through Para's `externalWalletConfig`
|
|
10
|
+
- All Wagmi Hooks Available: Use any Wagmi hook alongside Para hooks
|
|
11
|
+
|
|
12
|
+
###Prerequisites
|
|
13
|
+
|
|
14
|
+
To use Para, you need an API key. This key authenticates your requests to Para services and is essential for integration.
|
|
15
|
+
|
|
16
|
+
Don't have an API key yet? Request access to the [Developer Portal](https://developer.getpara.com/) to create API keys, manage billing, teams, and more.
|
|
17
|
+
|
|
18
|
+
###Learn more
|
|
19
|
+
|
|
20
|
+
For more information on Para’s EVM Wallet Connectors visit the [Para Docs](https://docs.getpara.com/v2/react/guides/external-wallets/evm-lite#evm-wallets-with-react-sdk-lite)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Compute, ExactPartial, Omit } from '@wagmi/core/internal';
|
|
2
|
+
import type { EthereumProvider } from '@walletconnect/ethereum-provider';
|
|
3
|
+
import { type Address, type ProviderConnectInfo } from 'viem';
|
|
4
|
+
type EthereumProviderOptions = Parameters<(typeof EthereumProvider)['init']>[0];
|
|
5
|
+
export type WalletConnectParameters = Compute<{
|
|
6
|
+
/**
|
|
7
|
+
* If a new chain is added to a previously existing configured connector `chains`, this flag
|
|
8
|
+
* will determine if that chain should be considered as stale. A stale chain is a chain that
|
|
9
|
+
* WalletConnect has yet to establish a relationship with (e.g. the user has not approved or
|
|
10
|
+
* rejected the chain).
|
|
11
|
+
*
|
|
12
|
+
* This flag mainly affects the behavior when a wallet does not support dynamic chain authorization
|
|
13
|
+
* with WalletConnect v2.
|
|
14
|
+
*
|
|
15
|
+
* If `true` (default), the new chain will be treated as a stale chain. If the user
|
|
16
|
+
* has yet to establish a relationship (approved/rejected) with this chain in their WalletConnect
|
|
17
|
+
* session, the connector will disconnect upon the dapp auto-connecting, and the user will have to
|
|
18
|
+
* reconnect to the dapp (revalidate the chain) in order to approve the newly added chain.
|
|
19
|
+
* This is the default behavior to avoid an unexpected error upon switching chains which may
|
|
20
|
+
* be a confusing user experience (e.g. the user will not know they have to reconnect
|
|
21
|
+
* unless the dapp handles these types of errors).
|
|
22
|
+
*
|
|
23
|
+
* If `false`, the new chain will be treated as a potentially valid chain. This means that if the user
|
|
24
|
+
* has yet to establish a relationship with the chain in their WalletConnect session, wagmi will successfully
|
|
25
|
+
* auto-connect the user. This comes with the trade-off that the connector will throw an error
|
|
26
|
+
* when attempting to switch to the unapproved chain if the wallet does not support dynamic session updates.
|
|
27
|
+
* This may be useful in cases where a dapp constantly
|
|
28
|
+
* modifies their configured chains, and they do not want to disconnect the user upon
|
|
29
|
+
* auto-connecting. If the user decides to switch to the unapproved chain, it is important that the
|
|
30
|
+
* dapp handles this error and prompts the user to reconnect to the dapp in order to approve
|
|
31
|
+
* the newly added chain.
|
|
32
|
+
*
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
isNewChainsStale?: boolean;
|
|
36
|
+
} & Omit<EthereumProviderOptions, 'chains' | 'events' | 'optionalChains' | 'optionalEvents' | 'optionalMethods' | 'methods' | 'rpcMap' | 'showQrModal'> & ExactPartial<Pick<EthereumProviderOptions, 'showQrModal'>>>;
|
|
37
|
+
type ConnectParams = {
|
|
38
|
+
chainId?: number | undefined;
|
|
39
|
+
isReconnecting?: boolean | undefined;
|
|
40
|
+
pairingTopic?: string | undefined;
|
|
41
|
+
};
|
|
42
|
+
export declare function walletConnect(parameters: WalletConnectParameters): import("@wagmi/core").CreateConnectorFn<import("@walletconnect/ethereum-provider").default, {
|
|
43
|
+
connect(parameters: ConnectParams): Promise<{
|
|
44
|
+
accounts: readonly Address[];
|
|
45
|
+
chainId: number;
|
|
46
|
+
}>;
|
|
47
|
+
getNamespaceChainsIds(): number[];
|
|
48
|
+
getRequestedChainsIds(): Promise<number[]>;
|
|
49
|
+
isChainsStale(): Promise<boolean>;
|
|
50
|
+
onConnect(connectInfo: ProviderConnectInfo): void;
|
|
51
|
+
onDisplayUri(uri: string): void;
|
|
52
|
+
onSessionDelete(data: {
|
|
53
|
+
topic: string;
|
|
54
|
+
}): void;
|
|
55
|
+
setRequestedChainsIds(chains: number[]): void;
|
|
56
|
+
requestedChainsStorageKey: `${string}.requestedChains`;
|
|
57
|
+
}, {
|
|
58
|
+
[x: `${string}.requestedChains`]: number[];
|
|
59
|
+
}>;
|
|
60
|
+
export declare namespace walletConnect {
|
|
61
|
+
var type: "walletConnect";
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__objRest,
|
|
5
|
+
__spreadProps,
|
|
6
|
+
__spreadValues
|
|
7
|
+
} from "../chunk-MMUBH76A.js";
|
|
8
|
+
import {
|
|
9
|
+
ChainNotConfiguredError,
|
|
10
|
+
ProviderNotFoundError,
|
|
11
|
+
createConnector,
|
|
12
|
+
extractRpcUrls
|
|
13
|
+
} from "@wagmi/core";
|
|
14
|
+
import {
|
|
15
|
+
SwitchChainError,
|
|
16
|
+
UserRejectedRequestError,
|
|
17
|
+
getAddress,
|
|
18
|
+
numberToHex
|
|
19
|
+
} from "viem";
|
|
20
|
+
walletConnect.type = "walletConnect";
|
|
21
|
+
function walletConnect(parameters) {
|
|
22
|
+
var _a;
|
|
23
|
+
const isNewChainsStale = (_a = parameters.isNewChainsStale) != null ? _a : true;
|
|
24
|
+
let provider_;
|
|
25
|
+
let providerPromise;
|
|
26
|
+
const NAMESPACE = "eip155";
|
|
27
|
+
let accountsChanged;
|
|
28
|
+
let chainChanged;
|
|
29
|
+
let connect;
|
|
30
|
+
let displayUri;
|
|
31
|
+
let sessionDelete;
|
|
32
|
+
let disconnect;
|
|
33
|
+
return createConnector((config) => ({
|
|
34
|
+
id: "walletConnect",
|
|
35
|
+
name: "WalletConnect",
|
|
36
|
+
type: walletConnect.type,
|
|
37
|
+
setup() {
|
|
38
|
+
return __async(this, null, function* () {
|
|
39
|
+
const provider = yield this.getProvider().catch(() => null);
|
|
40
|
+
if (!provider) return;
|
|
41
|
+
if (!connect) {
|
|
42
|
+
connect = this.onConnect.bind(this);
|
|
43
|
+
provider.on("connect", connect);
|
|
44
|
+
}
|
|
45
|
+
if (!sessionDelete) {
|
|
46
|
+
sessionDelete = this.onSessionDelete.bind(this);
|
|
47
|
+
provider.on("session_delete", sessionDelete);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
connect() {
|
|
52
|
+
return __async(this, arguments, function* (_b = {}) {
|
|
53
|
+
var _c = _b, { chainId } = _c, rest = __objRest(_c, ["chainId"]);
|
|
54
|
+
var _a3, _b2, _c2;
|
|
55
|
+
try {
|
|
56
|
+
const provider = yield this.getProvider();
|
|
57
|
+
if (!provider) throw new ProviderNotFoundError();
|
|
58
|
+
if (!displayUri) {
|
|
59
|
+
displayUri = this.onDisplayUri;
|
|
60
|
+
provider.on("display_uri", displayUri);
|
|
61
|
+
}
|
|
62
|
+
let targetChainId = chainId;
|
|
63
|
+
if (!targetChainId) {
|
|
64
|
+
const state = (_b2 = yield (_a3 = config.storage) == null ? void 0 : _a3.getItem("state")) != null ? _b2 : {};
|
|
65
|
+
const isChainSupported = config.chains.some((x) => x.id === state.chainId);
|
|
66
|
+
if (isChainSupported) targetChainId = state.chainId;
|
|
67
|
+
else targetChainId = (_c2 = config.chains[0]) == null ? void 0 : _c2.id;
|
|
68
|
+
}
|
|
69
|
+
if (!targetChainId) throw new Error("No chains found on connector.");
|
|
70
|
+
const isChainsStale = yield this.isChainsStale();
|
|
71
|
+
if (provider.session && isChainsStale) yield provider.disconnect();
|
|
72
|
+
if (!provider.session || isChainsStale) {
|
|
73
|
+
const optionalChains = config.chains.filter((chain) => chain.id !== targetChainId).map((optionalChain) => optionalChain.id);
|
|
74
|
+
yield provider.connect(__spreadValues({
|
|
75
|
+
optionalChains: [targetChainId, ...optionalChains]
|
|
76
|
+
}, "pairingTopic" in rest ? { pairingTopic: rest.pairingTopic } : {}));
|
|
77
|
+
this.setRequestedChainsIds(config.chains.map((x) => x.id));
|
|
78
|
+
}
|
|
79
|
+
const accounts = (yield provider.enable()).map((x) => getAddress(x));
|
|
80
|
+
const currentChainId = yield this.getChainId();
|
|
81
|
+
if (displayUri) {
|
|
82
|
+
provider.removeListener("display_uri", displayUri);
|
|
83
|
+
displayUri = void 0;
|
|
84
|
+
}
|
|
85
|
+
if (connect) {
|
|
86
|
+
provider.removeListener("connect", connect);
|
|
87
|
+
connect = void 0;
|
|
88
|
+
}
|
|
89
|
+
if (!accountsChanged) {
|
|
90
|
+
accountsChanged = this.onAccountsChanged.bind(this);
|
|
91
|
+
provider.on("accountsChanged", accountsChanged);
|
|
92
|
+
}
|
|
93
|
+
if (!chainChanged) {
|
|
94
|
+
chainChanged = this.onChainChanged.bind(this);
|
|
95
|
+
provider.on("chainChanged", chainChanged);
|
|
96
|
+
}
|
|
97
|
+
if (!disconnect) {
|
|
98
|
+
disconnect = this.onDisconnect.bind(this);
|
|
99
|
+
provider.on("disconnect", disconnect);
|
|
100
|
+
}
|
|
101
|
+
if (!sessionDelete) {
|
|
102
|
+
sessionDelete = this.onSessionDelete.bind(this);
|
|
103
|
+
provider.on("session_delete", sessionDelete);
|
|
104
|
+
}
|
|
105
|
+
return { accounts, chainId: currentChainId };
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (/(user rejected|connection request reset)/i.test(error == null ? void 0 : error.message)) {
|
|
108
|
+
throw new UserRejectedRequestError(error);
|
|
109
|
+
}
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
disconnect() {
|
|
115
|
+
return __async(this, null, function* () {
|
|
116
|
+
const provider = yield this.getProvider();
|
|
117
|
+
try {
|
|
118
|
+
yield provider == null ? void 0 : provider.disconnect();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (!/No matching key/i.test(error.message)) throw error;
|
|
121
|
+
} finally {
|
|
122
|
+
if (chainChanged) {
|
|
123
|
+
provider == null ? void 0 : provider.removeListener("chainChanged", chainChanged);
|
|
124
|
+
chainChanged = void 0;
|
|
125
|
+
}
|
|
126
|
+
if (disconnect) {
|
|
127
|
+
provider == null ? void 0 : provider.removeListener("disconnect", disconnect);
|
|
128
|
+
disconnect = void 0;
|
|
129
|
+
}
|
|
130
|
+
if (!connect) {
|
|
131
|
+
connect = this.onConnect.bind(this);
|
|
132
|
+
provider == null ? void 0 : provider.on("connect", connect);
|
|
133
|
+
}
|
|
134
|
+
if (accountsChanged) {
|
|
135
|
+
provider == null ? void 0 : provider.removeListener("accountsChanged", accountsChanged);
|
|
136
|
+
accountsChanged = void 0;
|
|
137
|
+
}
|
|
138
|
+
if (sessionDelete) {
|
|
139
|
+
provider == null ? void 0 : provider.removeListener("session_delete", sessionDelete);
|
|
140
|
+
sessionDelete = void 0;
|
|
141
|
+
}
|
|
142
|
+
this.setRequestedChainsIds([]);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
getAccounts() {
|
|
147
|
+
return __async(this, null, function* () {
|
|
148
|
+
const provider = yield this.getProvider();
|
|
149
|
+
return provider.accounts.map((x) => getAddress(x));
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
getProvider() {
|
|
153
|
+
return __async(this, arguments, function* ({ chainId } = {}) {
|
|
154
|
+
var _a3;
|
|
155
|
+
function initProvider() {
|
|
156
|
+
return __async(this, null, function* () {
|
|
157
|
+
var _a4;
|
|
158
|
+
const optionalChains = config.chains.map((x) => x.id);
|
|
159
|
+
if (!optionalChains.length) return;
|
|
160
|
+
const { EthereumProvider } = yield import("@walletconnect/ethereum-provider");
|
|
161
|
+
return yield EthereumProvider.init(__spreadProps(__spreadValues({}, parameters), {
|
|
162
|
+
disableProviderPing: true,
|
|
163
|
+
optionalChains,
|
|
164
|
+
projectId: parameters.projectId,
|
|
165
|
+
rpcMap: Object.fromEntries(
|
|
166
|
+
config.chains.map((chain) => {
|
|
167
|
+
const [url] = extractRpcUrls({
|
|
168
|
+
chain,
|
|
169
|
+
transports: config.transports
|
|
170
|
+
});
|
|
171
|
+
return [chain.id, url];
|
|
172
|
+
})
|
|
173
|
+
),
|
|
174
|
+
showQrModal: (_a4 = parameters.showQrModal) != null ? _a4 : true
|
|
175
|
+
}));
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
if (!provider_) {
|
|
179
|
+
if (!providerPromise) providerPromise = initProvider();
|
|
180
|
+
provider_ = yield providerPromise;
|
|
181
|
+
provider_ == null ? void 0 : provider_.events.setMaxListeners(Number.POSITIVE_INFINITY);
|
|
182
|
+
}
|
|
183
|
+
if (chainId) yield (_a3 = this.switchChain) == null ? void 0 : _a3.call(this, { chainId });
|
|
184
|
+
return provider_;
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
getChainId() {
|
|
188
|
+
return __async(this, null, function* () {
|
|
189
|
+
const provider = yield this.getProvider();
|
|
190
|
+
return provider.chainId;
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
isAuthorized() {
|
|
194
|
+
return __async(this, null, function* () {
|
|
195
|
+
try {
|
|
196
|
+
const [accounts, provider] = yield Promise.all([this.getAccounts(), this.getProvider()]);
|
|
197
|
+
if (!accounts.length) return false;
|
|
198
|
+
const isChainsStale = yield this.isChainsStale();
|
|
199
|
+
if (isChainsStale && provider.session) {
|
|
200
|
+
yield provider.disconnect().catch(() => {
|
|
201
|
+
});
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
} catch (e) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
switchChain(_0) {
|
|
211
|
+
return __async(this, arguments, function* ({ addEthereumChainParameter, chainId }) {
|
|
212
|
+
var _a3, _b, _c, _d, _e;
|
|
213
|
+
const provider = yield this.getProvider();
|
|
214
|
+
if (!provider) throw new ProviderNotFoundError();
|
|
215
|
+
const chain = config.chains.find((x) => x.id === chainId);
|
|
216
|
+
if (!chain) throw new SwitchChainError(new ChainNotConfiguredError());
|
|
217
|
+
try {
|
|
218
|
+
yield Promise.all([
|
|
219
|
+
new Promise((resolve) => {
|
|
220
|
+
const listener = ({ chainId: currentChainId }) => {
|
|
221
|
+
if (currentChainId === chainId) {
|
|
222
|
+
config.emitter.off("change", listener);
|
|
223
|
+
resolve();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
config.emitter.on("change", listener);
|
|
227
|
+
}),
|
|
228
|
+
provider.request({
|
|
229
|
+
method: "wallet_switchEthereumChain",
|
|
230
|
+
params: [{ chainId: numberToHex(chainId) }]
|
|
231
|
+
})
|
|
232
|
+
]);
|
|
233
|
+
const requestedChains = yield this.getRequestedChainsIds();
|
|
234
|
+
this.setRequestedChainsIds([...requestedChains, chainId]);
|
|
235
|
+
return chain;
|
|
236
|
+
} catch (err) {
|
|
237
|
+
const error = err;
|
|
238
|
+
if (/(user rejected)/i.test(error.message)) throw new UserRejectedRequestError(error);
|
|
239
|
+
try {
|
|
240
|
+
let blockExplorerUrls;
|
|
241
|
+
if (addEthereumChainParameter == null ? void 0 : addEthereumChainParameter.blockExplorerUrls) blockExplorerUrls = addEthereumChainParameter.blockExplorerUrls;
|
|
242
|
+
else blockExplorerUrls = ((_a3 = chain.blockExplorers) == null ? void 0 : _a3.default.url) ? [(_b = chain.blockExplorers) == null ? void 0 : _b.default.url] : [];
|
|
243
|
+
let rpcUrls;
|
|
244
|
+
if ((_c = addEthereumChainParameter == null ? void 0 : addEthereumChainParameter.rpcUrls) == null ? void 0 : _c.length) rpcUrls = addEthereumChainParameter.rpcUrls;
|
|
245
|
+
else rpcUrls = [...chain.rpcUrls.default.http];
|
|
246
|
+
const addEthereumChain = {
|
|
247
|
+
blockExplorerUrls,
|
|
248
|
+
chainId: numberToHex(chainId),
|
|
249
|
+
chainName: (_d = addEthereumChainParameter == null ? void 0 : addEthereumChainParameter.chainName) != null ? _d : chain.name,
|
|
250
|
+
iconUrls: addEthereumChainParameter == null ? void 0 : addEthereumChainParameter.iconUrls,
|
|
251
|
+
nativeCurrency: (_e = addEthereumChainParameter == null ? void 0 : addEthereumChainParameter.nativeCurrency) != null ? _e : chain.nativeCurrency,
|
|
252
|
+
rpcUrls
|
|
253
|
+
};
|
|
254
|
+
yield provider.request({
|
|
255
|
+
method: "wallet_addEthereumChain",
|
|
256
|
+
params: [addEthereumChain]
|
|
257
|
+
});
|
|
258
|
+
const requestedChains = yield this.getRequestedChainsIds();
|
|
259
|
+
this.setRequestedChainsIds([...requestedChains, chainId]);
|
|
260
|
+
return chain;
|
|
261
|
+
} catch (error2) {
|
|
262
|
+
throw new UserRejectedRequestError(error2);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
},
|
|
267
|
+
onAccountsChanged(accounts) {
|
|
268
|
+
if (accounts.length === 0) this.onDisconnect();
|
|
269
|
+
else
|
|
270
|
+
config.emitter.emit("change", {
|
|
271
|
+
accounts: accounts.map((x) => getAddress(x))
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
onChainChanged(chain) {
|
|
275
|
+
const chainId = Number(chain);
|
|
276
|
+
config.emitter.emit("change", { chainId });
|
|
277
|
+
},
|
|
278
|
+
onConnect(connectInfo) {
|
|
279
|
+
return __async(this, null, function* () {
|
|
280
|
+
const chainId = Number(connectInfo.chainId);
|
|
281
|
+
const accounts = yield this.getAccounts();
|
|
282
|
+
config.emitter.emit("connect", { accounts, chainId });
|
|
283
|
+
});
|
|
284
|
+
},
|
|
285
|
+
onDisconnect(_error) {
|
|
286
|
+
return __async(this, null, function* () {
|
|
287
|
+
this.setRequestedChainsIds([]);
|
|
288
|
+
config.emitter.emit("disconnect");
|
|
289
|
+
const provider = yield this.getProvider();
|
|
290
|
+
if (accountsChanged) {
|
|
291
|
+
provider.removeListener("accountsChanged", accountsChanged);
|
|
292
|
+
accountsChanged = void 0;
|
|
293
|
+
}
|
|
294
|
+
if (chainChanged) {
|
|
295
|
+
provider.removeListener("chainChanged", chainChanged);
|
|
296
|
+
chainChanged = void 0;
|
|
297
|
+
}
|
|
298
|
+
if (disconnect) {
|
|
299
|
+
provider.removeListener("disconnect", disconnect);
|
|
300
|
+
disconnect = void 0;
|
|
301
|
+
}
|
|
302
|
+
if (sessionDelete) {
|
|
303
|
+
provider.removeListener("session_delete", sessionDelete);
|
|
304
|
+
sessionDelete = void 0;
|
|
305
|
+
}
|
|
306
|
+
if (!connect) {
|
|
307
|
+
connect = this.onConnect.bind(this);
|
|
308
|
+
provider.on("connect", connect);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
},
|
|
312
|
+
onDisplayUri(uri) {
|
|
313
|
+
config.emitter.emit("message", { type: "display_uri", data: uri });
|
|
314
|
+
},
|
|
315
|
+
onSessionDelete() {
|
|
316
|
+
this.onDisconnect();
|
|
317
|
+
},
|
|
318
|
+
getNamespaceChainsIds() {
|
|
319
|
+
var _a3, _b, _c;
|
|
320
|
+
if (!provider_) return [];
|
|
321
|
+
const chainIds = (_c = (_b = (_a3 = provider_.session) == null ? void 0 : _a3.namespaces[NAMESPACE]) == null ? void 0 : _b.accounts) == null ? void 0 : _c.map(
|
|
322
|
+
(account) => Number.parseInt(account.split(":")[1] || "")
|
|
323
|
+
);
|
|
324
|
+
return chainIds != null ? chainIds : [];
|
|
325
|
+
},
|
|
326
|
+
getRequestedChainsIds() {
|
|
327
|
+
return __async(this, null, function* () {
|
|
328
|
+
var _a3, _b;
|
|
329
|
+
return (_b = yield (_a3 = config.storage) == null ? void 0 : _a3.getItem(this.requestedChainsStorageKey)) != null ? _b : [];
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
/**
|
|
333
|
+
* Checks if the target chains match the chains that were
|
|
334
|
+
* initially requested by the connector for the WalletConnect session.
|
|
335
|
+
* If there is a mismatch, this means that the chains on the connector
|
|
336
|
+
* are considered stale, and need to be revalidated at a later point (via
|
|
337
|
+
* connection).
|
|
338
|
+
*
|
|
339
|
+
* There may be a scenario where a dapp adds a chain to the
|
|
340
|
+
* connector later on, however, this chain will not have been approved or rejected
|
|
341
|
+
* by the wallet. In this case, the chain is considered stale.
|
|
342
|
+
*/
|
|
343
|
+
isChainsStale() {
|
|
344
|
+
return __async(this, null, function* () {
|
|
345
|
+
if (!isNewChainsStale) return false;
|
|
346
|
+
const connectorChains = config.chains.map((x) => x.id);
|
|
347
|
+
const namespaceChains = this.getNamespaceChainsIds();
|
|
348
|
+
if (namespaceChains.length && !namespaceChains.some((id) => connectorChains.includes(id))) return false;
|
|
349
|
+
const requestedChains = yield this.getRequestedChainsIds();
|
|
350
|
+
return !connectorChains.every((id) => requestedChains.includes(id));
|
|
351
|
+
});
|
|
352
|
+
},
|
|
353
|
+
setRequestedChainsIds(chains) {
|
|
354
|
+
return __async(this, null, function* () {
|
|
355
|
+
var _a3;
|
|
356
|
+
yield (_a3 = config.storage) == null ? void 0 : _a3.setItem(this.requestedChainsStorageKey, chains);
|
|
357
|
+
});
|
|
358
|
+
},
|
|
359
|
+
get requestedChainsStorageKey() {
|
|
360
|
+
return `${this.id}.requestedChains`;
|
|
361
|
+
}
|
|
362
|
+
}));
|
|
363
|
+
}
|
|
364
|
+
export {
|
|
365
|
+
walletConnect
|
|
366
|
+
};
|
|
@@ -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
|
-
export declare function EvmExternalWalletProvider({ children, onSwitchWallet, para, walletsWithFullAuth, connectedWallet, includeWalletVerification, connectionOnly, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
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,
|
|
@@ -19,22 +19,26 @@ import {
|
|
|
19
19
|
useBalance
|
|
20
20
|
} from "wagmi";
|
|
21
21
|
import { isEIP6963Connector } from "../utils/isEIP6963Connector.js";
|
|
22
|
-
import {
|
|
22
|
+
import { emitWalletConnectUri } from "../utils/getWalletConnectUri.js";
|
|
23
23
|
import { normalize } from "viem/ens";
|
|
24
24
|
import { useExternalWalletStore } from "../stores/useStore.js";
|
|
25
25
|
import {
|
|
26
|
-
defaultEvmExternalWallet
|
|
26
|
+
defaultEvmExternalWallet,
|
|
27
|
+
openMobileUrl
|
|
27
28
|
} from "@getpara/react-common";
|
|
28
29
|
import { isMobile } from "@getpara/web-sdk";
|
|
29
30
|
import { etherUnits, formatUnits } from "viem";
|
|
30
31
|
import { externalHooks } from "./externalHooks.js";
|
|
31
|
-
const EvmExternalWalletContext = createContext(defaultEvmExternalWallet)
|
|
32
|
+
const EvmExternalWalletContext = createContext(__spreadProps(__spreadValues({}, defaultEvmExternalWallet), {
|
|
33
|
+
farcasterStatus: void 0,
|
|
34
|
+
verificationStage: void 0
|
|
35
|
+
}));
|
|
32
36
|
function EvmExternalWalletProvider({
|
|
33
37
|
children,
|
|
34
38
|
onSwitchWallet,
|
|
35
39
|
para,
|
|
36
40
|
walletsWithFullAuth,
|
|
37
|
-
connectedWallet,
|
|
41
|
+
connectedWallet: connectedWalletProp,
|
|
38
42
|
includeWalletVerification,
|
|
39
43
|
connectionOnly
|
|
40
44
|
}) {
|
|
@@ -50,18 +54,20 @@ function EvmExternalWalletProvider({
|
|
|
50
54
|
} = useAccount();
|
|
51
55
|
const { switchAccount: wagmiSwitchAccount } = useSwitchAccount();
|
|
52
56
|
const { chains, switchChainAsync } = useSwitchChain();
|
|
53
|
-
const { disconnectAsync } = useDisconnect();
|
|
57
|
+
const { disconnectAsync, status: disconnectStatus } = useDisconnect();
|
|
54
58
|
const { data: ensName, refetch: refetchEnsName } = useEnsName({ address: wagmiAddress });
|
|
55
59
|
const { data: ensAvatar, refetch: refetchEnsAvatar } = useEnsAvatar({
|
|
56
60
|
name: normalize(ensName)
|
|
57
61
|
});
|
|
58
62
|
const { signMessageAsync } = useSignMessage();
|
|
59
|
-
const
|
|
63
|
+
const connectedWallet = connectedWalletProp ? para.findWallet(connectedWalletProp.id, connectedWalletProp.type) : null;
|
|
64
|
+
const disconnectTypeRef = useRef();
|
|
60
65
|
const verificationMessage = useRef();
|
|
61
66
|
const { refetch: getBalance } = useBalance({ address: wagmiAddress });
|
|
62
67
|
const connectors = untypedConnectors;
|
|
63
68
|
const connectionsRef = useRef(connections);
|
|
64
69
|
const connectorsRef = useRef(connectors);
|
|
70
|
+
const [verificationStage, setVerificationStage] = useState("verifying");
|
|
65
71
|
const isLocalConnecting = useExternalWalletStore((state) => state.isConnecting);
|
|
66
72
|
const updateExternalWalletState = useExternalWalletStore((state) => state.updateState);
|
|
67
73
|
const getStoredExternalWallets = () => {
|
|
@@ -75,14 +81,18 @@ function EvmExternalWalletProvider({
|
|
|
75
81
|
const switchAccount = useCallback(
|
|
76
82
|
(connectorName) => {
|
|
77
83
|
var _a;
|
|
78
|
-
const connector = (_a =
|
|
84
|
+
const connector = (_a = connectionsRef.current.find((c) => {
|
|
85
|
+
var _a2;
|
|
86
|
+
const paraDetails = (_a2 = c.connector) == null ? void 0 : _a2.paraDetails;
|
|
87
|
+
return [paraDetails == null ? void 0 : paraDetails.name, paraDetails == null ? void 0 : paraDetails.id, paraDetails == null ? void 0 : paraDetails.internalId].includes(connectorName);
|
|
88
|
+
})) == null ? void 0 : _a.connector;
|
|
79
89
|
if (!connector) {
|
|
80
90
|
console.warn(`connector not found: ${connectorName}`);
|
|
81
91
|
return;
|
|
82
92
|
}
|
|
83
93
|
wagmiSwitchAccount({ connector });
|
|
84
94
|
},
|
|
85
|
-
[
|
|
95
|
+
[wagmiSwitchAccount]
|
|
86
96
|
);
|
|
87
97
|
const findConnectorAndAccount = (externalWallet) => {
|
|
88
98
|
var _a;
|
|
@@ -90,12 +100,10 @@ function EvmExternalWalletProvider({
|
|
|
90
100
|
switch (true) {
|
|
91
101
|
case !!externalWallet.providerId:
|
|
92
102
|
{
|
|
93
|
-
connector = (_a = connectionsRef.current.find(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
)) == null ? void 0 : _a.connector;
|
|
103
|
+
connector = (_a = connectionsRef.current.find((c) => {
|
|
104
|
+
var _a2;
|
|
105
|
+
return ((_a2 = c.connector) == null ? void 0 : _a2.name) === externalWallet.providerId;
|
|
106
|
+
})) == null ? void 0 : _a.connector;
|
|
99
107
|
}
|
|
100
108
|
break;
|
|
101
109
|
}
|
|
@@ -111,40 +119,76 @@ function EvmExternalWalletProvider({
|
|
|
111
119
|
);
|
|
112
120
|
useEffect(() => {
|
|
113
121
|
const storedExternalWallet = getStoredExternalWallets()[wagmiAddress != null ? wagmiAddress : ""];
|
|
114
|
-
if (
|
|
122
|
+
if ((connectedConnector == null ? void 0 : connectedConnector.id) === "para") {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (!isConnecting && !isReconnecting && !isLocalConnecting && !!wagmiAddress && !storedExternalWallet && !disconnectTypeRef.current && para.isReady && !para.isFarcasterMiniApp) {
|
|
115
126
|
reset();
|
|
116
127
|
}
|
|
117
128
|
}, [isConnected, isLocalConnecting, wagmiAddress, connectedConnector, para.isReady, para.isFarcasterMiniApp]);
|
|
118
129
|
useEffect(() => {
|
|
119
130
|
const storedExternalWallet = Object.values(para.externalWallets || {})[0];
|
|
120
|
-
if (!isLocalConnecting && isConnected && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === "EVM" && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para" && !
|
|
131
|
+
if (!isLocalConnecting && isConnected && (storedExternalWallet == null ? void 0 : storedExternalWallet.type) === "EVM" && (storedExternalWallet == null ? void 0 : storedExternalWallet.address) !== wagmiAddress && (connectedConnector == null ? void 0 : connectedConnector.id) !== "para" && !disconnectTypeRef.current) {
|
|
121
132
|
switchWallet(wagmiAddress);
|
|
122
133
|
}
|
|
123
134
|
}, [isLocalConnecting, wagmiAddress, isConnected]);
|
|
124
135
|
useEffect(() => {
|
|
125
|
-
|
|
136
|
+
var _a;
|
|
137
|
+
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;
|
|
138
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && connectedWallet && connectedConnector && connectedWallet.type === "EVM" && connectedConnectorName !== connectedWallet.name) {
|
|
126
139
|
switchAccount(connectedWallet.isExternal ? connectedWallet.name : "Para");
|
|
127
140
|
}
|
|
128
141
|
}, [isLocalConnecting, isConnecting, isReconnecting, connectedWallet, wagmiSwitchAccount]);
|
|
129
142
|
useEffect(() => {
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
|
|
143
|
+
const connectPara = () => __async(this, null, function* () {
|
|
144
|
+
if (!isLocalConnecting && !isConnecting && !isReconnecting && !isConnected && !connectedConnector) {
|
|
145
|
+
if (Object.values(para.wallets).length === 0 || !(yield para.isFullyLoggedIn())) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
connectParaEmbedded();
|
|
133
149
|
}
|
|
134
|
-
|
|
135
|
-
|
|
150
|
+
});
|
|
151
|
+
connectPara();
|
|
136
152
|
}, [isLocalConnecting, isConnecting, isReconnecting, isConnected, connectedConnector]);
|
|
137
153
|
const reset = () => __async(this, null, function* () {
|
|
138
154
|
yield disconnectAsync();
|
|
139
155
|
yield para.logout();
|
|
140
156
|
});
|
|
157
|
+
const getChainParams = (chainId2) => {
|
|
158
|
+
var _a;
|
|
159
|
+
const chain = chains.find((c) => c.id === chainId2);
|
|
160
|
+
if (!chain) return null;
|
|
161
|
+
return {
|
|
162
|
+
chainId: `0x${chainId2.toString(16)}`,
|
|
163
|
+
chainName: chain.name,
|
|
164
|
+
nativeCurrency: {
|
|
165
|
+
name: chain.nativeCurrency.name,
|
|
166
|
+
symbol: chain.nativeCurrency.symbol,
|
|
167
|
+
decimals: chain.nativeCurrency.decimals
|
|
168
|
+
},
|
|
169
|
+
rpcUrls: [chain.rpcUrls.default.http[0]],
|
|
170
|
+
blockExplorerUrls: ((_a = chain.blockExplorers) == null ? void 0 : _a.default) ? [chain.blockExplorers.default.url] : void 0
|
|
171
|
+
};
|
|
172
|
+
};
|
|
141
173
|
const signMessage = (_0) => __async(this, [_0], function* ({ message, externalWallet }) {
|
|
174
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
142
175
|
let signOpts = {};
|
|
176
|
+
const connector = findConnector(
|
|
177
|
+
externalWallet ? externalWallet.providerId : getConnectorInfo(connectedConnector).providerId
|
|
178
|
+
);
|
|
179
|
+
const signUri = isMobile() && connector.type === "walletConnect" ? (_a = connector.paraDetails) == null ? void 0 : _a.deeplinkUri : void 0;
|
|
180
|
+
const openApp = () => {
|
|
181
|
+
if (signUri) {
|
|
182
|
+
openMobileUrl(signUri);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
openApp();
|
|
143
186
|
if (externalWallet) {
|
|
144
187
|
signOpts = findConnectorAndAccount(externalWallet);
|
|
188
|
+
yield switchAccount((_b = externalWallet.providerId) != null ? _b : "");
|
|
145
189
|
}
|
|
190
|
+
const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
|
|
146
191
|
try {
|
|
147
|
-
const address = signOpts.account ? typeof signOpts.account === "string" ? signOpts.account : signOpts.account.getAddress() : wagmiAddress;
|
|
148
192
|
const signature = yield signMessageAsync(__spreadValues({
|
|
149
193
|
message,
|
|
150
194
|
account: address
|
|
@@ -155,6 +199,29 @@ function EvmExternalWalletProvider({
|
|
|
155
199
|
};
|
|
156
200
|
} catch (e) {
|
|
157
201
|
console.error("Error signing message:", e);
|
|
202
|
+
console.error("Error signing message:", e.message, e.details);
|
|
203
|
+
if (e.message.includes("Chain not configured") || e.details.includes("Chain not configured")) {
|
|
204
|
+
setVerificationStage("switchingChain");
|
|
205
|
+
const currentChainParams = getChainParams((_d = (_c = chains[0]) == null ? void 0 : _c.id) != null ? _d : chainId);
|
|
206
|
+
if (!currentChainParams) {
|
|
207
|
+
return {
|
|
208
|
+
error: `Chain ${chainId} not found in configuration`
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
yield switchChainAsync({
|
|
213
|
+
addEthereumChainParameter: currentChainParams,
|
|
214
|
+
chainId: (_f = (_e = chains[0]) == null ? void 0 : _e.id) != null ? _f : chainId
|
|
215
|
+
});
|
|
216
|
+
setVerificationStage("verifying");
|
|
217
|
+
return yield signMessage({ message, externalWallet });
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error("Error adding chain:", error);
|
|
220
|
+
return {
|
|
221
|
+
error: `Error adding chain. You may need to add ${currentChainParams == null ? void 0 : currentChainParams.chainName} support to ${(_i = (_h = (_g = connectedConnector == null ? void 0 : connectedConnector.paraDetails) == null ? void 0 : _g.name) != null ? _h : connectedConnector == null ? void 0 : connectedConnector.name) != null ? _i : "the wallet"} manually.`
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
158
225
|
switch (e.name) {
|
|
159
226
|
case "UserRejectedRequestError": {
|
|
160
227
|
return { error: "Signature request rejected" };
|
|
@@ -166,6 +233,7 @@ function EvmExternalWalletProvider({
|
|
|
166
233
|
}
|
|
167
234
|
});
|
|
168
235
|
const signVerificationMessage = () => __async(this, null, function* () {
|
|
236
|
+
setVerificationStage("verifying");
|
|
169
237
|
const signature = yield signMessage({ message: verificationMessage.current });
|
|
170
238
|
return signature;
|
|
171
239
|
});
|
|
@@ -197,11 +265,13 @@ function EvmExternalWalletProvider({
|
|
|
197
265
|
return { error };
|
|
198
266
|
});
|
|
199
267
|
const login = (_0) => __async(this, [_0], function* ({ address, withFullParaAuth = false, providerId, provider }) {
|
|
268
|
+
var _a, _b, _c;
|
|
200
269
|
try {
|
|
201
270
|
refetchEnsName();
|
|
202
271
|
refetchEnsAvatar();
|
|
203
272
|
return yield para.loginExternalWallet({
|
|
204
273
|
externalWallet: {
|
|
274
|
+
partnerId: para.partnerId,
|
|
205
275
|
address,
|
|
206
276
|
type: "EVM",
|
|
207
277
|
provider,
|
|
@@ -211,9 +281,11 @@ function EvmExternalWalletProvider({
|
|
|
211
281
|
ensAvatar,
|
|
212
282
|
isConnectionOnly: connectionOnly,
|
|
213
283
|
withVerification: includeWalletVerification
|
|
214
|
-
}
|
|
284
|
+
},
|
|
285
|
+
uri: window == null ? void 0 : window.location.origin,
|
|
286
|
+
chainId: (_c = (_b = (_a = chains[0]) == null ? void 0 : _a.id) != null ? _b : chainId) == null ? void 0 : _c.toString()
|
|
215
287
|
});
|
|
216
|
-
} catch (
|
|
288
|
+
} catch (e) {
|
|
217
289
|
yield disconnectAsync();
|
|
218
290
|
yield para.logout();
|
|
219
291
|
throw "Error logging you in. Please try again.";
|
|
@@ -242,17 +314,20 @@ function EvmExternalWalletProvider({
|
|
|
242
314
|
updateExternalWalletState({ isConnecting: false });
|
|
243
315
|
});
|
|
244
316
|
const connectBase = (connector) => __async(this, null, function* () {
|
|
245
|
-
var _a, _b, _c, _d;
|
|
317
|
+
var _a, _b, _c, _d, _e, _f;
|
|
318
|
+
if (connector.type === "walletConnect" || ((_a = connector.paraDetails) == null ? void 0 : _a.internalId) === "WALLETCONNECT" || ((_b = connector.paraDetails) == null ? void 0 : _b.showQrModal)) {
|
|
319
|
+
yield emitWalletConnectUri(connector, connector.getUri);
|
|
320
|
+
}
|
|
246
321
|
const walletChainId = yield connector.getChainId();
|
|
247
322
|
const data = yield connectAsync({
|
|
248
323
|
// If the wallet is already on a supported chain, use that to avoid a chain switch prompt.
|
|
249
|
-
chainId: (
|
|
324
|
+
chainId: (_e = (_c = chains.find(({ id }) => id === walletChainId)) == null ? void 0 : _c.id) != null ? _e : (
|
|
250
325
|
// Fall back to the first chain provided.
|
|
251
|
-
(
|
|
326
|
+
(_d = chains[0]) == null ? void 0 : _d.id
|
|
252
327
|
),
|
|
253
328
|
connector
|
|
254
329
|
});
|
|
255
|
-
return (
|
|
330
|
+
return (_f = data.accounts) == null ? void 0 : _f[0];
|
|
256
331
|
});
|
|
257
332
|
const connect = (connector) => __async(this, null, function* () {
|
|
258
333
|
updateExternalWalletState({ isConnecting: true });
|
|
@@ -268,7 +343,7 @@ function EvmExternalWalletProvider({
|
|
|
268
343
|
authState = yield login(__spreadValues({
|
|
269
344
|
address
|
|
270
345
|
}, loginInfo));
|
|
271
|
-
verificationMessage.current = authState.
|
|
346
|
+
verificationMessage.current = authState.signatureVerificationMessage;
|
|
272
347
|
} catch (err) {
|
|
273
348
|
address = void 0;
|
|
274
349
|
error = err;
|
|
@@ -299,41 +374,59 @@ function EvmExternalWalletProvider({
|
|
|
299
374
|
const _connector = connector.walletConnectModalConnector && _isMobile ? connector.walletConnectModalConnector : connector;
|
|
300
375
|
return yield connect(_connector);
|
|
301
376
|
});
|
|
377
|
+
const findConnector = (providerId) => {
|
|
378
|
+
var _a;
|
|
379
|
+
const connector = connectorsRef.current.find(
|
|
380
|
+
(w) => {
|
|
381
|
+
var _a2, _b, _c;
|
|
382
|
+
return [(_a2 = w == null ? void 0 : w.paraDetails) == null ? void 0 : _a2.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);
|
|
383
|
+
}
|
|
384
|
+
);
|
|
385
|
+
return connector ? __spreadProps(__spreadValues({}, connector), { getUri: (_a = connector.paraDetails) == null ? void 0 : _a.getUri }) : void 0;
|
|
386
|
+
};
|
|
302
387
|
const requestInfo = (providerId) => __async(this, null, function* () {
|
|
303
|
-
var _a, _b;
|
|
304
|
-
const connector =
|
|
305
|
-
|
|
306
|
-
return ((_a2 = c.paraDetails) == null ? void 0 : _a2.internalId) === providerId;
|
|
307
|
-
});
|
|
308
|
-
if (connector.isAuthorized) isLinkingAccount.current = true;
|
|
388
|
+
var _a, _b, _c, _d;
|
|
389
|
+
const connector = findConnector(providerId);
|
|
390
|
+
disconnectTypeRef.current = "ACCOUNT_LINKING";
|
|
309
391
|
try {
|
|
310
|
-
|
|
392
|
+
let address;
|
|
393
|
+
if (connector.connected && ((_a = connector.accounts) == null ? void 0 : _a[0])) {
|
|
394
|
+
address = connector.accounts[0];
|
|
395
|
+
} else {
|
|
396
|
+
address = yield connectBase(connector);
|
|
397
|
+
}
|
|
398
|
+
const providerId2 = (_c = (_b = wallets.find((w) => {
|
|
399
|
+
var _a2, _b2;
|
|
400
|
+
return (w == null ? void 0 : w.name) === ((_b2 = (_a2 = connector == null ? void 0 : connector.paraDetails) == null ? void 0 : _a2.name) != null ? _b2 : "");
|
|
401
|
+
})) == null ? void 0 : _b.name) != null ? _c : connector == null ? void 0 : connector.name;
|
|
311
402
|
return {
|
|
403
|
+
partnerId: para.partnerId,
|
|
312
404
|
address,
|
|
313
405
|
type: "EVM",
|
|
314
|
-
providerId:
|
|
315
|
-
provider:
|
|
406
|
+
providerId: providerId2,
|
|
407
|
+
provider: providerId2,
|
|
316
408
|
ensName,
|
|
317
409
|
ensAvatar
|
|
318
410
|
};
|
|
319
411
|
} catch (e) {
|
|
320
|
-
throw new Error((
|
|
412
|
+
throw new Error((_d = e == null ? void 0 : e.message) != null ? _d : e);
|
|
321
413
|
}
|
|
322
414
|
});
|
|
323
|
-
const disconnectBase = (
|
|
415
|
+
const disconnectBase = (_0, ..._1) => __async(this, [_0, ..._1], function* (providerId, { disconnectType } = {}) {
|
|
324
416
|
var _a;
|
|
325
417
|
if (!providerId) {
|
|
326
418
|
throw new Error("Provider ID is required to disconnect");
|
|
327
419
|
}
|
|
328
|
-
const connector =
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
isLinkingAccount.current = true;
|
|
420
|
+
const connector = findConnector(providerId);
|
|
421
|
+
if (disconnectType) {
|
|
422
|
+
disconnectTypeRef.current = disconnectType;
|
|
423
|
+
}
|
|
333
424
|
try {
|
|
334
|
-
yield connector.disconnect();
|
|
425
|
+
yield connector == null ? void 0 : connector.disconnect();
|
|
335
426
|
} catch (e) {
|
|
336
427
|
throw new Error((_a = e == null ? void 0 : e.message) != null ? _a : e);
|
|
428
|
+
} finally {
|
|
429
|
+
disconnectTypeRef.current = void 0;
|
|
337
430
|
}
|
|
338
431
|
});
|
|
339
432
|
const nonEip6963ConnectorsByRdns = {};
|
|
@@ -346,45 +439,56 @@ function EvmExternalWalletProvider({
|
|
|
346
439
|
}
|
|
347
440
|
}
|
|
348
441
|
});
|
|
349
|
-
const
|
|
442
|
+
const eip6963Names = connectors.filter((c) => isEIP6963Connector(c)).map((c) => c.name);
|
|
350
443
|
const dedupedConnectors = connectors.map((c) => {
|
|
351
|
-
var _a, _b
|
|
444
|
+
var _a, _b;
|
|
352
445
|
if ((_a = c.paraDetails) == null ? void 0 : _a.isWalletConnectModalConnector) {
|
|
353
446
|
return;
|
|
354
447
|
}
|
|
355
|
-
if (!isEIP6963Connector(c) &&
|
|
448
|
+
if (!isEIP6963Connector(c) && eip6963Names.includes(c.name)) {
|
|
356
449
|
return;
|
|
357
450
|
}
|
|
358
451
|
if (isEIP6963Connector(c)) {
|
|
359
452
|
const paraMetadata = nonEip6963ConnectorsByRdns[c.id];
|
|
360
453
|
return __spreadProps(__spreadValues({}, c), { paraDetails: paraMetadata });
|
|
361
454
|
}
|
|
362
|
-
if (((
|
|
455
|
+
if (((_b = c.paraDetails) == null ? void 0 : _b.internalId) === "WALLETCONNECT" && walletConnectModalConnector) {
|
|
363
456
|
return __spreadProps(__spreadValues({}, c), { walletConnectModalConnector });
|
|
364
457
|
}
|
|
365
458
|
return c;
|
|
366
459
|
}).filter((c) => !!c);
|
|
367
460
|
const wallets = dedupedConnectors.map((c) => {
|
|
368
|
-
var _a, _b, _c;
|
|
461
|
+
var _a, _b, _c, _d, _e;
|
|
369
462
|
if (((_a = c.paraDetails) == null ? void 0 : _a.internalId) === "SAFE" && (typeof window === "undefined" || window.parent === window)) {
|
|
370
463
|
return void 0;
|
|
371
464
|
}
|
|
372
465
|
const connector = __spreadValues(__spreadValues({}, c), c.paraDetails);
|
|
373
|
-
const
|
|
374
|
-
|
|
466
|
+
const isInjected = !c.paraDetails && eip6963Names.includes(c.name);
|
|
467
|
+
if (isInjected && connectors.some((c2) => {
|
|
468
|
+
var _a2;
|
|
469
|
+
return ((_a2 = c2.paraDetails) == null ? void 0 : _a2.rdns) === c2.id;
|
|
470
|
+
})) {
|
|
471
|
+
return void 0;
|
|
472
|
+
}
|
|
473
|
+
return __spreadProps(__spreadValues({}, connector), {
|
|
474
|
+
// Using name here since that's the only common id across the networks
|
|
475
|
+
id: connector.name,
|
|
476
|
+
internalId: (_b = connector.internalId) != null ? _b : connector.name,
|
|
477
|
+
isExtension: (_c = connector.isExtension) != null ? _c : isInjected,
|
|
478
|
+
installed: (_d = connector.installed) != null ? _d : isInjected,
|
|
479
|
+
iconUrl: (_e = connector.iconUrl) != null ? _e : connector.icon,
|
|
375
480
|
connect: () => connect(connector),
|
|
376
481
|
connectMobile: (manual) => connectMobile(connector, manual),
|
|
377
482
|
type: "EVM"
|
|
378
|
-
})
|
|
483
|
+
});
|
|
379
484
|
}).filter(Boolean);
|
|
380
485
|
const getConnectorInfo = (connector) => {
|
|
381
486
|
const paraDetails = connector.paraDetails;
|
|
382
|
-
const
|
|
383
|
-
const withFullParaAuth = walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(providerId);
|
|
487
|
+
const withFullParaAuth = walletsWithFullAuth === "ALL" || (walletsWithFullAuth == null ? void 0 : walletsWithFullAuth.includes(paraDetails == null ? void 0 : paraDetails.internalId));
|
|
384
488
|
return {
|
|
385
489
|
type: "EVM",
|
|
386
|
-
providerId,
|
|
387
|
-
provider:
|
|
490
|
+
providerId: connector.name,
|
|
491
|
+
provider: connector.name,
|
|
388
492
|
withFullParaAuth
|
|
389
493
|
};
|
|
390
494
|
};
|
|
@@ -404,10 +508,10 @@ function EvmExternalWalletProvider({
|
|
|
404
508
|
}
|
|
405
509
|
);
|
|
406
510
|
if (!connection) {
|
|
407
|
-
return
|
|
511
|
+
return { isPresent: false };
|
|
408
512
|
}
|
|
409
513
|
const address = (_a = connection == null ? void 0 : connection.accounts) == null ? void 0 : _a[0];
|
|
410
|
-
return address ? { isConnected: true, address } : { isConnected: false };
|
|
514
|
+
return address ? { isPresent: true, isConnected: true, address } : { isPresent: true, isConnected: false };
|
|
411
515
|
}, [connections]);
|
|
412
516
|
const connectParaEmbedded = useCallback(() => __async(this, null, function* () {
|
|
413
517
|
const paraConnectorInstance = connectors.find((c) => c.id === "para");
|
|
@@ -438,6 +542,7 @@ function EvmExternalWalletProvider({
|
|
|
438
542
|
username,
|
|
439
543
|
avatar: ensAvatar,
|
|
440
544
|
disconnect: disconnectAsync,
|
|
545
|
+
disconnectStatus,
|
|
441
546
|
switchChain,
|
|
442
547
|
connectParaEmbedded,
|
|
443
548
|
signMessage,
|
|
@@ -445,7 +550,8 @@ function EvmExternalWalletProvider({
|
|
|
445
550
|
getWalletBalance,
|
|
446
551
|
requestInfo,
|
|
447
552
|
disconnectBase,
|
|
448
|
-
farcasterStatus
|
|
553
|
+
farcasterStatus,
|
|
554
|
+
verificationStage
|
|
449
555
|
}, externalHooks),
|
|
450
556
|
children
|
|
451
557
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "../chunk-MMUBH76A.js";
|
|
8
8
|
import { jsx } from "react/jsx-runtime";
|
|
9
9
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
-
import { createConfig, WagmiProvider } from "wagmi";
|
|
10
|
+
import { createConfig as createWagmiConfig, WagmiProvider } from "wagmi";
|
|
11
11
|
import { connectorsForWallets } from "../wallets/connectorsForWallets.js";
|
|
12
12
|
import { http } from "viem";
|
|
13
13
|
import { computeWalletConnectMetaData } from "../utils/computeWalletConnectMetaData.js";
|
|
@@ -30,16 +30,14 @@ function ParaEvmProvider({
|
|
|
30
30
|
config: _config,
|
|
31
31
|
wagmiProviderProps
|
|
32
32
|
}) {
|
|
33
|
-
const prevWallets = useRef(null);
|
|
34
33
|
const para = internalConfig.para;
|
|
35
|
-
const [config, setConfig] = useState(null);
|
|
36
34
|
const _a = _config, {
|
|
37
35
|
projectId,
|
|
38
36
|
appName,
|
|
39
37
|
appDescription,
|
|
40
38
|
appIcon,
|
|
41
39
|
appUrl,
|
|
42
|
-
wallets,
|
|
40
|
+
wallets: propsWallets,
|
|
43
41
|
chains,
|
|
44
42
|
transports,
|
|
45
43
|
paraConnectorOptions
|
|
@@ -54,6 +52,10 @@ function ParaEvmProvider({
|
|
|
54
52
|
"transports",
|
|
55
53
|
"paraConnectorOptions"
|
|
56
54
|
]);
|
|
55
|
+
const propsWalletList = useMemo(() => {
|
|
56
|
+
return resolveWalletList(propsWallets != null ? propsWallets : []);
|
|
57
|
+
}, [propsWallets]);
|
|
58
|
+
const prevWallets = useRef(propsWalletList);
|
|
57
59
|
const paraConnectorInstance = useMemo(() => {
|
|
58
60
|
return paraConnector({
|
|
59
61
|
para,
|
|
@@ -63,52 +65,54 @@ function ParaEvmProvider({
|
|
|
63
65
|
options: paraConnectorOptions != null ? paraConnectorOptions : {}
|
|
64
66
|
});
|
|
65
67
|
}, [para]);
|
|
68
|
+
const createConfig = (walletList, createFarcasterConnector) => {
|
|
69
|
+
const existing = getWagmiConfig();
|
|
70
|
+
if (existing && prevWallets.current === walletList) {
|
|
71
|
+
return existing;
|
|
72
|
+
}
|
|
73
|
+
prevWallets.current = walletList;
|
|
74
|
+
const wcMetadata = computeWalletConnectMetaData({ appName, appDescription, appUrl, appIcon });
|
|
75
|
+
const baseConnectors = connectorsForWallets(walletList, {
|
|
76
|
+
para,
|
|
77
|
+
createFarcasterConnector,
|
|
78
|
+
projectId,
|
|
79
|
+
appName,
|
|
80
|
+
appDescription,
|
|
81
|
+
appUrl,
|
|
82
|
+
appIcon,
|
|
83
|
+
walletConnectParameters: { metadata: wcMetadata }
|
|
84
|
+
});
|
|
85
|
+
const allConnectors = [...baseConnectors, paraConnectorInstance];
|
|
86
|
+
const createdConfig = createWagmiConfig(__spreadProps(__spreadValues({
|
|
87
|
+
ssr: true
|
|
88
|
+
}, wagmiConfigParams), {
|
|
89
|
+
chains,
|
|
90
|
+
transports: transports || createDefaultTransports(chains),
|
|
91
|
+
connectors: allConnectors
|
|
92
|
+
}));
|
|
93
|
+
setWagmiConfig(createdConfig);
|
|
94
|
+
return createdConfig;
|
|
95
|
+
};
|
|
96
|
+
const [config, setConfig] = useState(null);
|
|
66
97
|
useEffect(() => {
|
|
67
|
-
|
|
98
|
+
if (!para.isReady) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const initializeConfig = () => __async(this, null, function* () {
|
|
68
102
|
var _a2;
|
|
69
|
-
let createFarcasterConnector = null;
|
|
70
103
|
if (para.isFarcasterMiniApp) {
|
|
104
|
+
let createFarcasterConnector = null;
|
|
71
105
|
try {
|
|
72
106
|
createFarcasterConnector = (_a2 = (yield import("@farcaster/miniapp-wagmi-connector")).farcasterMiniApp) != null ? _a2 : void 0;
|
|
73
107
|
} catch (e) {
|
|
74
108
|
}
|
|
109
|
+
setConfig(createConfig([...propsWalletList, farcasterWallet], createFarcasterConnector));
|
|
110
|
+
} else {
|
|
111
|
+
setConfig(createConfig([...propsWalletList]));
|
|
75
112
|
}
|
|
76
|
-
if (!prevWallets.current) {
|
|
77
|
-
prevWallets.current = wallets;
|
|
78
|
-
}
|
|
79
|
-
const existing = getWagmiConfig();
|
|
80
|
-
if (existing && prevWallets.current === wallets) return existing;
|
|
81
|
-
const wcMetadata = computeWalletConnectMetaData({ appName, appDescription, appUrl, appIcon });
|
|
82
|
-
const walletFactories = resolveWalletList(wallets);
|
|
83
|
-
const baseConnectors = connectorsForWallets(
|
|
84
|
-
[...walletFactories, ...createFarcasterConnector ? [farcasterWallet] : []],
|
|
85
|
-
{
|
|
86
|
-
para,
|
|
87
|
-
createFarcasterConnector,
|
|
88
|
-
projectId,
|
|
89
|
-
appName,
|
|
90
|
-
appDescription,
|
|
91
|
-
appUrl,
|
|
92
|
-
appIcon,
|
|
93
|
-
walletConnectParameters: { metadata: wcMetadata }
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
const allConnectors = [...baseConnectors, paraConnectorInstance];
|
|
97
|
-
const createdConfig = createConfig(__spreadProps(__spreadValues({
|
|
98
|
-
ssr: true
|
|
99
|
-
}, wagmiConfigParams), {
|
|
100
|
-
chains,
|
|
101
|
-
transports: transports || createDefaultTransports(chains),
|
|
102
|
-
connectors: allConnectors
|
|
103
|
-
}));
|
|
104
|
-
setWagmiConfig(createdConfig);
|
|
105
|
-
setConfig(createdConfig);
|
|
106
|
-
prevWallets.current = wallets;
|
|
107
113
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
}, [wallets, para.isReady, para.isFarcasterMiniApp, paraConnectorInstance]);
|
|
114
|
+
initializeConfig();
|
|
115
|
+
}, [para.isFarcasterMiniApp, para.isReady, propsWalletList]);
|
|
112
116
|
if (!config) {
|
|
113
117
|
return null;
|
|
114
118
|
}
|
package/dist/types/Wallet.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { Connector, CreateConnectorFn } from 'wagmi';
|
|
2
|
-
import { WalletConnectParameters } from 'wagmi/connectors';
|
|
3
2
|
import { CoinbaseWalletOptions } from '../wallets/connectors/coinbase/coinbase.js';
|
|
4
3
|
import { WalletConnectWalletOptions } from '../wallets/connectors/walletConnect/walletConnect.js';
|
|
5
4
|
import { type WalletMetadata } from '@getpara/react-common';
|
|
6
5
|
import ParaWeb from '@getpara/web-sdk';
|
|
6
|
+
import { WalletConnectParameters } from '../connectors/walletConnect.js';
|
|
7
7
|
export type Wallet = {
|
|
8
8
|
createConnector?: (walletDetails: WalletDetailsParams) => CreateConnectorFn;
|
|
9
9
|
createMobileConnector?: (walletDetails: WalletDetailsParams) => CreateConnectorFn;
|
|
10
10
|
getUri?: (uri: string) => string;
|
|
11
|
+
deeplinkUri?: string;
|
|
11
12
|
} & WalletMetadata;
|
|
12
13
|
export interface DefaultWalletOptions {
|
|
13
14
|
para?: ParaWeb;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
__spreadValues
|
|
5
5
|
} from "../chunk-MMUBH76A.js";
|
|
6
6
|
import { createConnector } from "wagmi";
|
|
7
|
-
import { walletConnect } from "
|
|
7
|
+
import { walletConnect } from "../connectors/walletConnect.js";
|
|
8
8
|
const walletConnectInstances = /* @__PURE__ */ new Map();
|
|
9
9
|
const getOrCreateWalletConnectInstance = ({
|
|
10
10
|
projectId,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Connector } from 'wagmi';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const emitWalletConnectUri: (connector: Connector, uriConverter?: (uri: string) => string) => Promise<void>;
|
|
@@ -2,24 +2,27 @@
|
|
|
2
2
|
import {
|
|
3
3
|
__async
|
|
4
4
|
} from "../chunk-MMUBH76A.js";
|
|
5
|
-
const
|
|
5
|
+
const emitWalletConnectUri = (connector, uriConverter) => __async(void 0, null, function* () {
|
|
6
6
|
var _a, _b;
|
|
7
|
+
if (typeof window === "undefined") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
7
10
|
const provider = yield (_b = (_a = connector.getProvider) == null ? void 0 : _a.call(connector)) != null ? _b : void 0;
|
|
8
11
|
if (connector.type === "coinbaseWallet" && (provider == null ? void 0 : provider.qrUrl)) {
|
|
9
|
-
|
|
12
|
+
window.dispatchEvent(new CustomEvent("PARA_WALLETCONNECT_URI_READY", { detail: provider.qrUrl }));
|
|
10
13
|
}
|
|
11
14
|
if (!provider || typeof provider.once !== "function" && typeof provider.on !== "function") {
|
|
12
15
|
throw new Error("display_uri event not supported for this connector");
|
|
13
16
|
}
|
|
14
17
|
const listen = typeof provider.once === "function" ? provider.once.bind(provider) : provider.on.bind(provider);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const cancel = setTimeout(() => console.error("display_uri event not emitted"), 1e4);
|
|
19
|
+
listen("display_uri", (uri) => {
|
|
20
|
+
clearTimeout(cancel);
|
|
21
|
+
window.dispatchEvent(
|
|
22
|
+
new CustomEvent("PARA_WALLETCONNECT_URI_READY", { detail: uriConverter ? uriConverter(uri) : uri })
|
|
23
|
+
);
|
|
21
24
|
});
|
|
22
25
|
});
|
|
23
26
|
export {
|
|
24
|
-
|
|
27
|
+
emitWalletConnectUri
|
|
25
28
|
};
|
|
@@ -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
|
|
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://
|
|
16
|
+
downloadUrl: "https://farcaster.xyz/",
|
|
17
17
|
createConnector: (walletDetails) => createConnector((config) => __spreadValues(__spreadValues({}, createFarcasterConnector()(config)), walletDetails))
|
|
18
18
|
};
|
|
19
19
|
};
|
|
@@ -55,11 +55,13 @@ const metaMaskWallet = ({ projectId, walletConnectParameters }) => {
|
|
|
55
55
|
if (providerMapTarget) {
|
|
56
56
|
metaMaskTarget = providerMapTarget;
|
|
57
57
|
}
|
|
58
|
+
const deeplinkUri = "metamask://";
|
|
59
|
+
const baseUri = isAndroid() ? `${deeplinkUri}wc` : isIOS() ? !isTelegram() ? (
|
|
60
|
+
// currently broken in MetaMask v6.5.0 https://github.com/MetaMask/metamask-mobile/issues/6457
|
|
61
|
+
`${deeplinkUri}wc`
|
|
62
|
+
) : "https://metamask.app.link/wc" : "https://metamask.app.link/wc";
|
|
58
63
|
const getUri = (uri) => {
|
|
59
|
-
return
|
|
60
|
-
// currently broken in MetaMask v6.5.0 https://github.com/MetaMask/metamask-mobile/issues/6457
|
|
61
|
-
`metamask://wc?uri=${encodeURIComponent(uri)}`
|
|
62
|
-
) : `https://metamask.app.link/wc?uri=${encodeURIComponent(uri)}` : `https://metamask.app.link/wc?uri=${encodeURIComponent(uri)}`;
|
|
64
|
+
return `${baseUri}?uri=${encodeURIComponent(uri)}`;
|
|
63
65
|
};
|
|
64
66
|
return {
|
|
65
67
|
id: "metaMask",
|
|
@@ -72,6 +74,7 @@ const metaMaskWallet = ({ projectId, walletConnectParameters }) => {
|
|
|
72
74
|
isMobile: true,
|
|
73
75
|
downloadUrl: "https://metamask.io/download/",
|
|
74
76
|
getUri,
|
|
77
|
+
deeplinkUri,
|
|
75
78
|
createConnector: isMetaMaskInjected ? getInjectedConnector({
|
|
76
79
|
target: metaMaskTarget
|
|
77
80
|
}) : getWalletConnectConnector({
|
|
@@ -6,8 +6,13 @@ import { getWalletConnectConnector } from "../../../utils/getWalletConnectConnec
|
|
|
6
6
|
import { icon } from "./rainbowIcon.js";
|
|
7
7
|
const rainbowWallet = ({ projectId, walletConnectParameters }) => {
|
|
8
8
|
const isRainbowInjected = hasInjectedProvider({ flag: "isRainbow" });
|
|
9
|
+
const deeplinkUri = "rainbow://";
|
|
10
|
+
const baseUri = isAndroid() ? `${deeplinkUri}wc` : isIOS() ? !isTelegram() ? (
|
|
11
|
+
// currently broken in MetaMask v6.5.0 https://github.com/MetaMask/metamask-mobile/issues/6457
|
|
12
|
+
`${deeplinkUri}wc`
|
|
13
|
+
) : "https://rnbwapp.com/wc" : "https://rnbwapp.com/wc";
|
|
9
14
|
const getUri = (uri) => {
|
|
10
|
-
return
|
|
15
|
+
return `${baseUri}?uri=${encodeURIComponent(uri)}`;
|
|
11
16
|
};
|
|
12
17
|
return {
|
|
13
18
|
id: "rainbow",
|
|
@@ -20,6 +25,7 @@ const rainbowWallet = ({ projectId, walletConnectParameters }) => {
|
|
|
20
25
|
isMobile: true,
|
|
21
26
|
downloadUrl: "https://rainbow.me/",
|
|
22
27
|
getUri,
|
|
28
|
+
deeplinkUri,
|
|
23
29
|
createConnector: isRainbowInjected ? getInjectedConnector({ flag: "isRainbow" }) : getWalletConnectConnector({
|
|
24
30
|
projectId,
|
|
25
31
|
walletConnectParameters
|
|
@@ -9,8 +9,10 @@ const zerionWallet = ({ projectId, walletConnectParameters }) => {
|
|
|
9
9
|
namespace: "zerionWallet",
|
|
10
10
|
flag: "isZerion"
|
|
11
11
|
});
|
|
12
|
+
const deeplinkUri = "zerion://";
|
|
13
|
+
const baseUri = isTelegram() && isIOS() ? "https://app.zerion.io/wc" : `${deeplinkUri}wc`;
|
|
12
14
|
const getUri = (uri) => {
|
|
13
|
-
return
|
|
15
|
+
return `${baseUri}?uri=${encodeURIComponent(uri)}`;
|
|
14
16
|
};
|
|
15
17
|
return {
|
|
16
18
|
id: "zerion",
|
|
@@ -22,6 +24,7 @@ const zerionWallet = ({ projectId, walletConnectParameters }) => {
|
|
|
22
24
|
isExtension: true,
|
|
23
25
|
isMobile: true,
|
|
24
26
|
getUri,
|
|
27
|
+
deeplinkUri,
|
|
25
28
|
downloadUrl: "https://zerion.io/download",
|
|
26
29
|
createConnector: isZerionInjected ? getInjectedConnector({
|
|
27
30
|
namespace: "zerionWallet",
|
package/package.json
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/evm-wallet-connectors",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@coinbase/wallet-sdk": "4.3.0",
|
|
6
|
-
"@getpara/wagmi-v2-connector": "2.0.0
|
|
7
|
-
"@getpara/web-sdk": "2.0.0
|
|
6
|
+
"@getpara/wagmi-v2-connector": "2.0.0",
|
|
7
|
+
"@getpara/web-sdk": "2.0.0",
|
|
8
|
+
"@walletconnect/ethereum-provider": "2.23.0",
|
|
8
9
|
"zustand": "^4.5.2",
|
|
9
10
|
"zustand-sync-tabs": "^0.2.2"
|
|
10
11
|
},
|
|
11
12
|
"devDependencies": {
|
|
12
|
-
"@getpara/react-common": "2.0.0
|
|
13
|
+
"@getpara/react-common": "2.0.0",
|
|
13
14
|
"@tanstack/react-query": "^5.74.0",
|
|
14
15
|
"@types/react": "^18.0.31",
|
|
15
16
|
"@types/react-dom": "^18.2.7",
|
|
16
17
|
"typescript": "^5.8.3",
|
|
17
|
-
"viem": "^2.
|
|
18
|
+
"viem": "^2.38.5",
|
|
18
19
|
"wagmi": "^2.14.16"
|
|
19
20
|
},
|
|
20
21
|
"exports": {
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"dist",
|
|
26
27
|
"package.json"
|
|
27
28
|
],
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "a64b6aa9b3c481a2d955022f621e495fb55e549e",
|
|
29
30
|
"main": "dist/index.js",
|
|
30
31
|
"peerDependencies": {
|
|
31
32
|
"@farcaster/miniapp-wagmi-connector": "^1.0.0",
|