@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.mjs
CHANGED
|
@@ -1,3 +1,540 @@
|
|
|
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+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwIDAgMCAxMy40MzUgMTMuNDM1QzI1Ljg2NyAxMjggMzYuNDk1IDEyOCA1Ny43NSAxMjhoMTIuNWMyMS4yNTUgMCAzMS44ODMgMCAzOS44NTItNC40NjNhMzUgMzUgMCAwIDAgMTMuNDM1LTEzLjQzNUMxMjggMTAyLjEzMyAxMjggOTEuNTA1IDEyOCA3MC4yNXYtMTIuNWMwLTIxLjI1NSAwLTMxLjg4My00LjQ2My0zOS44NTJhMzUgMzUgMCAwIDAtMTMuNDM1LTEzLjQzNUMxMDIuMTMzIDAgOTEuNTA1IDAgNzAuMjUgMGgtMTIuNUMzNi40OTUgMCAyNS44NjcgMCAxNy44OTggNC40NjNBMzUgMzUgMCAwIDAgNC40NjMgMTcuODk4QzAgMjUuODY3IDAgMzYuNDk1IDAgNTcuNzVaIi8+CiAgICA8cGF0aCBmaWxsPSIjZWE1NzUwIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIG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C4zMjQzQzE1LjA4MTIgNjIuMzk5NyAxNCA1OS43ODk1IDE0IDU3LjA2NzhWMjQuMjYyNkMxNCAyMS41NDA5IDE1LjA4MTIgMTguOTMwNyAxNy4wMDU3IDE3LjAwNjJaTTQwLjE0NzkgMzMuNTQyM0g2MC45MTU3QzY0LjQ1OCAzMy41NDIzIDY3LjMyOTUgMzYuNDEzOCA2Ny4zMjk1IDM5Ljk1NjFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+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,PHN2ZyBmaWxsPSJub25lIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIHdpZHRoPSI0MDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPjxjbGlwUGF0aCBpZD0iYSI+PHBhdGggZD0ibTAgMGg0MDB2NDAwaC00MDB6Ii8+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD0iIzMzOTZmZiIgcj0iMTk5LjUiIHN0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YiLz48L2c+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
|
+
|
|
400
|
+
// src/api/config.ts
|
|
401
|
+
var DEFAULT_STORAGE_KEY = "kheopskit";
|
|
402
|
+
var DEFAULT_CONFIG = {
|
|
403
|
+
autoReconnect: true,
|
|
404
|
+
platforms: ["polkadot"],
|
|
405
|
+
debug: false,
|
|
406
|
+
storageKey: DEFAULT_STORAGE_KEY,
|
|
407
|
+
hydrationGracePeriod: 500
|
|
408
|
+
};
|
|
409
|
+
var resolveConfig = (config) => {
|
|
410
|
+
return Object.assign({}, DEFAULT_CONFIG, config);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
// src/api/kheopskit.ts
|
|
414
|
+
import {
|
|
415
|
+
combineLatest as combineLatest9,
|
|
416
|
+
debounceTime,
|
|
417
|
+
distinctUntilChanged as distinctUntilChanged6,
|
|
418
|
+
filter as filter3,
|
|
419
|
+
map as map9,
|
|
420
|
+
Observable as Observable9,
|
|
421
|
+
shareReplay as shareReplay9,
|
|
422
|
+
throttleTime
|
|
423
|
+
} from "rxjs";
|
|
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
|
+
|
|
1
538
|
// src/utils/logObservable.ts
|
|
2
539
|
import { tap } from "rxjs";
|
|
3
540
|
var logObservable = (label, opts) => tap((value) => {
|
|
@@ -8,14 +545,8 @@ var logObservable = (label, opts) => tap((value) => {
|
|
|
8
545
|
else console.debug(text);
|
|
9
546
|
});
|
|
10
547
|
|
|
11
|
-
// src/api/
|
|
12
|
-
import {
|
|
13
|
-
Observable as Observable8,
|
|
14
|
-
combineLatest as combineLatest8,
|
|
15
|
-
map as map9,
|
|
16
|
-
shareReplay as shareReplay8,
|
|
17
|
-
throttleTime
|
|
18
|
-
} from "rxjs";
|
|
548
|
+
// src/api/accounts.ts
|
|
549
|
+
import { combineLatest as combineLatest5, map as map5, Observable as Observable5, of as of4, shareReplay as shareReplay5 } from "rxjs";
|
|
19
550
|
|
|
20
551
|
// src/utils/sortAccounts.ts
|
|
21
552
|
var sortAccounts = (a1, a2) => {
|
|
@@ -36,31 +567,56 @@ var sortAccounts = (a1, a2) => {
|
|
|
36
567
|
if (a2.walletName === "Talisman") return 1;
|
|
37
568
|
return a1.walletName.localeCompare(a2.walletName);
|
|
38
569
|
}
|
|
39
|
-
return
|
|
570
|
+
return a1.id.localeCompare(a2.id);
|
|
40
571
|
}
|
|
41
572
|
return 0;
|
|
42
573
|
};
|
|
43
574
|
|
|
44
|
-
// src/api/accounts.ts
|
|
45
|
-
import {
|
|
575
|
+
// src/api/ethereum/accounts.ts
|
|
576
|
+
import {
|
|
577
|
+
combineLatest as combineLatest3,
|
|
578
|
+
distinctUntilChanged as distinctUntilChanged2,
|
|
579
|
+
map as map3,
|
|
580
|
+
Observable as Observable3,
|
|
581
|
+
of as of2,
|
|
582
|
+
ReplaySubject,
|
|
583
|
+
shareReplay as shareReplay3,
|
|
584
|
+
switchMap
|
|
585
|
+
} from "rxjs";
|
|
586
|
+
import {
|
|
587
|
+
createWalletClient,
|
|
588
|
+
custom,
|
|
589
|
+
getAddress
|
|
590
|
+
} from "viem";
|
|
46
591
|
|
|
47
592
|
// src/utils/createStore.ts
|
|
48
|
-
import { BehaviorSubject
|
|
49
|
-
var createStore = (key, defaultValue) => {
|
|
50
|
-
const subject = new
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
}
|
|
55
604
|
const update = (val) => {
|
|
56
|
-
setStoredData(key, val);
|
|
605
|
+
setStoredData(key, val, storage);
|
|
57
606
|
subject.next(val);
|
|
58
607
|
};
|
|
59
608
|
return {
|
|
60
609
|
observable: subject.asObservable(),
|
|
61
610
|
set: (val) => update(val),
|
|
62
611
|
mutate: (transform) => update(transform(subject.getValue())),
|
|
63
|
-
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
|
+
}
|
|
64
620
|
};
|
|
65
621
|
};
|
|
66
622
|
var parseData = (str, defaultValue) => {
|
|
@@ -70,13 +626,13 @@ var parseData = (str, defaultValue) => {
|
|
|
70
626
|
}
|
|
71
627
|
return defaultValue;
|
|
72
628
|
};
|
|
73
|
-
var getStoredData = (key, defaultValue) => {
|
|
74
|
-
const str =
|
|
629
|
+
var getStoredData = (key, defaultValue, storage) => {
|
|
630
|
+
const str = storage.getItem(key);
|
|
75
631
|
return parseData(str, defaultValue);
|
|
76
632
|
};
|
|
77
|
-
var setStoredData = (key, val) => {
|
|
633
|
+
var setStoredData = (key, val, storage) => {
|
|
78
634
|
const str = JSON.stringify(val);
|
|
79
|
-
|
|
635
|
+
storage.setItem(key, str);
|
|
80
636
|
};
|
|
81
637
|
|
|
82
638
|
// src/utils/isEthereumAddress.ts
|
|
@@ -108,37 +664,12 @@ var getWalletAccountId = (walletId, address) => {
|
|
|
108
664
|
return `${walletId}::${address}`;
|
|
109
665
|
};
|
|
110
666
|
|
|
111
|
-
// src/utils/isWalletPlatform.ts
|
|
112
|
-
var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
|
|
113
|
-
|
|
114
|
-
// src/utils/getCachedObservable.ts
|
|
115
|
-
var CACHE = /* @__PURE__ */ new Map();
|
|
116
|
-
var getCachedObservable$ = (key, create) => {
|
|
117
|
-
if (!CACHE.has(key)) CACHE.set(key, create());
|
|
118
|
-
return CACHE.get(key);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
667
|
// src/api/ethereum/accounts.ts
|
|
122
|
-
import {
|
|
123
|
-
Observable,
|
|
124
|
-
ReplaySubject,
|
|
125
|
-
combineLatest,
|
|
126
|
-
distinctUntilChanged,
|
|
127
|
-
map as map2,
|
|
128
|
-
of,
|
|
129
|
-
shareReplay,
|
|
130
|
-
switchMap
|
|
131
|
-
} from "rxjs";
|
|
132
|
-
import {
|
|
133
|
-
createWalletClient,
|
|
134
|
-
custom,
|
|
135
|
-
getAddress
|
|
136
|
-
} from "viem";
|
|
137
668
|
var getInjectedWalletAccounts$ = (wallet) => {
|
|
138
|
-
if (!wallet.isConnected) return
|
|
669
|
+
if (!wallet.isConnected) return of2([]);
|
|
139
670
|
return getCachedObservable$(
|
|
140
671
|
`accounts:${wallet.id}`,
|
|
141
|
-
() => new
|
|
672
|
+
() => new Observable3((subscriber) => {
|
|
142
673
|
const getAccount = (address, i) => {
|
|
143
674
|
const client = createWalletClient({
|
|
144
675
|
account: address,
|
|
@@ -170,7 +701,7 @@ var getInjectedWalletAccounts$ = (wallet) => {
|
|
|
170
701
|
handleAccountsChanged
|
|
171
702
|
);
|
|
172
703
|
};
|
|
173
|
-
}).pipe(
|
|
704
|
+
}).pipe(shareReplay3({ refCount: true, bufferSize: 1 }))
|
|
174
705
|
);
|
|
175
706
|
};
|
|
176
707
|
var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
|
|
@@ -191,10 +722,10 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
191
722
|
const account = wallet.appKit.getAccount("eip155");
|
|
192
723
|
const provider = wallet.appKit.getProvider("eip155");
|
|
193
724
|
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
194
|
-
return
|
|
725
|
+
return of2([]);
|
|
195
726
|
return getCachedObservable$(
|
|
196
727
|
"accounts:appKit",
|
|
197
|
-
() => new
|
|
728
|
+
() => new Observable3((subscriber) => {
|
|
198
729
|
const caipNetworkId$ = new ReplaySubject(1);
|
|
199
730
|
const handleChainChanged = (chainId) => {
|
|
200
731
|
caipNetworkId$.next(`eip155:${chainId}`);
|
|
@@ -202,18 +733,18 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
202
733
|
provider.on("chainChanged", handleChainChanged);
|
|
203
734
|
provider.request({ method: "eth_chainId" }).then(handleChainChanged);
|
|
204
735
|
const sub = caipNetworkId$.pipe(
|
|
205
|
-
|
|
206
|
-
|
|
736
|
+
distinctUntilChanged2(),
|
|
737
|
+
map3(
|
|
207
738
|
(caipNetworkId) => custom(
|
|
208
739
|
wrapWalletConnectProvider(
|
|
209
740
|
provider,
|
|
210
|
-
// biome-ignore lint/style/noNonNullAssertion:
|
|
741
|
+
// biome-ignore lint/style/noNonNullAssertion: legacy
|
|
211
742
|
provider.session.topic,
|
|
212
743
|
caipNetworkId
|
|
213
744
|
)
|
|
214
745
|
)
|
|
215
746
|
),
|
|
216
|
-
|
|
747
|
+
map3(
|
|
217
748
|
(transport) => account.allAccounts.map((acc, i) => {
|
|
218
749
|
const client = createWalletClient({
|
|
219
750
|
account: acc.address,
|
|
@@ -235,28 +766,28 @@ var getAppKitAccounts$ = (wallet) => {
|
|
|
235
766
|
provider.off("chainChanged", handleChainChanged);
|
|
236
767
|
sub.unsubscribe();
|
|
237
768
|
};
|
|
238
|
-
}).pipe(
|
|
769
|
+
}).pipe(shareReplay3({ refCount: true, bufferSize: 1 }))
|
|
239
770
|
);
|
|
240
771
|
};
|
|
241
|
-
var getEthereumAccounts$ = (ethereumWallets) => new
|
|
772
|
+
var getEthereumAccounts$ = (ethereumWallets) => new Observable3((subscriber) => {
|
|
242
773
|
const sub = ethereumWallets.pipe(
|
|
243
|
-
|
|
774
|
+
map3((wallets) => wallets.filter((w) => w.isConnected)),
|
|
244
775
|
switchMap((wallets) => {
|
|
245
|
-
return wallets.length ?
|
|
776
|
+
return wallets.length ? combineLatest3([
|
|
246
777
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
247
778
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
|
|
248
779
|
// todo appkit
|
|
249
|
-
]) :
|
|
780
|
+
]) : of2([]);
|
|
250
781
|
}),
|
|
251
|
-
|
|
252
|
-
|
|
782
|
+
map3((accounts) => accounts.flat()),
|
|
783
|
+
distinctUntilChanged2(isSameAccountsList)
|
|
253
784
|
).subscribe(subscriber);
|
|
254
785
|
return () => {
|
|
255
786
|
sub.unsubscribe();
|
|
256
787
|
};
|
|
257
788
|
}).pipe(
|
|
258
789
|
// logObservable("ethereumAccounts$", true),
|
|
259
|
-
|
|
790
|
+
shareReplay3({ refCount: true, bufferSize: 1 })
|
|
260
791
|
);
|
|
261
792
|
var isSameAccountsList = (a, b) => {
|
|
262
793
|
if (a.length !== b.length) return false;
|
|
@@ -268,17 +799,17 @@ import {
|
|
|
268
799
|
getPolkadotSignerFromPjs
|
|
269
800
|
} from "polkadot-api/pjs-signer";
|
|
270
801
|
import {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
of as
|
|
276
|
-
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,
|
|
277
808
|
switchMap as switchMap2
|
|
278
809
|
} from "rxjs";
|
|
279
810
|
var getInjectedWalletAccounts$2 = (wallet) => {
|
|
280
|
-
if (!wallet.isConnected) return
|
|
281
|
-
return new
|
|
811
|
+
if (!wallet.isConnected) return of3([]);
|
|
812
|
+
return new Observable4((subscriber) => {
|
|
282
813
|
const getAccount = (account) => ({
|
|
283
814
|
id: getWalletAccountId(wallet.id, account.address),
|
|
284
815
|
...account,
|
|
@@ -339,8 +870,8 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
339
870
|
const account = wallet.appKit.getAccount("polkadot");
|
|
340
871
|
const provider = wallet.appKit.getProvider("polkadot");
|
|
341
872
|
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
342
|
-
return
|
|
343
|
-
return
|
|
873
|
+
return of3([]);
|
|
874
|
+
return of3(
|
|
344
875
|
account.allAccounts.map(
|
|
345
876
|
(acc) => ({
|
|
346
877
|
id: getWalletAccountId(wallet.id, acc.address),
|
|
@@ -356,22 +887,22 @@ var getAppKitAccounts$2 = (wallet) => {
|
|
|
356
887
|
)
|
|
357
888
|
);
|
|
358
889
|
};
|
|
359
|
-
var getPolkadotAccounts$ = (polkadotWallets$) => new
|
|
890
|
+
var getPolkadotAccounts$ = (polkadotWallets$) => new Observable4((subscriber) => {
|
|
360
891
|
const sub = polkadotWallets$.pipe(
|
|
361
|
-
|
|
892
|
+
map4((wallets) => wallets.filter((w) => w.isConnected)),
|
|
362
893
|
switchMap2(
|
|
363
|
-
(wallets) => wallets.length ?
|
|
894
|
+
(wallets) => wallets.length ? combineLatest4([
|
|
364
895
|
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$2),
|
|
365
896
|
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
366
|
-
]) :
|
|
897
|
+
]) : of3([])
|
|
367
898
|
),
|
|
368
|
-
|
|
369
|
-
|
|
899
|
+
map4((accounts) => accounts.flat()),
|
|
900
|
+
distinctUntilChanged3(isSameAccountsList2)
|
|
370
901
|
).subscribe(subscriber);
|
|
371
902
|
return () => {
|
|
372
903
|
sub.unsubscribe();
|
|
373
904
|
};
|
|
374
|
-
}).pipe(
|
|
905
|
+
}).pipe(shareReplay4({ refCount: true, bufferSize: 1 }));
|
|
375
906
|
var isSameAccountsList2 = (a, b) => {
|
|
376
907
|
if (a.length !== b.length) return false;
|
|
377
908
|
return a.every((account, i) => account.id === b[i]?.id);
|
|
@@ -379,44 +910,201 @@ var isSameAccountsList2 = (a, b) => {
|
|
|
379
910
|
|
|
380
911
|
// src/api/accounts.ts
|
|
381
912
|
var getAccounts$ = (config, wallets) => {
|
|
382
|
-
return new
|
|
913
|
+
return new Observable5((subscriber) => {
|
|
383
914
|
const sources = config.platforms.map(
|
|
384
915
|
(platform) => {
|
|
385
916
|
switch (platform) {
|
|
386
917
|
case "polkadot":
|
|
387
918
|
return getPolkadotAccounts$(
|
|
388
919
|
wallets.pipe(
|
|
389
|
-
|
|
920
|
+
map5((w) => w.filter((w2) => w2.platform === "polkadot"))
|
|
390
921
|
)
|
|
391
922
|
);
|
|
392
923
|
case "ethereum":
|
|
393
924
|
return getEthereumAccounts$(
|
|
394
925
|
wallets.pipe(
|
|
395
|
-
|
|
926
|
+
map5((w) => w.filter((w2) => w2.platform === "ethereum"))
|
|
396
927
|
)
|
|
397
928
|
);
|
|
398
929
|
}
|
|
399
930
|
}
|
|
400
931
|
);
|
|
401
|
-
const accounts$ = sources.length ?
|
|
402
|
-
|
|
403
|
-
) :
|
|
932
|
+
const accounts$ = sources.length ? combineLatest5(sources).pipe(
|
|
933
|
+
map5((accounts) => accounts.flat().sort(sortAccounts))
|
|
934
|
+
) : of4([]);
|
|
404
935
|
const sub = accounts$.subscribe(subscriber);
|
|
405
936
|
return () => {
|
|
406
937
|
sub.unsubscribe();
|
|
407
938
|
};
|
|
408
|
-
}).pipe(
|
|
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
|
+
};
|
|
409
1094
|
};
|
|
410
1095
|
|
|
411
|
-
// src/api/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1096
|
+
// src/api/wallets.ts
|
|
1097
|
+
import {
|
|
1098
|
+
combineLatest as combineLatest8,
|
|
1099
|
+
distinct,
|
|
1100
|
+
filter as filter2,
|
|
1101
|
+
map as map8,
|
|
1102
|
+
mergeMap,
|
|
1103
|
+
Observable as Observable8,
|
|
1104
|
+
of as of5,
|
|
1105
|
+
shareReplay as shareReplay8,
|
|
1106
|
+
take as take2
|
|
1107
|
+
} from "rxjs";
|
|
420
1108
|
|
|
421
1109
|
// src/utils/sortWallets.ts
|
|
422
1110
|
var sortWallets = (w1, w2) => {
|
|
@@ -428,232 +1116,87 @@ var sortWallets = (w1, w2) => {
|
|
|
428
1116
|
return w1.name.localeCompare(w2.name);
|
|
429
1117
|
};
|
|
430
1118
|
|
|
431
|
-
// src/api/wallets.ts
|
|
432
|
-
import {
|
|
433
|
-
Observable as Observable7,
|
|
434
|
-
combineLatest as combineLatest7,
|
|
435
|
-
distinct,
|
|
436
|
-
filter as filter2,
|
|
437
|
-
map as map8,
|
|
438
|
-
mergeMap as mergeMap2,
|
|
439
|
-
of as of6,
|
|
440
|
-
shareReplay as shareReplay7,
|
|
441
|
-
take
|
|
442
|
-
} from "rxjs";
|
|
443
|
-
|
|
444
|
-
// src/utils/WalletId.ts
|
|
445
|
-
var getWalletId = (platform, identifier) => {
|
|
446
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
447
|
-
if (!identifier) throw new Error("Invalid name");
|
|
448
|
-
return `${platform}:${identifier}`;
|
|
449
|
-
};
|
|
450
|
-
var parseWalletId = (walletId) => {
|
|
451
|
-
if (!walletId) throw new Error("Invalid walletId");
|
|
452
|
-
const [platform, identifier] = walletId.split(":");
|
|
453
|
-
if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
|
|
454
|
-
if (!identifier) throw new Error("Invalid address");
|
|
455
|
-
return { platform, identifier };
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
// src/api/store.ts
|
|
459
|
-
import { uniq } from "lodash";
|
|
460
|
-
var LOCAL_STORAGE_KEY = "kheopskit";
|
|
461
|
-
var DEFAULT_SETTINGS = {};
|
|
462
|
-
var storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);
|
|
463
|
-
var addEnabledWalletId = (walletId) => {
|
|
464
|
-
parseWalletId(walletId);
|
|
465
|
-
storage.mutate((prev) => ({
|
|
466
|
-
...prev,
|
|
467
|
-
autoReconnect: uniq((prev.autoReconnect ?? []).concat(walletId))
|
|
468
|
-
}));
|
|
469
|
-
};
|
|
470
|
-
var removeEnabledWalletId = (walletId) => {
|
|
471
|
-
storage.mutate((prev) => ({
|
|
472
|
-
...prev,
|
|
473
|
-
autoReconnect: uniq(
|
|
474
|
-
(prev.autoReconnect ?? []).filter((id) => id !== walletId)
|
|
475
|
-
)
|
|
476
|
-
}));
|
|
477
|
-
};
|
|
478
|
-
var store = {
|
|
479
|
-
observable: storage.observable,
|
|
480
|
-
addEnabledWalletId,
|
|
481
|
-
removeEnabledWalletId
|
|
482
|
-
};
|
|
483
|
-
|
|
484
1119
|
// src/api/ethereum/wallets.ts
|
|
485
|
-
import { createStore as createStore2 } from "mipd";
|
|
486
1120
|
import {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
combineLatest as combineLatest5,
|
|
490
|
-
map as map6,
|
|
491
|
-
shareReplay as shareReplay5
|
|
492
|
-
} from "rxjs";
|
|
493
|
-
|
|
494
|
-
// src/api/appKit.ts
|
|
495
|
-
import { createAppKit } from "@reown/appkit/core";
|
|
1121
|
+
createStore as createMipdStore
|
|
1122
|
+
} from "mipd";
|
|
496
1123
|
import {
|
|
497
|
-
BehaviorSubject as
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
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
|
|
504
1130
|
} from "rxjs";
|
|
505
|
-
var
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const walletConnect = config.walletConnect;
|
|
510
|
-
if (!cachedAppKit) {
|
|
511
|
-
cachedAppKit = new Observable4((subscriber) => {
|
|
512
|
-
const appKit = createAppKit({
|
|
513
|
-
projectId: walletConnect.projectId,
|
|
514
|
-
metadata: walletConnect.metadata,
|
|
515
|
-
networks: walletConnect.networks,
|
|
516
|
-
themeMode: walletConnect.themeMode,
|
|
517
|
-
themeVariables: walletConnect.themeVariables,
|
|
518
|
-
universalProviderConfigOverride: {
|
|
519
|
-
methods: {
|
|
520
|
-
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
|
|
521
|
-
}
|
|
522
|
-
},
|
|
523
|
-
allWallets: "HIDE",
|
|
524
|
-
debug: config.debug,
|
|
525
|
-
allowUnsupportedChain: true
|
|
526
|
-
});
|
|
527
|
-
const status$ = new BehaviorSubject2({
|
|
528
|
-
isPolkadotConnected: false,
|
|
529
|
-
isEthereumConnected: false
|
|
530
|
-
});
|
|
531
|
-
const unsubProviders = appKit.subscribeProviders((providers) => {
|
|
532
|
-
status$.next({
|
|
533
|
-
isPolkadotConnected: !!providers.polkadot,
|
|
534
|
-
isEthereumConnected: !!providers.eip155
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
|
|
538
|
-
map5((s) => s.isPolkadotConnected),
|
|
539
|
-
distinctUntilChanged3(),
|
|
540
|
-
map5((isConnected) => {
|
|
541
|
-
const walletInfo = appKit.getWalletInfo();
|
|
542
|
-
return {
|
|
543
|
-
id: getWalletId("polkadot", "walletconnect"),
|
|
544
|
-
platform: "polkadot",
|
|
545
|
-
type: "appKit",
|
|
546
|
-
appKit,
|
|
547
|
-
// todo maybe we dont want to expose the appKit instance
|
|
548
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
549
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
550
|
-
connect: async () => {
|
|
551
|
-
if (!isConnected) await appKit.open();
|
|
552
|
-
},
|
|
553
|
-
disconnect: () => {
|
|
554
|
-
if (isConnected) appKit.disconnect();
|
|
555
|
-
},
|
|
556
|
-
isConnected
|
|
557
|
-
};
|
|
558
|
-
})
|
|
559
|
-
) : of4(void 0);
|
|
560
|
-
const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
|
|
561
|
-
map5((s) => s.isEthereumConnected),
|
|
562
|
-
distinctUntilChanged3(),
|
|
563
|
-
map5((isConnected) => {
|
|
564
|
-
const walletInfo = appKit.getWalletInfo();
|
|
565
|
-
return {
|
|
566
|
-
id: getWalletId("ethereum", "walletconnect"),
|
|
567
|
-
platform: "ethereum",
|
|
568
|
-
type: "appKit",
|
|
569
|
-
appKit,
|
|
570
|
-
name: walletInfo?.name ?? "WalletConnect",
|
|
571
|
-
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
572
|
-
connect: () => appKit.open(),
|
|
573
|
-
disconnect: () => appKit.disconnect(),
|
|
574
|
-
isConnected
|
|
575
|
-
};
|
|
576
|
-
})
|
|
577
|
-
) : of4(void 0);
|
|
578
|
-
const sub = combineLatest4({
|
|
579
|
-
polkadot: polkadotWallet$,
|
|
580
|
-
ethereum: ethereumWallet$
|
|
581
|
-
}).subscribe(subscriber);
|
|
1131
|
+
var providersDetails$ = new Observable6(
|
|
1132
|
+
(subscriber) => {
|
|
1133
|
+
if (typeof window === "undefined") {
|
|
1134
|
+
subscriber.next([]);
|
|
582
1135
|
return () => {
|
|
583
|
-
sub.unsubscribe();
|
|
584
|
-
unsubProviders();
|
|
585
1136
|
};
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
// src/api/ethereum/wallets.ts
|
|
592
|
-
var providersDetails$ = new Observable5(
|
|
593
|
-
(subscriber) => {
|
|
594
|
-
const store2 = createStore2();
|
|
595
|
-
const unsubscribe = store2.subscribe((providerDetails2) => {
|
|
1137
|
+
}
|
|
1138
|
+
const mipdStore = createMipdStore();
|
|
1139
|
+
const unsubscribe = mipdStore.subscribe((providerDetails2) => {
|
|
596
1140
|
subscriber.next(providerDetails2);
|
|
597
1141
|
});
|
|
598
|
-
const providerDetails =
|
|
1142
|
+
const providerDetails = mipdStore.getProviders();
|
|
599
1143
|
subscriber.next(providerDetails);
|
|
600
1144
|
return () => {
|
|
601
1145
|
unsubscribe();
|
|
602
|
-
|
|
1146
|
+
mipdStore.destroy();
|
|
603
1147
|
};
|
|
604
1148
|
}
|
|
605
|
-
).pipe(
|
|
606
|
-
var
|
|
607
|
-
(
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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
|
+
};
|
|
614
1188
|
});
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
store.removeEnabledWalletId(walletId);
|
|
627
|
-
};
|
|
628
|
-
const sub = combineLatest5([providersDetails$, enabledWalletIds$]).pipe(
|
|
629
|
-
map6(([providerDetails, enabledWalletIds]) => {
|
|
630
|
-
return providerDetails.map((pd) => {
|
|
631
|
-
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
632
|
-
const provider = pd.provider;
|
|
633
|
-
return {
|
|
634
|
-
platform: "ethereum",
|
|
635
|
-
type: "injected",
|
|
636
|
-
id: walletId,
|
|
637
|
-
name: pd.info.name,
|
|
638
|
-
icon: pd.info.icon,
|
|
639
|
-
provider,
|
|
640
|
-
isConnected: enabledWalletIds.has(walletId),
|
|
641
|
-
providerId: pd.info.rdns,
|
|
642
|
-
connect: () => connectWallet(walletId, provider),
|
|
643
|
-
disconnect: () => disconnectWallet(walletId)
|
|
644
|
-
};
|
|
645
|
-
});
|
|
646
|
-
})
|
|
647
|
-
).subscribe(subscriber);
|
|
648
|
-
return () => {
|
|
649
|
-
sub.unsubscribe();
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
).pipe(shareReplay5({ refCount: true, bufferSize: 1 }));
|
|
653
|
-
var getEthereumWallets$ = (config) => {
|
|
654
|
-
return new Observable5((subscriber) => {
|
|
655
|
-
const subscription = combineLatest5([
|
|
656
|
-
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),
|
|
657
1200
|
getAppKitWallets$(config)?.pipe(map6((w) => w.ethereum))
|
|
658
1201
|
]).pipe(
|
|
659
1202
|
map6(
|
|
@@ -663,49 +1206,54 @@ var getEthereumWallets$ = (config) => {
|
|
|
663
1206
|
return () => {
|
|
664
1207
|
subscription.unsubscribe();
|
|
665
1208
|
};
|
|
666
|
-
}).pipe(
|
|
1209
|
+
}).pipe(shareReplay6({ refCount: true, bufferSize: 1 }));
|
|
667
1210
|
};
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwIDAgMCAxMy40MzUgMTMuNDM1QzI1Ljg2NyAxMjggMzYuNDk1IDEyOCA1Ny43NSAxMjhoMTIuNWMyMS4yNTUgMCAzMS44ODMgMCAzOS44NTItNC40NjNhMzUgMzUgMCAwIDAgMTMuNDM1LTEzLjQzNUMxMjggMTAyLjEzMyAxMjggOTEuNTA1IDEyOCA3MC4yNXYtMTIuNWMwLTIxLjI1NSAwLTMxLjg4My00LjQ2My0zOS44NTJhMzUgMzUgMCAwIDAtMTMuNDM1LTEzLjQzNUMxMDIuMTMzIDAgOTEuNTA1IDAgNzAuMjUgMGgtMTIuNUMzNi40OTUgMCAyNS44NjcgMCAxNy44OTggNC40NjNBMzUgMzUgMCAwIDAgNC40NjMgMTcuODk4QzAgMjUuODY3IDAgMzY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5NiA1OS43NjI2VjY3LjMzSDI0LjI2MjJDMjEuNTQwNSA2Ny4zMyAxOC45MzAzIDY2LjI0ODggMTcuMDA1NyA2NC4zMjQzQzE1LjA4MTIgNjIuMzk5NyAxNCA1OS43ODk1IDE0IDU3LjA2NzhWMjQuMjYyNkMxNCAyMS41NDA5IDE1LjA4MTIgMTguOTMwNyAxNy4wMDU3IDE3LjAwNjJaTTQwLjE0NzkgMzMuNTQyM0g2MC45MTU3QzY0LjQ1OCAzMy41NDIzIDY3LjMyOTUgMzYuNDEzOCA2Ny4zMjk1IDM5Ljk1NjFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
|
|
686
|
-
}
|
|
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
|
+
);
|
|
687
1216
|
};
|
|
688
1217
|
|
|
689
1218
|
// src/api/polkadot/wallets.ts
|
|
690
|
-
import { isEqual } from "lodash";
|
|
1219
|
+
import { isEqual } from "lodash-es";
|
|
691
1220
|
import {
|
|
692
1221
|
connectInjectedExtension,
|
|
693
1222
|
getInjectedExtensions
|
|
694
1223
|
} from "polkadot-api/pjs-signer";
|
|
695
1224
|
import {
|
|
696
|
-
BehaviorSubject as
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
distinctUntilChanged as distinctUntilChanged4,
|
|
1225
|
+
BehaviorSubject as BehaviorSubject5,
|
|
1226
|
+
combineLatest as combineLatest7,
|
|
1227
|
+
distinctUntilChanged as distinctUntilChanged5,
|
|
700
1228
|
map as map7,
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
shareReplay as shareReplay6,
|
|
704
|
-
timer
|
|
1229
|
+
Observable as Observable7,
|
|
1230
|
+
shareReplay as shareReplay7
|
|
705
1231
|
} from "rxjs";
|
|
706
|
-
var getInjectedWalletsIds = () => getInjectedExtensions().map((name) => getWalletId("polkadot", name));
|
|
707
|
-
var
|
|
708
|
-
|
|
1232
|
+
var getInjectedWalletsIds = () => typeof window === "undefined" ? [] : getInjectedExtensions().map((name) => getWalletId("polkadot", name));
|
|
1233
|
+
var createWalletIdsPoller$ = () => {
|
|
1234
|
+
return new Observable7((subscriber) => {
|
|
1235
|
+
subscriber.next(getInjectedWalletsIds());
|
|
1236
|
+
const intervals = [100, 200, 300, 500];
|
|
1237
|
+
let index = 0;
|
|
1238
|
+
const poll = () => {
|
|
1239
|
+
subscriber.next(getInjectedWalletsIds());
|
|
1240
|
+
if (index < intervals.length) {
|
|
1241
|
+
const delay = intervals[index++];
|
|
1242
|
+
setTimeout(poll, delay);
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
if (intervals.length > 0) {
|
|
1246
|
+
setTimeout(poll, intervals[index++] ?? 100);
|
|
1247
|
+
}
|
|
1248
|
+
return () => {
|
|
1249
|
+
};
|
|
1250
|
+
}).pipe(
|
|
1251
|
+
distinctUntilChanged5(isEqual),
|
|
1252
|
+
shareReplay7({ refCount: true, bufferSize: 1 })
|
|
1253
|
+
);
|
|
1254
|
+
};
|
|
1255
|
+
var createPolkadotInjectedWallets$ = (store2) => new Observable7((subscriber) => {
|
|
1256
|
+
const enabledExtensions$ = new BehaviorSubject5(/* @__PURE__ */ new Map());
|
|
709
1257
|
const connect = async (walletId) => {
|
|
710
1258
|
if (enabledExtensions$.value.has(walletId))
|
|
711
1259
|
throw new Error(`Extension ${walletId} already connected`);
|
|
@@ -714,7 +1262,7 @@ var polkadotInjectedWallets$ = new Observable6((subscriber) => {
|
|
|
714
1262
|
const newMap = new Map(enabledExtensions$.value);
|
|
715
1263
|
newMap.set(walletId, extension);
|
|
716
1264
|
enabledExtensions$.next(newMap);
|
|
717
|
-
|
|
1265
|
+
store2.addEnabledWalletId(walletId);
|
|
718
1266
|
};
|
|
719
1267
|
const disconnect = (walletId) => {
|
|
720
1268
|
if (!enabledExtensions$.value.has(walletId))
|
|
@@ -722,14 +1270,10 @@ var polkadotInjectedWallets$ = new Observable6((subscriber) => {
|
|
|
722
1270
|
const newMap = new Map(enabledExtensions$.value);
|
|
723
1271
|
newMap.delete(walletId);
|
|
724
1272
|
enabledExtensions$.next(newMap);
|
|
725
|
-
|
|
1273
|
+
store2.removeEnabledWalletId(walletId);
|
|
726
1274
|
};
|
|
727
|
-
const walletIds$ =
|
|
728
|
-
|
|
729
|
-
map7(() => getInjectedWalletsIds()),
|
|
730
|
-
distinctUntilChanged4(isEqual)
|
|
731
|
-
);
|
|
732
|
-
const subscription = combineLatest6([walletIds$, enabledExtensions$]).pipe(
|
|
1275
|
+
const walletIds$ = createWalletIdsPoller$();
|
|
1276
|
+
const subscription = combineLatest7([walletIds$, enabledExtensions$]).pipe(
|
|
733
1277
|
map7(([walletIds, enabledExtensions]) => {
|
|
734
1278
|
return walletIds.map((id) => {
|
|
735
1279
|
const { identifier } = parseWalletId(id);
|
|
@@ -748,19 +1292,17 @@ var polkadotInjectedWallets$ = new Observable6((subscriber) => {
|
|
|
748
1292
|
disconnect: () => disconnect(id)
|
|
749
1293
|
};
|
|
750
1294
|
});
|
|
751
|
-
})
|
|
1295
|
+
}),
|
|
1296
|
+
distinctUntilChanged5(walletsEqual2)
|
|
752
1297
|
).subscribe(subscriber);
|
|
753
1298
|
return () => {
|
|
754
1299
|
subscription.unsubscribe();
|
|
755
1300
|
};
|
|
756
|
-
}).pipe(
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return new Observable6((subscriber) => {
|
|
762
|
-
const subscription = combineLatest6([
|
|
763
|
-
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),
|
|
764
1306
|
getAppKitWallets$(config)?.pipe(map7((w) => w.polkadot))
|
|
765
1307
|
]).pipe(
|
|
766
1308
|
map7(
|
|
@@ -770,48 +1312,55 @@ var getPolkadotWallets$ = (config) => {
|
|
|
770
1312
|
return () => {
|
|
771
1313
|
subscription.unsubscribe();
|
|
772
1314
|
};
|
|
773
|
-
}).pipe(
|
|
774
|
-
|
|
775
|
-
|
|
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
|
|
776
1321
|
);
|
|
777
1322
|
};
|
|
778
1323
|
|
|
779
1324
|
// src/api/wallets.ts
|
|
780
|
-
var
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
)
|
|
785
|
-
|
|
786
|
-
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) => {
|
|
787
1332
|
const observables = config.platforms.map(
|
|
788
1333
|
(platform) => {
|
|
789
1334
|
switch (platform) {
|
|
790
1335
|
case "polkadot":
|
|
791
|
-
return getPolkadotWallets$(config);
|
|
1336
|
+
return getPolkadotWallets$(config, store2);
|
|
792
1337
|
case "ethereum":
|
|
793
|
-
return getEthereumWallets$(config);
|
|
1338
|
+
return getEthereumWallets$(config, store2);
|
|
794
1339
|
}
|
|
795
1340
|
}
|
|
796
1341
|
);
|
|
797
|
-
const wallets$ = observables.length ?
|
|
1342
|
+
const wallets$ = observables.length ? combineLatest8(observables).pipe(
|
|
798
1343
|
map8((wallets) => wallets.flat().sort(sortWallets))
|
|
799
|
-
|
|
800
|
-
|
|
1344
|
+
// Note: No startWith([]) here - the hydration buffer handles initial state
|
|
1345
|
+
) : of5([]);
|
|
1346
|
+
const reconnectingWallets = /* @__PURE__ */ new Set();
|
|
1347
|
+
const subAutoReconnect = combineLatest8([wallets$, autoReconnectWalletIds$]).pipe(
|
|
801
1348
|
filter2(([, walletIds]) => config.autoReconnect && !!walletIds?.length),
|
|
802
|
-
|
|
1349
|
+
mergeMap(
|
|
803
1350
|
([wallets, walletIds]) => wallets.filter((wallet) => walletIds?.includes(wallet.id))
|
|
804
1351
|
),
|
|
805
1352
|
distinct((w) => w.id)
|
|
806
1353
|
).subscribe(async (wallet) => {
|
|
807
|
-
if (wallet.isConnected) {
|
|
808
|
-
console.warn("Wallet %s already connected", wallet.id);
|
|
1354
|
+
if (wallet.isConnected || reconnectingWallets.has(wallet.id)) {
|
|
809
1355
|
return;
|
|
810
1356
|
}
|
|
1357
|
+
reconnectingWallets.add(wallet.id);
|
|
811
1358
|
try {
|
|
812
1359
|
await wallet.connect();
|
|
813
1360
|
} catch (err) {
|
|
814
1361
|
console.error("Failed to reconnect wallet %s", wallet.id, { err });
|
|
1362
|
+
} finally {
|
|
1363
|
+
reconnectingWallets.delete(wallet.id);
|
|
815
1364
|
}
|
|
816
1365
|
});
|
|
817
1366
|
const subWallets = wallets$.subscribe(subscriber);
|
|
@@ -819,30 +1368,173 @@ var getWallets$ = (config) => {
|
|
|
819
1368
|
subAutoReconnect.unsubscribe();
|
|
820
1369
|
subWallets.unsubscribe();
|
|
821
1370
|
};
|
|
822
|
-
}).pipe(
|
|
1371
|
+
}).pipe(shareReplay8({ refCount: true, bufferSize: 1 }));
|
|
823
1372
|
};
|
|
824
1373
|
|
|
825
1374
|
// src/api/kheopskit.ts
|
|
826
|
-
var getKheopskit$ = (config) => {
|
|
1375
|
+
var getKheopskit$ = (config, ssrCookies, existingStore) => {
|
|
827
1376
|
const kc = resolveConfig(config);
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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
|
+
});
|
|
835
1512
|
return () => {
|
|
836
1513
|
subscription.unsubscribe();
|
|
1514
|
+
persistSub.unsubscribe();
|
|
837
1515
|
};
|
|
838
1516
|
}).pipe(
|
|
839
|
-
|
|
1517
|
+
distinctUntilChanged6(statesEqual),
|
|
1518
|
+
throttleTime(16, void 0, { leading: true, trailing: true }),
|
|
1519
|
+
// ~1 frame at 60fps
|
|
840
1520
|
logObservable("kheopskit$", { enabled: kc.debug, printValue: true }),
|
|
841
|
-
|
|
1521
|
+
shareReplay9({ bufferSize: 1, refCount: true })
|
|
842
1522
|
);
|
|
843
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);
|
|
844
1528
|
export {
|
|
1529
|
+
DEFAULT_STORAGE_KEY,
|
|
1530
|
+
clearAllCachedObservables,
|
|
1531
|
+
clearCachedObservable,
|
|
1532
|
+
createKheopskitStore,
|
|
1533
|
+
getCachedIcon,
|
|
845
1534
|
getKheopskit$,
|
|
1535
|
+
hydrateAccount,
|
|
1536
|
+
hydrateWallet,
|
|
1537
|
+
resetAppKitCache,
|
|
846
1538
|
resolveConfig
|
|
847
1539
|
};
|
|
848
1540
|
//# sourceMappingURL=index.mjs.map
|