@kheopskit/core 1.0.1 → 5.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/MIGRATING_TO_V4.md +259 -0
- package/README.md +67 -0
- package/dist/chunk-4ENHC7G4.js +210 -0
- package/dist/chunk-4ENHC7G4.js.map +1 -0
- package/dist/chunk-6XAZANB5.mjs +450 -0
- package/dist/chunk-6XAZANB5.mjs.map +1 -0
- package/dist/chunk-7QSGAJ4A.mjs +210 -0
- package/dist/chunk-7QSGAJ4A.mjs.map +1 -0
- package/dist/chunk-B4L6GAYD.js +179 -0
- package/dist/chunk-B4L6GAYD.js.map +1 -0
- package/dist/chunk-BWUUHUDK.mjs +24 -0
- package/dist/chunk-BWUUHUDK.mjs.map +1 -0
- package/dist/chunk-D3EQMFZ2.js +24 -0
- package/dist/chunk-D3EQMFZ2.js.map +1 -0
- package/dist/chunk-XQWJM3KC.js +450 -0
- package/dist/chunk-XQWJM3KC.js.map +1 -0
- package/dist/chunk-YDLCHYHH.mjs +179 -0
- package/dist/chunk-YDLCHYHH.mjs.map +1 -0
- package/dist/ethereum.d.mts +61 -0
- package/dist/ethereum.d.ts +61 -0
- package/dist/ethereum.js +351 -0
- package/dist/ethereum.js.map +1 -0
- package/dist/ethereum.mjs +351 -0
- package/dist/ethereum.mjs.map +1 -0
- package/dist/getCachedObservable-C4E8dfMp.d.mts +20 -0
- package/dist/getCachedObservable-C4E8dfMp.d.ts +20 -0
- package/dist/index.d.mts +55 -267
- package/dist/index.d.ts +55 -267
- package/dist/index.js +327 -1355
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -1325
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +86 -0
- package/dist/internal.d.ts +86 -0
- package/dist/internal.js +32 -0
- package/dist/internal.js.map +1 -0
- package/dist/internal.mjs +32 -0
- package/dist/internal.mjs.map +1 -0
- package/dist/polkadot.d.mts +70 -0
- package/dist/polkadot.d.ts +70 -0
- package/dist/polkadot.js +303 -0
- package/dist/polkadot.js.map +1 -0
- package/dist/polkadot.mjs +303 -0
- package/dist/polkadot.mjs.map +1 -0
- package/dist/solana.d.mts +98 -0
- package/dist/solana.d.ts +98 -0
- package/dist/solana.js +461 -0
- package/dist/solana.js.map +1 -0
- package/dist/solana.mjs +461 -0
- package/dist/solana.mjs.map +1 -0
- package/dist/types-C7V7DGlg.d.mts +349 -0
- package/dist/types-C7V7DGlg.d.ts +349 -0
- package/package.json +104 -18
package/dist/index.js
CHANGED
|
@@ -1,530 +1,259 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from2, except, desc) => {
|
|
13
|
-
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from2))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
DEFAULT_STORAGE_KEY: () => DEFAULT_STORAGE_KEY,
|
|
34
|
-
clearAllCachedObservables: () => clearAllCachedObservables,
|
|
35
|
-
clearCachedObservable: () => clearCachedObservable,
|
|
36
|
-
createKheopskitStore: () => createKheopskitStore,
|
|
37
|
-
getCachedIcon: () => getCachedIcon,
|
|
38
|
-
getDefaultStore: () => getDefaultStore,
|
|
39
|
-
getKheopskit$: () => getKheopskit$,
|
|
40
|
-
getSafeLocalStorage: () => getSafeLocalStorage,
|
|
41
|
-
hydrateAccount: () => hydrateAccount,
|
|
42
|
-
hydrateWallet: () => hydrateWallet,
|
|
43
|
-
resetAppKitCache: () => resetAppKitCache,
|
|
44
|
-
resolveConfig: () => resolveConfig
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(index_exports);
|
|
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(); } } 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; }
|
|
47
2
|
|
|
48
|
-
// src/utils/getCachedObservable.ts
|
|
49
|
-
var CACHE = /* @__PURE__ */ new Map();
|
|
50
|
-
var getCachedObservable$ = (key, create) => {
|
|
51
|
-
if (!CACHE.has(key)) CACHE.set(key, create());
|
|
52
|
-
return CACHE.get(key);
|
|
53
|
-
};
|
|
54
|
-
var clearCachedObservable = (key) => {
|
|
55
|
-
CACHE.delete(key);
|
|
56
|
-
};
|
|
57
|
-
var clearAllCachedObservables = () => {
|
|
58
|
-
CACHE.clear();
|
|
59
|
-
};
|
|
60
3
|
|
|
61
|
-
// src/utils/polkadotExtensions.ts
|
|
62
|
-
var POLKADOT_EXTENSIONS = {
|
|
63
|
-
talisman: {
|
|
64
|
-
name: "Talisman",
|
|
65
|
-
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwIDAgMCAxMy40MzUgMTMuNDM1QzI1Ljg2NyAxMjggMzYuNDk1IDEyOCA1Ny43NSAxMjhoMTIuNWMyMS4yNTUgMCAzMS44ODMgMCAzOS44NTItNC40NjNhMzUgMzUgMCAwIDAgMTMuNDM1LTEzLjQzNUMxMjggMTAyLjEzMyAxMjggOTEuNTA1IDEyOCA3MC4yNXYtMTIuNWMwLTIxLjI1NSAwLTMxLjg4My00LjQ2My0zOS44NTJhMzUgMzUgMCAwIDAtMTMuNDM1LTEzLjQzNUMxMDIuMTMzIDAgOTEuNTA1IDAgNzAuMjUgMGgtMTIuNUMzNi40OTUgMCAyNS44NjcgMCAx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atform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
|
|
83
5
|
|
|
84
|
-
// src/utils/WalletId.ts
|
|
85
|
-
var getWalletId = (platform, identifier) => {
|
|
86
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
87
|
-
if (!identifier) throw new Error("Invalid name");
|
|
88
|
-
return `${platform}:${identifier}`;
|
|
89
|
-
};
|
|
90
|
-
var parseWalletId = (walletId) => {
|
|
91
|
-
if (!walletId) throw new Error("Invalid walletId");
|
|
92
|
-
const [platform, identifier] = walletId.split(":");
|
|
93
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
94
|
-
if (!identifier) throw new Error("Invalid address");
|
|
95
|
-
return { platform, identifier };
|
|
96
|
-
};
|
|
97
6
|
|
|
98
|
-
// src/utils/hydrateState.ts
|
|
99
|
-
var lookupWalletIcon = (platform, identifier) => {
|
|
100
|
-
if (platform === "polkadot") {
|
|
101
|
-
return POLKADOT_EXTENSIONS[identifier]?.icon ?? "";
|
|
102
|
-
}
|
|
103
|
-
return "";
|
|
104
|
-
};
|
|
105
|
-
var PendingWalletError = class extends Error {
|
|
106
|
-
constructor(walletId) {
|
|
107
|
-
super(
|
|
108
|
-
`Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`
|
|
109
|
-
);
|
|
110
|
-
this.name = "PendingWalletError";
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
var hydrateWallet = (cached) => {
|
|
114
|
-
const { platform, identifier } = parseWalletId(cached.id);
|
|
115
|
-
const throwPending = () => {
|
|
116
|
-
throw new PendingWalletError(cached.id);
|
|
117
|
-
};
|
|
118
|
-
const icon = lookupWalletIcon(platform, identifier);
|
|
119
|
-
if (platform === "polkadot") {
|
|
120
|
-
return {
|
|
121
|
-
id: cached.id,
|
|
122
|
-
platform: "polkadot",
|
|
123
|
-
type: "injected",
|
|
124
|
-
extensionId: identifier,
|
|
125
|
-
extension: void 0,
|
|
126
|
-
name: cached.name,
|
|
127
|
-
icon,
|
|
128
|
-
isConnected: cached.isConnected,
|
|
129
|
-
connect: throwPending,
|
|
130
|
-
disconnect: throwPending
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if (platform === "ethereum") {
|
|
134
|
-
return {
|
|
135
|
-
id: cached.id,
|
|
136
|
-
platform: "ethereum",
|
|
137
|
-
type: "injected",
|
|
138
|
-
providerId: identifier,
|
|
139
|
-
provider: {},
|
|
140
|
-
// Placeholder - will be replaced by real wallet
|
|
141
|
-
name: cached.name,
|
|
142
|
-
icon,
|
|
143
|
-
isConnected: cached.isConnected,
|
|
144
|
-
connect: throwPending,
|
|
145
|
-
disconnect: throwPending
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
throw new Error(`Unknown platform: ${platform}`);
|
|
149
|
-
};
|
|
150
|
-
var hydrateAccount = (cached) => {
|
|
151
|
-
if (cached.platform === "polkadot") {
|
|
152
|
-
return {
|
|
153
|
-
id: cached.id,
|
|
154
|
-
platform: "polkadot",
|
|
155
|
-
type: cached.polkadotAccountType ?? "sr25519",
|
|
156
|
-
address: cached.address,
|
|
157
|
-
name: cached.name,
|
|
158
|
-
walletId: cached.walletId,
|
|
159
|
-
walletName: cached.walletName,
|
|
160
|
-
// PolkadotSigner is required but we can't provide a real one
|
|
161
|
-
// This is a placeholder that will be replaced by the real account
|
|
162
|
-
polkadotSigner: {}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
if (cached.platform === "ethereum") {
|
|
166
|
-
return {
|
|
167
|
-
id: cached.id,
|
|
168
|
-
platform: "ethereum",
|
|
169
|
-
address: cached.address,
|
|
170
|
-
chainId: cached.chainId,
|
|
171
|
-
walletId: cached.walletId,
|
|
172
|
-
walletName: cached.walletName,
|
|
173
|
-
isWalletDefault: false,
|
|
174
|
-
client: {}
|
|
175
|
-
// Placeholder
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
throw new Error(`Unknown platform: ${cached.platform}`);
|
|
179
|
-
};
|
|
180
|
-
var serializeWallet = (wallet) => ({
|
|
181
|
-
id: wallet.id,
|
|
182
|
-
platform: wallet.platform,
|
|
183
|
-
type: wallet.type,
|
|
184
|
-
name: wallet.name,
|
|
185
|
-
// Note: icon is NOT stored to save cookie space
|
|
186
|
-
isConnected: wallet.isConnected
|
|
187
|
-
});
|
|
188
|
-
var serializeAccount = (account) => ({
|
|
189
|
-
id: account.id,
|
|
190
|
-
platform: account.platform,
|
|
191
|
-
address: account.address,
|
|
192
|
-
name: "name" in account ? account.name : void 0,
|
|
193
|
-
chainId: account.platform === "ethereum" ? account.chainId : void 0,
|
|
194
|
-
polkadotAccountType: account.platform === "polkadot" ? account.type : void 0,
|
|
195
|
-
walletId: account.walletId,
|
|
196
|
-
walletName: account.walletName
|
|
197
|
-
});
|
|
198
7
|
|
|
199
|
-
// src/utils/storage.ts
|
|
200
|
-
var noopStorage = {
|
|
201
|
-
getItem: () => null,
|
|
202
|
-
setItem: () => {
|
|
203
|
-
},
|
|
204
|
-
removeItem: () => {
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
var _safeLocalStorage = null;
|
|
208
|
-
var createSafeLocalStorage = () => {
|
|
209
|
-
if (typeof window === "undefined") return noopStorage;
|
|
210
|
-
try {
|
|
211
|
-
const testKey = "__kheopskit_test__";
|
|
212
|
-
window.localStorage.setItem(testKey, testKey);
|
|
213
|
-
window.localStorage.removeItem(testKey);
|
|
214
|
-
return {
|
|
215
|
-
getItem: (key) => window.localStorage.getItem(key),
|
|
216
|
-
setItem: (key, value) => window.localStorage.setItem(key, value),
|
|
217
|
-
removeItem: (key) => window.localStorage.removeItem(key),
|
|
218
|
-
subscribe: (key, callback) => {
|
|
219
|
-
const handler = (event) => {
|
|
220
|
-
if (event.key === key) {
|
|
221
|
-
callback(event.newValue);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
window.addEventListener("storage", handler);
|
|
225
|
-
return () => window.removeEventListener("storage", handler);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
} catch {
|
|
229
|
-
return noopStorage;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
var getSafeLocalStorage = () => {
|
|
233
|
-
if (_safeLocalStorage === null) {
|
|
234
|
-
_safeLocalStorage = createSafeLocalStorage();
|
|
235
|
-
}
|
|
236
|
-
return _safeLocalStorage;
|
|
237
|
-
};
|
|
238
|
-
var safeLocalStorage = {
|
|
239
|
-
getItem: (key) => getSafeLocalStorage().getItem(key),
|
|
240
|
-
setItem: (key, value) => getSafeLocalStorage().setItem(key, value),
|
|
241
|
-
removeItem: (key) => getSafeLocalStorage().removeItem(key),
|
|
242
|
-
subscribe: (key, callback) => {
|
|
243
|
-
const storage = getSafeLocalStorage();
|
|
244
|
-
return storage.subscribe?.(key, callback) ?? (() => {
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
var parseCookie = (cookieString, key) => {
|
|
249
|
-
if (!cookieString) return null;
|
|
250
|
-
for (const cookie of cookieString.split(";")) {
|
|
251
|
-
const [k, ...v] = cookie.split("=");
|
|
252
|
-
const cookieKey = k?.trim();
|
|
253
|
-
if (cookieKey === key) {
|
|
254
|
-
try {
|
|
255
|
-
return decodeURIComponent(v.join("=").trim());
|
|
256
|
-
} catch {
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return null;
|
|
262
|
-
};
|
|
263
|
-
var COOKIE_MAX_SIZE = 3 * 1024;
|
|
264
|
-
var BROADCAST_CHANNEL_NAME = "kheopskit-storage-sync";
|
|
265
|
-
var sharedBroadcastChannel = null;
|
|
266
|
-
var getBroadcastChannel = () => {
|
|
267
|
-
if (sharedBroadcastChannel) return sharedBroadcastChannel;
|
|
268
|
-
if (typeof BroadcastChannel === "undefined") return null;
|
|
269
|
-
try {
|
|
270
|
-
sharedBroadcastChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
|
|
271
|
-
} catch {
|
|
272
|
-
}
|
|
273
|
-
return sharedBroadcastChannel;
|
|
274
|
-
};
|
|
275
|
-
var isSecureConnection = () => typeof window !== "undefined" && window.location.protocol === "https:";
|
|
276
|
-
var cookieStorage = (initialCookies) => {
|
|
277
|
-
return {
|
|
278
|
-
getItem: (key) => {
|
|
279
|
-
const cookieString = typeof document !== "undefined" ? document.cookie : initialCookies;
|
|
280
|
-
return parseCookie(cookieString, key);
|
|
281
|
-
},
|
|
282
|
-
setItem: (key, value) => {
|
|
283
|
-
if (typeof document === "undefined") return;
|
|
284
|
-
const encodedValue = encodeURIComponent(value);
|
|
285
|
-
if (encodedValue.length > COOKIE_MAX_SIZE) {
|
|
286
|
-
console.warn(
|
|
287
|
-
`[kheopskit] Cookie value for "${key}" exceeds recommended size limit (${encodedValue.length} > ${COOKIE_MAX_SIZE} bytes). This may cause issues with cookie storage. Consider reducing the number of connected wallets.`
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
const expires = /* @__PURE__ */ new Date();
|
|
291
|
-
expires.setFullYear(expires.getFullYear() + 1);
|
|
292
|
-
let cookieStr = `${key}=${encodedValue};expires=${expires.toUTCString()};path=/;SameSite=Lax`;
|
|
293
|
-
if (isSecureConnection()) {
|
|
294
|
-
cookieStr += ";Secure";
|
|
295
|
-
}
|
|
296
|
-
document.cookie = cookieStr;
|
|
297
|
-
getBroadcastChannel()?.postMessage({ type: "set", key, value });
|
|
298
|
-
},
|
|
299
|
-
removeItem: (key) => {
|
|
300
|
-
if (typeof document === "undefined") return;
|
|
301
|
-
let cookieStr = `${key}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;SameSite=Lax`;
|
|
302
|
-
if (isSecureConnection()) {
|
|
303
|
-
cookieStr += ";Secure";
|
|
304
|
-
}
|
|
305
|
-
document.cookie = cookieStr;
|
|
306
|
-
getBroadcastChannel()?.postMessage({ type: "remove", key });
|
|
307
|
-
},
|
|
308
|
-
subscribe: (key, callback) => {
|
|
309
|
-
const channel = getBroadcastChannel();
|
|
310
|
-
if (!channel) return () => {
|
|
311
|
-
};
|
|
312
|
-
const handler = (event) => {
|
|
313
|
-
const data = event.data;
|
|
314
|
-
if (data.key === key) {
|
|
315
|
-
if (data.type === "set") {
|
|
316
|
-
callback(data.value ?? null);
|
|
317
|
-
} else if (data.type === "remove") {
|
|
318
|
-
callback(null);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
channel.addEventListener("message", handler);
|
|
323
|
-
return () => {
|
|
324
|
-
channel.removeEventListener("message", handler);
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
};
|
|
329
8
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
var
|
|
355
|
-
const cache = loadCache();
|
|
356
|
-
let changed = false;
|
|
357
|
-
for (const [walletId, icon] of Object.entries(icons)) {
|
|
358
|
-
if (icon && cache[walletId] !== icon) {
|
|
359
|
-
cache[walletId] = icon;
|
|
360
|
-
changed = true;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
if (changed) {
|
|
364
|
-
saveCache(cache);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkB4L6GAYDjs = require('./chunk-B4L6GAYD.js');
|
|
12
|
+
require('./chunk-D3EQMFZ2.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkXQWJM3KCjs = require('./chunk-XQWJM3KC.js');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var _chunk4ENHC7G4js = require('./chunk-4ENHC7G4.js');
|
|
367
34
|
|
|
368
35
|
// src/api/appKit.ts
|
|
369
|
-
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
var _rxjs = require('rxjs');
|
|
370
47
|
var loadAppKit = async () => {
|
|
371
|
-
|
|
372
|
-
|
|
48
|
+
try {
|
|
49
|
+
const { createAppKit } = await Promise.resolve().then(() => _interopRequireWildcard(require("@reown/appkit/core")));
|
|
50
|
+
return createAppKit;
|
|
51
|
+
} catch (cause) {
|
|
52
|
+
console.error(
|
|
53
|
+
"[kheopskit] WalletConnect is configured but @reown/appkit could not be loaded. Install it with `pnpm add @reown/appkit` (or remove config.walletConnect). WalletConnect wallets are disabled; injected wallets still work.",
|
|
54
|
+
cause
|
|
55
|
+
);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
373
58
|
};
|
|
374
59
|
var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD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i4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
|
|
375
|
-
var
|
|
60
|
+
var APPKIT_SYMBOL = /* @__PURE__ */ Symbol.for("kheopskit.cachedAppKit");
|
|
61
|
+
var APPKIT_PROJECT_ID_SYMBOL = /* @__PURE__ */ Symbol.for("kheopskit.cachedAppKitProjectId");
|
|
62
|
+
var getCachedAppKit = () => globalThis[APPKIT_SYMBOL];
|
|
63
|
+
var getCachedAppKitProjectId = () => globalThis[APPKIT_PROJECT_ID_SYMBOL];
|
|
64
|
+
var setCachedAppKit = (value, projectId) => {
|
|
65
|
+
globalThis[APPKIT_SYMBOL] = value;
|
|
66
|
+
globalThis[APPKIT_PROJECT_ID_SYMBOL] = projectId;
|
|
67
|
+
};
|
|
376
68
|
var resetAppKitCache = () => {
|
|
377
|
-
|
|
69
|
+
setCachedAppKit(void 0);
|
|
70
|
+
};
|
|
71
|
+
var dropAccountsCache = (platform) => {
|
|
72
|
+
_chunk4ENHC7G4js.clearCachedObservablesByPrefix.call(void 0,
|
|
73
|
+
`accounts:${_chunk4ENHC7G4js.WALLET_CONNECT_WALLET_ID}:${platform}:`
|
|
74
|
+
);
|
|
378
75
|
};
|
|
379
|
-
var
|
|
380
|
-
if (!config.walletConnect) return (0,
|
|
381
|
-
if (typeof window === "undefined") return (0,
|
|
76
|
+
var getWalletConnectWallet$ = (config) => {
|
|
77
|
+
if (!config.walletConnect) return _rxjs.of.call(void 0, null);
|
|
78
|
+
if (typeof window === "undefined") return _rxjs.of.call(void 0, null);
|
|
382
79
|
const walletConnect = config.walletConnect;
|
|
80
|
+
const cachedProjectId = getCachedAppKitProjectId();
|
|
81
|
+
if (cachedProjectId !== void 0 && cachedProjectId !== walletConnect.projectId) {
|
|
82
|
+
console.warn(
|
|
83
|
+
"[kheopskit] WalletConnect is already initialised with projectId %s; AppKit is a process-wide singleton, so the first configuration wins and projectId %s is ignored. Call resetAppKitCache() before re-initialising if the WalletConnect config must change.",
|
|
84
|
+
cachedProjectId,
|
|
85
|
+
walletConnect.projectId
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
let cachedAppKit = getCachedAppKit();
|
|
383
89
|
if (!cachedAppKit) {
|
|
384
|
-
cachedAppKit = (0,
|
|
385
|
-
(0,
|
|
386
|
-
return
|
|
90
|
+
cachedAppKit = _rxjs.from.call(void 0, loadAppKit()).pipe(
|
|
91
|
+
_rxjs.switchMap.call(void 0, (createAppKit) => {
|
|
92
|
+
if (!createAppKit) return _rxjs.of.call(void 0, null);
|
|
93
|
+
return new (0, _rxjs.Observable)((subscriber) => {
|
|
387
94
|
const appKit = createAppKit({
|
|
388
95
|
projectId: walletConnect.projectId,
|
|
389
96
|
metadata: walletConnect.metadata,
|
|
97
|
+
// Loosely typed in WalletConnectConfig to keep @reown/appkit's
|
|
98
|
+
// types out of core; forwarded to AppKit verbatim.
|
|
390
99
|
networks: walletConnect.networks,
|
|
391
100
|
themeMode: walletConnect.themeMode,
|
|
392
101
|
themeVariables: walletConnect.themeVariables,
|
|
393
102
|
universalProviderConfigOverride: {
|
|
394
103
|
methods: {
|
|
395
|
-
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
|
|
104
|
+
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"],
|
|
105
|
+
solana: [
|
|
106
|
+
"solana_signTransaction",
|
|
107
|
+
"solana_signMessage",
|
|
108
|
+
"solana_signAndSendTransaction"
|
|
109
|
+
]
|
|
396
110
|
}
|
|
397
111
|
},
|
|
398
112
|
allWallets: "HIDE",
|
|
399
113
|
debug: config.debug,
|
|
400
114
|
allowUnsupportedChain: true
|
|
401
115
|
});
|
|
402
|
-
const
|
|
116
|
+
const appKitInstance = appKit;
|
|
117
|
+
const status$ = new (0, _rxjs.BehaviorSubject)({
|
|
403
118
|
isPolkadotConnected: false,
|
|
404
|
-
isEthereumConnected: false
|
|
119
|
+
isEthereumConnected: false,
|
|
120
|
+
isSolanaConnected: false
|
|
405
121
|
});
|
|
406
122
|
const unsubProviders = appKit.subscribeProviders((providers) => {
|
|
407
123
|
status$.next({
|
|
408
124
|
isPolkadotConnected: !!providers.polkadot,
|
|
409
|
-
isEthereumConnected: !!providers.eip155
|
|
125
|
+
isEthereumConnected: !!providers.eip155,
|
|
126
|
+
isSolanaConnected: !!providers.solana
|
|
410
127
|
});
|
|
411
128
|
});
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
129
|
+
const namespaceOf = {
|
|
130
|
+
polkadot: "polkadot",
|
|
131
|
+
ethereum: "eip155",
|
|
132
|
+
solana: "solana"
|
|
133
|
+
};
|
|
134
|
+
const allPlatforms = [
|
|
135
|
+
"polkadot",
|
|
136
|
+
"ethereum",
|
|
137
|
+
"solana"
|
|
138
|
+
];
|
|
139
|
+
const enabledPlatforms = allPlatforms.filter(
|
|
140
|
+
(p) => appKit.chainNamespaces.includes(namespaceOf[p])
|
|
141
|
+
);
|
|
142
|
+
let prevConnected = {
|
|
143
|
+
polkadot: false,
|
|
144
|
+
ethereum: false,
|
|
145
|
+
solana: false
|
|
146
|
+
};
|
|
147
|
+
const sub = status$.pipe(
|
|
148
|
+
_rxjs.map.call(void 0, (s) => ({
|
|
149
|
+
polkadot: s.isPolkadotConnected,
|
|
150
|
+
ethereum: s.isEthereumConnected,
|
|
151
|
+
solana: s.isSolanaConnected
|
|
152
|
+
})),
|
|
153
|
+
_rxjs.distinctUntilChanged.call(void 0,
|
|
154
|
+
(a, b) => a.polkadot === b.polkadot && a.ethereum === b.ethereum && a.solana === b.solana
|
|
155
|
+
),
|
|
156
|
+
_rxjs.tap.call(void 0, (connected) => {
|
|
157
|
+
for (const platform of allPlatforms)
|
|
158
|
+
if (prevConnected[platform] && !connected[platform])
|
|
159
|
+
dropAccountsCache(platform);
|
|
160
|
+
prevConnected = connected;
|
|
161
|
+
}),
|
|
162
|
+
_rxjs.map.call(void 0, (connected) => {
|
|
163
|
+
const platforms = enabledPlatforms.filter((p) => connected[p]);
|
|
164
|
+
const isConnected = platforms.length > 0;
|
|
416
165
|
const walletInfo = appKit.getWalletInfo();
|
|
417
166
|
return {
|
|
418
|
-
id:
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
appKit,
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
167
|
+
id: _chunk4ENHC7G4js.WALLET_CONNECT_WALLET_ID,
|
|
168
|
+
type: "walletconnect",
|
|
169
|
+
platforms,
|
|
170
|
+
appKit: appKitInstance,
|
|
171
|
+
name: _nullishCoalesce(_optionalChain([walletInfo, 'optionalAccess', _ => _.name]), () => ( "WalletConnect")),
|
|
172
|
+
icon: _nullishCoalesce(_optionalChain([walletInfo, 'optionalAccess', _2 => _2.icon]), () => ( WALLET_CONNECT_ICON)),
|
|
173
|
+
// One shared session: connecting opens the modal; the wallet
|
|
174
|
+
// approves namespaces in that single pairing. Disconnect is
|
|
175
|
+
// session-wide; re-pair to change the approved set.
|
|
425
176
|
connect: async () => {
|
|
426
177
|
if (!isConnected) await appKit.open();
|
|
427
178
|
},
|
|
428
|
-
disconnect: () => {
|
|
429
|
-
if (isConnected) appKit.disconnect();
|
|
179
|
+
disconnect: async () => {
|
|
180
|
+
if (isConnected) await appKit.disconnect();
|
|
430
181
|
},
|
|
431
182
|
isConnected
|
|
432
183
|
};
|
|
433
184
|
})
|
|
434
|
-
)
|
|
435
|
-
const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
|
|
436
|
-
(0, import_rxjs.map)((s) => s.isEthereumConnected),
|
|
437
|
-
(0, import_rxjs.distinctUntilChanged)(),
|
|
438
|
-
(0, import_rxjs.map)((isConnected) => {
|
|
439
|
-
const walletInfo = appKit.getWalletInfo();
|
|
440
|
-
return {
|
|
441
|
-
id: getWalletId("ethereum", "walletconnect"),
|
|
442
|
-
platform: "ethereum",
|
|
443
|
-
type: "appKit",
|
|
444
|
-
appKit,
|
|
445
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
446
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
447
|
-
connect: () => appKit.open(),
|
|
448
|
-
disconnect: () => appKit.disconnect(),
|
|
449
|
-
isConnected
|
|
450
|
-
};
|
|
451
|
-
})
|
|
452
|
-
) : (0, import_rxjs.of)(void 0);
|
|
453
|
-
const sub = (0, import_rxjs.combineLatest)({
|
|
454
|
-
polkadot: polkadotWallet$,
|
|
455
|
-
ethereum: ethereumWallet$
|
|
456
|
-
}).subscribe(subscriber);
|
|
185
|
+
).subscribe(subscriber);
|
|
457
186
|
return () => {
|
|
458
187
|
sub.unsubscribe();
|
|
459
188
|
unsubProviders();
|
|
460
189
|
};
|
|
461
190
|
});
|
|
462
191
|
}),
|
|
463
|
-
|
|
192
|
+
// refCount:false keeps the AppKit instance alive for the process lifetime
|
|
193
|
+
// once created: createAppKit runs at most once (Reown AppKit cannot be
|
|
194
|
+
// instantiated twice). With refCount:true the producer would re-run
|
|
195
|
+
// createAppKit whenever every subscriber drained and a new one
|
|
196
|
+
// re-subscribed — e.g. a React unmount/remount or StrictMode's
|
|
197
|
+
// mount→unmount→remount — throwing on the duplicate Lit web components and
|
|
198
|
+
// WalletConnect modal singleton. The replayed connector value also keeps
|
|
199
|
+
// the wallet list stable across such teardown/rebuild cycles.
|
|
200
|
+
_rxjs.shareReplay.call(void 0, { refCount: false, bufferSize: 1 })
|
|
464
201
|
);
|
|
202
|
+
setCachedAppKit(cachedAppKit, walletConnect.projectId);
|
|
465
203
|
}
|
|
466
204
|
return cachedAppKit;
|
|
467
205
|
};
|
|
468
206
|
|
|
469
|
-
// src/api/config.ts
|
|
470
|
-
var DEFAULT_STORAGE_KEY = "kheopskit";
|
|
471
|
-
var DEFAULT_CONFIG = {
|
|
472
|
-
autoReconnect: true,
|
|
473
|
-
platforms: ["polkadot"],
|
|
474
|
-
polkadotAccountTypes: ["sr25519", "ed25519", "ecdsa"],
|
|
475
|
-
debug: false,
|
|
476
|
-
storageKey: DEFAULT_STORAGE_KEY,
|
|
477
|
-
hydrationGracePeriod: 500
|
|
478
|
-
};
|
|
479
|
-
var VALID_POLKADOT_ACCOUNT_TYPES = /* @__PURE__ */ new Set([
|
|
480
|
-
"sr25519",
|
|
481
|
-
"ed25519",
|
|
482
|
-
"ecdsa",
|
|
483
|
-
"ethereum"
|
|
484
|
-
]);
|
|
485
|
-
var resolveConfig = (config) => {
|
|
486
|
-
const resolved = Object.assign({}, DEFAULT_CONFIG, config);
|
|
487
|
-
const invalid = resolved.polkadotAccountTypes.filter(
|
|
488
|
-
(t) => !VALID_POLKADOT_ACCOUNT_TYPES.has(t)
|
|
489
|
-
);
|
|
490
|
-
if (invalid.length > 0) {
|
|
491
|
-
console.warn(
|
|
492
|
-
`[kheopskit] Unknown polkadotAccountTypes: ${JSON.stringify(invalid)}. Valid values: "sr25519", "ed25519", "ecdsa", "ethereum".`
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
return resolved;
|
|
496
|
-
};
|
|
497
|
-
|
|
498
207
|
// src/api/kheopskit.ts
|
|
499
|
-
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
500
218
|
|
|
501
219
|
// src/utils/createHydrationBuffer.ts
|
|
502
|
-
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
503
232
|
var createBufferCore = (cachedItems, liveItems$, gracePeriodMs, mergeFn, isConverged) => {
|
|
504
233
|
if (gracePeriodMs <= 0 || cachedItems.length === 0) {
|
|
505
|
-
return liveItems$.pipe((0,
|
|
234
|
+
return liveItems$.pipe(_rxjs.map.call(void 0, (items) => ({ items, isHydrating: false })));
|
|
506
235
|
}
|
|
507
|
-
return new
|
|
508
|
-
const subscriptions = new
|
|
509
|
-
const isHydrating$ = new
|
|
510
|
-
const liveWithInitial$ = liveItems$.pipe((0,
|
|
236
|
+
return new (0, _rxjs.Observable)((subscriber) => {
|
|
237
|
+
const subscriptions = new (0, _rxjs.Subscription)();
|
|
238
|
+
const isHydrating$ = new (0, _rxjs.BehaviorSubject)(true);
|
|
239
|
+
const liveWithInitial$ = liveItems$.pipe(_rxjs.startWith.call(void 0, []));
|
|
511
240
|
if (isConverged) {
|
|
512
|
-
const timerFired$ = (0,
|
|
513
|
-
(0,
|
|
514
|
-
(0,
|
|
515
|
-
(0,
|
|
241
|
+
const timerFired$ = _rxjs.timer.call(void 0, gracePeriodMs).pipe(
|
|
242
|
+
_rxjs.map.call(void 0, () => true),
|
|
243
|
+
_rxjs.startWith.call(void 0, false),
|
|
244
|
+
_rxjs.shareReplay.call(void 0, { bufferSize: 1, refCount: true })
|
|
516
245
|
);
|
|
517
246
|
subscriptions.add(
|
|
518
|
-
(0,
|
|
519
|
-
(0,
|
|
520
|
-
(0,
|
|
521
|
-
(0,
|
|
247
|
+
_rxjs.combineLatest.call(void 0, [liveWithInitial$, timerFired$]).pipe(
|
|
248
|
+
_rxjs.filter.call(void 0, ([, timerFired]) => timerFired),
|
|
249
|
+
_rxjs.filter.call(void 0, ([liveItems]) => isConverged(liveItems, cachedItems)),
|
|
250
|
+
_rxjs.take.call(void 0, 1)
|
|
522
251
|
).subscribe(() => {
|
|
523
252
|
isHydrating$.next(false);
|
|
524
253
|
})
|
|
525
254
|
);
|
|
526
255
|
subscriptions.add(
|
|
527
|
-
(0,
|
|
256
|
+
_rxjs.timer.call(void 0, gracePeriodMs * 6).subscribe(() => {
|
|
528
257
|
if (isHydrating$.value) {
|
|
529
258
|
isHydrating$.next(false);
|
|
530
259
|
}
|
|
@@ -532,14 +261,14 @@ var createBufferCore = (cachedItems, liveItems$, gracePeriodMs, mergeFn, isConve
|
|
|
532
261
|
);
|
|
533
262
|
} else {
|
|
534
263
|
subscriptions.add(
|
|
535
|
-
(0,
|
|
264
|
+
_rxjs.timer.call(void 0, gracePeriodMs).subscribe(() => {
|
|
536
265
|
isHydrating$.next(false);
|
|
537
266
|
})
|
|
538
267
|
);
|
|
539
268
|
}
|
|
540
269
|
subscriptions.add(
|
|
541
|
-
(0,
|
|
542
|
-
(0,
|
|
270
|
+
_rxjs.combineLatest.call(void 0, [liveWithInitial$, isHydrating$]).pipe(
|
|
271
|
+
_rxjs.map.call(void 0, ([liveItems, isHydrating]) => {
|
|
543
272
|
if (!isHydrating) {
|
|
544
273
|
return { items: liveItems, isHydrating: false };
|
|
545
274
|
}
|
|
@@ -601,8 +330,8 @@ var createAccountHydrationBuffer = (cachedAccounts, liveAccounts$, gracePeriodMs
|
|
|
601
330
|
};
|
|
602
331
|
|
|
603
332
|
// src/utils/logObservable.ts
|
|
604
|
-
|
|
605
|
-
var logObservable = (label, opts) => (0,
|
|
333
|
+
|
|
334
|
+
var logObservable = (label, opts) => _rxjs.tap.call(void 0, (value) => {
|
|
606
335
|
const { printValue = false, enabled = true } = opts || {};
|
|
607
336
|
if (!label || !enabled) return;
|
|
608
337
|
const text = `[kheopskit] observable ${label} emit`;
|
|
@@ -611,873 +340,86 @@ var logObservable = (label, opts) => (0, import_rxjs3.tap)((value) => {
|
|
|
611
340
|
});
|
|
612
341
|
|
|
613
342
|
// src/api/accounts.ts
|
|
614
|
-
var import_rxjs7 = require("rxjs");
|
|
615
|
-
|
|
616
|
-
// src/utils/sortAccounts.ts
|
|
617
|
-
var sortAccounts = (a1, a2) => {
|
|
618
|
-
if (a1.platform === "polkadot") {
|
|
619
|
-
if (a2.platform === "polkadot") {
|
|
620
|
-
if (a1.walletName !== a2.walletName) {
|
|
621
|
-
if (a1.walletName === "talisman") return -1;
|
|
622
|
-
if (a2.walletName === "talisman") return 1;
|
|
623
|
-
return a1.walletName.localeCompare(a2.walletName);
|
|
624
|
-
}
|
|
625
|
-
return a1.name !== a2.name ? (a1.name ?? "").localeCompare(a2.name ?? "") : a1.address.localeCompare(a2.address);
|
|
626
|
-
}
|
|
627
|
-
return -1;
|
|
628
|
-
}
|
|
629
|
-
if (a2.platform === "ethereum") {
|
|
630
|
-
if (a1.walletName !== a2.walletName) {
|
|
631
|
-
if (a1.walletName === "Talisman") return -1;
|
|
632
|
-
if (a2.walletName === "Talisman") return 1;
|
|
633
|
-
return a1.walletName.localeCompare(a2.walletName);
|
|
634
|
-
}
|
|
635
|
-
return a1.id.localeCompare(a2.id);
|
|
636
|
-
}
|
|
637
|
-
return 0;
|
|
638
|
-
};
|
|
639
343
|
|
|
640
|
-
// src/api/ethereum/accounts.ts
|
|
641
|
-
var import_rxjs5 = require("rxjs");
|
|
642
|
-
var import_viem2 = require("viem");
|
|
643
|
-
|
|
644
|
-
// src/utils/createStore.ts
|
|
645
|
-
var import_rxjs4 = require("rxjs");
|
|
646
|
-
var createStore = (key, defaultValue, storage = safeLocalStorage) => {
|
|
647
|
-
const subject = new import_rxjs4.BehaviorSubject(
|
|
648
|
-
getStoredData(key, defaultValue, storage)
|
|
649
|
-
);
|
|
650
|
-
let unsubscribeStorage;
|
|
651
|
-
if (typeof window !== "undefined" && storage.subscribe) {
|
|
652
|
-
unsubscribeStorage = storage.subscribe(key, (newValue) => {
|
|
653
|
-
subject.next(parseData(newValue, defaultValue));
|
|
654
|
-
});
|
|
655
|
-
}
|
|
656
|
-
const update = (val) => {
|
|
657
|
-
setStoredData(key, val, storage);
|
|
658
|
-
subject.next(val);
|
|
659
|
-
};
|
|
660
|
-
return {
|
|
661
|
-
observable: subject.asObservable(),
|
|
662
|
-
set: (val) => update(val),
|
|
663
|
-
mutate: (transform) => update(transform(subject.getValue())),
|
|
664
|
-
get: () => structuredClone(subject.getValue()),
|
|
665
|
-
/**
|
|
666
|
-
* Cleanup subscriptions. Call this when the store is no longer needed.
|
|
667
|
-
*/
|
|
668
|
-
destroy: () => {
|
|
669
|
-
unsubscribeStorage?.();
|
|
670
|
-
subject.complete();
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
};
|
|
674
|
-
var parseData = (str, defaultValue) => {
|
|
675
|
-
try {
|
|
676
|
-
if (str) return JSON.parse(str);
|
|
677
|
-
} catch {
|
|
678
|
-
}
|
|
679
|
-
return defaultValue;
|
|
680
|
-
};
|
|
681
|
-
var getStoredData = (key, defaultValue, storage) => {
|
|
682
|
-
const str = storage.getItem(key);
|
|
683
|
-
return parseData(str, defaultValue);
|
|
684
|
-
};
|
|
685
|
-
var setStoredData = (key, val, storage) => {
|
|
686
|
-
const str = JSON.stringify(val);
|
|
687
|
-
storage.setItem(key, str);
|
|
688
|
-
};
|
|
689
|
-
|
|
690
|
-
// src/utils/isEthereumAddress.ts
|
|
691
|
-
var import_viem = require("viem");
|
|
692
|
-
var isEthereumAddress = (address) => (0, import_viem.isAddress)(address);
|
|
693
|
-
|
|
694
|
-
// src/utils/isSs58Address.ts
|
|
695
|
-
var import_polkadot_api = require("polkadot-api");
|
|
696
|
-
var accountIdEncoder = (0, import_polkadot_api.AccountId)().enc;
|
|
697
|
-
var isSs58Address = (address) => {
|
|
698
|
-
try {
|
|
699
|
-
if (!address) return false;
|
|
700
|
-
accountIdEncoder(address);
|
|
701
|
-
return true;
|
|
702
|
-
} catch {
|
|
703
|
-
return false;
|
|
704
|
-
}
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
// src/utils/isValidAddress.ts
|
|
708
|
-
var isValidAddress = (address) => {
|
|
709
|
-
return address.startsWith("0x") ? isEthereumAddress(address) : isSs58Address(address);
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
// src/utils/WalletAccountId.ts
|
|
713
|
-
var getWalletAccountId = (walletId, address) => {
|
|
714
|
-
if (!walletId) throw new Error("Missing walletId");
|
|
715
|
-
if (!isValidAddress(address)) throw new Error("Invalid address");
|
|
716
|
-
return `${walletId}::${address}`;
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
// src/api/ethereum/accounts.ts
|
|
720
|
-
var normalizeEvmChainId = (value) => {
|
|
721
|
-
let raw = value;
|
|
722
|
-
if (typeof raw === "string" && raw.startsWith("eip155:")) {
|
|
723
|
-
raw = raw.slice("eip155:".length);
|
|
724
|
-
}
|
|
725
|
-
if (typeof raw === "bigint") {
|
|
726
|
-
return raw >= 0n ? Number(raw) : void 0;
|
|
727
|
-
}
|
|
728
|
-
if (typeof raw === "number") {
|
|
729
|
-
return Number.isInteger(raw) && raw >= 0 ? raw : void 0;
|
|
730
|
-
}
|
|
731
|
-
if (typeof raw === "string") {
|
|
732
|
-
const normalized = raw.trim().toLowerCase();
|
|
733
|
-
if (!normalized) return void 0;
|
|
734
|
-
const parsed = normalized.startsWith("0x") ? Number.parseInt(normalized, 16) : Number.parseInt(normalized, 10);
|
|
735
|
-
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
736
|
-
}
|
|
737
|
-
return void 0;
|
|
738
|
-
};
|
|
739
|
-
var toCaipNetworkId = (value) => {
|
|
740
|
-
const chainId = normalizeEvmChainId(value);
|
|
741
|
-
return chainId === void 0 ? void 0 : `eip155:${chainId}`;
|
|
742
|
-
};
|
|
743
|
-
var getInjectedWalletAccounts$ = (wallet) => {
|
|
744
|
-
if (!wallet.isConnected) return (0, import_rxjs5.of)([]);
|
|
745
|
-
return getCachedObservable$(
|
|
746
|
-
`accounts:${wallet.id}`,
|
|
747
|
-
() => new import_rxjs5.Observable((subscriber) => {
|
|
748
|
-
const addresses$ = new import_rxjs5.ReplaySubject(1);
|
|
749
|
-
const chainId$ = new import_rxjs5.ReplaySubject(1);
|
|
750
|
-
const getAccount = (address, i, chainId) => {
|
|
751
|
-
const client = (0, import_viem2.createWalletClient)({
|
|
752
|
-
account: address,
|
|
753
|
-
transport: (0, import_viem2.custom)(wallet.provider)
|
|
754
|
-
});
|
|
755
|
-
return {
|
|
756
|
-
id: getWalletAccountId(wallet.id, address),
|
|
757
|
-
platform: "ethereum",
|
|
758
|
-
client,
|
|
759
|
-
address: (0, import_viem2.getAddress)(address),
|
|
760
|
-
chainId,
|
|
761
|
-
walletName: wallet.name,
|
|
762
|
-
walletId: wallet.id,
|
|
763
|
-
isWalletDefault: i === 0
|
|
764
|
-
};
|
|
765
|
-
};
|
|
766
|
-
const handleAccountsChanged = (addrs) => {
|
|
767
|
-
addresses$.next(addrs);
|
|
768
|
-
};
|
|
769
|
-
const handleChainChanged = (chainIdHex) => {
|
|
770
|
-
chainId$.next(normalizeEvmChainId(chainIdHex));
|
|
771
|
-
};
|
|
772
|
-
const handleDisconnect = () => {
|
|
773
|
-
chainId$.next(void 0);
|
|
774
|
-
};
|
|
775
|
-
wallet.provider.on("accountsChanged", handleAccountsChanged);
|
|
776
|
-
wallet.provider.on("chainChanged", handleChainChanged);
|
|
777
|
-
wallet.provider.on("disconnect", handleDisconnect);
|
|
778
|
-
wallet.provider.request({ method: "eth_accounts" }).then((addrs) => addresses$.next(addrs)).catch((err) => {
|
|
779
|
-
console.error("Failed to get accounts", err);
|
|
780
|
-
addresses$.next([]);
|
|
781
|
-
});
|
|
782
|
-
wallet.provider.request({ method: "eth_chainId" }).then(handleChainChanged).catch(() => chainId$.next(void 0));
|
|
783
|
-
const sub = (0, import_rxjs5.combineLatest)([addresses$, chainId$]).pipe(
|
|
784
|
-
(0, import_rxjs5.map)(
|
|
785
|
-
([addresses, chainId]) => addresses.map((addr, i) => getAccount(addr, i, chainId))
|
|
786
|
-
)
|
|
787
|
-
).subscribe(subscriber);
|
|
788
|
-
return () => {
|
|
789
|
-
wallet.provider.removeListener(
|
|
790
|
-
"accountsChanged",
|
|
791
|
-
handleAccountsChanged
|
|
792
|
-
);
|
|
793
|
-
wallet.provider.removeListener("chainChanged", handleChainChanged);
|
|
794
|
-
wallet.provider.removeListener("disconnect", handleDisconnect);
|
|
795
|
-
sub.unsubscribe();
|
|
796
|
-
};
|
|
797
|
-
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
798
|
-
);
|
|
799
|
-
};
|
|
800
|
-
var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
|
|
801
|
-
return new Proxy(provider, {
|
|
802
|
-
get(target, prop, receiver) {
|
|
803
|
-
if (prop !== "request") return Reflect.get(target, prop, receiver);
|
|
804
|
-
return (args) => {
|
|
805
|
-
if (args && typeof args === "object" && args.method) {
|
|
806
|
-
if (!args.topic) args.topic = sessionTopic;
|
|
807
|
-
if (!args.chainId) args.chainId = caipNetworkId;
|
|
808
|
-
}
|
|
809
|
-
return target.request(args);
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
};
|
|
814
|
-
var getAppKitAccounts$ = (wallet) => {
|
|
815
|
-
const account = wallet.appKit.getAccount("eip155");
|
|
816
|
-
const provider = wallet.appKit.getProvider("eip155");
|
|
817
|
-
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
818
|
-
return (0, import_rxjs5.of)([]);
|
|
819
|
-
return getCachedObservable$(
|
|
820
|
-
"accounts:appKit",
|
|
821
|
-
() => new import_rxjs5.Observable((subscriber) => {
|
|
822
|
-
const caipNetworkId$ = new import_rxjs5.ReplaySubject(1);
|
|
823
|
-
const handleChainChanged = (chainId) => {
|
|
824
|
-
const caipNetworkId = toCaipNetworkId(chainId);
|
|
825
|
-
if (caipNetworkId) {
|
|
826
|
-
caipNetworkId$.next(caipNetworkId);
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
provider.on("chainChanged", handleChainChanged);
|
|
830
|
-
provider.request({ method: "eth_chainId" }).then(handleChainChanged);
|
|
831
|
-
const sub = caipNetworkId$.pipe(
|
|
832
|
-
(0, import_rxjs5.distinctUntilChanged)(),
|
|
833
|
-
(0, import_rxjs5.map)((caipNetworkId) => {
|
|
834
|
-
const chainId = normalizeEvmChainId(caipNetworkId);
|
|
835
|
-
const transport = (0, import_viem2.custom)(
|
|
836
|
-
wrapWalletConnectProvider(
|
|
837
|
-
provider,
|
|
838
|
-
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
839
|
-
provider.session.topic,
|
|
840
|
-
caipNetworkId
|
|
841
|
-
)
|
|
842
|
-
);
|
|
843
|
-
return { transport, chainId };
|
|
844
|
-
}),
|
|
845
|
-
(0, import_rxjs5.map)(
|
|
846
|
-
({ transport, chainId }) => account.allAccounts.map((acc, i) => {
|
|
847
|
-
const client = (0, import_viem2.createWalletClient)({
|
|
848
|
-
account: acc.address,
|
|
849
|
-
transport
|
|
850
|
-
});
|
|
851
|
-
return {
|
|
852
|
-
id: getWalletAccountId(wallet.id, acc.address),
|
|
853
|
-
platform: "ethereum",
|
|
854
|
-
walletName: wallet.name,
|
|
855
|
-
walletId: wallet.id,
|
|
856
|
-
address: acc.address,
|
|
857
|
-
client,
|
|
858
|
-
chainId,
|
|
859
|
-
isWalletDefault: i === 0
|
|
860
|
-
};
|
|
861
|
-
})
|
|
862
|
-
)
|
|
863
|
-
).subscribe(subscriber);
|
|
864
|
-
return () => {
|
|
865
|
-
provider.off("chainChanged", handleChainChanged);
|
|
866
|
-
sub.unsubscribe();
|
|
867
|
-
};
|
|
868
|
-
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
869
|
-
);
|
|
870
|
-
};
|
|
871
|
-
var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs5.Observable((subscriber) => {
|
|
872
|
-
const sub = ethereumWallets.pipe(
|
|
873
|
-
(0, import_rxjs5.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
874
|
-
(0, import_rxjs5.switchMap)((wallets) => {
|
|
875
|
-
return wallets.length ? (0, import_rxjs5.combineLatest)([
|
|
876
|
-
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
877
|
-
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
|
|
878
|
-
// todo appkit
|
|
879
|
-
]) : (0, import_rxjs5.of)([]);
|
|
880
|
-
}),
|
|
881
|
-
(0, import_rxjs5.map)((accounts) => accounts.flat()),
|
|
882
|
-
(0, import_rxjs5.distinctUntilChanged)(isSameAccountsList)
|
|
883
|
-
).subscribe(subscriber);
|
|
884
|
-
return () => {
|
|
885
|
-
sub.unsubscribe();
|
|
886
|
-
};
|
|
887
|
-
}).pipe(
|
|
888
|
-
// logObservable("ethereumAccounts$", true),
|
|
889
|
-
(0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
890
|
-
);
|
|
891
|
-
var isSameAccountsList = (a, b) => {
|
|
892
|
-
if (a.length !== b.length) return false;
|
|
893
|
-
return a.every(
|
|
894
|
-
(account, i) => account.id === b[i]?.id && account.chainId === b[i]?.chainId
|
|
895
|
-
);
|
|
896
|
-
};
|
|
897
|
-
|
|
898
|
-
// src/api/polkadot/accounts.ts
|
|
899
|
-
var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
900
|
-
var import_rxjs6 = require("rxjs");
|
|
901
|
-
var getInjectedWalletAccounts$2 = (wallet) => {
|
|
902
|
-
if (!wallet.isConnected) return (0, import_rxjs6.of)([]);
|
|
903
|
-
return new import_rxjs6.Observable((subscriber) => {
|
|
904
|
-
const getAccount = (account) => ({
|
|
905
|
-
id: getWalletAccountId(wallet.id, account.address),
|
|
906
|
-
...account,
|
|
907
|
-
type: account.type ?? "sr25519",
|
|
908
|
-
platform: "polkadot",
|
|
909
|
-
walletName: wallet.name,
|
|
910
|
-
walletId: wallet.id
|
|
911
|
-
});
|
|
912
|
-
const extension = wallet.extension;
|
|
913
|
-
const unsubscribe = extension.subscribe((accounts) => {
|
|
914
|
-
subscriber.next(accounts.map(getAccount));
|
|
915
|
-
});
|
|
916
|
-
subscriber.next(extension.getAccounts().map(getAccount));
|
|
917
|
-
return () => {
|
|
918
|
-
return unsubscribe();
|
|
919
|
-
};
|
|
920
|
-
});
|
|
921
|
-
};
|
|
922
|
-
var getAppKitPolkadotSigner = (appKit, address) => {
|
|
923
|
-
const provider = appKit.getProvider("polkadot");
|
|
924
|
-
if (!provider) throw new Error("No provider found");
|
|
925
|
-
if (!provider.session) throw new Error("No session found");
|
|
926
|
-
return (0, import_pjs_signer.getPolkadotSignerFromPjs)(
|
|
927
|
-
address,
|
|
928
|
-
(transactionPayload) => {
|
|
929
|
-
if (!provider.session) throw new Error("No session found");
|
|
930
|
-
return provider.client.request({
|
|
931
|
-
topic: provider.session.topic,
|
|
932
|
-
chainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,
|
|
933
|
-
request: {
|
|
934
|
-
method: "polkadot_signTransaction",
|
|
935
|
-
params: {
|
|
936
|
-
address,
|
|
937
|
-
transactionPayload
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
});
|
|
941
|
-
},
|
|
942
|
-
async ({ address: address2, data }) => {
|
|
943
|
-
if (!provider.session) throw new Error("No session found");
|
|
944
|
-
const networks = appKit.getCaipNetworks("polkadot");
|
|
945
|
-
const chainId = networks[0]?.caipNetworkId;
|
|
946
|
-
if (!chainId) throw new Error("No chainId found");
|
|
947
|
-
return provider.client.request({
|
|
948
|
-
topic: provider.session.topic,
|
|
949
|
-
chainId,
|
|
950
|
-
request: {
|
|
951
|
-
method: "polkadot_signMessage",
|
|
952
|
-
params: {
|
|
953
|
-
address: address2,
|
|
954
|
-
message: data
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
);
|
|
960
|
-
};
|
|
961
|
-
var getAppKitAccounts$2 = (wallet) => {
|
|
962
|
-
const account = wallet.appKit.getAccount("polkadot");
|
|
963
|
-
const provider = wallet.appKit.getProvider("polkadot");
|
|
964
|
-
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
965
|
-
return (0, import_rxjs6.of)([]);
|
|
966
|
-
return (0, import_rxjs6.of)(
|
|
967
|
-
account.allAccounts.map(
|
|
968
|
-
(acc) => ({
|
|
969
|
-
id: getWalletAccountId(wallet.id, acc.address),
|
|
970
|
-
platform: "polkadot",
|
|
971
|
-
walletName: wallet.name,
|
|
972
|
-
walletId: wallet.id,
|
|
973
|
-
address: acc.address,
|
|
974
|
-
polkadotSigner: getAppKitPolkadotSigner(wallet.appKit, acc.address),
|
|
975
|
-
genesisHash: null,
|
|
976
|
-
name: `${wallet.name} Polkadot`,
|
|
977
|
-
// WalletConnect (Reown AppKit) doesn't expose account key type;
|
|
978
|
-
// default to sr25519, which is the most common Polkadot key type.
|
|
979
|
-
type: "sr25519"
|
|
980
|
-
})
|
|
981
|
-
)
|
|
982
|
-
);
|
|
983
|
-
};
|
|
984
|
-
var getPolkadotAccounts$ = (polkadotWallets$, polkadotAccountTypes) => new import_rxjs6.Observable((subscriber) => {
|
|
985
|
-
if (polkadotAccountTypes.length === 0) {
|
|
986
|
-
console.warn(
|
|
987
|
-
"[kheopskit] config.polkadotAccountTypes is empty; all Polkadot accounts will be filtered out."
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
const sub = polkadotWallets$.pipe(
|
|
991
|
-
(0, import_rxjs6.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
992
|
-
(0, import_rxjs6.switchMap)(
|
|
993
|
-
(wallets) => wallets.length ? (0, import_rxjs6.combineLatest)([
|
|
994
|
-
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$2),
|
|
995
|
-
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
996
|
-
]) : (0, import_rxjs6.of)([])
|
|
997
|
-
),
|
|
998
|
-
(0, import_rxjs6.map)(
|
|
999
|
-
(accounts) => accounts.flat().filter((account) => polkadotAccountTypes.includes(account.type))
|
|
1000
|
-
),
|
|
1001
|
-
(0, import_rxjs6.distinctUntilChanged)(isSameAccountsList2)
|
|
1002
|
-
).subscribe(subscriber);
|
|
1003
|
-
return () => {
|
|
1004
|
-
sub.unsubscribe();
|
|
1005
|
-
};
|
|
1006
|
-
}).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1007
|
-
var isSameAccountsList2 = (a, b) => {
|
|
1008
|
-
if (a.length !== b.length) return false;
|
|
1009
|
-
return a.every((account, i) => account.id === b[i]?.id);
|
|
1010
|
-
};
|
|
1011
|
-
|
|
1012
|
-
// src/api/accounts.ts
|
|
1013
344
|
var getAccounts$ = (config, wallets) => {
|
|
1014
|
-
return new
|
|
345
|
+
return new (0, _rxjs.Observable)((subscriber) => {
|
|
1015
346
|
const sources = config.platforms.map(
|
|
1016
|
-
(
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
case "ethereum":
|
|
1026
|
-
return getEthereumAccounts$(
|
|
1027
|
-
wallets.pipe(
|
|
1028
|
-
(0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "ethereum"))
|
|
1029
|
-
)
|
|
1030
|
-
);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
347
|
+
(plugin) => plugin.getAccounts$(
|
|
348
|
+
wallets.pipe(
|
|
349
|
+
_rxjs.map.call(void 0,
|
|
350
|
+
(ws) => ws.filter(
|
|
351
|
+
(w) => _chunk4ENHC7G4js.isWalletConnectWallet.call(void 0, w) || w.platform === plugin.platform
|
|
352
|
+
)
|
|
353
|
+
)
|
|
354
|
+
)
|
|
355
|
+
)
|
|
1033
356
|
);
|
|
1034
|
-
const accounts$ = sources.length ? (0,
|
|
1035
|
-
(0,
|
|
1036
|
-
) : (0,
|
|
357
|
+
const accounts$ = sources.length ? _rxjs.combineLatest.call(void 0, sources).pipe(
|
|
358
|
+
_rxjs.map.call(void 0, (accounts) => accounts.flat().sort(_chunkB4L6GAYDjs.sortAccounts))
|
|
359
|
+
) : _rxjs.of.call(void 0, []);
|
|
1037
360
|
const sub = accounts$.subscribe(subscriber);
|
|
1038
361
|
return () => {
|
|
1039
362
|
sub.unsubscribe();
|
|
1040
363
|
};
|
|
1041
|
-
}).pipe((0,
|
|
1042
|
-
};
|
|
1043
|
-
|
|
1044
|
-
// src/api/store.ts
|
|
1045
|
-
var import_lodash_es = require("lodash-es");
|
|
1046
|
-
var DEFAULT_SETTINGS = {};
|
|
1047
|
-
var toCompactPolkadotAccountType = (type) => {
|
|
1048
|
-
switch (type) {
|
|
1049
|
-
case "sr25519":
|
|
1050
|
-
return 0;
|
|
1051
|
-
case "ed25519":
|
|
1052
|
-
return 1;
|
|
1053
|
-
case "ecdsa":
|
|
1054
|
-
return 2;
|
|
1055
|
-
case "ethereum":
|
|
1056
|
-
return 3;
|
|
1057
|
-
default:
|
|
1058
|
-
return null;
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
var fromCompactPolkadotAccountType = (type) => {
|
|
1062
|
-
switch (type) {
|
|
1063
|
-
case 0:
|
|
1064
|
-
return "sr25519";
|
|
1065
|
-
case 1:
|
|
1066
|
-
return "ed25519";
|
|
1067
|
-
case 2:
|
|
1068
|
-
return "ecdsa";
|
|
1069
|
-
case 3:
|
|
1070
|
-
return "ethereum";
|
|
1071
|
-
default:
|
|
1072
|
-
return void 0;
|
|
1073
|
-
}
|
|
1074
|
-
};
|
|
1075
|
-
var createKheopskitStore = (options = {}) => {
|
|
1076
|
-
const { ssrCookies, storageKey = DEFAULT_STORAGE_KEY } = options;
|
|
1077
|
-
const storage = ssrCookies !== void 0 ? createCompactCookieStorage(ssrCookies) : safeLocalStorage;
|
|
1078
|
-
const store2 = createStore(storageKey, DEFAULT_SETTINGS, storage);
|
|
1079
|
-
const addEnabledWalletId = (walletId) => {
|
|
1080
|
-
parseWalletId(walletId);
|
|
1081
|
-
store2.mutate((prev) => ({
|
|
1082
|
-
...prev,
|
|
1083
|
-
autoReconnect: (0, import_lodash_es.uniq)((prev.autoReconnect ?? []).concat(walletId))
|
|
1084
|
-
}));
|
|
1085
|
-
};
|
|
1086
|
-
const removeEnabledWalletId = (walletId) => {
|
|
1087
|
-
store2.mutate((prev) => ({
|
|
1088
|
-
...prev,
|
|
1089
|
-
autoReconnect: (0, import_lodash_es.uniq)(
|
|
1090
|
-
(prev.autoReconnect ?? []).filter((id) => id !== walletId)
|
|
1091
|
-
)
|
|
1092
|
-
}));
|
|
1093
|
-
};
|
|
1094
|
-
const getCachedState = () => {
|
|
1095
|
-
const data = store2.get();
|
|
1096
|
-
return {
|
|
1097
|
-
wallets: data.cachedWallets ?? [],
|
|
1098
|
-
accounts: data.cachedAccounts ?? []
|
|
1099
|
-
};
|
|
1100
|
-
};
|
|
1101
|
-
const setCachedState = (wallets, accounts) => {
|
|
1102
|
-
store2.mutate((prev) => ({
|
|
1103
|
-
...prev,
|
|
1104
|
-
cachedWallets: wallets,
|
|
1105
|
-
cachedAccounts: accounts
|
|
1106
|
-
}));
|
|
1107
|
-
};
|
|
1108
|
-
return {
|
|
1109
|
-
observable: store2.observable,
|
|
1110
|
-
addEnabledWalletId,
|
|
1111
|
-
removeEnabledWalletId,
|
|
1112
|
-
getCachedState,
|
|
1113
|
-
setCachedState
|
|
1114
|
-
};
|
|
1115
|
-
};
|
|
1116
|
-
var _defaultStore = null;
|
|
1117
|
-
var getDefaultStore = () => {
|
|
1118
|
-
if (_defaultStore === null) {
|
|
1119
|
-
_defaultStore = createKheopskitStore();
|
|
1120
|
-
}
|
|
1121
|
-
return _defaultStore;
|
|
1122
|
-
};
|
|
1123
|
-
var store = {
|
|
1124
|
-
get observable() {
|
|
1125
|
-
return getDefaultStore().observable;
|
|
1126
|
-
},
|
|
1127
|
-
addEnabledWalletId: (walletId) => getDefaultStore().addEnabledWalletId(walletId),
|
|
1128
|
-
removeEnabledWalletId: (walletId) => getDefaultStore().removeEnabledWalletId(walletId),
|
|
1129
|
-
getCachedState: () => getDefaultStore().getCachedState(),
|
|
1130
|
-
setCachedState: (wallets, accounts) => getDefaultStore().setCachedState(wallets, accounts)
|
|
1131
|
-
};
|
|
1132
|
-
var isCompactStore = (value) => {
|
|
1133
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1134
|
-
if ("cachedWallets" in value || "cachedAccounts" in value) return false;
|
|
1135
|
-
return "v" in value || "w" in value || "a" in value || "r" in value;
|
|
1136
|
-
};
|
|
1137
|
-
var toCompactStore = (data) => {
|
|
1138
|
-
const wallets = data.cachedWallets?.map(
|
|
1139
|
-
(wallet) => [
|
|
1140
|
-
wallet.id,
|
|
1141
|
-
wallet.name,
|
|
1142
|
-
wallet.isConnected ? 1 : 0,
|
|
1143
|
-
wallet.type === "appKit" ? 1 : 0
|
|
1144
|
-
]
|
|
1145
|
-
);
|
|
1146
|
-
const accounts = data.cachedAccounts?.map(
|
|
1147
|
-
(account) => [
|
|
1148
|
-
account.walletId,
|
|
1149
|
-
account.address,
|
|
1150
|
-
account.name ?? null,
|
|
1151
|
-
account.chainId ?? null,
|
|
1152
|
-
toCompactPolkadotAccountType(account.polkadotAccountType)
|
|
1153
|
-
]
|
|
1154
|
-
);
|
|
1155
|
-
return {
|
|
1156
|
-
v: 1,
|
|
1157
|
-
r: data.autoReconnect,
|
|
1158
|
-
w: wallets?.length ? wallets : void 0,
|
|
1159
|
-
a: accounts?.length ? accounts : void 0
|
|
1160
|
-
};
|
|
1161
|
-
};
|
|
1162
|
-
var fromCompactStore = (data) => {
|
|
1163
|
-
const walletNameMap = /* @__PURE__ */ new Map();
|
|
1164
|
-
const wallets = (data.w ?? []).map((item) => {
|
|
1165
|
-
const [id, name, isConnected, type] = item;
|
|
1166
|
-
walletNameMap.set(id, name);
|
|
1167
|
-
const { platform } = parseWalletId(id);
|
|
1168
|
-
return {
|
|
1169
|
-
id,
|
|
1170
|
-
platform,
|
|
1171
|
-
type: type === 1 ? "appKit" : "injected",
|
|
1172
|
-
name,
|
|
1173
|
-
isConnected: isConnected === 1
|
|
1174
|
-
};
|
|
1175
|
-
});
|
|
1176
|
-
const accounts = (data.a ?? []).map((item) => {
|
|
1177
|
-
const [walletId, address, name, chainId, polkadotAccountType] = item;
|
|
1178
|
-
const { platform } = parseWalletId(walletId);
|
|
1179
|
-
return {
|
|
1180
|
-
id: getWalletAccountId(walletId, address),
|
|
1181
|
-
platform,
|
|
1182
|
-
address,
|
|
1183
|
-
name: name ?? void 0,
|
|
1184
|
-
chainId: chainId ?? void 0,
|
|
1185
|
-
polkadotAccountType: platform === "polkadot" ? fromCompactPolkadotAccountType(polkadotAccountType) : void 0,
|
|
1186
|
-
walletId,
|
|
1187
|
-
walletName: walletNameMap.get(walletId) ?? walletId
|
|
1188
|
-
};
|
|
1189
|
-
});
|
|
1190
|
-
return {
|
|
1191
|
-
autoReconnect: data.r,
|
|
1192
|
-
cachedWallets: wallets,
|
|
1193
|
-
cachedAccounts: accounts
|
|
1194
|
-
};
|
|
1195
|
-
};
|
|
1196
|
-
var decodeStore = (raw, fallback) => {
|
|
1197
|
-
try {
|
|
1198
|
-
const parsed = JSON.parse(raw);
|
|
1199
|
-
if (isCompactStore(parsed)) return fromCompactStore(parsed);
|
|
1200
|
-
return parsed;
|
|
1201
|
-
} catch {
|
|
1202
|
-
return fallback;
|
|
1203
|
-
}
|
|
1204
|
-
};
|
|
1205
|
-
var encodeStore = (data) => JSON.stringify(toCompactStore(data));
|
|
1206
|
-
var createCompactCookieStorage = (initialCookies) => {
|
|
1207
|
-
const base = cookieStorage(initialCookies);
|
|
1208
|
-
return {
|
|
1209
|
-
getItem: (key) => {
|
|
1210
|
-
const raw = base.getItem(key);
|
|
1211
|
-
if (!raw) return null;
|
|
1212
|
-
const expanded = decodeStore(raw, DEFAULT_SETTINGS);
|
|
1213
|
-
if (typeof document !== "undefined") {
|
|
1214
|
-
try {
|
|
1215
|
-
const parsed = JSON.parse(raw);
|
|
1216
|
-
if (!isCompactStore(parsed)) {
|
|
1217
|
-
base.setItem(key, encodeStore(expanded));
|
|
1218
|
-
}
|
|
1219
|
-
} catch {
|
|
1220
|
-
}
|
|
1221
|
-
}
|
|
1222
|
-
return JSON.stringify(expanded);
|
|
1223
|
-
},
|
|
1224
|
-
setItem: (key, value) => {
|
|
1225
|
-
const expanded = decodeStore(value, DEFAULT_SETTINGS);
|
|
1226
|
-
base.setItem(key, encodeStore(expanded));
|
|
1227
|
-
},
|
|
1228
|
-
removeItem: base.removeItem,
|
|
1229
|
-
subscribe: (key, callback) => {
|
|
1230
|
-
const unsubscribe = base.subscribe?.(key, (value) => {
|
|
1231
|
-
if (!value) {
|
|
1232
|
-
callback(null);
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
const expanded = decodeStore(value, DEFAULT_SETTINGS);
|
|
1236
|
-
callback(JSON.stringify(expanded));
|
|
1237
|
-
});
|
|
1238
|
-
return () => {
|
|
1239
|
-
unsubscribe?.();
|
|
1240
|
-
};
|
|
1241
|
-
}
|
|
1242
|
-
};
|
|
364
|
+
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
1243
365
|
};
|
|
1244
366
|
|
|
1245
367
|
// src/api/wallets.ts
|
|
1246
|
-
var import_rxjs10 = require("rxjs");
|
|
1247
368
|
|
|
1248
|
-
// src/utils/sortWallets.ts
|
|
1249
|
-
var sortWallets = (w1, w2) => {
|
|
1250
|
-
if (w1.platform !== w2.platform) {
|
|
1251
|
-
return w1.platform === "polkadot" ? -1 : 1;
|
|
1252
|
-
}
|
|
1253
|
-
if (w1.name.toLowerCase() === "talisman") return -1;
|
|
1254
|
-
if (w2.name.toLowerCase() === "talisman") return 1;
|
|
1255
|
-
return w1.name.localeCompare(w2.name);
|
|
1256
|
-
};
|
|
1257
369
|
|
|
1258
|
-
// src/api/ethereum/wallets.ts
|
|
1259
|
-
var import_mipd = require("mipd");
|
|
1260
|
-
var import_rxjs8 = require("rxjs");
|
|
1261
|
-
var providersDetails$ = new import_rxjs8.Observable(
|
|
1262
|
-
(subscriber) => {
|
|
1263
|
-
if (typeof window === "undefined") {
|
|
1264
|
-
subscriber.next([]);
|
|
1265
|
-
return () => {
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
const mipdStore = (0, import_mipd.createStore)();
|
|
1269
|
-
const unsubscribe = mipdStore.subscribe((providerDetails2) => {
|
|
1270
|
-
subscriber.next(providerDetails2);
|
|
1271
|
-
});
|
|
1272
|
-
const providerDetails = mipdStore.getProviders();
|
|
1273
|
-
subscriber.next(providerDetails);
|
|
1274
|
-
return () => {
|
|
1275
|
-
unsubscribe();
|
|
1276
|
-
mipdStore.destroy();
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1280
|
-
var createEthereumInjectedWallets$ = (store2) => new import_rxjs8.Observable((subscriber) => {
|
|
1281
|
-
const enabledWalletIds$ = new import_rxjs8.BehaviorSubject(/* @__PURE__ */ new Set());
|
|
1282
|
-
const connectWallet = async (walletId, provider) => {
|
|
1283
|
-
if (enabledWalletIds$.value.has(walletId))
|
|
1284
|
-
throw new Error(`Extension ${walletId} already connected`);
|
|
1285
|
-
await provider.request({
|
|
1286
|
-
method: "eth_requestAccounts"
|
|
1287
|
-
});
|
|
1288
|
-
const newSet = new Set(enabledWalletIds$.value);
|
|
1289
|
-
newSet.add(walletId);
|
|
1290
|
-
enabledWalletIds$.next(newSet);
|
|
1291
|
-
store2.addEnabledWalletId(walletId);
|
|
1292
|
-
};
|
|
1293
|
-
const disconnectWallet = async (walletId) => {
|
|
1294
|
-
if (!enabledWalletIds$.value.has(walletId))
|
|
1295
|
-
throw new Error(`Extension ${walletId} is not connected`);
|
|
1296
|
-
const newSet = new Set(enabledWalletIds$.value);
|
|
1297
|
-
newSet.delete(walletId);
|
|
1298
|
-
enabledWalletIds$.next(newSet);
|
|
1299
|
-
store2.removeEnabledWalletId(walletId);
|
|
1300
|
-
};
|
|
1301
|
-
const sub = (0, import_rxjs8.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
|
|
1302
|
-
(0, import_rxjs8.map)(([providerDetails, enabledWalletIds]) => {
|
|
1303
|
-
return providerDetails.map((pd) => {
|
|
1304
|
-
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
1305
|
-
const provider = pd.provider;
|
|
1306
|
-
return {
|
|
1307
|
-
platform: "ethereum",
|
|
1308
|
-
type: "injected",
|
|
1309
|
-
id: walletId,
|
|
1310
|
-
name: pd.info.name,
|
|
1311
|
-
icon: pd.info.icon,
|
|
1312
|
-
provider,
|
|
1313
|
-
isConnected: enabledWalletIds.has(walletId),
|
|
1314
|
-
providerId: pd.info.rdns,
|
|
1315
|
-
connect: () => connectWallet(walletId, provider),
|
|
1316
|
-
disconnect: () => disconnectWallet(walletId)
|
|
1317
|
-
};
|
|
1318
|
-
});
|
|
1319
|
-
}),
|
|
1320
|
-
(0, import_rxjs8.distinctUntilChanged)(walletsEqual)
|
|
1321
|
-
).subscribe(subscriber);
|
|
1322
|
-
return () => {
|
|
1323
|
-
sub.unsubscribe();
|
|
1324
|
-
};
|
|
1325
|
-
}).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1326
|
-
var getEthereumWallets$ = (config, store2 = store) => {
|
|
1327
|
-
return new import_rxjs8.Observable((subscriber) => {
|
|
1328
|
-
const subscription = (0, import_rxjs8.combineLatest)([
|
|
1329
|
-
createEthereumInjectedWallets$(store2),
|
|
1330
|
-
getAppKitWallets$(config)?.pipe((0, import_rxjs8.map)((w) => w.ethereum))
|
|
1331
|
-
]).pipe(
|
|
1332
|
-
(0, import_rxjs8.map)(
|
|
1333
|
-
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
1334
|
-
)
|
|
1335
|
-
).subscribe(subscriber);
|
|
1336
|
-
return () => {
|
|
1337
|
-
subscription.unsubscribe();
|
|
1338
|
-
};
|
|
1339
|
-
}).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1340
|
-
};
|
|
1341
|
-
var walletsEqual = (a, b) => {
|
|
1342
|
-
if (a.length !== b.length) return false;
|
|
1343
|
-
return a.every(
|
|
1344
|
-
(w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name
|
|
1345
|
-
);
|
|
1346
|
-
};
|
|
1347
370
|
|
|
1348
|
-
// src/api/polkadot/wallets.ts
|
|
1349
|
-
var import_lodash_es2 = require("lodash-es");
|
|
1350
|
-
var import_pjs_signer2 = require("polkadot-api/pjs-signer");
|
|
1351
|
-
var import_rxjs9 = require("rxjs");
|
|
1352
|
-
var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
|
|
1353
|
-
var createWalletIdsPoller$ = () => {
|
|
1354
|
-
return new import_rxjs9.Observable((subscriber) => {
|
|
1355
|
-
subscriber.next(getInjectedWalletsIds());
|
|
1356
|
-
const intervals = [100, 200, 300, 500];
|
|
1357
|
-
let index = 0;
|
|
1358
|
-
const poll = () => {
|
|
1359
|
-
subscriber.next(getInjectedWalletsIds());
|
|
1360
|
-
if (index < intervals.length) {
|
|
1361
|
-
const delay = intervals[index++];
|
|
1362
|
-
setTimeout(poll, delay);
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
if (intervals.length > 0) {
|
|
1366
|
-
setTimeout(poll, intervals[index++] ?? 100);
|
|
1367
|
-
}
|
|
1368
|
-
return () => {
|
|
1369
|
-
};
|
|
1370
|
-
}).pipe(
|
|
1371
|
-
(0, import_rxjs9.distinctUntilChanged)(import_lodash_es2.isEqual),
|
|
1372
|
-
(0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
1373
|
-
);
|
|
1374
|
-
};
|
|
1375
|
-
var createPolkadotInjectedWallets$ = (store2) => new import_rxjs9.Observable((subscriber) => {
|
|
1376
|
-
const enabledExtensions$ = new import_rxjs9.BehaviorSubject(/* @__PURE__ */ new Map());
|
|
1377
|
-
const connect = async (walletId) => {
|
|
1378
|
-
if (enabledExtensions$.value.has(walletId))
|
|
1379
|
-
throw new Error(`Extension ${walletId} already connected`);
|
|
1380
|
-
const { identifier } = parseWalletId(walletId);
|
|
1381
|
-
const extension = await (0, import_pjs_signer2.connectInjectedExtension)(identifier);
|
|
1382
|
-
const newMap = new Map(enabledExtensions$.value);
|
|
1383
|
-
newMap.set(walletId, extension);
|
|
1384
|
-
enabledExtensions$.next(newMap);
|
|
1385
|
-
store2.addEnabledWalletId(walletId);
|
|
1386
|
-
};
|
|
1387
|
-
const disconnect = (walletId) => {
|
|
1388
|
-
if (!enabledExtensions$.value.has(walletId))
|
|
1389
|
-
throw new Error(`Extension ${walletId} is not connected`);
|
|
1390
|
-
const newMap = new Map(enabledExtensions$.value);
|
|
1391
|
-
newMap.delete(walletId);
|
|
1392
|
-
enabledExtensions$.next(newMap);
|
|
1393
|
-
store2.removeEnabledWalletId(walletId);
|
|
1394
|
-
};
|
|
1395
|
-
const walletIds$ = createWalletIdsPoller$();
|
|
1396
|
-
const subscription = (0, import_rxjs9.combineLatest)([walletIds$, enabledExtensions$]).pipe(
|
|
1397
|
-
(0, import_rxjs9.map)(([walletIds, enabledExtensions]) => {
|
|
1398
|
-
return walletIds.map((id) => {
|
|
1399
|
-
const { identifier } = parseWalletId(id);
|
|
1400
|
-
const extension = enabledExtensions.get(id);
|
|
1401
|
-
const extInfo = POLKADOT_EXTENSIONS[identifier];
|
|
1402
|
-
return {
|
|
1403
|
-
id,
|
|
1404
|
-
type: "injected",
|
|
1405
|
-
platform: "polkadot",
|
|
1406
|
-
name: extInfo?.name ?? identifier,
|
|
1407
|
-
icon: extInfo?.icon ?? "",
|
|
1408
|
-
extensionId: identifier,
|
|
1409
|
-
extension,
|
|
1410
|
-
isConnected: !!extension,
|
|
1411
|
-
connect: () => connect(id),
|
|
1412
|
-
disconnect: () => disconnect(id)
|
|
1413
|
-
};
|
|
1414
|
-
});
|
|
1415
|
-
}),
|
|
1416
|
-
(0, import_rxjs9.distinctUntilChanged)(walletsEqual2)
|
|
1417
|
-
).subscribe(subscriber);
|
|
1418
|
-
return () => {
|
|
1419
|
-
subscription.unsubscribe();
|
|
1420
|
-
};
|
|
1421
|
-
}).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1422
|
-
var getPolkadotWallets$ = (config, store2 = store) => {
|
|
1423
|
-
return new import_rxjs9.Observable((subscriber) => {
|
|
1424
|
-
const subscription = (0, import_rxjs9.combineLatest)([
|
|
1425
|
-
createPolkadotInjectedWallets$(store2),
|
|
1426
|
-
getAppKitWallets$(config)?.pipe((0, import_rxjs9.map)((w) => w.polkadot))
|
|
1427
|
-
]).pipe(
|
|
1428
|
-
(0, import_rxjs9.map)(
|
|
1429
|
-
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
1430
|
-
)
|
|
1431
|
-
).subscribe(subscriber);
|
|
1432
|
-
return () => {
|
|
1433
|
-
subscription.unsubscribe();
|
|
1434
|
-
};
|
|
1435
|
-
}).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1436
|
-
};
|
|
1437
|
-
var walletsEqual2 = (a, b) => {
|
|
1438
|
-
if (a.length !== b.length) return false;
|
|
1439
|
-
return a.every(
|
|
1440
|
-
(w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name
|
|
1441
|
-
);
|
|
1442
|
-
};
|
|
1443
371
|
|
|
1444
|
-
|
|
1445
|
-
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
var getWallets$ = (config, store2 = _chunkXQWJM3KCjs.store) => {
|
|
1446
379
|
const autoReconnectWalletIds$ = store2.observable.pipe(
|
|
1447
|
-
(0,
|
|
1448
|
-
(0,
|
|
1449
|
-
(0,
|
|
380
|
+
_rxjs.map.call(void 0, (s) => _nullishCoalesce(s.autoReconnect, () => ( []))),
|
|
381
|
+
_rxjs.take.call(void 0, 1),
|
|
382
|
+
_rxjs.shareReplay.call(void 0, { bufferSize: 1, refCount: true })
|
|
1450
383
|
);
|
|
1451
|
-
return new
|
|
384
|
+
return new (0, _rxjs.Observable)((subscriber) => {
|
|
385
|
+
const ctx = { config, store: store2 };
|
|
1452
386
|
const observables = config.platforms.map(
|
|
1453
|
-
(
|
|
1454
|
-
switch (platform) {
|
|
1455
|
-
case "polkadot":
|
|
1456
|
-
return getPolkadotWallets$(config, store2);
|
|
1457
|
-
case "ethereum":
|
|
1458
|
-
return getEthereumWallets$(config, store2);
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
387
|
+
(plugin) => plugin.getWallets$(ctx)
|
|
1461
388
|
);
|
|
1462
|
-
const
|
|
1463
|
-
|
|
389
|
+
const platformWallets$ = observables.length ? _rxjs.combineLatest.call(void 0, observables).pipe(_rxjs.map.call(void 0, (wallets) => wallets.flat())) : _rxjs.of.call(void 0, []);
|
|
390
|
+
const wallets$ = _rxjs.combineLatest.call(void 0, [
|
|
391
|
+
platformWallets$,
|
|
392
|
+
getWalletConnectWallet$(config)
|
|
393
|
+
]).pipe(
|
|
394
|
+
_rxjs.map.call(void 0, ([platformWallets, walletConnect]) => {
|
|
395
|
+
const all = walletConnect ? [...platformWallets, walletConnect] : platformWallets;
|
|
396
|
+
return all.sort(_chunkB4L6GAYDjs.sortWallets);
|
|
397
|
+
})
|
|
1464
398
|
// Note: No startWith([]) here - the hydration buffer handles initial state
|
|
1465
|
-
)
|
|
399
|
+
);
|
|
1466
400
|
const reconnectingWallets = /* @__PURE__ */ new Set();
|
|
1467
|
-
const
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
),
|
|
1472
|
-
(0,
|
|
401
|
+
const reconnectedWallets = /* @__PURE__ */ new Set();
|
|
402
|
+
const MAX_RECONNECT_ATTEMPTS = 3;
|
|
403
|
+
const failedAttempts = /* @__PURE__ */ new Map();
|
|
404
|
+
const subAutoReconnect = _rxjs.combineLatest.call(void 0, [wallets$, autoReconnectWalletIds$]).pipe(
|
|
405
|
+
_rxjs.filter.call(void 0, ([, walletIds]) => config.autoReconnect && !!_optionalChain([walletIds, 'optionalAccess', _3 => _3.length])),
|
|
406
|
+
_rxjs.mergeMap.call(void 0,
|
|
407
|
+
([wallets, walletIds]) => wallets.filter((wallet) => _optionalChain([walletIds, 'optionalAccess', _4 => _4.includes, 'call', _5 => _5(wallet.id)]))
|
|
408
|
+
)
|
|
1473
409
|
).subscribe(async (wallet) => {
|
|
1474
|
-
if (wallet.isConnected || reconnectingWallets.has(wallet.id)) {
|
|
410
|
+
if (wallet.isConnected || reconnectingWallets.has(wallet.id) || reconnectedWallets.has(wallet.id) || (_nullishCoalesce(failedAttempts.get(wallet.id), () => ( 0))) >= MAX_RECONNECT_ATTEMPTS) {
|
|
1475
411
|
return;
|
|
1476
412
|
}
|
|
1477
413
|
reconnectingWallets.add(wallet.id);
|
|
1478
414
|
try {
|
|
1479
415
|
await wallet.connect();
|
|
416
|
+
reconnectedWallets.add(wallet.id);
|
|
417
|
+
failedAttempts.delete(wallet.id);
|
|
1480
418
|
} catch (err) {
|
|
419
|
+
failedAttempts.set(
|
|
420
|
+
wallet.id,
|
|
421
|
+
(_nullishCoalesce(failedAttempts.get(wallet.id), () => ( 0))) + 1
|
|
422
|
+
);
|
|
1481
423
|
console.error("Failed to reconnect wallet %s", wallet.id, { err });
|
|
1482
424
|
} finally {
|
|
1483
425
|
reconnectingWallets.delete(wallet.id);
|
|
@@ -1488,13 +430,14 @@ var getWallets$ = (config, store2 = store) => {
|
|
|
1488
430
|
subAutoReconnect.unsubscribe();
|
|
1489
431
|
subWallets.unsubscribe();
|
|
1490
432
|
};
|
|
1491
|
-
}).pipe((0,
|
|
433
|
+
}).pipe(_rxjs.shareReplay.call(void 0, { refCount: true, bufferSize: 1 }));
|
|
1492
434
|
};
|
|
1493
435
|
|
|
1494
436
|
// src/api/kheopskit.ts
|
|
1495
|
-
var getKheopskit$ = (config,
|
|
1496
|
-
const
|
|
1497
|
-
const
|
|
437
|
+
var getKheopskit$ = (config, options = {}) => {
|
|
438
|
+
const { ssrCookies, store: existingStore } = options;
|
|
439
|
+
const kc = _chunkXQWJM3KCjs.resolveConfig.call(void 0, config);
|
|
440
|
+
const store2 = _nullishCoalesce(existingStore, () => ( _chunkXQWJM3KCjs.createKheopskitStore.call(void 0, { ssrCookies, storageKey: kc.storageKey })));
|
|
1498
441
|
if (kc.debug) console.debug("[kheopskit] config", kc);
|
|
1499
442
|
if (kc.debug && typeof window === "undefined" && ssrCookies === void 0) {
|
|
1500
443
|
console.warn(
|
|
@@ -1503,25 +446,23 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1503
446
|
}
|
|
1504
447
|
const cachedState = store2.getCachedState();
|
|
1505
448
|
const cachedWallets = cachedState.wallets.map((w) => {
|
|
1506
|
-
const wallet = hydrateWallet(w);
|
|
449
|
+
const wallet = _chunkB4L6GAYDjs.hydrateWallet.call(void 0, w);
|
|
1507
450
|
if (!wallet.icon) {
|
|
1508
|
-
const cachedIcon = getCachedIcon(wallet.id);
|
|
451
|
+
const cachedIcon = _chunkB4L6GAYDjs.getCachedIcon.call(void 0, wallet.id);
|
|
1509
452
|
if (cachedIcon) {
|
|
1510
453
|
return { ...wallet, icon: cachedIcon };
|
|
1511
454
|
}
|
|
1512
455
|
}
|
|
1513
456
|
return wallet;
|
|
1514
457
|
});
|
|
1515
|
-
const cachedAccounts = cachedState.accounts.map(hydrateAccount)
|
|
1516
|
-
(account) => account.platform !== "polkadot" || kc.polkadotAccountTypes.includes(account.type)
|
|
1517
|
-
);
|
|
458
|
+
const cachedAccounts = cachedState.accounts.filter((cached) => _chunkB4L6GAYDjs.acceptsCachedAccount.call(void 0, cached, kc.platforms)).map(_chunkB4L6GAYDjs.hydrateAccount);
|
|
1518
459
|
if (kc.debug && cachedWallets.length > 0) {
|
|
1519
460
|
console.debug("[kheopskit] hydrating from cache:", {
|
|
1520
461
|
wallets: cachedWallets.length,
|
|
1521
462
|
accounts: cachedAccounts.length
|
|
1522
463
|
});
|
|
1523
464
|
}
|
|
1524
|
-
return new
|
|
465
|
+
return new (0, _rxjs.Observable)((subscriber) => {
|
|
1525
466
|
const liveWallets$ = getWallets$(kc, store2);
|
|
1526
467
|
const liveAccounts$ = getAccounts$(kc, liveWallets$);
|
|
1527
468
|
const bufferedWallets$ = createHydrationBuffer(
|
|
@@ -1543,7 +484,7 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1543
484
|
(live, cached) => ({
|
|
1544
485
|
...cached,
|
|
1545
486
|
// Priority: cached icon > localStorage cache > live icon
|
|
1546
|
-
icon: cached.icon || getCachedIcon(cached.id) || live.icon,
|
|
487
|
+
icon: cached.icon || _chunkB4L6GAYDjs.getCachedIcon.call(void 0, cached.id) || live.icon,
|
|
1547
488
|
// Use live wallet's connect/disconnect functions
|
|
1548
489
|
connect: live.connect,
|
|
1549
490
|
disconnect: live.disconnect
|
|
@@ -1551,7 +492,7 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1551
492
|
// Transform cached-only items: add icon from localStorage cache
|
|
1552
493
|
(cached) => ({
|
|
1553
494
|
...cached,
|
|
1554
|
-
icon: cached.icon || getCachedIcon(cached.id) || ""
|
|
495
|
+
icon: cached.icon || _chunkB4L6GAYDjs.getCachedIcon.call(void 0, cached.id) || ""
|
|
1555
496
|
})
|
|
1556
497
|
);
|
|
1557
498
|
const bufferedAccounts$ = createAccountHydrationBuffer(
|
|
@@ -1567,11 +508,17 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1567
508
|
return [...cachedWalletIds].every((id) => liveWalletIds.has(id));
|
|
1568
509
|
}
|
|
1569
510
|
);
|
|
1570
|
-
const
|
|
1571
|
-
|
|
1572
|
-
|
|
511
|
+
const sharedWallets$ = bufferedWallets$.pipe(
|
|
512
|
+
_rxjs.shareReplay.call(void 0, { bufferSize: 1, refCount: true })
|
|
513
|
+
);
|
|
514
|
+
const sharedAccounts$ = bufferedAccounts$.pipe(
|
|
515
|
+
_rxjs.shareReplay.call(void 0, { bufferSize: 1, refCount: true })
|
|
516
|
+
);
|
|
517
|
+
const subscription = _rxjs.combineLatest.call(void 0, {
|
|
518
|
+
wallets: sharedWallets$,
|
|
519
|
+
accounts: sharedAccounts$
|
|
1573
520
|
}).pipe(
|
|
1574
|
-
(0,
|
|
521
|
+
_rxjs.map.call(void 0, ({ wallets, accounts }) => {
|
|
1575
522
|
if (kc.debug) {
|
|
1576
523
|
console.debug("[kheopskit] hydration state", {
|
|
1577
524
|
walletsHydrating: wallets.isHydrating,
|
|
@@ -1582,29 +529,32 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1582
529
|
}
|
|
1583
530
|
return {
|
|
1584
531
|
config: kc,
|
|
1585
|
-
wallets: wallets.items,
|
|
1586
|
-
accounts: accounts.items,
|
|
532
|
+
wallets: [...wallets.items].sort(_chunkB4L6GAYDjs.sortWallets),
|
|
533
|
+
accounts: [...accounts.items].sort(_chunkB4L6GAYDjs.sortAccounts),
|
|
1587
534
|
isHydrating: wallets.isHydrating || accounts.isHydrating
|
|
1588
535
|
};
|
|
1589
536
|
})
|
|
1590
537
|
).subscribe(subscriber);
|
|
1591
|
-
const persistSub = (0,
|
|
1592
|
-
wallets:
|
|
1593
|
-
accounts:
|
|
538
|
+
const persistSub = _rxjs.combineLatest.call(void 0, {
|
|
539
|
+
wallets: sharedWallets$,
|
|
540
|
+
accounts: sharedAccounts$
|
|
1594
541
|
}).pipe(
|
|
1595
542
|
// Wait for hydration to complete
|
|
1596
|
-
(0,
|
|
543
|
+
_rxjs.filter.call(void 0,
|
|
1597
544
|
({ wallets, accounts }) => !wallets.isHydrating && !accounts.isHydrating
|
|
1598
545
|
),
|
|
1599
546
|
// Debounce to avoid excessive writes
|
|
1600
|
-
(0,
|
|
1601
|
-
// Only persist if
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
const
|
|
1607
|
-
|
|
547
|
+
_rxjs.debounceTime.call(void 0, 1e3),
|
|
548
|
+
// Only persist if the serialized snapshot would actually change.
|
|
549
|
+
// Compare the persisted fields (not just ids): an Ethereum chain switch
|
|
550
|
+
// keeps the same account id but changes the cached chainId, so an
|
|
551
|
+
// id-only comparator would skip persisting it.
|
|
552
|
+
_rxjs.distinctUntilChanged.call(void 0, (prev, curr) => {
|
|
553
|
+
const prevWalletKeys = prev.wallets.items.map(walletPersistKey);
|
|
554
|
+
const currWalletKeys = curr.wallets.items.map(walletPersistKey);
|
|
555
|
+
const prevAccountKeys = prev.accounts.items.map(accountChangeKey);
|
|
556
|
+
const currAccountKeys = curr.accounts.items.map(accountChangeKey);
|
|
557
|
+
return arraysEqual(prevWalletKeys, currWalletKeys) && arraysEqual(prevAccountKeys, currAccountKeys);
|
|
1608
558
|
})
|
|
1609
559
|
).subscribe(({ wallets, accounts }) => {
|
|
1610
560
|
const connectedWalletIds = new Set(
|
|
@@ -1620,8 +570,8 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1620
570
|
});
|
|
1621
571
|
}
|
|
1622
572
|
store2.setCachedState(
|
|
1623
|
-
wallets.items.map(serializeWallet),
|
|
1624
|
-
relevantAccounts.map(serializeAccount)
|
|
573
|
+
wallets.items.map(_chunkB4L6GAYDjs.serializeWallet),
|
|
574
|
+
relevantAccounts.map(_chunkB4L6GAYDjs.serializeAccount)
|
|
1625
575
|
);
|
|
1626
576
|
const icons = {};
|
|
1627
577
|
for (const wallet of wallets.items) {
|
|
@@ -1629,39 +579,61 @@ var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
|
1629
579
|
icons[wallet.id] = wallet.icon;
|
|
1630
580
|
}
|
|
1631
581
|
}
|
|
1632
|
-
setCachedIcons(icons);
|
|
582
|
+
_chunkB4L6GAYDjs.setCachedIcons.call(void 0, icons);
|
|
1633
583
|
});
|
|
1634
584
|
return () => {
|
|
1635
585
|
subscription.unsubscribe();
|
|
1636
586
|
persistSub.unsubscribe();
|
|
1637
587
|
};
|
|
1638
588
|
}).pipe(
|
|
1639
|
-
(0,
|
|
1640
|
-
(0,
|
|
589
|
+
_rxjs.distinctUntilChanged.call(void 0, statesEqual),
|
|
590
|
+
_rxjs.throttleTime.call(void 0, 16, void 0, { leading: true, trailing: true }),
|
|
1641
591
|
// ~1 frame at 60fps
|
|
1642
592
|
logObservable("kheopskit$", { enabled: kc.debug, printValue: true }),
|
|
1643
|
-
(0,
|
|
593
|
+
_rxjs.shareReplay.call(void 0, { bufferSize: 1, refCount: true })
|
|
594
|
+
// The runtime objects are the concrete per-plugin wallet/account types;
|
|
595
|
+
// recover the precise KheopskitState<P> the caller's plugins imply.
|
|
1644
596
|
);
|
|
1645
597
|
};
|
|
1646
598
|
var arraysEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
1647
|
-
var
|
|
1648
|
-
(
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
599
|
+
var accountChangeKey = (account) => {
|
|
600
|
+
switch (account.platform) {
|
|
601
|
+
case "ethereum":
|
|
602
|
+
return `${account.id}|${_nullishCoalesce(account.chainId, () => ( ""))}`;
|
|
603
|
+
case "polkadot":
|
|
604
|
+
return `${account.id}|${_nullishCoalesce(account.type, () => ( ""))}`;
|
|
605
|
+
case "solana":
|
|
606
|
+
return `${account.id}|${(_nullishCoalesce(account.chains, () => ( []))).join(",")}`;
|
|
607
|
+
default:
|
|
608
|
+
return account.id;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
var walletPlatforms = (wallet) => _chunk4ENHC7G4js.isWalletConnectWallet.call(void 0, wallet) ? wallet.platforms.join(",") : "";
|
|
612
|
+
var walletPersistKey = (wallet) => `${wallet.id}|${wallet.isConnected ? 1 : 0}|${wallet.name}`;
|
|
613
|
+
var walletUiKey = (wallet) => `${walletPersistKey(wallet)}|${wallet.icon}|${walletPlatforms(wallet)}`;
|
|
614
|
+
var statesEqual = (a, b) => a.isHydrating === b.isHydrating && a.wallets.length === b.wallets.length && a.accounts.length === b.accounts.length && a.wallets.every((w, i) => {
|
|
615
|
+
const other = b.wallets[i];
|
|
616
|
+
return !!other && walletUiKey(w) === walletUiKey(other);
|
|
617
|
+
}) && a.accounts.every((acc, i) => {
|
|
618
|
+
const other = b.accounts[i];
|
|
619
|
+
return !!other && accountChangeKey(acc) === accountChangeKey(other);
|
|
1666
620
|
});
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
exports.DEFAULT_STORAGE_KEY = _chunkXQWJM3KCjs.DEFAULT_STORAGE_KEY; exports.KheopskitError = _chunkXQWJM3KCjs.KheopskitError; exports.clearAllCachedObservables = _chunk4ENHC7G4js.clearAllCachedObservables; exports.createKheopskitStore = _chunkXQWJM3KCjs.createKheopskitStore; exports.getDefaultStore = _chunkXQWJM3KCjs.getDefaultStore; exports.getKheopskit$ = getKheopskit$; exports.getWalletAccountId = _chunkXQWJM3KCjs.getWalletAccountId; exports.getWalletId = _chunk4ENHC7G4js.getWalletId; exports.isInjectedWallet = _chunk4ENHC7G4js.isInjectedWallet; exports.isValidAddress = _chunkXQWJM3KCjs.isValidAddress; exports.isValidWalletId = _chunk4ENHC7G4js.isValidWalletId; exports.isWalletConnectWallet = _chunk4ENHC7G4js.isWalletConnectWallet; exports.parseWalletAccountId = _chunkXQWJM3KCjs.parseWalletAccountId; exports.parseWalletId = _chunk4ENHC7G4js.parseWalletId; exports.resetAppKitCache = resetAppKitCache; exports.resolveConfig = _chunkXQWJM3KCjs.resolveConfig;
|
|
1667
639
|
//# sourceMappingURL=index.js.map
|