@kheopskit/core 0.0.10 → 0.0.12
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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +805 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +843 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +1 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,805 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
getKheopskit$: () => getKheopskit$,
|
|
24
|
+
resolveConfig: () => resolveConfig
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/utils/logObservable.ts
|
|
29
|
+
var import_rxjs = require("rxjs");
|
|
30
|
+
var logObservable = (label, opts) => (0, import_rxjs.tap)((value) => {
|
|
31
|
+
const { printValue = false, enabled = true } = opts || {};
|
|
32
|
+
if (!label || !enabled) return;
|
|
33
|
+
const text = `[kheopskit] observable ${label} emit`;
|
|
34
|
+
if (printValue) console.debug(text, value);
|
|
35
|
+
else console.debug(text);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// src/api/kheopskit.ts
|
|
39
|
+
var import_rxjs10 = require("rxjs");
|
|
40
|
+
|
|
41
|
+
// src/utils/sortAccounts.ts
|
|
42
|
+
var sortAccounts = (a1, a2) => {
|
|
43
|
+
if (a1.platform === "polkadot") {
|
|
44
|
+
if (a2.platform === "polkadot") {
|
|
45
|
+
if (a1.walletName !== a2.walletName) {
|
|
46
|
+
if (a1.walletName === "talisman") return -1;
|
|
47
|
+
if (a2.walletName === "talisman") return 1;
|
|
48
|
+
return a1.walletName.localeCompare(a2.walletName);
|
|
49
|
+
}
|
|
50
|
+
return a1.name !== a2.name ? (a1.name ?? "").localeCompare(a2.name ?? "") : a1.address.localeCompare(a2.address);
|
|
51
|
+
}
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
if (a2.platform === "ethereum") {
|
|
55
|
+
if (a1.walletName !== a2.walletName) {
|
|
56
|
+
if (a1.walletName === "Talisman") return -1;
|
|
57
|
+
if (a2.walletName === "Talisman") return 1;
|
|
58
|
+
return a1.walletName.localeCompare(a2.walletName);
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
return 0;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/api/accounts.ts
|
|
66
|
+
var import_rxjs5 = require("rxjs");
|
|
67
|
+
|
|
68
|
+
// src/utils/createStore.ts
|
|
69
|
+
var import_rxjs2 = require("rxjs");
|
|
70
|
+
var createStore = (key, defaultValue) => {
|
|
71
|
+
const subject = new import_rxjs2.BehaviorSubject(getStoredData(key, defaultValue));
|
|
72
|
+
(0, import_rxjs2.fromEvent)(window, "storage").pipe(
|
|
73
|
+
(0, import_rxjs2.filter)((event) => event.key === key),
|
|
74
|
+
(0, import_rxjs2.map)((event) => parseData(event.newValue, defaultValue))
|
|
75
|
+
).subscribe((newValue) => subject.next(newValue));
|
|
76
|
+
const update = (val) => {
|
|
77
|
+
setStoredData(key, val);
|
|
78
|
+
subject.next(val);
|
|
79
|
+
};
|
|
80
|
+
return {
|
|
81
|
+
observable: subject.asObservable(),
|
|
82
|
+
set: (val) => update(val),
|
|
83
|
+
mutate: (transform) => update(transform(subject.getValue())),
|
|
84
|
+
get: () => structuredClone(subject.getValue())
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
var parseData = (str, defaultValue) => {
|
|
88
|
+
try {
|
|
89
|
+
if (str) return JSON.parse(str);
|
|
90
|
+
} catch {
|
|
91
|
+
}
|
|
92
|
+
return defaultValue;
|
|
93
|
+
};
|
|
94
|
+
var getStoredData = (key, defaultValue) => {
|
|
95
|
+
const str = localStorage.getItem(key);
|
|
96
|
+
return parseData(str, defaultValue);
|
|
97
|
+
};
|
|
98
|
+
var setStoredData = (key, val) => {
|
|
99
|
+
const str = JSON.stringify(val);
|
|
100
|
+
localStorage.setItem(key, str);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/utils/isEthereumAddress.ts
|
|
104
|
+
var import_viem = require("viem");
|
|
105
|
+
var isEthereumAddress = (address) => (0, import_viem.isAddress)(address);
|
|
106
|
+
|
|
107
|
+
// src/utils/isSs58Address.ts
|
|
108
|
+
var import_polkadot_api = require("polkadot-api");
|
|
109
|
+
var accountIdEncoder = (0, import_polkadot_api.AccountId)().enc;
|
|
110
|
+
var isSs58Address = (address) => {
|
|
111
|
+
try {
|
|
112
|
+
if (!address) return false;
|
|
113
|
+
accountIdEncoder(address);
|
|
114
|
+
return true;
|
|
115
|
+
} catch {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/utils/isValidAddress.ts
|
|
121
|
+
var isValidAddress = (address) => {
|
|
122
|
+
return address.startsWith("0x") ? isEthereumAddress(address) : isSs58Address(address);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/utils/WalletAccountId.ts
|
|
126
|
+
var getWalletAccountId = (walletId, address) => {
|
|
127
|
+
if (!walletId) throw new Error("Missing walletId");
|
|
128
|
+
if (!isValidAddress(address)) throw new Error("Invalid address");
|
|
129
|
+
return `${walletId}::${address}`;
|
|
130
|
+
};
|
|
131
|
+
|
|
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
|
+
// src/api/ethereum/accounts.ts
|
|
143
|
+
var import_rxjs3 = require("rxjs");
|
|
144
|
+
var import_viem2 = require("viem");
|
|
145
|
+
var getInjectedWalletAccounts$ = (wallet) => {
|
|
146
|
+
if (!wallet.isConnected) return (0, import_rxjs3.of)([]);
|
|
147
|
+
return getCachedObservable$(
|
|
148
|
+
`accounts:${wallet.id}`,
|
|
149
|
+
() => new import_rxjs3.Observable((subscriber) => {
|
|
150
|
+
const getAccount = (address, i) => {
|
|
151
|
+
const client = (0, import_viem2.createWalletClient)({
|
|
152
|
+
account: address,
|
|
153
|
+
transport: (0, import_viem2.custom)(wallet.provider)
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
id: getWalletAccountId(wallet.id, address),
|
|
157
|
+
platform: "ethereum",
|
|
158
|
+
client,
|
|
159
|
+
address: (0, import_viem2.getAddress)(address),
|
|
160
|
+
walletName: wallet.name,
|
|
161
|
+
walletId: wallet.id,
|
|
162
|
+
isWalletDefault: i === 0
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
const handleAccountsChanged = (addresses) => {
|
|
166
|
+
subscriber.next(addresses.map(getAccount));
|
|
167
|
+
};
|
|
168
|
+
wallet.provider.on("accountsChanged", handleAccountsChanged);
|
|
169
|
+
wallet.provider.request({ method: "eth_accounts" }).then((addresses) => {
|
|
170
|
+
subscriber.next(addresses.map(getAccount));
|
|
171
|
+
}).catch((err) => {
|
|
172
|
+
console.error("Failed to get accounts", err);
|
|
173
|
+
subscriber.next([]);
|
|
174
|
+
});
|
|
175
|
+
return () => {
|
|
176
|
+
wallet.provider.removeListener(
|
|
177
|
+
"accountsChanged",
|
|
178
|
+
handleAccountsChanged
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
}).pipe((0, import_rxjs3.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
var wrapWalletConnectProvider = (provider, sessionTopic, caipNetworkId) => {
|
|
185
|
+
return new Proxy(provider, {
|
|
186
|
+
get(target, prop, receiver) {
|
|
187
|
+
if (prop !== "request") return Reflect.get(target, prop, receiver);
|
|
188
|
+
return (args) => {
|
|
189
|
+
if (args && typeof args === "object" && args.method) {
|
|
190
|
+
if (!args.topic) args.topic = sessionTopic;
|
|
191
|
+
if (!args.chainId) args.chainId = caipNetworkId;
|
|
192
|
+
}
|
|
193
|
+
return target.request(args);
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
var getAppKitAccounts$ = (wallet) => {
|
|
199
|
+
const account = wallet.appKit.getAccount("eip155");
|
|
200
|
+
const provider = wallet.appKit.getProvider("eip155");
|
|
201
|
+
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
202
|
+
return (0, import_rxjs3.of)([]);
|
|
203
|
+
return getCachedObservable$(
|
|
204
|
+
"accounts:appKit",
|
|
205
|
+
() => new import_rxjs3.Observable((subscriber) => {
|
|
206
|
+
const caipNetworkId$ = new import_rxjs3.ReplaySubject(1);
|
|
207
|
+
const handleChainChanged = (chainId) => {
|
|
208
|
+
caipNetworkId$.next(`eip155:${chainId}`);
|
|
209
|
+
};
|
|
210
|
+
provider.on("chainChanged", handleChainChanged);
|
|
211
|
+
provider.request({ method: "eth_chainId" }).then(handleChainChanged);
|
|
212
|
+
const sub = caipNetworkId$.pipe(
|
|
213
|
+
(0, import_rxjs3.distinctUntilChanged)(),
|
|
214
|
+
(0, import_rxjs3.map)(
|
|
215
|
+
(caipNetworkId) => (0, import_viem2.custom)(
|
|
216
|
+
wrapWalletConnectProvider(
|
|
217
|
+
provider,
|
|
218
|
+
// biome-ignore lint/style/noNonNullAssertion: <explanation>
|
|
219
|
+
provider.session.topic,
|
|
220
|
+
caipNetworkId
|
|
221
|
+
)
|
|
222
|
+
)
|
|
223
|
+
),
|
|
224
|
+
(0, import_rxjs3.map)(
|
|
225
|
+
(transport) => account.allAccounts.map((acc, i) => {
|
|
226
|
+
const client = (0, import_viem2.createWalletClient)({
|
|
227
|
+
account: acc.address,
|
|
228
|
+
transport
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
id: getWalletAccountId(wallet.id, acc.address),
|
|
232
|
+
platform: "ethereum",
|
|
233
|
+
walletName: wallet.name,
|
|
234
|
+
walletId: wallet.id,
|
|
235
|
+
address: acc.address,
|
|
236
|
+
client,
|
|
237
|
+
isWalletDefault: i === 0
|
|
238
|
+
};
|
|
239
|
+
})
|
|
240
|
+
)
|
|
241
|
+
).subscribe(subscriber);
|
|
242
|
+
return () => {
|
|
243
|
+
provider.off("chainChanged", handleChainChanged);
|
|
244
|
+
sub.unsubscribe();
|
|
245
|
+
};
|
|
246
|
+
}).pipe((0, import_rxjs3.shareReplay)({ refCount: true, bufferSize: 1 }))
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
var getEthereumAccounts$ = (ethereumWallets) => new import_rxjs3.Observable((subscriber) => {
|
|
250
|
+
const sub = ethereumWallets.pipe(
|
|
251
|
+
(0, import_rxjs3.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
252
|
+
(0, import_rxjs3.switchMap)((wallets) => {
|
|
253
|
+
return wallets.length ? (0, import_rxjs3.combineLatest)([
|
|
254
|
+
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$),
|
|
255
|
+
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$)
|
|
256
|
+
// todo appkit
|
|
257
|
+
]) : (0, import_rxjs3.of)([]);
|
|
258
|
+
}),
|
|
259
|
+
(0, import_rxjs3.map)((accounts) => accounts.flat()),
|
|
260
|
+
(0, import_rxjs3.distinctUntilChanged)(isSameAccountsList)
|
|
261
|
+
).subscribe(subscriber);
|
|
262
|
+
return () => {
|
|
263
|
+
sub.unsubscribe();
|
|
264
|
+
};
|
|
265
|
+
}).pipe(
|
|
266
|
+
// logObservable("ethereumAccounts$", true),
|
|
267
|
+
(0, import_rxjs3.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
268
|
+
);
|
|
269
|
+
var isSameAccountsList = (a, b) => {
|
|
270
|
+
if (a.length !== b.length) return false;
|
|
271
|
+
return a.every((account, i) => account.id === b[i]?.id);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// src/api/polkadot/accounts.ts
|
|
275
|
+
var import_pjs_signer = require("polkadot-api/pjs-signer");
|
|
276
|
+
var import_rxjs4 = require("rxjs");
|
|
277
|
+
var getInjectedWalletAccounts$2 = (wallet) => {
|
|
278
|
+
if (!wallet.isConnected) return (0, import_rxjs4.of)([]);
|
|
279
|
+
return new import_rxjs4.Observable((subscriber) => {
|
|
280
|
+
const getAccount = (account) => ({
|
|
281
|
+
id: getWalletAccountId(wallet.id, account.address),
|
|
282
|
+
...account,
|
|
283
|
+
platform: "polkadot",
|
|
284
|
+
walletName: wallet.name,
|
|
285
|
+
walletId: wallet.id
|
|
286
|
+
});
|
|
287
|
+
const extension = wallet.extension;
|
|
288
|
+
const unsubscribe = extension.subscribe((accounts) => {
|
|
289
|
+
subscriber.next(accounts.map(getAccount));
|
|
290
|
+
});
|
|
291
|
+
subscriber.next(extension.getAccounts().map(getAccount));
|
|
292
|
+
return () => {
|
|
293
|
+
return unsubscribe();
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
var getAppKitPolkadotSigner = (appKit, address) => {
|
|
298
|
+
const provider = appKit.getProvider("polkadot");
|
|
299
|
+
if (!provider) throw new Error("No provider found");
|
|
300
|
+
if (!provider.session) throw new Error("No session found");
|
|
301
|
+
return (0, import_pjs_signer.getPolkadotSignerFromPjs)(
|
|
302
|
+
address,
|
|
303
|
+
(transactionPayload) => {
|
|
304
|
+
if (!provider.session) throw new Error("No session found");
|
|
305
|
+
return provider.client.request({
|
|
306
|
+
topic: provider.session.topic,
|
|
307
|
+
chainId: `polkadot:${transactionPayload.genesisHash.substring(2, 34)}`,
|
|
308
|
+
request: {
|
|
309
|
+
method: "polkadot_signTransaction",
|
|
310
|
+
params: {
|
|
311
|
+
address,
|
|
312
|
+
transactionPayload
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
async ({ address: address2, data }) => {
|
|
318
|
+
if (!provider.session) throw new Error("No session found");
|
|
319
|
+
const networks = appKit.getCaipNetworks("polkadot");
|
|
320
|
+
const chainId = networks[0]?.caipNetworkId;
|
|
321
|
+
if (!chainId) throw new Error("No chainId found");
|
|
322
|
+
return provider.client.request({
|
|
323
|
+
topic: provider.session.topic,
|
|
324
|
+
chainId,
|
|
325
|
+
request: {
|
|
326
|
+
method: "polkadot_signMessage",
|
|
327
|
+
params: {
|
|
328
|
+
address: address2,
|
|
329
|
+
message: data
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
};
|
|
336
|
+
var getAppKitAccounts$2 = (wallet) => {
|
|
337
|
+
const account = wallet.appKit.getAccount("polkadot");
|
|
338
|
+
const provider = wallet.appKit.getProvider("polkadot");
|
|
339
|
+
if (!wallet.isConnected || !wallet.appKit || !account?.allAccounts.length || !provider?.session)
|
|
340
|
+
return (0, import_rxjs4.of)([]);
|
|
341
|
+
return (0, import_rxjs4.of)(
|
|
342
|
+
account.allAccounts.map(
|
|
343
|
+
(acc) => ({
|
|
344
|
+
id: getWalletAccountId(wallet.id, acc.address),
|
|
345
|
+
platform: "polkadot",
|
|
346
|
+
walletName: wallet.name,
|
|
347
|
+
walletId: wallet.id,
|
|
348
|
+
address: acc.address,
|
|
349
|
+
polkadotSigner: getAppKitPolkadotSigner(wallet.appKit, acc.address),
|
|
350
|
+
genesisHash: null,
|
|
351
|
+
name: `${wallet.name} Polkadot`,
|
|
352
|
+
type: "sr25519"
|
|
353
|
+
})
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
};
|
|
357
|
+
var getPolkadotAccounts$ = (polkadotWallets$) => new import_rxjs4.Observable((subscriber) => {
|
|
358
|
+
const sub = polkadotWallets$.pipe(
|
|
359
|
+
(0, import_rxjs4.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
360
|
+
(0, import_rxjs4.switchMap)(
|
|
361
|
+
(wallets) => wallets.length ? (0, import_rxjs4.combineLatest)([
|
|
362
|
+
...wallets.filter((w) => w.type === "injected").map(getInjectedWalletAccounts$2),
|
|
363
|
+
...wallets.filter((w) => w.type === "appKit").map(getAppKitAccounts$2)
|
|
364
|
+
]) : (0, import_rxjs4.of)([])
|
|
365
|
+
),
|
|
366
|
+
(0, import_rxjs4.map)((accounts) => accounts.flat()),
|
|
367
|
+
(0, import_rxjs4.distinctUntilChanged)(isSameAccountsList2)
|
|
368
|
+
).subscribe(subscriber);
|
|
369
|
+
return () => {
|
|
370
|
+
sub.unsubscribe();
|
|
371
|
+
};
|
|
372
|
+
}).pipe((0, import_rxjs4.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
373
|
+
var isSameAccountsList2 = (a, b) => {
|
|
374
|
+
if (a.length !== b.length) return false;
|
|
375
|
+
return a.every((account, i) => account.id === b[i]?.id);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/api/accounts.ts
|
|
379
|
+
var getAccounts$ = (config, wallets) => {
|
|
380
|
+
return new import_rxjs5.Observable((subscriber) => {
|
|
381
|
+
const sources = config.platforms.map(
|
|
382
|
+
(platform) => {
|
|
383
|
+
switch (platform) {
|
|
384
|
+
case "polkadot":
|
|
385
|
+
return getPolkadotAccounts$(
|
|
386
|
+
wallets.pipe(
|
|
387
|
+
(0, import_rxjs5.map)((w) => w.filter((w2) => w2.platform === "polkadot"))
|
|
388
|
+
)
|
|
389
|
+
);
|
|
390
|
+
case "ethereum":
|
|
391
|
+
return getEthereumAccounts$(
|
|
392
|
+
wallets.pipe(
|
|
393
|
+
(0, import_rxjs5.map)((w) => w.filter((w2) => w2.platform === "ethereum"))
|
|
394
|
+
)
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
const accounts$ = sources.length ? (0, import_rxjs5.combineLatest)(sources).pipe(
|
|
400
|
+
(0, import_rxjs5.map)((accounts) => accounts.flat().sort(sortAccounts))
|
|
401
|
+
) : (0, import_rxjs5.of)([]);
|
|
402
|
+
const sub = accounts$.subscribe(subscriber);
|
|
403
|
+
return () => {
|
|
404
|
+
sub.unsubscribe();
|
|
405
|
+
};
|
|
406
|
+
}).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// src/api/config.ts
|
|
410
|
+
var DEFAULT_CONFIG = {
|
|
411
|
+
autoReconnect: true,
|
|
412
|
+
platforms: ["polkadot"],
|
|
413
|
+
debug: false
|
|
414
|
+
};
|
|
415
|
+
var resolveConfig = (config) => {
|
|
416
|
+
return Object.assign({}, DEFAULT_CONFIG, config);
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
// src/utils/sortWallets.ts
|
|
420
|
+
var sortWallets = (w1, w2) => {
|
|
421
|
+
if (w1.platform !== w2.platform) {
|
|
422
|
+
return w1.platform === "polkadot" ? -1 : 1;
|
|
423
|
+
}
|
|
424
|
+
if (w1.name.toLowerCase() === "talisman") return -1;
|
|
425
|
+
if (w2.name.toLowerCase() === "talisman") return 1;
|
|
426
|
+
return w1.name.localeCompare(w2.name);
|
|
427
|
+
};
|
|
428
|
+
|
|
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
|
+
// src/api/ethereum/wallets.ts
|
|
473
|
+
var import_mipd = require("mipd");
|
|
474
|
+
var import_rxjs7 = require("rxjs");
|
|
475
|
+
|
|
476
|
+
// src/api/appKit.ts
|
|
477
|
+
var import_core = require("@reown/appkit/core");
|
|
478
|
+
var import_rxjs6 = require("rxjs");
|
|
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
|
+
universalProviderConfigOverride: {
|
|
491
|
+
methods: {
|
|
492
|
+
polkadot: ["polkadot_signTransaction", "polkadot_signMessage"]
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
const status$ = new import_rxjs6.BehaviorSubject({
|
|
497
|
+
isPolkadotConnected: false,
|
|
498
|
+
isEthereumConnected: false
|
|
499
|
+
});
|
|
500
|
+
const unsubProviders = appKit.subscribeProviders((providers) => {
|
|
501
|
+
status$.next({
|
|
502
|
+
isPolkadotConnected: !!providers.polkadot,
|
|
503
|
+
isEthereumConnected: !!providers.eip155
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
const polkadotWallet$ = appKit.chainNamespaces.includes("polkadot") ? status$.pipe(
|
|
507
|
+
(0, import_rxjs6.map)((s) => s.isPolkadotConnected),
|
|
508
|
+
(0, import_rxjs6.distinctUntilChanged)(),
|
|
509
|
+
(0, import_rxjs6.map)((isConnected) => {
|
|
510
|
+
const walletInfo = appKit.getWalletInfo();
|
|
511
|
+
return {
|
|
512
|
+
id: getWalletId("polkadot", "walletconnect"),
|
|
513
|
+
platform: "polkadot",
|
|
514
|
+
type: "appKit",
|
|
515
|
+
appKit,
|
|
516
|
+
// todo maybe we dont want to expose the appKit instance
|
|
517
|
+
name: walletInfo?.name ?? "WalletConnect",
|
|
518
|
+
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
519
|
+
connect: async () => {
|
|
520
|
+
if (!isConnected) await appKit.open();
|
|
521
|
+
},
|
|
522
|
+
disconnect: () => {
|
|
523
|
+
if (isConnected) appKit.disconnect();
|
|
524
|
+
},
|
|
525
|
+
isConnected
|
|
526
|
+
};
|
|
527
|
+
})
|
|
528
|
+
) : (0, import_rxjs6.of)(void 0);
|
|
529
|
+
const ethereumWallet$ = appKit.chainNamespaces.includes("eip155") ? status$.pipe(
|
|
530
|
+
(0, import_rxjs6.map)((s) => s.isEthereumConnected),
|
|
531
|
+
(0, import_rxjs6.distinctUntilChanged)(),
|
|
532
|
+
(0, import_rxjs6.map)((isConnected) => {
|
|
533
|
+
const walletInfo = appKit.getWalletInfo();
|
|
534
|
+
return {
|
|
535
|
+
id: getWalletId("ethereum", "walletconnect"),
|
|
536
|
+
platform: "ethereum",
|
|
537
|
+
type: "appKit",
|
|
538
|
+
appKit,
|
|
539
|
+
name: walletInfo?.name ?? "WalletConnect",
|
|
540
|
+
icon: walletInfo?.icon ?? WALLET_CONNECT_ICON,
|
|
541
|
+
connect: () => appKit.open(),
|
|
542
|
+
disconnect: () => appKit.disconnect(),
|
|
543
|
+
isConnected
|
|
544
|
+
};
|
|
545
|
+
})
|
|
546
|
+
) : (0, import_rxjs6.of)(void 0);
|
|
547
|
+
const sub = (0, import_rxjs6.combineLatest)({
|
|
548
|
+
polkadot: polkadotWallet$,
|
|
549
|
+
ethereum: ethereumWallet$
|
|
550
|
+
}).subscribe(subscriber);
|
|
551
|
+
return () => {
|
|
552
|
+
sub.unsubscribe();
|
|
553
|
+
unsubProviders();
|
|
554
|
+
};
|
|
555
|
+
}).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
556
|
+
}
|
|
557
|
+
return cachedAppKit;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
// src/api/ethereum/wallets.ts
|
|
561
|
+
var providersDetails$ = new import_rxjs7.Observable(
|
|
562
|
+
(subscriber) => {
|
|
563
|
+
const store2 = (0, import_mipd.createStore)();
|
|
564
|
+
const unsubscribe = store2.subscribe((providerDetails2) => {
|
|
565
|
+
subscriber.next(providerDetails2);
|
|
566
|
+
});
|
|
567
|
+
const providerDetails = store2.getProviders();
|
|
568
|
+
subscriber.next(providerDetails);
|
|
569
|
+
return () => {
|
|
570
|
+
unsubscribe();
|
|
571
|
+
store2.destroy();
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
575
|
+
var ethereumInjectedWallets$ = new import_rxjs7.Observable(
|
|
576
|
+
(subscriber) => {
|
|
577
|
+
const enabledWalletIds$ = new import_rxjs7.BehaviorSubject(/* @__PURE__ */ new Set());
|
|
578
|
+
const connectWallet = async (walletId, provider) => {
|
|
579
|
+
if (enabledWalletIds$.value.has(walletId))
|
|
580
|
+
throw new Error(`Extension ${walletId} already connected`);
|
|
581
|
+
await provider.request({
|
|
582
|
+
method: "eth_requestAccounts"
|
|
583
|
+
});
|
|
584
|
+
const newSet = new Set(enabledWalletIds$.value);
|
|
585
|
+
newSet.add(walletId);
|
|
586
|
+
enabledWalletIds$.next(newSet);
|
|
587
|
+
store.addEnabledWalletId(walletId);
|
|
588
|
+
};
|
|
589
|
+
const disconnectWallet = async (walletId) => {
|
|
590
|
+
if (!enabledWalletIds$.value.has(walletId))
|
|
591
|
+
throw new Error(`Extension ${walletId} is not connected`);
|
|
592
|
+
const newSet = new Set(enabledWalletIds$.value);
|
|
593
|
+
newSet.delete(walletId);
|
|
594
|
+
enabledWalletIds$.next(newSet);
|
|
595
|
+
store.removeEnabledWalletId(walletId);
|
|
596
|
+
};
|
|
597
|
+
const sub = (0, import_rxjs7.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
|
|
598
|
+
(0, import_rxjs7.map)(([providerDetails, enabledWalletIds]) => {
|
|
599
|
+
return providerDetails.map((pd) => {
|
|
600
|
+
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
601
|
+
const provider = pd.provider;
|
|
602
|
+
return {
|
|
603
|
+
platform: "ethereum",
|
|
604
|
+
type: "injected",
|
|
605
|
+
id: walletId,
|
|
606
|
+
name: pd.info.name,
|
|
607
|
+
icon: pd.info.icon,
|
|
608
|
+
provider,
|
|
609
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
610
|
+
providerId: pd.info.rdns,
|
|
611
|
+
connect: () => connectWallet(walletId, provider),
|
|
612
|
+
disconnect: () => disconnectWallet(walletId)
|
|
613
|
+
};
|
|
614
|
+
});
|
|
615
|
+
})
|
|
616
|
+
).subscribe(subscriber);
|
|
617
|
+
return () => {
|
|
618
|
+
sub.unsubscribe();
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
622
|
+
var getEthereumWallets$ = (config) => {
|
|
623
|
+
return new import_rxjs7.Observable((subscriber) => {
|
|
624
|
+
const subscription = (0, import_rxjs7.combineLatest)([
|
|
625
|
+
ethereumInjectedWallets$,
|
|
626
|
+
getAppKitWallets$(config)?.pipe((0, import_rxjs7.map)((w) => w.ethereum))
|
|
627
|
+
]).pipe(
|
|
628
|
+
(0, import_rxjs7.map)(
|
|
629
|
+
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
630
|
+
)
|
|
631
|
+
).subscribe(subscriber);
|
|
632
|
+
return () => {
|
|
633
|
+
subscription.unsubscribe();
|
|
634
|
+
};
|
|
635
|
+
}).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
// src/utils/polkadotExtensions.ts
|
|
639
|
+
var POLKADOT_EXTENSIONS = {
|
|
640
|
+
talisman: {
|
|
641
|
+
name: "Talisman",
|
|
642
|
+
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwIDAgMCAxMy40MzUgMTMuNDM1QzI1Ljg2NyAxMjggMzYuNDk1I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2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
// src/api/polkadot/wallets.ts
|
|
659
|
+
var import_lodash2 = require("lodash");
|
|
660
|
+
var import_pjs_signer2 = require("polkadot-api/pjs-signer");
|
|
661
|
+
var import_rxjs8 = require("rxjs");
|
|
662
|
+
var getInjectedWalletsIds = () => (0, import_pjs_signer2.getInjectedExtensions)().map((name) => getWalletId("polkadot", name));
|
|
663
|
+
var polkadotInjectedWallets$ = new import_rxjs8.Observable((subscriber) => {
|
|
664
|
+
const enabledExtensions$ = new import_rxjs8.BehaviorSubject(/* @__PURE__ */ new Map());
|
|
665
|
+
const connect = async (walletId) => {
|
|
666
|
+
if (enabledExtensions$.value.has(walletId))
|
|
667
|
+
throw new Error(`Extension ${walletId} already connected`);
|
|
668
|
+
const { identifier } = parseWalletId(walletId);
|
|
669
|
+
const extension = await (0, import_pjs_signer2.connectInjectedExtension)(identifier);
|
|
670
|
+
const newMap = new Map(enabledExtensions$.value);
|
|
671
|
+
newMap.set(walletId, extension);
|
|
672
|
+
enabledExtensions$.next(newMap);
|
|
673
|
+
store.addEnabledWalletId(walletId);
|
|
674
|
+
};
|
|
675
|
+
const disconnect = (walletId) => {
|
|
676
|
+
if (!enabledExtensions$.value.has(walletId))
|
|
677
|
+
throw new Error(`Extension ${walletId} is not connected`);
|
|
678
|
+
const newMap = new Map(enabledExtensions$.value);
|
|
679
|
+
newMap.delete(walletId);
|
|
680
|
+
enabledExtensions$.next(newMap);
|
|
681
|
+
store.removeEnabledWalletId(walletId);
|
|
682
|
+
};
|
|
683
|
+
const walletIds$ = (0, import_rxjs8.of)(0, 200, 500, 1e3).pipe(
|
|
684
|
+
(0, import_rxjs8.mergeMap)((time) => (0, import_rxjs8.timer)(time)),
|
|
685
|
+
(0, import_rxjs8.map)(() => getInjectedWalletsIds()),
|
|
686
|
+
(0, import_rxjs8.distinctUntilChanged)(import_lodash2.isEqual)
|
|
687
|
+
);
|
|
688
|
+
const subscription = (0, import_rxjs8.combineLatest)([walletIds$, enabledExtensions$]).pipe(
|
|
689
|
+
(0, import_rxjs8.map)(([walletIds, enabledExtensions]) => {
|
|
690
|
+
return walletIds.map((id) => {
|
|
691
|
+
const { identifier } = parseWalletId(id);
|
|
692
|
+
const extension = enabledExtensions.get(id);
|
|
693
|
+
const extInfo = POLKADOT_EXTENSIONS[identifier];
|
|
694
|
+
return {
|
|
695
|
+
id,
|
|
696
|
+
type: "injected",
|
|
697
|
+
platform: "polkadot",
|
|
698
|
+
name: extInfo?.name ?? identifier,
|
|
699
|
+
icon: extInfo?.icon ?? "",
|
|
700
|
+
extensionId: identifier,
|
|
701
|
+
extension,
|
|
702
|
+
isConnected: !!extension,
|
|
703
|
+
connect: () => connect(id),
|
|
704
|
+
disconnect: () => disconnect(id)
|
|
705
|
+
};
|
|
706
|
+
});
|
|
707
|
+
})
|
|
708
|
+
).subscribe(subscriber);
|
|
709
|
+
return () => {
|
|
710
|
+
subscription.unsubscribe();
|
|
711
|
+
};
|
|
712
|
+
}).pipe(
|
|
713
|
+
// logObservable("polkadotInjectedWallets$"),
|
|
714
|
+
(0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
715
|
+
);
|
|
716
|
+
var getPolkadotWallets$ = (config) => {
|
|
717
|
+
return new import_rxjs8.Observable((subscriber) => {
|
|
718
|
+
const subscription = (0, import_rxjs8.combineLatest)([
|
|
719
|
+
polkadotInjectedWallets$,
|
|
720
|
+
getAppKitWallets$(config)?.pipe((0, import_rxjs8.map)((w) => w.polkadot))
|
|
721
|
+
]).pipe(
|
|
722
|
+
(0, import_rxjs8.map)(
|
|
723
|
+
([injectedWallets, appKitWallet]) => appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets
|
|
724
|
+
)
|
|
725
|
+
).subscribe(subscriber);
|
|
726
|
+
return () => {
|
|
727
|
+
subscription.unsubscribe();
|
|
728
|
+
};
|
|
729
|
+
}).pipe(
|
|
730
|
+
// logObservable("getPolkadotWallets$"),
|
|
731
|
+
(0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
732
|
+
);
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
// src/api/wallets.ts
|
|
736
|
+
var autoReconnectWalletIds$ = store.observable.pipe(
|
|
737
|
+
(0, import_rxjs9.map)((s) => s.autoReconnect ?? []),
|
|
738
|
+
(0, import_rxjs9.take)(1),
|
|
739
|
+
(0, import_rxjs9.shareReplay)(1)
|
|
740
|
+
);
|
|
741
|
+
var getWallets$ = (config) => {
|
|
742
|
+
return new import_rxjs9.Observable((subscriber) => {
|
|
743
|
+
const observables = config.platforms.map(
|
|
744
|
+
(platform) => {
|
|
745
|
+
switch (platform) {
|
|
746
|
+
case "polkadot":
|
|
747
|
+
return getPolkadotWallets$(config);
|
|
748
|
+
case "ethereum":
|
|
749
|
+
return getEthereumWallets$(config);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
);
|
|
753
|
+
const wallets$ = observables.length ? (0, import_rxjs9.combineLatest)(observables).pipe(
|
|
754
|
+
(0, import_rxjs9.map)((wallets) => wallets.flat().sort(sortWallets))
|
|
755
|
+
) : (0, import_rxjs9.of)([]);
|
|
756
|
+
const subAutoReconnect = (0, import_rxjs9.combineLatest)([wallets$, autoReconnectWalletIds$]).pipe(
|
|
757
|
+
(0, import_rxjs9.filter)(([, walletIds]) => config.autoReconnect && !!walletIds?.length),
|
|
758
|
+
(0, import_rxjs9.mergeMap)(
|
|
759
|
+
([wallets, walletIds]) => wallets.filter((wallet) => walletIds?.includes(wallet.id))
|
|
760
|
+
),
|
|
761
|
+
(0, import_rxjs9.distinct)((w) => w.id)
|
|
762
|
+
).subscribe(async (wallet) => {
|
|
763
|
+
if (wallet.isConnected) {
|
|
764
|
+
console.warn("Wallet %s already connected", wallet.id);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
try {
|
|
768
|
+
await wallet.connect();
|
|
769
|
+
} catch (err) {
|
|
770
|
+
console.error("Failed to reconnect wallet %s", wallet.id, { err });
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
const subWallets = wallets$.subscribe(subscriber);
|
|
774
|
+
return () => {
|
|
775
|
+
subAutoReconnect.unsubscribe();
|
|
776
|
+
subWallets.unsubscribe();
|
|
777
|
+
};
|
|
778
|
+
}).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
// src/api/kheopskit.ts
|
|
782
|
+
var getKheopskit$ = (config) => {
|
|
783
|
+
const kc = resolveConfig(config);
|
|
784
|
+
console.debug("[kheopskit] config", kc);
|
|
785
|
+
return new import_rxjs10.Observable((subscriber) => {
|
|
786
|
+
const wallets$ = getWallets$(kc);
|
|
787
|
+
const subscription = (0, import_rxjs10.combineLatest)({
|
|
788
|
+
wallets: wallets$,
|
|
789
|
+
accounts: getAccounts$(kc, wallets$)
|
|
790
|
+
}).pipe((0, import_rxjs10.map)(({ wallets, accounts }) => ({ config: kc, wallets, accounts }))).subscribe(subscriber);
|
|
791
|
+
return () => {
|
|
792
|
+
subscription.unsubscribe();
|
|
793
|
+
};
|
|
794
|
+
}).pipe(
|
|
795
|
+
(0, import_rxjs10.throttleTime)(50, void 0, { leading: true, trailing: true }),
|
|
796
|
+
logObservable("kheopskit$", { enabled: kc.debug, printValue: true }),
|
|
797
|
+
(0, import_rxjs10.shareReplay)({ bufferSize: 1, refCount: true })
|
|
798
|
+
);
|
|
799
|
+
};
|
|
800
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
801
|
+
0 && (module.exports = {
|
|
802
|
+
getKheopskit$,
|
|
803
|
+
resolveConfig
|
|
804
|
+
});
|
|
805
|
+
//# sourceMappingURL=index.js.map
|