@kheopskit/core 0.0.22 → 0.1.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/index.d.mts +143 -2
- package/dist/index.d.ts +143 -2
- package/dist/index.js +994 -338
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1024 -360
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -15
package/dist/index.js
CHANGED
|
@@ -20,27 +20,531 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
DEFAULT_STORAGE_KEY: () => DEFAULT_STORAGE_KEY,
|
|
24
|
+
clearAllCachedObservables: () => clearAllCachedObservables,
|
|
25
|
+
clearCachedObservable: () => clearCachedObservable,
|
|
26
|
+
createKheopskitStore: () => createKheopskitStore,
|
|
27
|
+
getCachedIcon: () => getCachedIcon,
|
|
23
28
|
getKheopskit$: () => getKheopskit$,
|
|
29
|
+
hydrateAccount: () => hydrateAccount,
|
|
30
|
+
hydrateWallet: () => hydrateWallet,
|
|
31
|
+
resetAppKitCache: () => resetAppKitCache,
|
|
24
32
|
resolveConfig: () => resolveConfig
|
|
25
33
|
});
|
|
26
34
|
module.exports = __toCommonJS(index_exports);
|
|
27
35
|
|
|
36
|
+
// src/utils/getCachedObservable.ts
|
|
37
|
+
var CACHE = /* @__PURE__ */ new Map();
|
|
38
|
+
var getCachedObservable$ = (key, create) => {
|
|
39
|
+
if (!CACHE.has(key)) CACHE.set(key, create());
|
|
40
|
+
return CACHE.get(key);
|
|
41
|
+
};
|
|
42
|
+
var clearCachedObservable = (key) => {
|
|
43
|
+
CACHE.delete(key);
|
|
44
|
+
};
|
|
45
|
+
var clearAllCachedObservables = () => {
|
|
46
|
+
CACHE.clear();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/utils/polkadotExtensions.ts
|
|
50
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Ljk1NjFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/utils/isWalletPlatform.ts
|
|
70
|
+
var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
|
|
71
|
+
|
|
72
|
+
// src/utils/WalletId.ts
|
|
73
|
+
var getWalletId = (platform, identifier) => {
|
|
74
|
+
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
75
|
+
if (!identifier) throw new Error("Invalid name");
|
|
76
|
+
return `${platform}:${identifier}`;
|
|
77
|
+
};
|
|
78
|
+
var parseWalletId = (walletId) => {
|
|
79
|
+
if (!walletId) throw new Error("Invalid walletId");
|
|
80
|
+
const [platform, identifier] = walletId.split(":");
|
|
81
|
+
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
82
|
+
if (!identifier) throw new Error("Invalid address");
|
|
83
|
+
return { platform, identifier };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/utils/hydrateState.ts
|
|
87
|
+
var lookupWalletIcon = (platform, identifier) => {
|
|
88
|
+
if (platform === "polkadot") {
|
|
89
|
+
return POLKADOT_EXTENSIONS[identifier]?.icon ?? "";
|
|
90
|
+
}
|
|
91
|
+
return "";
|
|
92
|
+
};
|
|
93
|
+
var PendingWalletError = class extends Error {
|
|
94
|
+
constructor(walletId) {
|
|
95
|
+
super(
|
|
96
|
+
`Wallet ${walletId} is still loading. Wait for isHydrating to be false before calling connect/disconnect.`
|
|
97
|
+
);
|
|
98
|
+
this.name = "PendingWalletError";
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var hydrateWallet = (cached) => {
|
|
102
|
+
const { platform, identifier } = parseWalletId(cached.id);
|
|
103
|
+
const throwPending = () => {
|
|
104
|
+
throw new PendingWalletError(cached.id);
|
|
105
|
+
};
|
|
106
|
+
const icon = lookupWalletIcon(platform, identifier);
|
|
107
|
+
if (platform === "polkadot") {
|
|
108
|
+
return {
|
|
109
|
+
id: cached.id,
|
|
110
|
+
platform: "polkadot",
|
|
111
|
+
type: "injected",
|
|
112
|
+
extensionId: identifier,
|
|
113
|
+
extension: void 0,
|
|
114
|
+
name: cached.name,
|
|
115
|
+
icon,
|
|
116
|
+
isConnected: cached.isConnected,
|
|
117
|
+
connect: throwPending,
|
|
118
|
+
disconnect: throwPending
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (platform === "ethereum") {
|
|
122
|
+
return {
|
|
123
|
+
id: cached.id,
|
|
124
|
+
platform: "ethereum",
|
|
125
|
+
type: "injected",
|
|
126
|
+
providerId: identifier,
|
|
127
|
+
provider: {},
|
|
128
|
+
// Placeholder - will be replaced by real wallet
|
|
129
|
+
name: cached.name,
|
|
130
|
+
icon,
|
|
131
|
+
isConnected: cached.isConnected,
|
|
132
|
+
connect: throwPending,
|
|
133
|
+
disconnect: throwPending
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
throw new Error(`Unknown platform: ${platform}`);
|
|
137
|
+
};
|
|
138
|
+
var hydrateAccount = (cached) => {
|
|
139
|
+
if (cached.platform === "polkadot") {
|
|
140
|
+
return {
|
|
141
|
+
id: cached.id,
|
|
142
|
+
platform: "polkadot",
|
|
143
|
+
address: cached.address,
|
|
144
|
+
name: cached.name,
|
|
145
|
+
walletId: cached.walletId,
|
|
146
|
+
walletName: cached.walletName,
|
|
147
|
+
// PolkadotSigner is required but we can't provide a real one
|
|
148
|
+
// This is a placeholder that will be replaced by the real account
|
|
149
|
+
polkadotSigner: {}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (cached.platform === "ethereum") {
|
|
153
|
+
return {
|
|
154
|
+
id: cached.id,
|
|
155
|
+
platform: "ethereum",
|
|
156
|
+
address: cached.address,
|
|
157
|
+
walletId: cached.walletId,
|
|
158
|
+
walletName: cached.walletName,
|
|
159
|
+
isWalletDefault: false,
|
|
160
|
+
client: {}
|
|
161
|
+
// Placeholder
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
throw new Error(`Unknown platform: ${cached.platform}`);
|
|
165
|
+
};
|
|
166
|
+
var serializeWallet = (wallet) => ({
|
|
167
|
+
id: wallet.id,
|
|
168
|
+
platform: wallet.platform,
|
|
169
|
+
type: wallet.type,
|
|
170
|
+
name: wallet.name,
|
|
171
|
+
// Note: icon is NOT stored to save cookie space
|
|
172
|
+
isConnected: wallet.isConnected
|
|
173
|
+
});
|
|
174
|
+
var serializeAccount = (account) => ({
|
|
175
|
+
id: account.id,
|
|
176
|
+
platform: account.platform,
|
|
177
|
+
address: account.address,
|
|
178
|
+
name: "name" in account ? account.name : void 0,
|
|
179
|
+
walletId: account.walletId,
|
|
180
|
+
walletName: account.walletName
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// src/utils/storage.ts
|
|
184
|
+
var noopStorage = {
|
|
185
|
+
getItem: () => null,
|
|
186
|
+
setItem: () => {
|
|
187
|
+
},
|
|
188
|
+
removeItem: () => {
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var safeLocalStorage = (() => {
|
|
192
|
+
if (typeof window === "undefined") return noopStorage;
|
|
193
|
+
try {
|
|
194
|
+
const testKey = "__kheopskit_test__";
|
|
195
|
+
window.localStorage.setItem(testKey, testKey);
|
|
196
|
+
window.localStorage.removeItem(testKey);
|
|
197
|
+
return {
|
|
198
|
+
getItem: (key) => window.localStorage.getItem(key),
|
|
199
|
+
setItem: (key, value) => window.localStorage.setItem(key, value),
|
|
200
|
+
removeItem: (key) => window.localStorage.removeItem(key),
|
|
201
|
+
subscribe: (key, callback) => {
|
|
202
|
+
const handler = (event) => {
|
|
203
|
+
if (event.key === key) {
|
|
204
|
+
callback(event.newValue);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
window.addEventListener("storage", handler);
|
|
208
|
+
return () => window.removeEventListener("storage", handler);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
} catch {
|
|
212
|
+
return noopStorage;
|
|
213
|
+
}
|
|
214
|
+
})();
|
|
215
|
+
var parseCookie = (cookieString, key) => {
|
|
216
|
+
if (!cookieString) return null;
|
|
217
|
+
for (const cookie of cookieString.split(";")) {
|
|
218
|
+
const [k, ...v] = cookie.split("=");
|
|
219
|
+
const cookieKey = k?.trim();
|
|
220
|
+
if (cookieKey === key) {
|
|
221
|
+
try {
|
|
222
|
+
return decodeURIComponent(v.join("=").trim());
|
|
223
|
+
} catch {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
};
|
|
230
|
+
var COOKIE_MAX_SIZE = 3 * 1024;
|
|
231
|
+
var BROADCAST_CHANNEL_NAME = "kheopskit-storage-sync";
|
|
232
|
+
var sharedBroadcastChannel = null;
|
|
233
|
+
var getBroadcastChannel = () => {
|
|
234
|
+
if (sharedBroadcastChannel) return sharedBroadcastChannel;
|
|
235
|
+
if (typeof BroadcastChannel === "undefined") return null;
|
|
236
|
+
try {
|
|
237
|
+
sharedBroadcastChannel = new BroadcastChannel(BROADCAST_CHANNEL_NAME);
|
|
238
|
+
} catch {
|
|
239
|
+
}
|
|
240
|
+
return sharedBroadcastChannel;
|
|
241
|
+
};
|
|
242
|
+
var isSecureConnection = () => typeof window !== "undefined" && window.location.protocol === "https:";
|
|
243
|
+
var cookieStorage = (initialCookies) => {
|
|
244
|
+
return {
|
|
245
|
+
getItem: (key) => {
|
|
246
|
+
const cookieString = typeof document !== "undefined" ? document.cookie : initialCookies;
|
|
247
|
+
return parseCookie(cookieString, key);
|
|
248
|
+
},
|
|
249
|
+
setItem: (key, value) => {
|
|
250
|
+
if (typeof document === "undefined") return;
|
|
251
|
+
const encodedValue = encodeURIComponent(value);
|
|
252
|
+
if (encodedValue.length > COOKIE_MAX_SIZE) {
|
|
253
|
+
console.warn(
|
|
254
|
+
`[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.`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
const expires = /* @__PURE__ */ new Date();
|
|
258
|
+
expires.setFullYear(expires.getFullYear() + 1);
|
|
259
|
+
let cookieStr = `${key}=${encodedValue};expires=${expires.toUTCString()};path=/;SameSite=Lax`;
|
|
260
|
+
if (isSecureConnection()) {
|
|
261
|
+
cookieStr += ";Secure";
|
|
262
|
+
}
|
|
263
|
+
document.cookie = cookieStr;
|
|
264
|
+
getBroadcastChannel()?.postMessage({ type: "set", key, value });
|
|
265
|
+
},
|
|
266
|
+
removeItem: (key) => {
|
|
267
|
+
if (typeof document === "undefined") return;
|
|
268
|
+
let cookieStr = `${key}=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;SameSite=Lax`;
|
|
269
|
+
if (isSecureConnection()) {
|
|
270
|
+
cookieStr += ";Secure";
|
|
271
|
+
}
|
|
272
|
+
document.cookie = cookieStr;
|
|
273
|
+
getBroadcastChannel()?.postMessage({ type: "remove", key });
|
|
274
|
+
},
|
|
275
|
+
subscribe: (key, callback) => {
|
|
276
|
+
const channel = getBroadcastChannel();
|
|
277
|
+
if (!channel) return () => {
|
|
278
|
+
};
|
|
279
|
+
const handler = (event) => {
|
|
280
|
+
const data = event.data;
|
|
281
|
+
if (data.key === key) {
|
|
282
|
+
if (data.type === "set") {
|
|
283
|
+
callback(data.value ?? null);
|
|
284
|
+
} else if (data.type === "remove") {
|
|
285
|
+
callback(null);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
channel.addEventListener("message", handler);
|
|
290
|
+
return () => {
|
|
291
|
+
channel.removeEventListener("message", handler);
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// src/utils/iconCache.ts
|
|
298
|
+
var ICON_CACHE_KEY = "kheopskit-icons";
|
|
299
|
+
var memoryCache = null;
|
|
300
|
+
var loadCache = () => {
|
|
301
|
+
if (memoryCache !== null) return memoryCache;
|
|
302
|
+
try {
|
|
303
|
+
const stored = safeLocalStorage.getItem(ICON_CACHE_KEY);
|
|
304
|
+
memoryCache = stored ? JSON.parse(stored) : {};
|
|
305
|
+
} catch {
|
|
306
|
+
memoryCache = {};
|
|
307
|
+
}
|
|
308
|
+
return memoryCache;
|
|
309
|
+
};
|
|
310
|
+
var saveCache = (cache) => {
|
|
311
|
+
try {
|
|
312
|
+
safeLocalStorage.setItem(ICON_CACHE_KEY, JSON.stringify(cache));
|
|
313
|
+
memoryCache = cache;
|
|
314
|
+
} catch {
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
var getCachedIcon = (walletId) => {
|
|
318
|
+
const cache = loadCache();
|
|
319
|
+
return cache[walletId] || void 0;
|
|
320
|
+
};
|
|
321
|
+
var setCachedIcons = (icons) => {
|
|
322
|
+
const cache = loadCache();
|
|
323
|
+
let changed = false;
|
|
324
|
+
for (const [walletId, icon] of Object.entries(icons)) {
|
|
325
|
+
if (icon && cache[walletId] !== icon) {
|
|
326
|
+
cache[walletId] = icon;
|
|
327
|
+
changed = true;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (changed) {
|
|
331
|
+
saveCache(cache);
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// src/api/appKit.ts
|
|
336
|
+
var import_core = require("@reown/appkit/core");
|
|
337
|
+
var import_rxjs = require("rxjs");
|
|
338
|
+
var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0cm9rZT0iIzY2YjFmZiIvPjxwYXRoIGQ9Im0xMjIuNTE5IDE0OC45NjVjNDIuNzkxLTQxLjcyOSAxMTIuMTcxLTQxLjcyOSAxNTQuOTYyIDBsNS4xNSA1LjAyMmMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtMTcuNjE3IDE3LjE4Yy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTcuMDg3LTYuOTExYy0yOS44NTMtMjkuMTExLTc4LjI1My0yOS4xMTEtMTA4LjEwNiAwbC03LjU5IDcuNDAxYy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTE3LjYxNy0xNy4xOGMtMi4xNC0yLjA4Ni0yLjE0LTUuNDY5IDAtNy41NTV6bTE5MS4zOTcgMzUuNTI5IDE1LjY3OSAxNS4yOWMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtNzAuNyA2OC45NDRjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTUwLjE3OC00OC45MzFjLS41MzUtLjUyMi0xLjQwMi0uNTIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
|
|
339
|
+
var cachedAppKit = null;
|
|
340
|
+
var resetAppKitCache = () => {
|
|
341
|
+
cachedAppKit = null;
|
|
342
|
+
};
|
|
343
|
+
var getAppKitWallets$ = (config) => {
|
|
344
|
+
if (!config.walletConnect) return (0, import_rxjs.of)({});
|
|
345
|
+
const walletConnect = config.walletConnect;
|
|
346
|
+
if (!cachedAppKit) {
|
|
347
|
+
cachedAppKit = new import_rxjs.Observable((subscriber) => {
|
|
348
|
+
const appKit = (0, import_core.createAppKit)({
|
|
349
|
+
projectId: walletConnect.projectId,
|
|
350
|
+
metadata: walletConnect.metadata,
|
|
351
|
+
networks: walletConnect.networks,
|
|
352
|
+
themeMode: walletConnect.themeMode,
|
|
353
|
+
themeVariables: walletConnect.themeVariables,
|
|
354
|
+
universalProviderConfigOverride: {
|
|
355
|
+
methods: {
|
|
356
|
+
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
allWallets: "HIDE",
|
|
360
|
+
debug: config.debug,
|
|
361
|
+
allowUnsupportedChain: true
|
|
362
|
+
});
|
|
363
|
+
const status$ = new import_rxjs.BehaviorSubject({
|
|
364
|
+
isPolkadotConnected: false,
|
|
365
|
+
isEthereumConnected: false
|
|
366
|
+
});
|
|
367
|
+
const unsubProviders = appKit.subscribeProviders((providers) => {
|
|
368
|
+
status$.next({
|
|
369
|
+
isPolkadotConnected: !!providers.polkadot,
|
|
370
|
+
isEthereumConnected: !!providers.eip155
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
|
|
374
|
+
(0, import_rxjs.map)((s) => s.isPolkadotConnected),
|
|
375
|
+
(0, import_rxjs.distinctUntilChanged)(),
|
|
376
|
+
(0, import_rxjs.map)((isConnected) => {
|
|
377
|
+
const walletInfo = appKit.getWalletInfo();
|
|
378
|
+
return {
|
|
379
|
+
id: getWalletId("polkadot", "walletconnect"),
|
|
380
|
+
platform: "polkadot",
|
|
381
|
+
type: "appKit",
|
|
382
|
+
appKit,
|
|
383
|
+
// todo maybe we dont want to expose the appKit instance
|
|
384
|
+
name: walletInfo?.name ?? "WalletConnect",
|
|
385
|
+
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
386
|
+
connect: async () => {
|
|
387
|
+
if (!isConnected) await appKit.open();
|
|
388
|
+
},
|
|
389
|
+
disconnect: () => {
|
|
390
|
+
if (isConnected) appKit.disconnect();
|
|
391
|
+
},
|
|
392
|
+
isConnected
|
|
393
|
+
};
|
|
394
|
+
})
|
|
395
|
+
) : (0, import_rxjs.of)(void 0);
|
|
396
|
+
const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
|
|
397
|
+
(0, import_rxjs.map)((s) => s.isEthereumConnected),
|
|
398
|
+
(0, import_rxjs.distinctUntilChanged)(),
|
|
399
|
+
(0, import_rxjs.map)((isConnected) => {
|
|
400
|
+
const walletInfo = appKit.getWalletInfo();
|
|
401
|
+
return {
|
|
402
|
+
id: getWalletId("ethereum", "walletconnect"),
|
|
403
|
+
platform: "ethereum",
|
|
404
|
+
type: "appKit",
|
|
405
|
+
appKit,
|
|
406
|
+
name: walletInfo?.name ?? "WalletConnect",
|
|
407
|
+
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
408
|
+
connect: () => appKit.open(),
|
|
409
|
+
disconnect: () => appKit.disconnect(),
|
|
410
|
+
isConnected
|
|
411
|
+
};
|
|
412
|
+
})
|
|
413
|
+
) : (0, import_rxjs.of)(void 0);
|
|
414
|
+
const sub = (0, import_rxjs.combineLatest)({
|
|
415
|
+
polkadot: polkadotWallet$,
|
|
416
|
+
ethereum: ethereumWallet$
|
|
417
|
+
}).subscribe(subscriber);
|
|
418
|
+
return () => {
|
|
419
|
+
sub.unsubscribe();
|
|
420
|
+
unsubProviders();
|
|
421
|
+
};
|
|
422
|
+
}).pipe((0, import_rxjs.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
423
|
+
}
|
|
424
|
+
return cachedAppKit;
|
|
425
|
+
};
|
|
426
|
+
|
|
28
427
|
// src/api/config.ts
|
|
428
|
+
var DEFAULT_STORAGE_KEY = "kheopskit";
|
|
29
429
|
var DEFAULT_CONFIG = {
|
|
30
430
|
autoReconnect: true,
|
|
31
431
|
platforms: ["polkadot"],
|
|
32
|
-
debug: false
|
|
432
|
+
debug: false,
|
|
433
|
+
storageKey: DEFAULT_STORAGE_KEY,
|
|
434
|
+
hydrationGracePeriod: 500
|
|
33
435
|
};
|
|
34
436
|
var resolveConfig = (config) => {
|
|
35
437
|
return Object.assign({}, DEFAULT_CONFIG, config);
|
|
36
438
|
};
|
|
37
439
|
|
|
38
440
|
// src/api/kheopskit.ts
|
|
39
|
-
var
|
|
441
|
+
var import_rxjs11 = require("rxjs");
|
|
442
|
+
|
|
443
|
+
// src/utils/createHydrationBuffer.ts
|
|
444
|
+
var import_rxjs2 = require("rxjs");
|
|
445
|
+
var createBufferCore = (cachedItems, liveItems$, gracePeriodMs, mergeFn, isConverged) => {
|
|
446
|
+
if (gracePeriodMs <= 0 || cachedItems.length === 0) {
|
|
447
|
+
return liveItems$.pipe((0, import_rxjs2.map)((items) => ({ items, isHydrating: false })));
|
|
448
|
+
}
|
|
449
|
+
return new import_rxjs2.Observable((subscriber) => {
|
|
450
|
+
const subscriptions = new import_rxjs2.Subscription();
|
|
451
|
+
const isHydrating$ = new import_rxjs2.BehaviorSubject(true);
|
|
452
|
+
const liveWithInitial$ = liveItems$.pipe((0, import_rxjs2.startWith)([]));
|
|
453
|
+
if (isConverged) {
|
|
454
|
+
const timerFired$ = (0, import_rxjs2.timer)(gracePeriodMs).pipe(
|
|
455
|
+
(0, import_rxjs2.map)(() => true),
|
|
456
|
+
(0, import_rxjs2.startWith)(false),
|
|
457
|
+
(0, import_rxjs2.shareReplay)({ bufferSize: 1, refCount: true })
|
|
458
|
+
);
|
|
459
|
+
subscriptions.add(
|
|
460
|
+
(0, import_rxjs2.combineLatest)([liveWithInitial$, timerFired$]).pipe(
|
|
461
|
+
(0, import_rxjs2.filter)(([, timerFired]) => timerFired),
|
|
462
|
+
(0, import_rxjs2.filter)(([liveItems]) => isConverged(liveItems, cachedItems)),
|
|
463
|
+
(0, import_rxjs2.take)(1)
|
|
464
|
+
).subscribe(() => {
|
|
465
|
+
isHydrating$.next(false);
|
|
466
|
+
})
|
|
467
|
+
);
|
|
468
|
+
subscriptions.add(
|
|
469
|
+
(0, import_rxjs2.timer)(gracePeriodMs * 6).subscribe(() => {
|
|
470
|
+
if (isHydrating$.value) {
|
|
471
|
+
isHydrating$.next(false);
|
|
472
|
+
}
|
|
473
|
+
})
|
|
474
|
+
);
|
|
475
|
+
} else {
|
|
476
|
+
subscriptions.add(
|
|
477
|
+
(0, import_rxjs2.timer)(gracePeriodMs).subscribe(() => {
|
|
478
|
+
isHydrating$.next(false);
|
|
479
|
+
})
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
subscriptions.add(
|
|
483
|
+
(0, import_rxjs2.combineLatest)([liveWithInitial$, isHydrating$]).pipe(
|
|
484
|
+
(0, import_rxjs2.map)(([liveItems, isHydrating]) => {
|
|
485
|
+
if (!isHydrating) {
|
|
486
|
+
return { items: liveItems, isHydrating: false };
|
|
487
|
+
}
|
|
488
|
+
return {
|
|
489
|
+
items: mergeFn(liveItems, cachedItems),
|
|
490
|
+
isHydrating: true
|
|
491
|
+
};
|
|
492
|
+
})
|
|
493
|
+
).subscribe(subscriber)
|
|
494
|
+
);
|
|
495
|
+
return () => {
|
|
496
|
+
subscriptions.unsubscribe();
|
|
497
|
+
isHydrating$.complete();
|
|
498
|
+
};
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
var createHydrationBuffer = (cachedItems, liveItems$, gracePeriodMs, getKey, isConverged, mergeItem, transformCachedOnly) => {
|
|
502
|
+
return createBufferCore(
|
|
503
|
+
cachedItems,
|
|
504
|
+
liveItems$,
|
|
505
|
+
gracePeriodMs,
|
|
506
|
+
(liveItems, cached) => {
|
|
507
|
+
const cachedByKey = new Map(cached.map((item) => [getKey(item), item]));
|
|
508
|
+
const liveKeys = new Set(liveItems.map(getKey));
|
|
509
|
+
const mergedItems = liveItems.map((liveItem) => {
|
|
510
|
+
const key = getKey(liveItem);
|
|
511
|
+
const cachedItem = cachedByKey.get(key);
|
|
512
|
+
if (!cachedItem) return liveItem;
|
|
513
|
+
return mergeItem ? mergeItem(liveItem, cachedItem) : cachedItem;
|
|
514
|
+
});
|
|
515
|
+
for (const cachedItem of cached) {
|
|
516
|
+
if (!liveKeys.has(getKey(cachedItem))) {
|
|
517
|
+
const transformed = transformCachedOnly ? transformCachedOnly(cachedItem) : cachedItem;
|
|
518
|
+
mergedItems.push(transformed);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return mergedItems;
|
|
522
|
+
},
|
|
523
|
+
isConverged
|
|
524
|
+
);
|
|
525
|
+
};
|
|
526
|
+
var createAccountHydrationBuffer = (cachedAccounts, liveAccounts$, gracePeriodMs, getWalletId2, isConverged) => {
|
|
527
|
+
return createBufferCore(
|
|
528
|
+
cachedAccounts,
|
|
529
|
+
liveAccounts$,
|
|
530
|
+
gracePeriodMs,
|
|
531
|
+
(liveAccounts, cached) => {
|
|
532
|
+
const walletsWithLiveAccounts = new Set(liveAccounts.map(getWalletId2));
|
|
533
|
+
const mergedAccounts = [...liveAccounts];
|
|
534
|
+
for (const cachedAccount of cached) {
|
|
535
|
+
if (!walletsWithLiveAccounts.has(getWalletId2(cachedAccount))) {
|
|
536
|
+
mergedAccounts.push(cachedAccount);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return mergedAccounts;
|
|
540
|
+
},
|
|
541
|
+
isConverged
|
|
542
|
+
);
|
|
543
|
+
};
|
|
40
544
|
|
|
41
545
|
// src/utils/logObservable.ts
|
|
42
|
-
var
|
|
43
|
-
var logObservable = (label, opts) => (0,
|
|
546
|
+
var import_rxjs3 = require("rxjs");
|
|
547
|
+
var logObservable = (label, opts) => (0, import_rxjs3.tap)((value) => {
|
|
44
548
|
const { printValue = false, enabled = true } = opts || {};
|
|
45
549
|
if (!label || !enabled) return;
|
|
46
550
|
const text = `[kheopskit] observable ${label} emit`;
|
|
@@ -49,7 +553,7 @@ var logObservable = (label, opts) => (0, import_rxjs.tap)((value) => {
|
|
|
49
553
|
});
|
|
50
554
|
|
|
51
555
|
// src/api/accounts.ts
|
|
52
|
-
var
|
|
556
|
+
var import_rxjs7 = require("rxjs");
|
|
53
557
|
|
|
54
558
|
// src/utils/sortAccounts.ts
|
|
55
559
|
var sortAccounts = (a1, a2) => {
|
|
@@ -70,32 +574,43 @@ var sortAccounts = (a1, a2) => {
|
|
|
70
574
|
if (a2.walletName === "Talisman") return 1;
|
|
71
575
|
return a1.walletName.localeCompare(a2.walletName);
|
|
72
576
|
}
|
|
73
|
-
return
|
|
577
|
+
return a1.id.localeCompare(a2.id);
|
|
74
578
|
}
|
|
75
579
|
return 0;
|
|
76
580
|
};
|
|
77
581
|
|
|
78
582
|
// src/api/ethereum/accounts.ts
|
|
79
|
-
var
|
|
583
|
+
var import_rxjs5 = require("rxjs");
|
|
80
584
|
var import_viem2 = require("viem");
|
|
81
585
|
|
|
82
586
|
// src/utils/createStore.ts
|
|
83
|
-
var
|
|
84
|
-
var createStore = (key, defaultValue) => {
|
|
85
|
-
const subject = new
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
587
|
+
var import_rxjs4 = require("rxjs");
|
|
588
|
+
var createStore = (key, defaultValue, storage = safeLocalStorage) => {
|
|
589
|
+
const subject = new import_rxjs4.BehaviorSubject(
|
|
590
|
+
getStoredData(key, defaultValue, storage)
|
|
591
|
+
);
|
|
592
|
+
let unsubscribeStorage;
|
|
593
|
+
if (typeof window !== "undefined" && storage.subscribe) {
|
|
594
|
+
unsubscribeStorage = storage.subscribe(key, (newValue) => {
|
|
595
|
+
subject.next(parseData(newValue, defaultValue));
|
|
596
|
+
});
|
|
597
|
+
}
|
|
90
598
|
const update = (val) => {
|
|
91
|
-
setStoredData(key, val);
|
|
599
|
+
setStoredData(key, val, storage);
|
|
92
600
|
subject.next(val);
|
|
93
601
|
};
|
|
94
602
|
return {
|
|
95
603
|
observable: subject.asObservable(),
|
|
96
604
|
set: (val) => update(val),
|
|
97
605
|
mutate: (transform) => update(transform(subject.getValue())),
|
|
98
|
-
get: () => structuredClone(subject.getValue())
|
|
606
|
+
get: () => structuredClone(subject.getValue()),
|
|
607
|
+
/**
|
|
608
|
+
* Cleanup subscriptions. Call this when the store is no longer needed.
|
|
609
|
+
*/
|
|
610
|
+
destroy: () => {
|
|
611
|
+
unsubscribeStorage?.();
|
|
612
|
+
subject.complete();
|
|
613
|
+
}
|
|
99
614
|
};
|
|
100
615
|
};
|
|
101
616
|
var parseData = (str, defaultValue) => {
|
|
@@ -105,13 +620,13 @@ var parseData = (str, defaultValue) => {
|
|
|
105
620
|
}
|
|
106
621
|
return defaultValue;
|
|
107
622
|
};
|
|
108
|
-
var getStoredData = (key, defaultValue) => {
|
|
109
|
-
const str =
|
|
623
|
+
var getStoredData = (key, defaultValue, storage) => {
|
|
624
|
+
const str = storage.getItem(key);
|
|
110
625
|
return parseData(str, defaultValue);
|
|
111
626
|
};
|
|
112
|
-
var setStoredData = (key, val) => {
|
|
627
|
+
var setStoredData = (key, val, storage) => {
|
|
113
628
|
const str = JSON.stringify(val);
|
|
114
|
-
|
|
629
|
+
storage.setItem(key, str);
|
|
115
630
|
};
|
|
116
631
|
|
|
117
632
|
// src/utils/isEthereumAddress.ts
|
|
@@ -136,9 +651,6 @@ var isValidAddress = (address) => {
|
|
|
136
651
|
return address.startsWith("0x") ? isEthereumAddress(address) : isSs58Address(address);
|
|
137
652
|
};
|
|
138
653
|
|
|
139
|
-
// src/utils/isWalletPlatform.ts
|
|
140
|
-
var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
|
|
141
|
-
|
|
142
654
|
// src/utils/WalletAccountId.ts
|
|
143
655
|
var getWalletAccountId = (walletId, address) => {
|
|
144
656
|
if (!walletId) throw new Error("Missing walletId");
|
|
@@ -146,19 +658,12 @@ var getWalletAccountId = (walletId, address) => {
|
|
|
146
658
|
return `${walletId}::${address}`;
|
|
147
659
|
};
|
|
148
660
|
|
|
149
|
-
// src/utils/getCachedObservable.ts
|
|
150
|
-
var CACHE = /* @__PURE__ */ new Map();
|
|
151
|
-
var getCachedObservable$ = (key, create) => {
|
|
152
|
-
if (!CACHE.has(key)) CACHE.set(key, create());
|
|
153
|
-
return CACHE.get(key);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
661
|
// src/api/ethereum/accounts.ts
|
|
157
662
|
var getInjectedWalletAccounts$ = (wallet) => {
|
|
158
|
-
if (!wallet.isConnected) return (0,
|
|
663
|
+
if (!wallet.isConnected) return (0, import_rxjs5.of)([]);
|
|
159
664
|
return getCachedObservable$(
|
|
160
665
|
`accounts:${wallet.id}`,
|
|
161
|
-
() => new
|
|
666
|
+
() => new import_rxjs5.Observable((subscriber) => {
|
|
162
667
|
const getAccount = (address, i) => {
|
|
163
668
|
const client = (0, import_viem2.createWalletClient)({
|
|
164
669
|
account: address,
|
|
@@ -190,7 +695,7 @@ var getInjectedWalletAccounts$ = (wallet) => {
|
|
|
190
695
|
handleAccountsChanged
|
|
191
696
|
);
|
|
192
697
|
};
|
|
193
|
-
}).pipe((0,
|
|
698
|
+
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
194
699
|
);
|
|
195
700
|
};
|
|
196
701
|
var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
|
|
@@ -211,19 +716,19 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
211
716
|
const account = wallet.appKit.getAccount("eip155");
|
|
212
717
|
const provider = wallet.appKit.getProvider("eip155");
|
|
213
718
|
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
214
|
-
return (0,
|
|
719
|
+
return (0, import_rxjs5.of)([]);
|
|
215
720
|
return getCachedObservable$(
|
|
216
721
|
"accounts:appKit",
|
|
217
|
-
() => new
|
|
218
|
-
const caipNetworkId$ = new
|
|
722
|
+
() => new import_rxjs5.Observable((subscriber) => {
|
|
723
|
+
const caipNetworkId$ = new import_rxjs5.ReplaySubject(1);
|
|
219
724
|
const handleChainChanged = (chainId) => {
|
|
220
725
|
caipNetworkId$.next(`eip155:${chainId}`);
|
|
221
726
|
};
|
|
222
727
|
provider.on("chainChanged", handleChainChanged);
|
|
223
728
|
provider.request({ method: "eth_chainId" }).then(handleChainChanged);
|
|
224
729
|
const sub = caipNetworkId$.pipe(
|
|
225
|
-
(0,
|
|
226
|
-
(0,
|
|
730
|
+
(0, import_rxjs5.distinctUntilChanged)(),
|
|
731
|
+
(0, import_rxjs5.map)(
|
|
227
732
|
(caipNetworkId) => (0, import_viem2.custom)(
|
|
228
733
|
wrapWalletConnectProvider(
|
|
229
734
|
provider,
|
|
@@ -233,7 +738,7 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
233
738
|
)
|
|
234
739
|
)
|
|
235
740
|
),
|
|
236
|
-
(0,
|
|
741
|
+
(0, import_rxjs5.map)(
|
|
237
742
|
(transport) => account.allAccounts.map((acc, i) => {
|
|
238
743
|
const client = (0, import_viem2.createWalletClient)({
|
|
239
744
|
account: acc.address,
|
|
@@ -255,28 +760,28 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
255
760
|
provider.off("chainChanged", handleChainChanged);
|
|
256
761
|
sub.unsubscribe();
|
|
257
762
|
};
|
|
258
|
-
}).pipe((0,
|
|
763
|
+
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
259
764
|
);
|
|
260
765
|
};
|
|
261
|
-
var getEthereumAccounts$ = (ethereumWallets) => new
|
|
766
|
+
var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs5.Observable((subscriber) => {
|
|
262
767
|
const sub = ethereumWallets.pipe(
|
|
263
|
-
(0,
|
|
264
|
-
(0,
|
|
265
|
-
return wallets.length ? (0,
|
|
768
|
+
(0, import_rxjs5.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
769
|
+
(0, import_rxjs5.switchMap)((wallets) => {
|
|
770
|
+
return wallets.length ? (0, import_rxjs5.combineLatest)([
|
|
266
771
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
267
772
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
|
|
268
773
|
// todo appkit
|
|
269
|
-
]) : (0,
|
|
774
|
+
]) : (0, import_rxjs5.of)([]);
|
|
270
775
|
}),
|
|
271
|
-
(0,
|
|
272
|
-
(0,
|
|
776
|
+
(0, import_rxjs5.map)((accounts) => accounts.flat()),
|
|
777
|
+
(0, import_rxjs5.distinctUntilChanged)(isSameAccountsList)
|
|
273
778
|
).subscribe(subscriber);
|
|
274
779
|
return () => {
|
|
275
780
|
sub.unsubscribe();
|
|
276
781
|
};
|
|
277
782
|
}).pipe(
|
|
278
783
|
// logObservable("ethereumAccounts$", true),
|
|
279
|
-
(0,
|
|
784
|
+
(0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
280
785
|
);
|
|
281
786
|
var isSameAccountsList = (a, b) => {
|
|
282
787
|
if (a.length !== b.length) return false;
|
|
@@ -285,10 +790,10 @@ var isSameAccountsList = (a, b) => {
|
|
|
285
790
|
|
|
286
791
|
// src/api/polkadot/accounts.ts
|
|
287
792
|
var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
288
|
-
var
|
|
793
|
+
var import_rxjs6 = require("rxjs");
|
|
289
794
|
var getInjectedWalletAccounts$2 = (wallet) => {
|
|
290
|
-
if (!wallet.isConnected) return (0,
|
|
291
|
-
return new
|
|
795
|
+
if (!wallet.isConnected) return (0, import_rxjs6.of)([]);
|
|
796
|
+
return new import_rxjs6.Observable((subscriber) => {
|
|
292
797
|
const getAccount = (account) => ({
|
|
293
798
|
id: getWalletAccountId(wallet.id, account.address),
|
|
294
799
|
...account,
|
|
@@ -349,8 +854,8 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
349
854
|
const account = wallet.appKit.getAccount("polkadot");
|
|
350
855
|
const provider = wallet.appKit.getProvider("polkadot");
|
|
351
856
|
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
352
|
-
return (0,
|
|
353
|
-
return (0,
|
|
857
|
+
return (0, import_rxjs6.of)([]);
|
|
858
|
+
return (0, import_rxjs6.of)(
|
|
354
859
|
account.allAccounts.map(
|
|
355
860
|
(acc) => ({
|
|
356
861
|
id: getWalletAccountId(wallet.id, acc.address),
|
|
@@ -366,22 +871,22 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
366
871
|
)
|
|
367
872
|
);
|
|
368
873
|
};
|
|
369
|
-
var getPolkadotAccounts$ = (polkadotWallets$) => new
|
|
874
|
+
var getPolkadotAccounts$ = (polkadotWallets$) => new import_rxjs6.Observable((subscriber) => {
|
|
370
875
|
const sub = polkadotWallets$.pipe(
|
|
371
|
-
(0,
|
|
372
|
-
(0,
|
|
373
|
-
(wallets) => wallets.length ? (0,
|
|
876
|
+
(0, import_rxjs6.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
877
|
+
(0, import_rxjs6.switchMap)(
|
|
878
|
+
(wallets) => wallets.length ? (0, import_rxjs6.combineLatest)([
|
|
374
879
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$2),
|
|
375
880
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
376
|
-
]) : (0,
|
|
881
|
+
]) : (0, import_rxjs6.of)([])
|
|
377
882
|
),
|
|
378
|
-
(0,
|
|
379
|
-
(0,
|
|
883
|
+
(0, import_rxjs6.map)((accounts) => accounts.flat()),
|
|
884
|
+
(0, import_rxjs6.distinctUntilChanged)(isSameAccountsList2)
|
|
380
885
|
).subscribe(subscriber);
|
|
381
886
|
return () => {
|
|
382
887
|
sub.unsubscribe();
|
|
383
888
|
};
|
|
384
|
-
}).pipe((0,
|
|
889
|
+
}).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
385
890
|
var isSameAccountsList2 = (a, b) => {
|
|
386
891
|
if (a.length !== b.length) return false;
|
|
387
892
|
return a.every((account, i) => account.id === b[i]?.id);
|
|
@@ -389,37 +894,191 @@ var isSameAccountsList2 = (a, b) => {
|
|
|
389
894
|
|
|
390
895
|
// src/api/accounts.ts
|
|
391
896
|
var getAccounts$ = (config, wallets) => {
|
|
392
|
-
return new
|
|
897
|
+
return new import_rxjs7.Observable((subscriber) => {
|
|
393
898
|
const sources = config.platforms.map(
|
|
394
899
|
(platform) => {
|
|
395
900
|
switch (platform) {
|
|
396
901
|
case "polkadot":
|
|
397
902
|
return getPolkadotAccounts$(
|
|
398
903
|
wallets.pipe(
|
|
399
|
-
(0,
|
|
904
|
+
(0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "polkadot"))
|
|
400
905
|
)
|
|
401
906
|
);
|
|
402
907
|
case "ethereum":
|
|
403
908
|
return getEthereumAccounts$(
|
|
404
909
|
wallets.pipe(
|
|
405
|
-
(0,
|
|
910
|
+
(0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "ethereum"))
|
|
406
911
|
)
|
|
407
912
|
);
|
|
408
913
|
}
|
|
409
914
|
}
|
|
410
915
|
);
|
|
411
|
-
const accounts$ = sources.length ? (0,
|
|
412
|
-
(0,
|
|
413
|
-
) : (0,
|
|
916
|
+
const accounts$ = sources.length ? (0, import_rxjs7.combineLatest)(sources).pipe(
|
|
917
|
+
(0, import_rxjs7.map)((accounts) => accounts.flat().sort(sortAccounts))
|
|
918
|
+
) : (0, import_rxjs7.of)([]);
|
|
414
919
|
const sub = accounts$.subscribe(subscriber);
|
|
415
920
|
return () => {
|
|
416
921
|
sub.unsubscribe();
|
|
417
922
|
};
|
|
418
|
-
}).pipe((0,
|
|
923
|
+
}).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
924
|
+
};
|
|
925
|
+
|
|
926
|
+
// src/api/store.ts
|
|
927
|
+
var import_lodash_es = require("lodash-es");
|
|
928
|
+
var DEFAULT_SETTINGS = {};
|
|
929
|
+
var createKheopskitStore = (options = {}) => {
|
|
930
|
+
const { ssrCookies, storageKey = DEFAULT_STORAGE_KEY } = options;
|
|
931
|
+
const storage = ssrCookies !== void 0 ? createCompactCookieStorage(ssrCookies) : safeLocalStorage;
|
|
932
|
+
const store2 = createStore(storageKey, DEFAULT_SETTINGS, storage);
|
|
933
|
+
const addEnabledWalletId = (walletId) => {
|
|
934
|
+
parseWalletId(walletId);
|
|
935
|
+
store2.mutate((prev) => ({
|
|
936
|
+
...prev,
|
|
937
|
+
autoReconnect: (0, import_lodash_es.uniq)((prev.autoReconnect ?? []).concat(walletId))
|
|
938
|
+
}));
|
|
939
|
+
};
|
|
940
|
+
const removeEnabledWalletId = (walletId) => {
|
|
941
|
+
store2.mutate((prev) => ({
|
|
942
|
+
...prev,
|
|
943
|
+
autoReconnect: (0, import_lodash_es.uniq)(
|
|
944
|
+
(prev.autoReconnect ?? []).filter((id) => id !== walletId)
|
|
945
|
+
)
|
|
946
|
+
}));
|
|
947
|
+
};
|
|
948
|
+
const getCachedState = () => {
|
|
949
|
+
const data = store2.get();
|
|
950
|
+
return {
|
|
951
|
+
wallets: data.cachedWallets ?? [],
|
|
952
|
+
accounts: data.cachedAccounts ?? []
|
|
953
|
+
};
|
|
954
|
+
};
|
|
955
|
+
const setCachedState = (wallets, accounts) => {
|
|
956
|
+
store2.mutate((prev) => ({
|
|
957
|
+
...prev,
|
|
958
|
+
cachedWallets: wallets,
|
|
959
|
+
cachedAccounts: accounts
|
|
960
|
+
}));
|
|
961
|
+
};
|
|
962
|
+
return {
|
|
963
|
+
observable: store2.observable,
|
|
964
|
+
addEnabledWalletId,
|
|
965
|
+
removeEnabledWalletId,
|
|
966
|
+
getCachedState,
|
|
967
|
+
setCachedState
|
|
968
|
+
};
|
|
969
|
+
};
|
|
970
|
+
var store = createKheopskitStore();
|
|
971
|
+
var isCompactStore = (value) => {
|
|
972
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
973
|
+
if ("cachedWallets" in value || "cachedAccounts" in value) return false;
|
|
974
|
+
return "v" in value || "w" in value || "a" in value || "r" in value;
|
|
975
|
+
};
|
|
976
|
+
var toCompactStore = (data) => {
|
|
977
|
+
const wallets = data.cachedWallets?.map(
|
|
978
|
+
(wallet) => [
|
|
979
|
+
wallet.id,
|
|
980
|
+
wallet.name,
|
|
981
|
+
wallet.isConnected ? 1 : 0,
|
|
982
|
+
wallet.type === "appKit" ? 1 : 0
|
|
983
|
+
]
|
|
984
|
+
);
|
|
985
|
+
const accounts = data.cachedAccounts?.map(
|
|
986
|
+
(account) => [
|
|
987
|
+
account.walletId,
|
|
988
|
+
account.address,
|
|
989
|
+
account.name ?? null
|
|
990
|
+
]
|
|
991
|
+
);
|
|
992
|
+
return {
|
|
993
|
+
v: 1,
|
|
994
|
+
r: data.autoReconnect,
|
|
995
|
+
w: wallets?.length ? wallets : void 0,
|
|
996
|
+
a: accounts?.length ? accounts : void 0
|
|
997
|
+
};
|
|
998
|
+
};
|
|
999
|
+
var fromCompactStore = (data) => {
|
|
1000
|
+
const walletNameMap = /* @__PURE__ */ new Map();
|
|
1001
|
+
const wallets = (data.w ?? []).map((item) => {
|
|
1002
|
+
const [id, name, isConnected, type] = item;
|
|
1003
|
+
walletNameMap.set(id, name);
|
|
1004
|
+
const { platform } = parseWalletId(id);
|
|
1005
|
+
return {
|
|
1006
|
+
id,
|
|
1007
|
+
platform,
|
|
1008
|
+
type: type === 1 ? "appKit" : "injected",
|
|
1009
|
+
name,
|
|
1010
|
+
isConnected: isConnected === 1
|
|
1011
|
+
};
|
|
1012
|
+
});
|
|
1013
|
+
const accounts = (data.a ?? []).map((item) => {
|
|
1014
|
+
const [walletId, address, name] = item;
|
|
1015
|
+
const { platform } = parseWalletId(walletId);
|
|
1016
|
+
return {
|
|
1017
|
+
id: getWalletAccountId(walletId, address),
|
|
1018
|
+
platform,
|
|
1019
|
+
address,
|
|
1020
|
+
name: name ?? void 0,
|
|
1021
|
+
walletId,
|
|
1022
|
+
walletName: walletNameMap.get(walletId) ?? walletId
|
|
1023
|
+
};
|
|
1024
|
+
});
|
|
1025
|
+
return {
|
|
1026
|
+
autoReconnect: data.r,
|
|
1027
|
+
cachedWallets: wallets,
|
|
1028
|
+
cachedAccounts: accounts
|
|
1029
|
+
};
|
|
1030
|
+
};
|
|
1031
|
+
var decodeStore = (raw, fallback) => {
|
|
1032
|
+
try {
|
|
1033
|
+
const parsed = JSON.parse(raw);
|
|
1034
|
+
if (isCompactStore(parsed)) return fromCompactStore(parsed);
|
|
1035
|
+
return parsed;
|
|
1036
|
+
} catch {
|
|
1037
|
+
return fallback;
|
|
1038
|
+
}
|
|
1039
|
+
};
|
|
1040
|
+
var encodeStore = (data) => JSON.stringify(toCompactStore(data));
|
|
1041
|
+
var createCompactCookieStorage = (initialCookies) => {
|
|
1042
|
+
const base = cookieStorage(initialCookies);
|
|
1043
|
+
return {
|
|
1044
|
+
getItem: (key) => {
|
|
1045
|
+
const raw = base.getItem(key);
|
|
1046
|
+
if (!raw) return null;
|
|
1047
|
+
const expanded = decodeStore(raw, DEFAULT_SETTINGS);
|
|
1048
|
+
if (typeof document !== "undefined") {
|
|
1049
|
+
try {
|
|
1050
|
+
const parsed = JSON.parse(raw);
|
|
1051
|
+
if (!isCompactStore(parsed)) {
|
|
1052
|
+
base.setItem(key, encodeStore(expanded));
|
|
1053
|
+
}
|
|
1054
|
+
} catch {
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
return JSON.stringify(expanded);
|
|
1058
|
+
},
|
|
1059
|
+
setItem: (key, value) => {
|
|
1060
|
+
const expanded = decodeStore(value, DEFAULT_SETTINGS);
|
|
1061
|
+
base.setItem(key, encodeStore(expanded));
|
|
1062
|
+
},
|
|
1063
|
+
removeItem: base.removeItem,
|
|
1064
|
+
subscribe: (key, callback) => {
|
|
1065
|
+
const unsubscribe = base.subscribe?.(key, (value) => {
|
|
1066
|
+
if (!value) {
|
|
1067
|
+
callback(null);
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const expanded = decodeStore(value, DEFAULT_SETTINGS);
|
|
1071
|
+
callback(JSON.stringify(expanded));
|
|
1072
|
+
});
|
|
1073
|
+
return () => {
|
|
1074
|
+
unsubscribe?.();
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
419
1078
|
};
|
|
420
1079
|
|
|
421
1080
|
// src/api/wallets.ts
|
|
422
|
-
var
|
|
1081
|
+
var import_rxjs10 = require("rxjs");
|
|
423
1082
|
|
|
424
1083
|
// src/utils/sortWallets.ts
|
|
425
1084
|
var sortWallets = (w1, w2) => {
|
|
@@ -433,246 +1092,101 @@ var sortWallets = (w1, w2) => {
|
|
|
433
1092
|
|
|
434
1093
|
// src/api/ethereum/wallets.ts
|
|
435
1094
|
var import_mipd = require("mipd");
|
|
436
|
-
var
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
// src/utils/WalletId.ts
|
|
442
|
-
var getWalletId = (platform, identifier) => {
|
|
443
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
444
|
-
if (!identifier) throw new Error("Invalid name");
|
|
445
|
-
return `${platform}:${identifier}`;
|
|
446
|
-
};
|
|
447
|
-
var parseWalletId = (walletId) => {
|
|
448
|
-
if (!walletId) throw new Error("Invalid walletId");
|
|
449
|
-
const [platform, identifier] = walletId.split(":");
|
|
450
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
451
|
-
if (!identifier) throw new Error("Invalid address");
|
|
452
|
-
return { platform, identifier };
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
// src/api/store.ts
|
|
456
|
-
var LOCAL_STORAGE_KEY = "kheopskit";
|
|
457
|
-
var DEFAULT_SETTINGS = {};
|
|
458
|
-
var storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);
|
|
459
|
-
var addEnabledWalletId = (walletId) => {
|
|
460
|
-
parseWalletId(walletId);
|
|
461
|
-
storage.mutate((prev) => ({
|
|
462
|
-
...prev,
|
|
463
|
-
autoReconnect: (0, import_lodash.uniq)((prev.autoReconnect ?? []).concat(walletId))
|
|
464
|
-
}));
|
|
465
|
-
};
|
|
466
|
-
var removeEnabledWalletId = (walletId) => {
|
|
467
|
-
storage.mutate((prev) => ({
|
|
468
|
-
...prev,
|
|
469
|
-
autoReconnect: (0, import_lodash.uniq)(
|
|
470
|
-
(prev.autoReconnect ?? []).filter((id) => id !== walletId)
|
|
471
|
-
)
|
|
472
|
-
}));
|
|
473
|
-
};
|
|
474
|
-
var store = {
|
|
475
|
-
observable: storage.observable,
|
|
476
|
-
addEnabledWalletId,
|
|
477
|
-
removeEnabledWalletId
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
// src/api/appKit.ts
|
|
481
|
-
var import_core = require("@reown/appkit/core");
|
|
482
|
-
var import_rxjs6 = require("rxjs");
|
|
483
|
-
var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0cm9rZT0iIzY2YjFmZiIvPjxwYXRoIGQ9Im0xMjIuNTE5IDE0OC45NjVjNDIuNzkxLTQxLjcyOSAxMTIuMTcxLTQxLjcyOSAxNTQuOTYyIDBsNS4xNSA1LjAyMmMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtMTcuNjE3IDE3LjE4Yy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTcuMDg3LTYuOTExYy0yOS44NTMtMjkuMTExLTc4LjI1My0yOS4xMTEtMTA4LjEwNiAwbC03LjU5IDcuNDAxYy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTE3LjYxNy0xNy4xOGMtMi4xNC0yLjA4Ni0yLjE0LTUuNDY5IDAtNy41NTV6bTE5MS4zOTcgMzUuNTI5IDE1LjY3OSAxNS4yOWMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtNzAuNyA2OC45NDRjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTUwLjE3OC00OC45MzFjLS41MzUtLjUyMi0xLjQwMi0uNTIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
|
|
484
|
-
var cachedAppKit = null;
|
|
485
|
-
var getAppKitWallets$ = (config) => {
|
|
486
|
-
if (!config.walletConnect) return (0, import_rxjs6.of)({});
|
|
487
|
-
const walletConnect = config.walletConnect;
|
|
488
|
-
if (!cachedAppKit) {
|
|
489
|
-
cachedAppKit = new import_rxjs6.Observable((subscriber) => {
|
|
490
|
-
const appKit = (0, import_core.createAppKit)({
|
|
491
|
-
projectId: walletConnect.projectId,
|
|
492
|
-
metadata: walletConnect.metadata,
|
|
493
|
-
networks: walletConnect.networks,
|
|
494
|
-
themeMode: walletConnect.themeMode,
|
|
495
|
-
themeVariables: walletConnect.themeVariables,
|
|
496
|
-
universalProviderConfigOverride: {
|
|
497
|
-
methods: {
|
|
498
|
-
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
|
|
499
|
-
}
|
|
500
|
-
},
|
|
501
|
-
allWallets: "HIDE",
|
|
502
|
-
debug: config.debug,
|
|
503
|
-
allowUnsupportedChain: true
|
|
504
|
-
});
|
|
505
|
-
const status$ = new import_rxjs6.BehaviorSubject({
|
|
506
|
-
isPolkadotConnected: false,
|
|
507
|
-
isEthereumConnected: false
|
|
508
|
-
});
|
|
509
|
-
const unsubProviders = appKit.subscribeProviders((providers) => {
|
|
510
|
-
status$.next({
|
|
511
|
-
isPolkadotConnected: !!providers.polkadot,
|
|
512
|
-
isEthereumConnected: !!providers.eip155
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
|
|
516
|
-
(0, import_rxjs6.map)((s) => s.isPolkadotConnected),
|
|
517
|
-
(0, import_rxjs6.distinctUntilChanged)(),
|
|
518
|
-
(0, import_rxjs6.map)((isConnected) => {
|
|
519
|
-
const walletInfo = appKit.getWalletInfo();
|
|
520
|
-
return {
|
|
521
|
-
id: getWalletId("polkadot", "walletconnect"),
|
|
522
|
-
platform: "polkadot",
|
|
523
|
-
type: "appKit",
|
|
524
|
-
appKit,
|
|
525
|
-
// todo maybe we dont want to expose the appKit instance
|
|
526
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
527
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
528
|
-
connect: async () => {
|
|
529
|
-
if (!isConnected) await appKit.open();
|
|
530
|
-
},
|
|
531
|
-
disconnect: () => {
|
|
532
|
-
if (isConnected) appKit.disconnect();
|
|
533
|
-
},
|
|
534
|
-
isConnected
|
|
535
|
-
};
|
|
536
|
-
})
|
|
537
|
-
) : (0, import_rxjs6.of)(void 0);
|
|
538
|
-
const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
|
|
539
|
-
(0, import_rxjs6.map)((s) => s.isEthereumConnected),
|
|
540
|
-
(0, import_rxjs6.distinctUntilChanged)(),
|
|
541
|
-
(0, import_rxjs6.map)((isConnected) => {
|
|
542
|
-
const walletInfo = appKit.getWalletInfo();
|
|
543
|
-
return {
|
|
544
|
-
id: getWalletId("ethereum", "walletconnect"),
|
|
545
|
-
platform: "ethereum",
|
|
546
|
-
type: "appKit",
|
|
547
|
-
appKit,
|
|
548
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
549
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
550
|
-
connect: () => appKit.open(),
|
|
551
|
-
disconnect: () => appKit.disconnect(),
|
|
552
|
-
isConnected
|
|
553
|
-
};
|
|
554
|
-
})
|
|
555
|
-
) : (0, import_rxjs6.of)(void 0);
|
|
556
|
-
const sub = (0, import_rxjs6.combineLatest)({
|
|
557
|
-
polkadot: polkadotWallet$,
|
|
558
|
-
ethereum: ethereumWallet$
|
|
559
|
-
}).subscribe(subscriber);
|
|
1095
|
+
var import_rxjs8 = require("rxjs");
|
|
1096
|
+
var providersDetails$ = new import_rxjs8.Observable(
|
|
1097
|
+
(subscriber) => {
|
|
1098
|
+
if (typeof window === "undefined") {
|
|
1099
|
+
subscriber.next([]);
|
|
560
1100
|
return () => {
|
|
561
|
-
sub.unsubscribe();
|
|
562
|
-
unsubProviders();
|
|
563
1101
|
};
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
// src/api/ethereum/wallets.ts
|
|
570
|
-
var providersDetails$ = new import_rxjs7.Observable(
|
|
571
|
-
(subscriber) => {
|
|
572
|
-
const store2 = (0, import_mipd.createStore)();
|
|
573
|
-
const unsubscribe = store2.subscribe((providerDetails2) => {
|
|
1102
|
+
}
|
|
1103
|
+
const mipdStore = (0, import_mipd.createStore)();
|
|
1104
|
+
const unsubscribe = mipdStore.subscribe((providerDetails2) => {
|
|
574
1105
|
subscriber.next(providerDetails2);
|
|
575
1106
|
});
|
|
576
|
-
const providerDetails =
|
|
1107
|
+
const providerDetails = mipdStore.getProviders();
|
|
577
1108
|
subscriber.next(providerDetails);
|
|
578
1109
|
return () => {
|
|
579
1110
|
unsubscribe();
|
|
580
|
-
|
|
1111
|
+
mipdStore.destroy();
|
|
581
1112
|
};
|
|
582
1113
|
}
|
|
583
|
-
).pipe((0,
|
|
584
|
-
var
|
|
585
|
-
(
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
1114
|
+
).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1115
|
+
var createEthereumInjectedWallets$ = (store2) => new import_rxjs8.Observable((subscriber) => {
|
|
1116
|
+
const enabledWalletIds$ = new import_rxjs8.BehaviorSubject(/* @__PURE__ */ new Set());
|
|
1117
|
+
const connectWallet = async (walletId, provider) => {
|
|
1118
|
+
if (enabledWalletIds$.value.has(walletId))
|
|
1119
|
+
throw new Error(`Extension ${walletId} already connected`);
|
|
1120
|
+
await provider.request({
|
|
1121
|
+
method: "eth_requestAccounts"
|
|
1122
|
+
});
|
|
1123
|
+
const newSet = new Set(enabledWalletIds$.value);
|
|
1124
|
+
newSet.add(walletId);
|
|
1125
|
+
enabledWalletIds$.next(newSet);
|
|
1126
|
+
store2.addEnabledWalletId(walletId);
|
|
1127
|
+
};
|
|
1128
|
+
const disconnectWallet = async (walletId) => {
|
|
1129
|
+
if (!enabledWalletIds$.value.has(walletId))
|
|
1130
|
+
throw new Error(`Extension ${walletId} is not connected`);
|
|
1131
|
+
const newSet = new Set(enabledWalletIds$.value);
|
|
1132
|
+
newSet.delete(walletId);
|
|
1133
|
+
enabledWalletIds$.next(newSet);
|
|
1134
|
+
store2.removeEnabledWalletId(walletId);
|
|
1135
|
+
};
|
|
1136
|
+
const sub = (0, import_rxjs8.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
|
|
1137
|
+
(0, import_rxjs8.map)(([providerDetails, enabledWalletIds]) => {
|
|
1138
|
+
return providerDetails.map((pd) => {
|
|
1139
|
+
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
1140
|
+
const provider = pd.provider;
|
|
1141
|
+
return {
|
|
1142
|
+
platform: "ethereum",
|
|
1143
|
+
type: "injected",
|
|
1144
|
+
id: walletId,
|
|
1145
|
+
name: pd.info.name,
|
|
1146
|
+
icon: pd.info.icon,
|
|
1147
|
+
provider,
|
|
1148
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
1149
|
+
providerId: pd.info.rdns,
|
|
1150
|
+
connect: () => connectWallet(walletId, provider),
|
|
1151
|
+
disconnect: () => disconnectWallet(walletId)
|
|
1152
|
+
};
|
|
592
1153
|
});
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
};
|
|
606
|
-
const sub = (0, import_rxjs7.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
|
|
607
|
-
(0, import_rxjs7.map)(([providerDetails, enabledWalletIds]) => {
|
|
608
|
-
return providerDetails.map((pd) => {
|
|
609
|
-
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
610
|
-
const provider = pd.provider;
|
|
611
|
-
return {
|
|
612
|
-
platform: "ethereum",
|
|
613
|
-
type: "injected",
|
|
614
|
-
id: walletId,
|
|
615
|
-
name: pd.info.name,
|
|
616
|
-
icon: pd.info.icon,
|
|
617
|
-
provider,
|
|
618
|
-
isConnected: enabledWalletIds.has(walletId),
|
|
619
|
-
providerId: pd.info.rdns,
|
|
620
|
-
connect: () => connectWallet(walletId, provider),
|
|
621
|
-
disconnect: () => disconnectWallet(walletId)
|
|
622
|
-
};
|
|
623
|
-
});
|
|
624
|
-
})
|
|
625
|
-
).subscribe(subscriber);
|
|
626
|
-
return () => {
|
|
627
|
-
sub.unsubscribe();
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
631
|
-
var getEthereumWallets$ = (config) => {
|
|
632
|
-
return new import_rxjs7.Observable((subscriber) => {
|
|
633
|
-
const subscription = (0, import_rxjs7.combineLatest)([
|
|
634
|
-
ethereumInjectedWallets$,
|
|
635
|
-
getAppKitWallets$(config)?.pipe((0, import_rxjs7.map)((w) => w.ethereum))
|
|
1154
|
+
}),
|
|
1155
|
+
(0, import_rxjs8.distinctUntilChanged)(walletsEqual)
|
|
1156
|
+
).subscribe(subscriber);
|
|
1157
|
+
return () => {
|
|
1158
|
+
sub.unsubscribe();
|
|
1159
|
+
};
|
|
1160
|
+
}).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1161
|
+
var getEthereumWallets$ = (config, store2 = store) => {
|
|
1162
|
+
return new import_rxjs8.Observable((subscriber) => {
|
|
1163
|
+
const subscription = (0, import_rxjs8.combineLatest)([
|
|
1164
|
+
createEthereumInjectedWallets$(store2),
|
|
1165
|
+
getAppKitWallets$(config)?.pipe((0, import_rxjs8.map)((w) => w.ethereum))
|
|
636
1166
|
]).pipe(
|
|
637
|
-
(0,
|
|
1167
|
+
(0, import_rxjs8.map)(
|
|
638
1168
|
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
639
1169
|
)
|
|
640
1170
|
).subscribe(subscriber);
|
|
641
1171
|
return () => {
|
|
642
1172
|
subscription.unsubscribe();
|
|
643
1173
|
};
|
|
644
|
-
}).pipe((0,
|
|
1174
|
+
}).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
645
1175
|
};
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
// src/utils/polkadotExtensions.ts
|
|
653
|
-
var PO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jFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
|
|
669
|
-
}
|
|
1176
|
+
var walletsEqual = (a, b) => {
|
|
1177
|
+
if (a.length !== b.length) return false;
|
|
1178
|
+
return a.every(
|
|
1179
|
+
(w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name
|
|
1180
|
+
);
|
|
670
1181
|
};
|
|
671
1182
|
|
|
672
1183
|
// src/api/polkadot/wallets.ts
|
|
673
|
-
var
|
|
1184
|
+
var import_lodash_es2 = require("lodash-es");
|
|
1185
|
+
var import_pjs_signer2 = require("polkadot-api/pjs-signer");
|
|
1186
|
+
var import_rxjs9 = require("rxjs");
|
|
1187
|
+
var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
|
|
674
1188
|
var createWalletIdsPoller$ = () => {
|
|
675
|
-
return new
|
|
1189
|
+
return new import_rxjs9.Observable((subscriber) => {
|
|
676
1190
|
subscriber.next(getInjectedWalletsIds());
|
|
677
1191
|
const intervals = [100, 200, 300, 500];
|
|
678
1192
|
let index = 0;
|
|
@@ -689,12 +1203,12 @@ var createWalletIdsPoller$ = () => {
|
|
|
689
1203
|
return () => {
|
|
690
1204
|
};
|
|
691
1205
|
}).pipe(
|
|
692
|
-
(0,
|
|
693
|
-
(0,
|
|
1206
|
+
(0, import_rxjs9.distinctUntilChanged)(import_lodash_es2.isEqual),
|
|
1207
|
+
(0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
694
1208
|
);
|
|
695
1209
|
};
|
|
696
|
-
var
|
|
697
|
-
const enabledExtensions$ = new
|
|
1210
|
+
var createPolkadotInjectedWallets$ = (store2) => new import_rxjs9.Observable((subscriber) => {
|
|
1211
|
+
const enabledExtensions$ = new import_rxjs9.BehaviorSubject(/* @__PURE__ */ new Map());
|
|
698
1212
|
const connect = async (walletId) => {
|
|
699
1213
|
if (enabledExtensions$.value.has(walletId))
|
|
700
1214
|
throw new Error(`Extension ${walletId} already connected`);
|
|
@@ -703,7 +1217,7 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
|
703
1217
|
const newMap = new Map(enabledExtensions$.value);
|
|
704
1218
|
newMap.set(walletId, extension);
|
|
705
1219
|
enabledExtensions$.next(newMap);
|
|
706
|
-
|
|
1220
|
+
store2.addEnabledWalletId(walletId);
|
|
707
1221
|
};
|
|
708
1222
|
const disconnect = (walletId) => {
|
|
709
1223
|
if (!enabledExtensions$.value.has(walletId))
|
|
@@ -711,11 +1225,11 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
|
711
1225
|
const newMap = new Map(enabledExtensions$.value);
|
|
712
1226
|
newMap.delete(walletId);
|
|
713
1227
|
enabledExtensions$.next(newMap);
|
|
714
|
-
|
|
1228
|
+
store2.removeEnabledWalletId(walletId);
|
|
715
1229
|
};
|
|
716
1230
|
const walletIds$ = createWalletIdsPoller$();
|
|
717
|
-
const subscription = (0,
|
|
718
|
-
(0,
|
|
1231
|
+
const subscription = (0, import_rxjs9.combineLatest)([walletIds$, enabledExtensions$]).pipe(
|
|
1232
|
+
(0, import_rxjs9.map)(([walletIds, enabledExtensions]) => {
|
|
719
1233
|
return walletIds.map((id) => {
|
|
720
1234
|
const { identifier } = parseWalletId(id);
|
|
721
1235
|
const extension = enabledExtensions.get(id);
|
|
@@ -733,64 +1247,64 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
|
733
1247
|
disconnect: () => disconnect(id)
|
|
734
1248
|
};
|
|
735
1249
|
});
|
|
736
|
-
})
|
|
1250
|
+
}),
|
|
1251
|
+
(0, import_rxjs9.distinctUntilChanged)(walletsEqual2)
|
|
737
1252
|
).subscribe(subscriber);
|
|
738
1253
|
return () => {
|
|
739
1254
|
subscription.unsubscribe();
|
|
740
1255
|
};
|
|
741
|
-
}).pipe(
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
)
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const subscription = (0, import_rxjs8.combineLatest)([
|
|
748
|
-
polkadotInjectedWallets$,
|
|
749
|
-
getAppKitWallets$(config)?.pipe((0, import_rxjs8.map)((w) => w.polkadot))
|
|
1256
|
+
}).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1257
|
+
var getPolkadotWallets$ = (config, store2 = store) => {
|
|
1258
|
+
return new import_rxjs9.Observable((subscriber) => {
|
|
1259
|
+
const subscription = (0, import_rxjs9.combineLatest)([
|
|
1260
|
+
createPolkadotInjectedWallets$(store2),
|
|
1261
|
+
getAppKitWallets$(config)?.pipe((0, import_rxjs9.map)((w) => w.polkadot))
|
|
750
1262
|
]).pipe(
|
|
751
|
-
(0,
|
|
1263
|
+
(0, import_rxjs9.map)(
|
|
752
1264
|
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
753
1265
|
)
|
|
754
1266
|
).subscribe(subscriber);
|
|
755
1267
|
return () => {
|
|
756
1268
|
subscription.unsubscribe();
|
|
757
1269
|
};
|
|
758
|
-
}).pipe(
|
|
759
|
-
|
|
760
|
-
|
|
1270
|
+
}).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
1271
|
+
};
|
|
1272
|
+
var walletsEqual2 = (a, b) => {
|
|
1273
|
+
if (a.length !== b.length) return false;
|
|
1274
|
+
return a.every(
|
|
1275
|
+
(w, i) => w.id === b[i]?.id && w.isConnected === b[i]?.isConnected && w.name === b[i]?.name
|
|
761
1276
|
);
|
|
762
1277
|
};
|
|
763
1278
|
|
|
764
1279
|
// src/api/wallets.ts
|
|
765
|
-
var
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
)
|
|
770
|
-
|
|
771
|
-
return new
|
|
1280
|
+
var getWallets$ = (config, store2 = store) => {
|
|
1281
|
+
const autoReconnectWalletIds$ = store2.observable.pipe(
|
|
1282
|
+
(0, import_rxjs10.map)((s) => s.autoReconnect ?? []),
|
|
1283
|
+
(0, import_rxjs10.take)(1),
|
|
1284
|
+
(0, import_rxjs10.shareReplay)({ bufferSize: 1, refCount: true })
|
|
1285
|
+
);
|
|
1286
|
+
return new import_rxjs10.Observable((subscriber) => {
|
|
772
1287
|
const observables = config.platforms.map(
|
|
773
1288
|
(platform) => {
|
|
774
1289
|
switch (platform) {
|
|
775
1290
|
case "polkadot":
|
|
776
|
-
return getPolkadotWallets$(config);
|
|
1291
|
+
return getPolkadotWallets$(config, store2);
|
|
777
1292
|
case "ethereum":
|
|
778
|
-
return getEthereumWallets$(config);
|
|
1293
|
+
return getEthereumWallets$(config, store2);
|
|
779
1294
|
}
|
|
780
1295
|
}
|
|
781
1296
|
);
|
|
782
|
-
const wallets$ = observables.length ? (0,
|
|
783
|
-
(0,
|
|
784
|
-
//
|
|
785
|
-
|
|
786
|
-
) : (0, import_rxjs9.of)([]);
|
|
1297
|
+
const wallets$ = observables.length ? (0, import_rxjs10.combineLatest)(observables).pipe(
|
|
1298
|
+
(0, import_rxjs10.map)((wallets) => wallets.flat().sort(sortWallets))
|
|
1299
|
+
// Note: No startWith([]) here - the hydration buffer handles initial state
|
|
1300
|
+
) : (0, import_rxjs10.of)([]);
|
|
787
1301
|
const reconnectingWallets = /* @__PURE__ */ new Set();
|
|
788
|
-
const subAutoReconnect = (0,
|
|
789
|
-
(0,
|
|
790
|
-
(0,
|
|
1302
|
+
const subAutoReconnect = (0, import_rxjs10.combineLatest)([wallets$, autoReconnectWalletIds$]).pipe(
|
|
1303
|
+
(0, import_rxjs10.filter)(([, walletIds]) => config.autoReconnect && !!walletIds?.length),
|
|
1304
|
+
(0, import_rxjs10.mergeMap)(
|
|
791
1305
|
([wallets, walletIds]) => wallets.filter((wallet) => walletIds?.includes(wallet.id))
|
|
792
1306
|
),
|
|
793
|
-
(0,
|
|
1307
|
+
(0, import_rxjs10.distinct)((w) => w.id)
|
|
794
1308
|
).subscribe(async (wallet) => {
|
|
795
1309
|
if (wallet.isConnected || reconnectingWallets.has(wallet.id)) {
|
|
796
1310
|
return;
|
|
@@ -809,32 +1323,174 @@ var getWallets$ = (config) => {
|
|
|
809
1323
|
subAutoReconnect.unsubscribe();
|
|
810
1324
|
subWallets.unsubscribe();
|
|
811
1325
|
};
|
|
812
|
-
}).pipe((0,
|
|
1326
|
+
}).pipe((0, import_rxjs10.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
813
1327
|
};
|
|
814
1328
|
|
|
815
1329
|
// src/api/kheopskit.ts
|
|
816
|
-
var getKheopskit$ = (config) => {
|
|
1330
|
+
var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
817
1331
|
const kc = resolveConfig(config);
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1332
|
+
const store2 = existingStore ?? createKheopskitStore({ ssrCookies, storageKey: kc.storageKey });
|
|
1333
|
+
if (kc.debug) console.debug("[kheopskit] config", kc);
|
|
1334
|
+
if (kc.debug && typeof window === "undefined" && ssrCookies === void 0) {
|
|
1335
|
+
console.warn(
|
|
1336
|
+
"[kheopskit] Running on server without `ssrCookies`. Wallet state will not be hydrated. Pass cookies for SSR support."
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
const cachedState = store2.getCachedState();
|
|
1340
|
+
const cachedWallets = cachedState.wallets.map((w) => {
|
|
1341
|
+
const wallet = hydrateWallet(w);
|
|
1342
|
+
if (!wallet.icon) {
|
|
1343
|
+
const cachedIcon = getCachedIcon(wallet.id);
|
|
1344
|
+
if (cachedIcon) {
|
|
1345
|
+
return { ...wallet, icon: cachedIcon };
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
return wallet;
|
|
1349
|
+
});
|
|
1350
|
+
const cachedAccounts = cachedState.accounts.map(hydrateAccount);
|
|
1351
|
+
if (kc.debug && cachedWallets.length > 0) {
|
|
1352
|
+
console.debug("[kheopskit] hydrating from cache:", {
|
|
1353
|
+
wallets: cachedWallets.length,
|
|
1354
|
+
accounts: cachedAccounts.length
|
|
1355
|
+
});
|
|
1356
|
+
}
|
|
1357
|
+
return new import_rxjs11.Observable((subscriber) => {
|
|
1358
|
+
const liveWallets$ = getWallets$(kc, store2);
|
|
1359
|
+
const liveAccounts$ = getAccounts$(kc, liveWallets$);
|
|
1360
|
+
const bufferedWallets$ = createHydrationBuffer(
|
|
1361
|
+
cachedWallets,
|
|
1362
|
+
liveWallets$,
|
|
1363
|
+
kc.hydrationGracePeriod,
|
|
1364
|
+
(w) => w.id,
|
|
1365
|
+
// Hydration converges when all cached-connected wallets are connected in live
|
|
1366
|
+
(liveWallets, cached) => {
|
|
1367
|
+
const cachedConnectedIds = new Set(
|
|
1368
|
+
cached.filter((w) => w.isConnected).map((w) => w.id)
|
|
1369
|
+
);
|
|
1370
|
+
if (cachedConnectedIds.size === 0) return true;
|
|
1371
|
+
return [...cachedConnectedIds].every(
|
|
1372
|
+
(id) => liveWallets.some((w) => w.id === id && w.isConnected)
|
|
1373
|
+
);
|
|
1374
|
+
},
|
|
1375
|
+
// Merge: prefer cached isConnected state but get icon from cache or live
|
|
1376
|
+
(live, cached) => ({
|
|
1377
|
+
...cached,
|
|
1378
|
+
// Priority: cached icon > localStorage cache > live icon
|
|
1379
|
+
icon: cached.icon || getCachedIcon(cached.id) || live.icon,
|
|
1380
|
+
// Use live wallet's connect/disconnect functions
|
|
1381
|
+
connect: live.connect,
|
|
1382
|
+
disconnect: live.disconnect
|
|
1383
|
+
}),
|
|
1384
|
+
// Transform cached-only items: add icon from localStorage cache
|
|
1385
|
+
(cached) => ({
|
|
1386
|
+
...cached,
|
|
1387
|
+
icon: cached.icon || getCachedIcon(cached.id) || ""
|
|
1388
|
+
})
|
|
1389
|
+
);
|
|
1390
|
+
const bufferedAccounts$ = createAccountHydrationBuffer(
|
|
1391
|
+
cachedAccounts,
|
|
1392
|
+
liveAccounts$,
|
|
1393
|
+
kc.hydrationGracePeriod,
|
|
1394
|
+
(a) => a.walletId,
|
|
1395
|
+
// Hydration converges when all wallets with cached accounts have provided live accounts
|
|
1396
|
+
(liveAccounts, cached) => {
|
|
1397
|
+
const cachedWalletIds = new Set(cached.map((a) => a.walletId));
|
|
1398
|
+
if (cachedWalletIds.size === 0) return true;
|
|
1399
|
+
const liveWalletIds = new Set(liveAccounts.map((a) => a.walletId));
|
|
1400
|
+
return [...cachedWalletIds].every((id) => liveWalletIds.has(id));
|
|
1401
|
+
}
|
|
1402
|
+
);
|
|
1403
|
+
const subscription = (0, import_rxjs11.combineLatest)({
|
|
1404
|
+
wallets: bufferedWallets$,
|
|
1405
|
+
accounts: bufferedAccounts$
|
|
1406
|
+
}).pipe(
|
|
1407
|
+
(0, import_rxjs11.map)(({ wallets, accounts }) => {
|
|
1408
|
+
if (kc.debug) {
|
|
1409
|
+
console.debug("[kheopskit] hydration state", {
|
|
1410
|
+
walletsHydrating: wallets.isHydrating,
|
|
1411
|
+
accountsHydrating: accounts.isHydrating,
|
|
1412
|
+
walletsConnected: wallets.items.filter((w) => w.isConnected).length,
|
|
1413
|
+
walletsTotal: wallets.items.length
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
return {
|
|
1417
|
+
config: kc,
|
|
1418
|
+
wallets: wallets.items,
|
|
1419
|
+
accounts: accounts.items,
|
|
1420
|
+
isHydrating: wallets.isHydrating || accounts.isHydrating
|
|
1421
|
+
};
|
|
1422
|
+
})
|
|
1423
|
+
).subscribe(subscriber);
|
|
1424
|
+
const persistSub = (0, import_rxjs11.combineLatest)({
|
|
1425
|
+
wallets: bufferedWallets$,
|
|
1426
|
+
accounts: bufferedAccounts$
|
|
1427
|
+
}).pipe(
|
|
1428
|
+
// Wait for hydration to complete
|
|
1429
|
+
(0, import_rxjs11.filter)(
|
|
1430
|
+
({ wallets, accounts }) => !wallets.isHydrating && !accounts.isHydrating
|
|
1431
|
+
),
|
|
1432
|
+
// Debounce to avoid excessive writes
|
|
1433
|
+
(0, import_rxjs11.debounceTime)(1e3),
|
|
1434
|
+
// Only persist if state actually changed
|
|
1435
|
+
(0, import_rxjs11.distinctUntilChanged)((prev, curr) => {
|
|
1436
|
+
const prevWalletIds = prev.wallets.items.map((w) => w.id);
|
|
1437
|
+
const currWalletIds = curr.wallets.items.map((w) => w.id);
|
|
1438
|
+
const prevAccountIds = prev.accounts.items.map((a) => a.id);
|
|
1439
|
+
const currAccountIds = curr.accounts.items.map((a) => a.id);
|
|
1440
|
+
return arraysEqual(prevWalletIds, currWalletIds) && arraysEqual(prevAccountIds, currAccountIds);
|
|
1441
|
+
})
|
|
1442
|
+
).subscribe(({ wallets, accounts }) => {
|
|
1443
|
+
const connectedWalletIds = new Set(
|
|
1444
|
+
wallets.items.filter((w) => w.isConnected).map((w) => w.id)
|
|
1445
|
+
);
|
|
1446
|
+
const relevantAccounts = accounts.items.filter(
|
|
1447
|
+
(a) => connectedWalletIds.has(a.walletId)
|
|
1448
|
+
);
|
|
1449
|
+
if (kc.debug) {
|
|
1450
|
+
console.debug("[kheopskit] persisting state snapshot:", {
|
|
1451
|
+
wallets: wallets.items.length,
|
|
1452
|
+
accounts: relevantAccounts.length
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
store2.setCachedState(
|
|
1456
|
+
wallets.items.map(serializeWallet),
|
|
1457
|
+
relevantAccounts.map(serializeAccount)
|
|
1458
|
+
);
|
|
1459
|
+
const icons = {};
|
|
1460
|
+
for (const wallet of wallets.items) {
|
|
1461
|
+
if (wallet.icon) {
|
|
1462
|
+
icons[wallet.id] = wallet.icon;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
setCachedIcons(icons);
|
|
1466
|
+
});
|
|
825
1467
|
return () => {
|
|
826
1468
|
subscription.unsubscribe();
|
|
1469
|
+
persistSub.unsubscribe();
|
|
827
1470
|
};
|
|
828
1471
|
}).pipe(
|
|
829
|
-
(0,
|
|
1472
|
+
(0, import_rxjs11.distinctUntilChanged)(statesEqual),
|
|
1473
|
+
(0, import_rxjs11.throttleTime)(16, void 0, { leading: true, trailing: true }),
|
|
830
1474
|
// ~1 frame at 60fps
|
|
831
1475
|
logObservable("kheopskit$", { enabled: kc.debug, printValue: true }),
|
|
832
|
-
(0,
|
|
1476
|
+
(0, import_rxjs11.shareReplay)({ bufferSize: 1, refCount: true })
|
|
833
1477
|
);
|
|
834
1478
|
};
|
|
1479
|
+
var arraysEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
|
|
1480
|
+
var statesEqual = (a, b) => a.isHydrating === b.isHydrating && a.wallets.length === b.wallets.length && a.accounts.length === b.accounts.length && a.wallets.every(
|
|
1481
|
+
(w, i) => w.id === b.wallets[i]?.id && w.isConnected === b.wallets[i]?.isConnected
|
|
1482
|
+
) && a.accounts.every((acc, i) => acc.id === b.accounts[i]?.id);
|
|
835
1483
|
// Annotate the CommonJS export names for ESM import in node:
|
|
836
1484
|
0 && (module.exports = {
|
|
1485
|
+
DEFAULT_STORAGE_KEY,
|
|
1486
|
+
clearAllCachedObservables,
|
|
1487
|
+
clearCachedObservable,
|
|
1488
|
+
createKheopskitStore,
|
|
1489
|
+
getCachedIcon,
|
|
837
1490
|
getKheopskit$,
|
|
1491
|
+
hydrateAccount,
|
|
1492
|
+
hydrateWallet,
|
|
1493
|
+
resetAppKitCache,
|
|
838
1494
|
resolveConfig
|
|
839
1495
|
});
|
|
840
1496
|
//# sourceMappingURL=index.js.map
|