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