@getpara/evm-wallet-connectors 2.0.0-alpha.7 → 2.0.0-alpha.71
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/index.d.ts +4 -2
- package/dist/index.js +5 -1
- package/dist/providers/EvmExternalWalletContext.d.ts +7 -35
- package/dist/providers/EvmExternalWalletContext.js +280 -86
- 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 +5 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/utils/getWalletConnectConnector.js +1 -1
- package/dist/utils/getWalletConnectUri.d.ts +1 -1
- package/dist/utils/getWalletConnectUri.js +20 -14
- 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 +8 -4
- 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 +8 -1
- 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 +5 -1
- package/dist/wallets/connectorsForWallets.d.ts +4 -1
- package/dist/wallets/connectorsForWallets.js +14 -3
- package/package.json +34 -26
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
|
+
};
|
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: connectedWalletProp, includeWalletVerification, connectionOnly, }: EvmExternalWalletProviderConfig & PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|