@aurum-sdk/core 0.2.8 → 0.3.0-canary.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/dist/{Aurum-B0Okb4Qv.d.mts → Aurum-BoIhHFKm.d.mts} +25 -2
- package/dist/{Aurum-B0Okb4Qv.d.ts → Aurum-BoIhHFKm.d.ts} +25 -2
- package/dist/BraveAdapter-GTB4OCMH.mjs +153 -0
- package/dist/BraveAdapter-XGUK2CH7.js +153 -0
- package/dist/CoinbaseWalletAdapter-A6RMB5AG.mjs +144 -0
- package/dist/CoinbaseWalletAdapter-EV44SYND.js +144 -0
- package/dist/EmailAdapter-Q63KI6DV.js +212 -0
- package/dist/EmailAdapter-T5FVQLCY.mjs +212 -0
- package/dist/MetaMaskAdapter-KX7EJ73V.mjs +152 -0
- package/dist/MetaMaskAdapter-X5MUH2DT.js +152 -0
- package/dist/PhantomAdapter-C7PQCQHP.js +151 -0
- package/dist/PhantomAdapter-REAJL27H.mjs +151 -0
- package/dist/RabbyAdapter-4SEMVMND.mjs +146 -0
- package/dist/RabbyAdapter-QLBUCYWB.js +146 -0
- package/dist/WalletConnectAdapter-J5J3ILFG.mjs +540 -0
- package/dist/WalletConnectAdapter-NKQZY25A.js +540 -0
- package/dist/chunk-4S5E6KOY.mjs +21 -0
- package/dist/{chunk-K64T6WW3.js → chunk-4XQZ5JBS.js} +420 -6850
- package/dist/{chunk-GMFEFDGS.mjs → chunk-7WLUHQA3.mjs} +348 -6778
- package/dist/chunk-ALDVMRQG.js +6558 -0
- package/dist/chunk-D7M3K26I.mjs +6558 -0
- package/dist/chunk-PFK6YHOX.mjs +15 -0
- package/dist/chunk-QOCN4F47.js +21 -0
- package/dist/chunk-XVRTCAR4.js +15 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +304 -1573
- package/dist/index.mjs +243 -1512
- package/dist/{index.web-Q2L3EMC3.mjs → index.web-NX7JZBIY.mjs} +267 -267
- package/dist/{index.web-V7DLWC7H.js → index.web-OPNRZHYZ.js} +267 -267
- package/dist/widgets.d.mts +1 -1
- package/dist/widgets.d.ts +1 -1
- package/dist/widgets.js +14 -12
- package/dist/widgets.mjs +3 -1
- package/package.json +3 -7
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkQOCN4F47js = require('./chunk-QOCN4F47.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkALDVMRQGjs = require('./chunk-ALDVMRQG.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkQIPVNM7Tjs = require('./chunk-QIPVNM7T.js');
|
|
13
|
+
|
|
14
|
+
// src/wallet-adapters/WalletConnectAdapter.ts
|
|
15
|
+
_chunkQIPVNM7Tjs.init_polyfills.call(void 0, );
|
|
16
|
+
|
|
17
|
+
// src/constants/adapters.ts
|
|
18
|
+
_chunkQIPVNM7Tjs.init_polyfills.call(void 0, );
|
|
19
|
+
var WALLETCONNECT_NAMESPACE = {
|
|
20
|
+
eip155: {
|
|
21
|
+
methods: [
|
|
22
|
+
// Transaction methods
|
|
23
|
+
"eth_sendTransaction",
|
|
24
|
+
"eth_signTransaction",
|
|
25
|
+
"eth_sendRawTransaction",
|
|
26
|
+
// Signing methods
|
|
27
|
+
"eth_sign",
|
|
28
|
+
"personal_sign",
|
|
29
|
+
"eth_signTypedData",
|
|
30
|
+
"eth_signTypedData_v3",
|
|
31
|
+
"eth_signTypedData_v4",
|
|
32
|
+
// Account methods
|
|
33
|
+
"eth_accounts",
|
|
34
|
+
"eth_requestAccounts",
|
|
35
|
+
// Chain management
|
|
36
|
+
"wallet_switchEthereumChain",
|
|
37
|
+
"wallet_addEthereumChain",
|
|
38
|
+
// Permissions (EIP-2255)
|
|
39
|
+
"wallet_requestPermissions",
|
|
40
|
+
"wallet_getPermissions"
|
|
41
|
+
],
|
|
42
|
+
chains: [
|
|
43
|
+
// Ethereum
|
|
44
|
+
"eip155:1",
|
|
45
|
+
// Mainnet
|
|
46
|
+
"eip155:11155111",
|
|
47
|
+
// Sepolia
|
|
48
|
+
// Base
|
|
49
|
+
"eip155:8453",
|
|
50
|
+
// Mainnet
|
|
51
|
+
"eip155:84532",
|
|
52
|
+
// Sepolia
|
|
53
|
+
// Optimism
|
|
54
|
+
"eip155:10",
|
|
55
|
+
// Mainnet
|
|
56
|
+
"eip155:11155420",
|
|
57
|
+
// Sepolia
|
|
58
|
+
// Arbitrum
|
|
59
|
+
"eip155:42161",
|
|
60
|
+
// Mainnet
|
|
61
|
+
"eip155:421614",
|
|
62
|
+
// Sepolia
|
|
63
|
+
// BNB Chain
|
|
64
|
+
"eip155:56",
|
|
65
|
+
// Mainnet
|
|
66
|
+
"eip155:97",
|
|
67
|
+
// Testnet
|
|
68
|
+
// Polygon
|
|
69
|
+
"eip155:137",
|
|
70
|
+
// Mainnet
|
|
71
|
+
"eip155:80002",
|
|
72
|
+
// Amoy
|
|
73
|
+
// Fantom
|
|
74
|
+
"eip155:250",
|
|
75
|
+
// Mainnet
|
|
76
|
+
"eip155:4002",
|
|
77
|
+
// Testnet
|
|
78
|
+
// Linea
|
|
79
|
+
"eip155:59144",
|
|
80
|
+
// Mainnet
|
|
81
|
+
"eip155:59141",
|
|
82
|
+
// Sepolia
|
|
83
|
+
// Gnosis
|
|
84
|
+
"eip155:100",
|
|
85
|
+
// Mainnet
|
|
86
|
+
"eip155:10200",
|
|
87
|
+
// Chiado
|
|
88
|
+
// Polygon zkEVM
|
|
89
|
+
"eip155:1101",
|
|
90
|
+
// Mainnet
|
|
91
|
+
"eip155:2442",
|
|
92
|
+
// Cardona
|
|
93
|
+
// Avalanche C-Chain
|
|
94
|
+
"eip155:43114",
|
|
95
|
+
// Mainnet
|
|
96
|
+
"eip155:43113"
|
|
97
|
+
// Fuji
|
|
98
|
+
],
|
|
99
|
+
events: ["chainChanged", "accountsChanged"]
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/wallet-adapters/WalletConnectAdapter.ts
|
|
104
|
+
function extractAddressFromSession(namespaces) {
|
|
105
|
+
const accounts = _optionalChain([namespaces, 'optionalAccess', _ => _.eip155, 'optionalAccess', _2 => _2.accounts]) || [];
|
|
106
|
+
const firstAccount = accounts[0];
|
|
107
|
+
return _nullishCoalesce(_optionalChain([firstAccount, 'optionalAccess', _3 => _3.split, 'call', _4 => _4(":"), 'access', _5 => _5[2]]), () => ( null));
|
|
108
|
+
}
|
|
109
|
+
var WalletConnectAdapter = class {
|
|
110
|
+
constructor(config) {
|
|
111
|
+
this.id = _chunkALDVMRQGjs.WalletId.WalletConnect;
|
|
112
|
+
this.name = _chunkALDVMRQGjs.WalletName.WalletConnect;
|
|
113
|
+
this.icon = _nullishCoalesce(_chunkALDVMRQGjs.getLogoDataUri.call(void 0, _chunkALDVMRQGjs.WalletId.WalletConnect, "brand"), () => ( ""));
|
|
114
|
+
this.hide = false;
|
|
115
|
+
this.downloadUrl = null;
|
|
116
|
+
this.wcDeepLinkUrl = null;
|
|
117
|
+
this.modal = null;
|
|
118
|
+
this.wagmiAdapter = null;
|
|
119
|
+
this.universalProvider = null;
|
|
120
|
+
this.provider = null;
|
|
121
|
+
this.address = null;
|
|
122
|
+
this.connectionUri = null;
|
|
123
|
+
this.accountsChangedCallback = null;
|
|
124
|
+
this.chainChangedCallback = null;
|
|
125
|
+
this.disconnectCallback = null;
|
|
126
|
+
this.sessionUpdateHandler = null;
|
|
127
|
+
this.unsubscribeFunctions = [];
|
|
128
|
+
this.initPromise = null;
|
|
129
|
+
this.lastKnownAccounts = [];
|
|
130
|
+
this.lastKnownChainId = null;
|
|
131
|
+
this.config = config;
|
|
132
|
+
}
|
|
133
|
+
async ensureInitialized() {
|
|
134
|
+
if (this.modal) return;
|
|
135
|
+
if (!this.initPromise) {
|
|
136
|
+
this.initPromise = this.initializeAppKit();
|
|
137
|
+
}
|
|
138
|
+
await this.initPromise;
|
|
139
|
+
}
|
|
140
|
+
async initializeAppKit() {
|
|
141
|
+
if (typeof window === "undefined") return;
|
|
142
|
+
const [{ createAppKit }, { WagmiAdapter }, { mainnet }] = await Promise.all([
|
|
143
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("@reown/appkit"))),
|
|
144
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("@reown/appkit-adapter-wagmi"))),
|
|
145
|
+
Promise.resolve().then(() => _interopRequireWildcard(require("@reown/appkit/networks")))
|
|
146
|
+
]);
|
|
147
|
+
const networks = [mainnet];
|
|
148
|
+
this.wagmiAdapter = new WagmiAdapter({
|
|
149
|
+
projectId: this.config.projectId,
|
|
150
|
+
networks,
|
|
151
|
+
ssr: true
|
|
152
|
+
});
|
|
153
|
+
this.modal = createAppKit({
|
|
154
|
+
adapters: [this.wagmiAdapter],
|
|
155
|
+
networks,
|
|
156
|
+
projectId: this.config.projectId,
|
|
157
|
+
metadata: {
|
|
158
|
+
name: this.config.appName,
|
|
159
|
+
description: this.config.appName,
|
|
160
|
+
url: window.location.origin,
|
|
161
|
+
icons: []
|
|
162
|
+
},
|
|
163
|
+
allowUnsupportedChain: true,
|
|
164
|
+
themeMode: this.config.theme,
|
|
165
|
+
themeVariables: {
|
|
166
|
+
"--apkt-z-index": this.config.modalZIndex + 1
|
|
167
|
+
},
|
|
168
|
+
features: {
|
|
169
|
+
analytics: _nullishCoalesce(this.config.telemetry, () => ( false))
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
this.universalProvider = await _asyncNullishCoalesce(await this.modal.getUniversalProvider(), async () => ( null));
|
|
173
|
+
this.setupEventListeners();
|
|
174
|
+
}
|
|
175
|
+
setupEventListeners() {
|
|
176
|
+
if (!this.modal) return;
|
|
177
|
+
const unsubscribeProviders = this.modal.subscribeProviders((state) => {
|
|
178
|
+
const eip155Provider = state["eip155"];
|
|
179
|
+
this.provider = eip155Provider || null;
|
|
180
|
+
if (!eip155Provider) {
|
|
181
|
+
this.address = null;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
this.unsubscribeFunctions.push(unsubscribeProviders);
|
|
185
|
+
if (this.universalProvider) {
|
|
186
|
+
this.universalProvider.on("display_uri", (uri) => {
|
|
187
|
+
this.connectionUri = uri;
|
|
188
|
+
if (typeof window !== "undefined") {
|
|
189
|
+
window.dispatchEvent(new CustomEvent("walletconnect:uri", { detail: { uri } }));
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
this.universalProvider.on("session_delete", () => {
|
|
193
|
+
this.handleRemoteDisconnect();
|
|
194
|
+
});
|
|
195
|
+
this.universalProvider.on("session_expire", () => {
|
|
196
|
+
this.handleRemoteDisconnect();
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Called when user disconnects from the wallet side (mobile app) */
|
|
201
|
+
handleRemoteDisconnect() {
|
|
202
|
+
this.connectionUri = null;
|
|
203
|
+
this.address = null;
|
|
204
|
+
this.provider = null;
|
|
205
|
+
this.lastKnownAccounts = [];
|
|
206
|
+
this.lastKnownChainId = null;
|
|
207
|
+
if (this.accountsChangedCallback) {
|
|
208
|
+
this.accountsChangedCallback([]);
|
|
209
|
+
}
|
|
210
|
+
if (this.disconnectCallback) {
|
|
211
|
+
this.disconnectCallback();
|
|
212
|
+
}
|
|
213
|
+
if (typeof window !== "undefined") {
|
|
214
|
+
window.dispatchEvent(new CustomEvent("walletconnect:disconnect"));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
syncAddressFromWagmi() {
|
|
218
|
+
if (!_optionalChain([this, 'access', _6 => _6.wagmiAdapter, 'optionalAccess', _7 => _7.wagmiConfig])) return;
|
|
219
|
+
const { state } = this.wagmiAdapter.wagmiConfig;
|
|
220
|
+
if (state.current && state.connections) {
|
|
221
|
+
const connection = state.connections.get(state.current);
|
|
222
|
+
if (_optionalChain([connection, 'optionalAccess', _8 => _8.accounts, 'optionalAccess', _9 => _9[0]])) {
|
|
223
|
+
this.address = connection.accounts[0];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async syncProviderFromModal() {
|
|
228
|
+
if (!this.modal) return;
|
|
229
|
+
try {
|
|
230
|
+
const getProvidersFn = this.modal.getProviders;
|
|
231
|
+
if (typeof getProvidersFn === "function") {
|
|
232
|
+
const providers = getProvidersFn.call(this.modal);
|
|
233
|
+
const eip155Provider = _optionalChain([providers, 'optionalAccess', _10 => _10["eip155"]]);
|
|
234
|
+
if (eip155Provider) {
|
|
235
|
+
this.provider = eip155Provider;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (_optionalChain([this, 'access', _11 => _11.wagmiAdapter, 'optionalAccess', _12 => _12.wagmiConfig])) {
|
|
240
|
+
const { state } = this.wagmiAdapter.wagmiConfig;
|
|
241
|
+
if (state.current && state.connections) {
|
|
242
|
+
const connection = state.connections.get(state.current);
|
|
243
|
+
const connector = _optionalChain([connection, 'optionalAccess', _13 => _13.connector]);
|
|
244
|
+
if (connector && typeof connector.getProvider === "function") {
|
|
245
|
+
try {
|
|
246
|
+
const provider = await connector.getProvider();
|
|
247
|
+
if (provider) {
|
|
248
|
+
this.provider = provider;
|
|
249
|
+
}
|
|
250
|
+
} catch (error) {
|
|
251
|
+
_chunkALDVMRQGjs.sentryLogger.warn("Failed to get provider from wagmi connector", { error });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} catch (error) {
|
|
257
|
+
_chunkALDVMRQGjs.sentryLogger.warn("Failed to get provider from WalletConnect", { error });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
isInstalled() {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
getConnectionUri() {
|
|
264
|
+
return this.connectionUri;
|
|
265
|
+
}
|
|
266
|
+
/** Resets connection state for a fresh connection flow */
|
|
267
|
+
async resetConnectionState() {
|
|
268
|
+
this.connectionUri = null;
|
|
269
|
+
this.address = null;
|
|
270
|
+
this.lastKnownAccounts = [];
|
|
271
|
+
this.lastKnownChainId = null;
|
|
272
|
+
try {
|
|
273
|
+
const { state } = _optionalChain([this, 'access', _14 => _14.wagmiAdapter, 'optionalAccess', _15 => _15.wagmiConfig]) || {};
|
|
274
|
+
const connection = _optionalChain([state, 'optionalAccess', _16 => _16.current]) && _optionalChain([state, 'access', _17 => _17.connections, 'optionalAccess', _18 => _18.get, 'call', _19 => _19(state.current)]);
|
|
275
|
+
if (connection && typeof connection !== "string" && _optionalChain([connection, 'access', _20 => _20.connector, 'optionalAccess', _21 => _21.disconnect])) {
|
|
276
|
+
await connection.connector.disconnect();
|
|
277
|
+
}
|
|
278
|
+
} catch (e) {
|
|
279
|
+
}
|
|
280
|
+
if (_optionalChain([this, 'access', _22 => _22.modal, 'optionalAccess', _23 => _23.getIsConnectedState, 'call', _24 => _24()])) {
|
|
281
|
+
try {
|
|
282
|
+
await this.modal.disconnect("eip155");
|
|
283
|
+
} catch (e2) {
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (_optionalChain([this, 'access', _25 => _25.universalProvider, 'optionalAccess', _26 => _26.session])) {
|
|
287
|
+
try {
|
|
288
|
+
await this.universalProvider.disconnect();
|
|
289
|
+
} catch (e3) {
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
293
|
+
this.provider = null;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Connects via WalletConnect QR code flow.
|
|
297
|
+
* Emits walletconnect:uri event for QR code display.
|
|
298
|
+
*/
|
|
299
|
+
async connect() {
|
|
300
|
+
if (!this.config.projectId) throw _chunkQOCN4F47js.createConfigError.call(void 0, "WalletConnect");
|
|
301
|
+
await this.ensureInitialized();
|
|
302
|
+
if (!this.universalProvider) throw new Error("WalletConnect is not available");
|
|
303
|
+
await this.resetConnectionState();
|
|
304
|
+
try {
|
|
305
|
+
const session = await this.universalProvider.connect({ namespaces: WALLETCONNECT_NAMESPACE });
|
|
306
|
+
if (!session) throw new Error("Failed to establish WalletConnect session");
|
|
307
|
+
const address = extractAddressFromSession(session.namespaces);
|
|
308
|
+
if (!address) throw new Error("No accounts returned from WalletConnect");
|
|
309
|
+
this.provider = this.universalProvider;
|
|
310
|
+
this.address = address;
|
|
311
|
+
this.lastKnownAccounts = [address];
|
|
312
|
+
return { address, provider: this.provider, walletId: this.id };
|
|
313
|
+
} catch (error) {
|
|
314
|
+
this.connectionUri = null;
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Starts a WalletConnect session for headless/custom QR code flows.
|
|
320
|
+
* Returns the URI immediately and a function to wait for the connection.
|
|
321
|
+
*/
|
|
322
|
+
async startSession(timeout = 1e4) {
|
|
323
|
+
if (!this.config.projectId) throw new Error("WalletConnect projectId is required");
|
|
324
|
+
await this.ensureInitialized();
|
|
325
|
+
if (!this.universalProvider) throw new Error("WalletConnect is not available");
|
|
326
|
+
await this.resetConnectionState();
|
|
327
|
+
const uriPromise = new Promise((resolve, reject) => {
|
|
328
|
+
const timeoutId = setTimeout(() => reject(new Error("Timeout waiting for WalletConnect URI")), timeout);
|
|
329
|
+
this.universalProvider.once("display_uri", (uri2) => {
|
|
330
|
+
clearTimeout(timeoutId);
|
|
331
|
+
this.connectionUri = uri2;
|
|
332
|
+
resolve(uri2);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
const connectionPromise = (async () => {
|
|
336
|
+
const session = await this.universalProvider.connect({ namespaces: WALLETCONNECT_NAMESPACE });
|
|
337
|
+
if (!session) throw new Error("Failed to establish WalletConnect session");
|
|
338
|
+
const address = extractAddressFromSession(session.namespaces);
|
|
339
|
+
if (!address) throw new Error("No accounts returned from WalletConnect");
|
|
340
|
+
this.provider = this.universalProvider;
|
|
341
|
+
this.address = address;
|
|
342
|
+
this.lastKnownAccounts = [address];
|
|
343
|
+
return { address, provider: this.provider, walletId: this.id };
|
|
344
|
+
})();
|
|
345
|
+
const uri = await uriPromise;
|
|
346
|
+
return {
|
|
347
|
+
uri,
|
|
348
|
+
waitForConnection: async () => {
|
|
349
|
+
try {
|
|
350
|
+
return await connectionPromise;
|
|
351
|
+
} catch (error) {
|
|
352
|
+
this.connectionUri = null;
|
|
353
|
+
throw error;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Opens the AppKit modal for wallet selection.
|
|
360
|
+
* Used on mobile and when user clicks "Open Modal" button.
|
|
361
|
+
*/
|
|
362
|
+
async openModal() {
|
|
363
|
+
if (!this.config.projectId) throw _chunkQOCN4F47js.createConfigError.call(void 0, "WalletConnect");
|
|
364
|
+
await this.ensureInitialized();
|
|
365
|
+
if (!this.modal) throw new Error("AppKit is not available");
|
|
366
|
+
await this.resetConnectionState();
|
|
367
|
+
this.modal.open({ view: "AllWallets" });
|
|
368
|
+
return this.waitForModalConnection();
|
|
369
|
+
}
|
|
370
|
+
waitForModalConnection(timeout = 6e4) {
|
|
371
|
+
return new Promise((resolve, reject) => {
|
|
372
|
+
const startTime = Date.now();
|
|
373
|
+
let unsubscribe = null;
|
|
374
|
+
let resolved = false;
|
|
375
|
+
const cleanup = () => _optionalChain([unsubscribe, 'optionalCall', _27 => _27()]);
|
|
376
|
+
const checkConnection = async () => {
|
|
377
|
+
if (resolved) return true;
|
|
378
|
+
this.syncAddressFromWagmi();
|
|
379
|
+
if (this.address && !this.provider) await this.syncProviderFromModal();
|
|
380
|
+
if (this.provider && this.address) {
|
|
381
|
+
try {
|
|
382
|
+
const accounts = await this.provider.request({ method: "eth_accounts" });
|
|
383
|
+
if (_optionalChain([accounts, 'optionalAccess', _28 => _28.length])) {
|
|
384
|
+
resolved = true;
|
|
385
|
+
cleanup();
|
|
386
|
+
_optionalChain([this, 'access', _29 => _29.modal, 'optionalAccess', _30 => _30.close, 'call', _31 => _31()]);
|
|
387
|
+
this.lastKnownAccounts = accounts;
|
|
388
|
+
resolve({ address: this.address, provider: this.provider, walletId: this.id });
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
} catch (e4) {
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return false;
|
|
395
|
+
};
|
|
396
|
+
unsubscribe = this.modal.subscribeState(async (state) => {
|
|
397
|
+
if (await checkConnection()) return;
|
|
398
|
+
if (!state.open && !this.address && !resolved) {
|
|
399
|
+
cleanup();
|
|
400
|
+
reject(new Error("Connection rejected by user"));
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
const poll = async () => {
|
|
404
|
+
if (await checkConnection()) return;
|
|
405
|
+
if (Date.now() - startTime > timeout) {
|
|
406
|
+
cleanup();
|
|
407
|
+
reject(new Error("Connection timeout"));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
setTimeout(poll, 500);
|
|
411
|
+
};
|
|
412
|
+
poll();
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
async tryRestoreConnection() {
|
|
416
|
+
await this.ensureInitialized();
|
|
417
|
+
if (!this.wagmiAdapter) return null;
|
|
418
|
+
try {
|
|
419
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
420
|
+
const { state } = this.wagmiAdapter.wagmiConfig || {};
|
|
421
|
+
const connection = _optionalChain([state, 'optionalAccess', _32 => _32.current]) && _optionalChain([state, 'access', _33 => _33.connections, 'optionalAccess', _34 => _34.get, 'call', _35 => _35(state.current)]);
|
|
422
|
+
if (!connection || typeof connection === "string") return null;
|
|
423
|
+
const address = _optionalChain([connection, 'access', _36 => _36.accounts, 'optionalAccess', _37 => _37[0]]);
|
|
424
|
+
if (address && this.provider) {
|
|
425
|
+
this.address = address;
|
|
426
|
+
this.lastKnownAccounts = [...connection.accounts || []];
|
|
427
|
+
return { address, provider: this.provider, walletId: this.id };
|
|
428
|
+
}
|
|
429
|
+
return null;
|
|
430
|
+
} catch (e5) {
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
async disconnect() {
|
|
435
|
+
if (this.modal) {
|
|
436
|
+
await this.modal.disconnect("eip155");
|
|
437
|
+
const deadline = Date.now() + 2e3;
|
|
438
|
+
while (Date.now() < deadline && (this.modal.getIsConnectedState() || this.modal.getAddress())) {
|
|
439
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
this.address = null;
|
|
443
|
+
this.provider = null;
|
|
444
|
+
this.connectionUri = null;
|
|
445
|
+
this.lastKnownAccounts = [];
|
|
446
|
+
this.lastKnownChainId = null;
|
|
447
|
+
}
|
|
448
|
+
getProvider() {
|
|
449
|
+
return this.provider;
|
|
450
|
+
}
|
|
451
|
+
onAccountsChanged(callback) {
|
|
452
|
+
if (this.accountsChangedCallback && _optionalChain([this, 'access', _38 => _38.provider, 'optionalAccess', _39 => _39.removeListener])) {
|
|
453
|
+
this.provider.removeListener("accountsChanged", this.accountsChangedCallback);
|
|
454
|
+
}
|
|
455
|
+
if (this.sessionUpdateHandler && _optionalChain([this, 'access', _40 => _40.universalProvider, 'optionalAccess', _41 => _41.removeListener])) {
|
|
456
|
+
this.universalProvider.removeListener("session_update", this.sessionUpdateHandler);
|
|
457
|
+
}
|
|
458
|
+
if (!this.lastKnownAccounts.length && this.address) this.lastKnownAccounts = [this.address];
|
|
459
|
+
this.accountsChangedCallback = (accounts) => {
|
|
460
|
+
this.address = accounts[0] || null;
|
|
461
|
+
this.lastKnownAccounts = accounts;
|
|
462
|
+
callback(accounts);
|
|
463
|
+
};
|
|
464
|
+
if (_optionalChain([this, 'access', _42 => _42.provider, 'optionalAccess', _43 => _43.on])) {
|
|
465
|
+
this.provider.on("accountsChanged", this.accountsChangedCallback);
|
|
466
|
+
}
|
|
467
|
+
if (_optionalChain([this, 'access', _44 => _44.universalProvider, 'optionalAccess', _45 => _45.on])) {
|
|
468
|
+
this.sessionUpdateHandler = (args) => {
|
|
469
|
+
const accounts = this.extractAccountsFromNamespaces(_optionalChain([args, 'optionalAccess', _46 => _46.params, 'optionalAccess', _47 => _47.namespaces]));
|
|
470
|
+
if (accounts.length && this.hasAccountsChanged(accounts)) {
|
|
471
|
+
this.lastKnownAccounts = accounts;
|
|
472
|
+
this.address = accounts[0];
|
|
473
|
+
callback(accounts);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
this.universalProvider.on("session_update", this.sessionUpdateHandler);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
onChainChanged(callback) {
|
|
480
|
+
if (!_optionalChain([this, 'access', _48 => _48.provider, 'optionalAccess', _49 => _49.on])) return;
|
|
481
|
+
if (this.chainChangedCallback) _optionalChain([this, 'access', _50 => _50.provider, 'access', _51 => _51.removeListener, 'optionalCall', _52 => _52("chainChanged", this.chainChangedCallback)]);
|
|
482
|
+
this.chainChangedCallback = (chainId) => {
|
|
483
|
+
const normalized = typeof chainId === "string" ? chainId : `0x${Number(chainId).toString(16)}`;
|
|
484
|
+
if (normalized !== this.lastKnownChainId) {
|
|
485
|
+
this.lastKnownChainId = normalized;
|
|
486
|
+
callback(normalized);
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
this.provider.on("chainChanged", this.chainChangedCallback);
|
|
490
|
+
}
|
|
491
|
+
/** Called when remote wallet disconnects (user disconnects from mobile app) */
|
|
492
|
+
onDisconnect(callback) {
|
|
493
|
+
this.disconnectCallback = callback;
|
|
494
|
+
}
|
|
495
|
+
/** Updates the AppKit modal theme */
|
|
496
|
+
updateTheme(theme) {
|
|
497
|
+
this.config.theme = theme;
|
|
498
|
+
if (this.modal && typeof this.modal.setThemeMode === "function") {
|
|
499
|
+
this.modal.setThemeMode(theme);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
extractAccountsFromNamespaces(namespaces) {
|
|
503
|
+
if (!namespaces) return [];
|
|
504
|
+
const accounts = [];
|
|
505
|
+
Object.values(namespaces).forEach((ns) => {
|
|
506
|
+
_optionalChain([ns, 'optionalAccess', _53 => _53.accounts, 'optionalAccess', _54 => _54.forEach, 'call', _55 => _55((account) => {
|
|
507
|
+
const address = account.split(":")[2];
|
|
508
|
+
if (address) accounts.push(address);
|
|
509
|
+
})]);
|
|
510
|
+
});
|
|
511
|
+
return [...new Set(accounts)];
|
|
512
|
+
}
|
|
513
|
+
hasAccountsChanged(newAccounts) {
|
|
514
|
+
if (newAccounts.length !== this.lastKnownAccounts.length) return true;
|
|
515
|
+
return newAccounts.some((acc, i) => acc.toLowerCase() !== _optionalChain([this, 'access', _56 => _56.lastKnownAccounts, 'access', _57 => _57[i], 'optionalAccess', _58 => _58.toLowerCase, 'call', _59 => _59()]));
|
|
516
|
+
}
|
|
517
|
+
removeListeners() {
|
|
518
|
+
if (this.accountsChangedCallback) {
|
|
519
|
+
_optionalChain([this, 'access', _60 => _60.provider, 'optionalAccess', _61 => _61.removeListener, 'optionalCall', _62 => _62("accountsChanged", this.accountsChangedCallback)]);
|
|
520
|
+
this.accountsChangedCallback = null;
|
|
521
|
+
}
|
|
522
|
+
if (this.chainChangedCallback) {
|
|
523
|
+
_optionalChain([this, 'access', _63 => _63.provider, 'optionalAccess', _64 => _64.removeListener, 'optionalCall', _65 => _65("chainChanged", this.chainChangedCallback)]);
|
|
524
|
+
this.chainChangedCallback = null;
|
|
525
|
+
}
|
|
526
|
+
if (this.sessionUpdateHandler) {
|
|
527
|
+
_optionalChain([this, 'access', _66 => _66.universalProvider, 'optionalAccess', _67 => _67.removeListener, 'optionalCall', _68 => _68("session_update", this.sessionUpdateHandler)]);
|
|
528
|
+
this.sessionUpdateHandler = null;
|
|
529
|
+
}
|
|
530
|
+
this.disconnectCallback = null;
|
|
531
|
+
this.unsubscribeFunctions.forEach((unsub) => unsub());
|
|
532
|
+
this.unsubscribeFunctions = [];
|
|
533
|
+
this.lastKnownAccounts = [];
|
|
534
|
+
this.lastKnownChainId = null;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
exports.WalletConnectAdapter = WalletConnectAdapter;
|
|
540
|
+
//# sourceMappingURL=WalletConnectAdapter-NKQZY25A.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_polyfills
|
|
3
|
+
} from "./chunk-J6XFKNJN.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/isConfigError.ts
|
|
6
|
+
init_polyfills();
|
|
7
|
+
var isConfigError = (error) => {
|
|
8
|
+
const name = error?.name;
|
|
9
|
+
return name === "ConfigError";
|
|
10
|
+
};
|
|
11
|
+
var createConfigError = (adapterName) => {
|
|
12
|
+
const error = new Error(`Missing required project ID for ${adapterName}`);
|
|
13
|
+
error.name = "ConfigError";
|
|
14
|
+
return error;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
isConfigError,
|
|
19
|
+
createConfigError
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-4S5E6KOY.mjs.map
|