@kheopskit/core 0.0.21 → 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 +146 -5
- package/dist/index.d.ts +146 -5
- package/dist/index.js +1055 -369
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1081 -389
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -17
- package/CHANGELOG.md +0 -131
- package/src/api/accounts.ts +0 -43
- package/src/api/appKit.ts +0 -127
- package/src/api/config.ts +0 -13
- package/src/api/ethereum/accounts.ts +0 -207
- package/src/api/ethereum/wallets.ts +0 -117
- package/src/api/index.ts +0 -3
- package/src/api/kheopskit.ts +0 -45
- package/src/api/polkadot/accounts.ts +0 -159
- package/src/api/polkadot/wallets.ts +0 -123
- package/src/api/store.ts +0 -36
- package/src/api/types.ts +0 -111
- package/src/api/wallets.ts +0 -72
- package/src/index.ts +0 -1
- package/src/utils/WalletAccountId.ts +0 -22
- package/src/utils/WalletId.ts +0 -21
- package/src/utils/createStore.ts +0 -45
- package/src/utils/getAccountAddressType.ts +0 -11
- package/src/utils/getCachedObservable.ts +0 -12
- package/src/utils/getQuery.ts +0 -72
- package/src/utils/index.ts +0 -10
- package/src/utils/isEthereumAddress.ts +0 -4
- package/src/utils/isSs58Address.ts +0 -15
- package/src/utils/isValidAddress.ts +0 -8
- package/src/utils/isWalletPlatform.ts +0 -7
- package/src/utils/logObservable.ts +0 -21
- package/src/utils/polkadotExtensions.ts +0 -21
- package/src/utils/sleep.ts +0 -2
- package/src/utils/sortAccounts.ts +0 -36
- package/src/utils/sortWallets.ts +0 -14
- package/src/utils/throwAfter.ts +0 -6
- package/tsconfig.json +0 -10
package/dist/index.js
CHANGED
|
@@ -20,14 +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
|
|
|
28
|
-
// src/utils/
|
|
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
|
+
var POLKADOT_EXTENSIONS = {
|
|
51
|
+
talisman: {
|
|
52
|
+
name: "Talisman",
|
|
53
|
+
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwID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ODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+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");
|
|
29
337
|
var import_rxjs = require("rxjs");
|
|
30
|
-
var
|
|
338
|
+
var WALLET_CONNECT_ICON = "data:image/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4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+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
|
+
|
|
427
|
+
// src/api/config.ts
|
|
428
|
+
var DEFAULT_STORAGE_KEY = "kheopskit";
|
|
429
|
+
var DEFAULT_CONFIG = {
|
|
430
|
+
autoReconnect: true,
|
|
431
|
+
platforms: ["polkadot"],
|
|
432
|
+
debug: false,
|
|
433
|
+
storageKey: DEFAULT_STORAGE_KEY,
|
|
434
|
+
hydrationGracePeriod: 500
|
|
435
|
+
};
|
|
436
|
+
var resolveConfig = (config) => {
|
|
437
|
+
return Object.assign({}, DEFAULT_CONFIG, config);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/api/kheopskit.ts
|
|
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
|
+
};
|
|
544
|
+
|
|
545
|
+
// src/utils/logObservable.ts
|
|
546
|
+
var import_rxjs3 = require("rxjs");
|
|
547
|
+
var logObservable = (label, opts) => (0, import_rxjs3.tap)((value) => {
|
|
31
548
|
const { printValue = false, enabled = true } = opts || {};
|
|
32
549
|
if (!label || !enabled) return;
|
|
33
550
|
const text = `[kheopskit] observable ${label} emit`;
|
|
@@ -35,8 +552,8 @@ var logObservable = (label, opts) => (0, import_rxjs.tap)((value) => {
|
|
|
35
552
|
else console.debug(text);
|
|
36
553
|
});
|
|
37
554
|
|
|
38
|
-
// src/api/
|
|
39
|
-
var
|
|
555
|
+
// src/api/accounts.ts
|
|
556
|
+
var import_rxjs7 = require("rxjs");
|
|
40
557
|
|
|
41
558
|
// src/utils/sortAccounts.ts
|
|
42
559
|
var sortAccounts = (a1, a2) => {
|
|
@@ -57,31 +574,43 @@ var sortAccounts = (a1, a2) => {
|
|
|
57
574
|
if (a2.walletName === "Talisman") return 1;
|
|
58
575
|
return a1.walletName.localeCompare(a2.walletName);
|
|
59
576
|
}
|
|
60
|
-
return
|
|
577
|
+
return a1.id.localeCompare(a2.id);
|
|
61
578
|
}
|
|
62
579
|
return 0;
|
|
63
580
|
};
|
|
64
581
|
|
|
65
|
-
// src/api/accounts.ts
|
|
582
|
+
// src/api/ethereum/accounts.ts
|
|
66
583
|
var import_rxjs5 = require("rxjs");
|
|
584
|
+
var import_viem2 = require("viem");
|
|
67
585
|
|
|
68
586
|
// src/utils/createStore.ts
|
|
69
|
-
var
|
|
70
|
-
var createStore = (key, defaultValue) => {
|
|
71
|
-
const subject = new
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
}
|
|
76
598
|
const update = (val) => {
|
|
77
|
-
setStoredData(key, val);
|
|
599
|
+
setStoredData(key, val, storage);
|
|
78
600
|
subject.next(val);
|
|
79
601
|
};
|
|
80
602
|
return {
|
|
81
603
|
observable: subject.asObservable(),
|
|
82
604
|
set: (val) => update(val),
|
|
83
605
|
mutate: (transform) => update(transform(subject.getValue())),
|
|
84
|
-
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
|
+
}
|
|
85
614
|
};
|
|
86
615
|
};
|
|
87
616
|
var parseData = (str, defaultValue) => {
|
|
@@ -91,13 +620,13 @@ var parseData = (str, defaultValue) => {
|
|
|
91
620
|
}
|
|
92
621
|
return defaultValue;
|
|
93
622
|
};
|
|
94
|
-
var getStoredData = (key, defaultValue) => {
|
|
95
|
-
const str =
|
|
623
|
+
var getStoredData = (key, defaultValue, storage) => {
|
|
624
|
+
const str = storage.getItem(key);
|
|
96
625
|
return parseData(str, defaultValue);
|
|
97
626
|
};
|
|
98
|
-
var setStoredData = (key, val) => {
|
|
627
|
+
var setStoredData = (key, val, storage) => {
|
|
99
628
|
const str = JSON.stringify(val);
|
|
100
|
-
|
|
629
|
+
storage.setItem(key, str);
|
|
101
630
|
};
|
|
102
631
|
|
|
103
632
|
// src/utils/isEthereumAddress.ts
|
|
@@ -129,24 +658,12 @@ var getWalletAccountId = (walletId, address) => {
|
|
|
129
658
|
return `${walletId}::${address}`;
|
|
130
659
|
};
|
|
131
660
|
|
|
132
|
-
// src/utils/isWalletPlatform.ts
|
|
133
|
-
var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
|
|
134
|
-
|
|
135
|
-
// src/utils/getCachedObservable.ts
|
|
136
|
-
var CACHE = /* @__PURE__ */ new Map();
|
|
137
|
-
var getCachedObservable$ = (key, create) => {
|
|
138
|
-
if (!CACHE.has(key)) CACHE.set(key, create());
|
|
139
|
-
return CACHE.get(key);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
661
|
// src/api/ethereum/accounts.ts
|
|
143
|
-
var import_rxjs3 = require("rxjs");
|
|
144
|
-
var import_viem2 = require("viem");
|
|
145
662
|
var getInjectedWalletAccounts$ = (wallet) => {
|
|
146
|
-
if (!wallet.isConnected) return (0,
|
|
663
|
+
if (!wallet.isConnected) return (0, import_rxjs5.of)([]);
|
|
147
664
|
return getCachedObservable$(
|
|
148
665
|
`accounts:${wallet.id}`,
|
|
149
|
-
() => new
|
|
666
|
+
() => new import_rxjs5.Observable((subscriber) => {
|
|
150
667
|
const getAccount = (address, i) => {
|
|
151
668
|
const client = (0, import_viem2.createWalletClient)({
|
|
152
669
|
account: address,
|
|
@@ -178,7 +695,7 @@ var getInjectedWalletAccounts$ = (wallet) => {
|
|
|
178
695
|
handleAccountsChanged
|
|
179
696
|
);
|
|
180
697
|
};
|
|
181
|
-
}).pipe((0,
|
|
698
|
+
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
182
699
|
);
|
|
183
700
|
};
|
|
184
701
|
var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
|
|
@@ -199,29 +716,29 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
199
716
|
const account = wallet.appKit.getAccount("eip155");
|
|
200
717
|
const provider = wallet.appKit.getProvider("eip155");
|
|
201
718
|
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
202
|
-
return (0,
|
|
719
|
+
return (0, import_rxjs5.of)([]);
|
|
203
720
|
return getCachedObservable$(
|
|
204
721
|
"accounts:appKit",
|
|
205
|
-
() => new
|
|
206
|
-
const caipNetworkId$ = new
|
|
722
|
+
() => new import_rxjs5.Observable((subscriber) => {
|
|
723
|
+
const caipNetworkId$ = new import_rxjs5.ReplaySubject(1);
|
|
207
724
|
const handleChainChanged = (chainId) => {
|
|
208
725
|
caipNetworkId$.next(`eip155:${chainId}`);
|
|
209
726
|
};
|
|
210
727
|
provider.on("chainChanged", handleChainChanged);
|
|
211
728
|
provider.request({ method: "eth_chainId" }).then(handleChainChanged);
|
|
212
729
|
const sub = caipNetworkId$.pipe(
|
|
213
|
-
(0,
|
|
214
|
-
(0,
|
|
730
|
+
(0, import_rxjs5.distinctUntilChanged)(),
|
|
731
|
+
(0, import_rxjs5.map)(
|
|
215
732
|
(caipNetworkId) => (0, import_viem2.custom)(
|
|
216
733
|
wrapWalletConnectProvider(
|
|
217
734
|
provider,
|
|
218
|
-
// biome-ignore lint/style/noNonNullAssertion:
|
|
735
|
+
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
219
736
|
provider.session.topic,
|
|
220
737
|
caipNetworkId
|
|
221
738
|
)
|
|
222
739
|
)
|
|
223
740
|
),
|
|
224
|
-
(0,
|
|
741
|
+
(0, import_rxjs5.map)(
|
|
225
742
|
(transport) => account.allAccounts.map((acc, i) => {
|
|
226
743
|
const client = (0, import_viem2.createWalletClient)({
|
|
227
744
|
account: acc.address,
|
|
@@ -243,28 +760,28 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
243
760
|
provider.off("chainChanged", handleChainChanged);
|
|
244
761
|
sub.unsubscribe();
|
|
245
762
|
};
|
|
246
|
-
}).pipe((0,
|
|
763
|
+
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
247
764
|
);
|
|
248
765
|
};
|
|
249
|
-
var getEthereumAccounts$ = (ethereumWallets) => new
|
|
766
|
+
var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs5.Observable((subscriber) => {
|
|
250
767
|
const sub = ethereumWallets.pipe(
|
|
251
|
-
(0,
|
|
252
|
-
(0,
|
|
253
|
-
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)([
|
|
254
771
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
255
772
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
|
|
256
773
|
// todo appkit
|
|
257
|
-
]) : (0,
|
|
774
|
+
]) : (0, import_rxjs5.of)([]);
|
|
258
775
|
}),
|
|
259
|
-
(0,
|
|
260
|
-
(0,
|
|
776
|
+
(0, import_rxjs5.map)((accounts) => accounts.flat()),
|
|
777
|
+
(0, import_rxjs5.distinctUntilChanged)(isSameAccountsList)
|
|
261
778
|
).subscribe(subscriber);
|
|
262
779
|
return () => {
|
|
263
780
|
sub.unsubscribe();
|
|
264
781
|
};
|
|
265
782
|
}).pipe(
|
|
266
783
|
// logObservable("ethereumAccounts$", true),
|
|
267
|
-
(0,
|
|
784
|
+
(0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
268
785
|
);
|
|
269
786
|
var isSameAccountsList = (a, b) => {
|
|
270
787
|
if (a.length !== b.length) return false;
|
|
@@ -273,10 +790,10 @@ var isSameAccountsList = (a, b) => {
|
|
|
273
790
|
|
|
274
791
|
// src/api/polkadot/accounts.ts
|
|
275
792
|
var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
276
|
-
var
|
|
793
|
+
var import_rxjs6 = require("rxjs");
|
|
277
794
|
var getInjectedWalletAccounts$2 = (wallet) => {
|
|
278
|
-
if (!wallet.isConnected) return (0,
|
|
279
|
-
return new
|
|
795
|
+
if (!wallet.isConnected) return (0, import_rxjs6.of)([]);
|
|
796
|
+
return new import_rxjs6.Observable((subscriber) => {
|
|
280
797
|
const getAccount = (account) => ({
|
|
281
798
|
id: getWalletAccountId(wallet.id, account.address),
|
|
282
799
|
...account,
|
|
@@ -337,8 +854,8 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
337
854
|
const account = wallet.appKit.getAccount("polkadot");
|
|
338
855
|
const provider = wallet.appKit.getProvider("polkadot");
|
|
339
856
|
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
340
|
-
return (0,
|
|
341
|
-
return (0,
|
|
857
|
+
return (0, import_rxjs6.of)([]);
|
|
858
|
+
return (0, import_rxjs6.of)(
|
|
342
859
|
account.allAccounts.map(
|
|
343
860
|
(acc) => ({
|
|
344
861
|
id: getWalletAccountId(wallet.id, acc.address),
|
|
@@ -354,67 +871,214 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
354
871
|
)
|
|
355
872
|
);
|
|
356
873
|
};
|
|
357
|
-
var getPolkadotAccounts$ = (polkadotWallets$) => new
|
|
874
|
+
var getPolkadotAccounts$ = (polkadotWallets$) => new import_rxjs6.Observable((subscriber) => {
|
|
358
875
|
const sub = polkadotWallets$.pipe(
|
|
359
|
-
(0,
|
|
360
|
-
(0,
|
|
361
|
-
(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)([
|
|
362
879
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$2),
|
|
363
880
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
364
|
-
]) : (0,
|
|
881
|
+
]) : (0, import_rxjs6.of)([])
|
|
365
882
|
),
|
|
366
|
-
(0,
|
|
367
|
-
(0,
|
|
883
|
+
(0, import_rxjs6.map)((accounts) => accounts.flat()),
|
|
884
|
+
(0, import_rxjs6.distinctUntilChanged)(isSameAccountsList2)
|
|
368
885
|
).subscribe(subscriber);
|
|
369
886
|
return () => {
|
|
370
887
|
sub.unsubscribe();
|
|
371
888
|
};
|
|
372
|
-
}).pipe((0,
|
|
889
|
+
}).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
373
890
|
var isSameAccountsList2 = (a, b) => {
|
|
374
891
|
if (a.length !== b.length) return false;
|
|
375
892
|
return a.every((account, i) => account.id === b[i]?.id);
|
|
376
893
|
};
|
|
377
|
-
|
|
378
|
-
// src/api/accounts.ts
|
|
379
|
-
var getAccounts$ = (config, wallets) => {
|
|
380
|
-
return new
|
|
381
|
-
const sources = config.platforms.map(
|
|
382
|
-
(platform) => {
|
|
383
|
-
switch (platform) {
|
|
384
|
-
case "polkadot":
|
|
385
|
-
return getPolkadotAccounts$(
|
|
386
|
-
wallets.pipe(
|
|
387
|
-
(0,
|
|
388
|
-
)
|
|
389
|
-
);
|
|
390
|
-
case "ethereum":
|
|
391
|
-
return getEthereumAccounts$(
|
|
392
|
-
wallets.pipe(
|
|
393
|
-
(0,
|
|
394
|
-
)
|
|
395
|
-
);
|
|
894
|
+
|
|
895
|
+
// src/api/accounts.ts
|
|
896
|
+
var getAccounts$ = (config, wallets) => {
|
|
897
|
+
return new import_rxjs7.Observable((subscriber) => {
|
|
898
|
+
const sources = config.platforms.map(
|
|
899
|
+
(platform) => {
|
|
900
|
+
switch (platform) {
|
|
901
|
+
case "polkadot":
|
|
902
|
+
return getPolkadotAccounts$(
|
|
903
|
+
wallets.pipe(
|
|
904
|
+
(0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "polkadot"))
|
|
905
|
+
)
|
|
906
|
+
);
|
|
907
|
+
case "ethereum":
|
|
908
|
+
return getEthereumAccounts$(
|
|
909
|
+
wallets.pipe(
|
|
910
|
+
(0, import_rxjs7.map)((w) => w.filter((w2) => w2.platform === "ethereum"))
|
|
911
|
+
)
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
);
|
|
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)([]);
|
|
919
|
+
const sub = accounts$.subscribe(subscriber);
|
|
920
|
+
return () => {
|
|
921
|
+
sub.unsubscribe();
|
|
922
|
+
};
|
|
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 {
|
|
396
1055
|
}
|
|
397
1056
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
+
};
|
|
407
1078
|
};
|
|
408
1079
|
|
|
409
|
-
// src/api/
|
|
410
|
-
var
|
|
411
|
-
autoReconnect: true,
|
|
412
|
-
platforms: ["polkadot"],
|
|
413
|
-
debug: false
|
|
414
|
-
};
|
|
415
|
-
var resolveConfig = (config) => {
|
|
416
|
-
return Object.assign({}, DEFAULT_CONFIG, config);
|
|
417
|
-
};
|
|
1080
|
+
// src/api/wallets.ts
|
|
1081
|
+
var import_rxjs10 = require("rxjs");
|
|
418
1082
|
|
|
419
1083
|
// src/utils/sortWallets.ts
|
|
420
1084
|
var sortWallets = (w1, w2) => {
|
|
@@ -426,247 +1090,125 @@ var sortWallets = (w1, w2) => {
|
|
|
426
1090
|
return w1.name.localeCompare(w2.name);
|
|
427
1091
|
};
|
|
428
1092
|
|
|
429
|
-
// src/api/wallets.ts
|
|
430
|
-
var import_rxjs9 = require("rxjs");
|
|
431
|
-
|
|
432
|
-
// src/utils/WalletId.ts
|
|
433
|
-
var getWalletId = (platform, identifier) => {
|
|
434
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
435
|
-
if (!identifier) throw new Error("Invalid name");
|
|
436
|
-
return `${platform}:${identifier}`;
|
|
437
|
-
};
|
|
438
|
-
var parseWalletId = (walletId) => {
|
|
439
|
-
if (!walletId) throw new Error("Invalid walletId");
|
|
440
|
-
const [platform, identifier] = walletId.split(":");
|
|
441
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
442
|
-
if (!identifier) throw new Error("Invalid address");
|
|
443
|
-
return { platform, identifier };
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
// src/api/store.ts
|
|
447
|
-
var import_lodash = require("lodash");
|
|
448
|
-
var LOCAL_STORAGE_KEY = "kheopskit";
|
|
449
|
-
var DEFAULT_SETTINGS = {};
|
|
450
|
-
var storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);
|
|
451
|
-
var addEnabledWalletId = (walletId) => {
|
|
452
|
-
parseWalletId(walletId);
|
|
453
|
-
storage.mutate((prev) => ({
|
|
454
|
-
...prev,
|
|
455
|
-
autoReconnect: (0, import_lodash.uniq)((prev.autoReconnect ?? []).concat(walletId))
|
|
456
|
-
}));
|
|
457
|
-
};
|
|
458
|
-
var removeEnabledWalletId = (walletId) => {
|
|
459
|
-
storage.mutate((prev) => ({
|
|
460
|
-
...prev,
|
|
461
|
-
autoReconnect: (0, import_lodash.uniq)(
|
|
462
|
-
(prev.autoReconnect ?? []).filter((id) => id !== walletId)
|
|
463
|
-
)
|
|
464
|
-
}));
|
|
465
|
-
};
|
|
466
|
-
var store = {
|
|
467
|
-
observable: storage.observable,
|
|
468
|
-
addEnabledWalletId,
|
|
469
|
-
removeEnabledWalletId
|
|
470
|
-
};
|
|
471
|
-
|
|
472
1093
|
// src/api/ethereum/wallets.ts
|
|
473
1094
|
var import_mipd = require("mipd");
|
|
474
|
-
var
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
var WALLET_CONNECT_ICON = "data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0cm9rZT0iIzY2YjFmZiIvPjxwYXRoIGQ9Im0xMjIuNTE5IDE0OC45NjVjNDIuNzkxLTQxLjcyOSAxMTIuMTcxLTQxLjcyOSAxNTQuOTYyIDBsNS4xNSA1LjAyMmMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtMTcuNjE3IDE3LjE4Yy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTcuMDg3LTYuOTExYy0yOS44NTMtMjkuMTExLTc4LjI1My0yOS4xMTEtMTA4LjEwNiAwbC03LjU5IDcuNDAxYy0xLjA3IDEuMDQzLTIuODA0IDEuMDQzLTMuODc0IDBsLTE3LjYxNy0xNy4xOGMtMi4xNC0yLjA4Ni0yLjE0LTUuNDY5IDAtNy41NTV6bTE5MS4zOTcgMzUuNTI5IDE1LjY3OSAxNS4yOWMyLjE0IDIuMDg2IDIuMTQgNS40NjkgMCA3LjU1NWwtNzAuNyA2OC45NDRjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTUwLjE3OC00OC45MzFjLS41MzUtLjUyMi0xLjQwMi0uNTIyLTEuOTM3IDBsLTUwLjE3OCA0OC45MzFjLTIuMTM5IDIuMDg3LTUuNjA4IDIuMDg3LTcuNzQ4IDBsLTcwLjcwMTUtNjguOTQ1Yy0yLjEzOTYtMi4wODYtMi4xMzk2LTUuNDY5IDAtNy41NTVsMTUuNjc5NS0xNS4yOWMyLjEzOTYtMi4wODYgNS42MDg1LTIuMDg2IDcuNzQ4MSAwbDUwLjE3ODkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3Ny00OC45MzJjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMGw1MC4xNzkgNDguOTMyYy41MzUuNTIyIDEuNDAyLjUyMiAxLjkzNyAwbDUwLjE3OS00OC45MzFjMi4xMzktMi4wODcgNS42MDgtMi4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+PC9zdmc+";
|
|
480
|
-
var cachedAppKit = null;
|
|
481
|
-
var getAppKitWallets$ = (config) => {
|
|
482
|
-
if (!config.walletConnect) return (0, import_rxjs6.of)({});
|
|
483
|
-
const walletConnect = config.walletConnect;
|
|
484
|
-
if (!cachedAppKit) {
|
|
485
|
-
cachedAppKit = new import_rxjs6.Observable((subscriber) => {
|
|
486
|
-
const appKit = (0, import_core.createAppKit)({
|
|
487
|
-
projectId: walletConnect.projectId,
|
|
488
|
-
metadata: walletConnect.metadata,
|
|
489
|
-
networks: walletConnect.networks,
|
|
490
|
-
themeMode: walletConnect.themeMode,
|
|
491
|
-
themeVariables: walletConnect.themeVariables,
|
|
492
|
-
universalProviderConfigOverride: {
|
|
493
|
-
methods: {
|
|
494
|
-
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
|
-
allWallets: "HIDE",
|
|
498
|
-
debug: config.debug,
|
|
499
|
-
allowUnsupportedChain: true
|
|
500
|
-
});
|
|
501
|
-
const status$ = new import_rxjs6.BehaviorSubject({
|
|
502
|
-
isPolkadotConnected: false,
|
|
503
|
-
isEthereumConnected: false
|
|
504
|
-
});
|
|
505
|
-
const unsubProviders = appKit.subscribeProviders((providers) => {
|
|
506
|
-
status$.next({
|
|
507
|
-
isPolkadotConnected: !!providers.polkadot,
|
|
508
|
-
isEthereumConnected: !!providers.eip155
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
|
|
512
|
-
(0, import_rxjs6.map)((s) => s.isPolkadotConnected),
|
|
513
|
-
(0, import_rxjs6.distinctUntilChanged)(),
|
|
514
|
-
(0, import_rxjs6.map)((isConnected) => {
|
|
515
|
-
const walletInfo = appKit.getWalletInfo();
|
|
516
|
-
return {
|
|
517
|
-
id: getWalletId("polkadot", "walletconnect"),
|
|
518
|
-
platform: "polkadot",
|
|
519
|
-
type: "appKit",
|
|
520
|
-
appKit,
|
|
521
|
-
// todo maybe we dont want to expose the appKit instance
|
|
522
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
523
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
524
|
-
connect: async () => {
|
|
525
|
-
if (!isConnected) await appKit.open();
|
|
526
|
-
},
|
|
527
|
-
disconnect: () => {
|
|
528
|
-
if (isConnected) appKit.disconnect();
|
|
529
|
-
},
|
|
530
|
-
isConnected
|
|
531
|
-
};
|
|
532
|
-
})
|
|
533
|
-
) : (0, import_rxjs6.of)(void 0);
|
|
534
|
-
const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
|
|
535
|
-
(0, import_rxjs6.map)((s) => s.isEthereumConnected),
|
|
536
|
-
(0, import_rxjs6.distinctUntilChanged)(),
|
|
537
|
-
(0, import_rxjs6.map)((isConnected) => {
|
|
538
|
-
const walletInfo = appKit.getWalletInfo();
|
|
539
|
-
return {
|
|
540
|
-
id: getWalletId("ethereum", "walletconnect"),
|
|
541
|
-
platform: "ethereum",
|
|
542
|
-
type: "appKit",
|
|
543
|
-
appKit,
|
|
544
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
545
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
546
|
-
connect: () => appKit.open(),
|
|
547
|
-
disconnect: () => appKit.disconnect(),
|
|
548
|
-
isConnected
|
|
549
|
-
};
|
|
550
|
-
})
|
|
551
|
-
) : (0, import_rxjs6.of)(void 0);
|
|
552
|
-
const sub = (0, import_rxjs6.combineLatest)({
|
|
553
|
-
polkadot: polkadotWallet$,
|
|
554
|
-
ethereum: ethereumWallet$
|
|
555
|
-
}).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([]);
|
|
556
1100
|
return () => {
|
|
557
|
-
sub.unsubscribe();
|
|
558
|
-
unsubProviders();
|
|
559
1101
|
};
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
// src/api/ethereum/wallets.ts
|
|
566
|
-
var providersDetails$ = new import_rxjs7.Observable(
|
|
567
|
-
(subscriber) => {
|
|
568
|
-
const store2 = (0, import_mipd.createStore)();
|
|
569
|
-
const unsubscribe = store2.subscribe((providerDetails2) => {
|
|
1102
|
+
}
|
|
1103
|
+
const mipdStore = (0, import_mipd.createStore)();
|
|
1104
|
+
const unsubscribe = mipdStore.subscribe((providerDetails2) => {
|
|
570
1105
|
subscriber.next(providerDetails2);
|
|
571
1106
|
});
|
|
572
|
-
const providerDetails =
|
|
1107
|
+
const providerDetails = mipdStore.getProviders();
|
|
573
1108
|
subscriber.next(providerDetails);
|
|
574
1109
|
return () => {
|
|
575
1110
|
unsubscribe();
|
|
576
|
-
|
|
1111
|
+
mipdStore.destroy();
|
|
577
1112
|
};
|
|
578
1113
|
}
|
|
579
|
-
).pipe((0,
|
|
580
|
-
var
|
|
581
|
-
(
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
+
};
|
|
588
1153
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
};
|
|
602
|
-
const sub = (0, import_rxjs7.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
|
|
603
|
-
(0, import_rxjs7.map)(([providerDetails, enabledWalletIds]) => {
|
|
604
|
-
return providerDetails.map((pd) => {
|
|
605
|
-
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
606
|
-
const provider = pd.provider;
|
|
607
|
-
return {
|
|
608
|
-
platform: "ethereum",
|
|
609
|
-
type: "injected",
|
|
610
|
-
id: walletId,
|
|
611
|
-
name: pd.info.name,
|
|
612
|
-
icon: pd.info.icon,
|
|
613
|
-
provider,
|
|
614
|
-
isConnected: enabledWalletIds.has(walletId),
|
|
615
|
-
providerId: pd.info.rdns,
|
|
616
|
-
connect: () => connectWallet(walletId, provider),
|
|
617
|
-
disconnect: () => disconnectWallet(walletId)
|
|
618
|
-
};
|
|
619
|
-
});
|
|
620
|
-
})
|
|
621
|
-
).subscribe(subscriber);
|
|
622
|
-
return () => {
|
|
623
|
-
sub.unsubscribe();
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
627
|
-
var getEthereumWallets$ = (config) => {
|
|
628
|
-
return new import_rxjs7.Observable((subscriber) => {
|
|
629
|
-
const subscription = (0, import_rxjs7.combineLatest)([
|
|
630
|
-
ethereumInjectedWallets$,
|
|
631
|
-
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))
|
|
632
1166
|
]).pipe(
|
|
633
|
-
(0,
|
|
1167
|
+
(0, import_rxjs8.map)(
|
|
634
1168
|
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
635
1169
|
)
|
|
636
1170
|
).subscribe(subscriber);
|
|
637
1171
|
return () => {
|
|
638
1172
|
subscription.unsubscribe();
|
|
639
1173
|
};
|
|
640
|
-
}).pipe((0,
|
|
1174
|
+
}).pipe((0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
641
1175
|
};
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|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4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
|
|
660
|
-
}
|
|
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
|
+
);
|
|
661
1181
|
};
|
|
662
1182
|
|
|
663
1183
|
// src/api/polkadot/wallets.ts
|
|
664
|
-
var
|
|
1184
|
+
var import_lodash_es2 = require("lodash-es");
|
|
665
1185
|
var import_pjs_signer2 = require("polkadot-api/pjs-signer");
|
|
666
|
-
var
|
|
667
|
-
var getInjectedWalletsIds = () => (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
|
|
668
|
-
var
|
|
669
|
-
|
|
1186
|
+
var import_rxjs9 = require("rxjs");
|
|
1187
|
+
var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
|
|
1188
|
+
var createWalletIdsPoller$ = () => {
|
|
1189
|
+
return new import_rxjs9.Observable((subscriber) => {
|
|
1190
|
+
subscriber.next(getInjectedWalletsIds());
|
|
1191
|
+
const intervals = [100, 200, 300, 500];
|
|
1192
|
+
let index = 0;
|
|
1193
|
+
const poll = () => {
|
|
1194
|
+
subscriber.next(getInjectedWalletsIds());
|
|
1195
|
+
if (index < intervals.length) {
|
|
1196
|
+
const delay = intervals[index++];
|
|
1197
|
+
setTimeout(poll, delay);
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
if (intervals.length > 0) {
|
|
1201
|
+
setTimeout(poll, intervals[index++] ?? 100);
|
|
1202
|
+
}
|
|
1203
|
+
return () => {
|
|
1204
|
+
};
|
|
1205
|
+
}).pipe(
|
|
1206
|
+
(0, import_rxjs9.distinctUntilChanged)(import_lodash_es2.isEqual),
|
|
1207
|
+
(0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
1208
|
+
);
|
|
1209
|
+
};
|
|
1210
|
+
var createPolkadotInjectedWallets$ = (store2) => new import_rxjs9.Observable((subscriber) => {
|
|
1211
|
+
const enabledExtensions$ = new import_rxjs9.BehaviorSubject(/* @__PURE__ */ new Map());
|
|
670
1212
|
const connect = async (walletId) => {
|
|
671
1213
|
if (enabledExtensions$.value.has(walletId))
|
|
672
1214
|
throw new Error(`Extension ${walletId} already connected`);
|
|
@@ -675,7 +1217,7 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
|
675
1217
|
const newMap = new Map(enabledExtensions$.value);
|
|
676
1218
|
newMap.set(walletId, extension);
|
|
677
1219
|
enabledExtensions$.next(newMap);
|
|
678
|
-
|
|
1220
|
+
store2.addEnabledWalletId(walletId);
|
|
679
1221
|
};
|
|
680
1222
|
const disconnect = (walletId) => {
|
|
681
1223
|
if (!enabledExtensions$.value.has(walletId))
|
|
@@ -683,15 +1225,11 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
|
683
1225
|
const newMap = new Map(enabledExtensions$.value);
|
|
684
1226
|
newMap.delete(walletId);
|
|
685
1227
|
enabledExtensions$.next(newMap);
|
|
686
|
-
|
|
1228
|
+
store2.removeEnabledWalletId(walletId);
|
|
687
1229
|
};
|
|
688
|
-
const walletIds$ = (
|
|
689
|
-
|
|
690
|
-
(0,
|
|
691
|
-
(0, import_rxjs8.distinctUntilChanged)(import_lodash2.isEqual)
|
|
692
|
-
);
|
|
693
|
-
const subscription = (0, import_rxjs8.combineLatest)([walletIds$, enabledExtensions$]).pipe(
|
|
694
|
-
(0, import_rxjs8.map)(([walletIds, enabledExtensions]) => {
|
|
1230
|
+
const walletIds$ = createWalletIdsPoller$();
|
|
1231
|
+
const subscription = (0, import_rxjs9.combineLatest)([walletIds$, enabledExtensions$]).pipe(
|
|
1232
|
+
(0, import_rxjs9.map)(([walletIds, enabledExtensions]) => {
|
|
695
1233
|
return walletIds.map((id) => {
|
|
696
1234
|
const { identifier } = parseWalletId(id);
|
|
697
1235
|
const extension = enabledExtensions.get(id);
|
|
@@ -709,70 +1247,75 @@ var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
|
709
1247
|
disconnect: () => disconnect(id)
|
|
710
1248
|
};
|
|
711
1249
|
});
|
|
712
|
-
})
|
|
1250
|
+
}),
|
|
1251
|
+
(0, import_rxjs9.distinctUntilChanged)(walletsEqual2)
|
|
713
1252
|
).subscribe(subscriber);
|
|
714
1253
|
return () => {
|
|
715
1254
|
subscription.unsubscribe();
|
|
716
1255
|
};
|
|
717
|
-
}).pipe(
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
)
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const subscription = (0, import_rxjs8.combineLatest)([
|
|
724
|
-
polkadotInjectedWallets$,
|
|
725
|
-
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))
|
|
726
1262
|
]).pipe(
|
|
727
|
-
(0,
|
|
1263
|
+
(0, import_rxjs9.map)(
|
|
728
1264
|
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
729
1265
|
)
|
|
730
1266
|
).subscribe(subscriber);
|
|
731
1267
|
return () => {
|
|
732
1268
|
subscription.unsubscribe();
|
|
733
1269
|
};
|
|
734
|
-
}).pipe(
|
|
735
|
-
|
|
736
|
-
|
|
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
|
|
737
1276
|
);
|
|
738
1277
|
};
|
|
739
1278
|
|
|
740
1279
|
// src/api/wallets.ts
|
|
741
|
-
var
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
)
|
|
746
|
-
|
|
747
|
-
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) => {
|
|
748
1287
|
const observables = config.platforms.map(
|
|
749
1288
|
(platform) => {
|
|
750
1289
|
switch (platform) {
|
|
751
1290
|
case "polkadot":
|
|
752
|
-
return getPolkadotWallets$(config);
|
|
1291
|
+
return getPolkadotWallets$(config, store2);
|
|
753
1292
|
case "ethereum":
|
|
754
|
-
return getEthereumWallets$(config);
|
|
1293
|
+
return getEthereumWallets$(config, store2);
|
|
755
1294
|
}
|
|
756
1295
|
}
|
|
757
1296
|
);
|
|
758
|
-
const wallets$ = observables.length ? (0,
|
|
759
|
-
(0,
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
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)([]);
|
|
1301
|
+
const reconnectingWallets = /* @__PURE__ */ new Set();
|
|
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)(
|
|
764
1305
|
([wallets, walletIds]) => wallets.filter((wallet) => walletIds?.includes(wallet.id))
|
|
765
1306
|
),
|
|
766
|
-
(0,
|
|
1307
|
+
(0, import_rxjs10.distinct)((w) => w.id)
|
|
767
1308
|
).subscribe(async (wallet) => {
|
|
768
|
-
if (wallet.isConnected) {
|
|
769
|
-
console.warn("Wallet %s already connected", wallet.id);
|
|
1309
|
+
if (wallet.isConnected || reconnectingWallets.has(wallet.id)) {
|
|
770
1310
|
return;
|
|
771
1311
|
}
|
|
1312
|
+
reconnectingWallets.add(wallet.id);
|
|
772
1313
|
try {
|
|
773
1314
|
await wallet.connect();
|
|
774
1315
|
} catch (err) {
|
|
775
1316
|
console.error("Failed to reconnect wallet %s", wallet.id, { err });
|
|
1317
|
+
} finally {
|
|
1318
|
+
reconnectingWallets.delete(wallet.id);
|
|
776
1319
|
}
|
|
777
1320
|
});
|
|
778
1321
|
const subWallets = wallets$.subscribe(subscriber);
|
|
@@ -780,31 +1323,174 @@ var getWallets$ = (config) => {
|
|
|
780
1323
|
subAutoReconnect.unsubscribe();
|
|
781
1324
|
subWallets.unsubscribe();
|
|
782
1325
|
};
|
|
783
|
-
}).pipe((0,
|
|
1326
|
+
}).pipe((0, import_rxjs10.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
784
1327
|
};
|
|
785
1328
|
|
|
786
1329
|
// src/api/kheopskit.ts
|
|
787
|
-
var getKheopskit$ = (config) => {
|
|
1330
|
+
var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
788
1331
|
const kc = resolveConfig(config);
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
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
|
+
});
|
|
796
1467
|
return () => {
|
|
797
1468
|
subscription.unsubscribe();
|
|
1469
|
+
persistSub.unsubscribe();
|
|
798
1470
|
};
|
|
799
1471
|
}).pipe(
|
|
800
|
-
(0,
|
|
1472
|
+
(0, import_rxjs11.distinctUntilChanged)(statesEqual),
|
|
1473
|
+
(0, import_rxjs11.throttleTime)(16, void 0, { leading: true, trailing: true }),
|
|
1474
|
+
// ~1 frame at 60fps
|
|
801
1475
|
logObservable("kheopskit$", { enabled: kc.debug, printValue: true }),
|
|
802
|
-
(0,
|
|
1476
|
+
(0, import_rxjs11.shareReplay)({ bufferSize: 1, refCount: true })
|
|
803
1477
|
);
|
|
804
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);
|
|
805
1483
|
// Annotate the CommonJS export names for ESM import in node:
|
|
806
1484
|
0 && (module.exports = {
|
|
1485
|
+
DEFAULT_STORAGE_KEY,
|
|
1486
|
+
clearAllCachedObservables,
|
|
1487
|
+
clearCachedObservable,
|
|
1488
|
+
createKheopskitStore,
|
|
1489
|
+
getCachedIcon,
|
|
807
1490
|
getKheopskit$,
|
|
1491
|
+
hydrateAccount,
|
|
1492
|
+
hydrateWallet,
|
|
1493
|
+
resetAppKitCache,
|
|
808
1494
|
resolveConfig
|
|
809
1495
|
});
|
|
810
1496
|
//# sourceMappingURL=index.js.map
|