@kheopskit/core 0.0.1-alpha.0 → 0.0.1
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 +14 -0
- package/dist/index.d.mts +70 -60
- package/dist/index.d.ts +70 -60
- package/dist/index.js +574 -227
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +613 -244
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -6
- package/src/api/accounts.ts +25 -12
- package/src/api/appKit.ts +122 -0
- package/src/api/config.ts +5 -4
- package/src/api/ethereum/accounts.ts +183 -62
- package/src/api/ethereum/wallets.ts +38 -24
- package/src/api/index.ts +1 -0
- package/src/api/kheopskit.ts +35 -13
- package/src/api/polkadot/accounts.ts +117 -29
- package/src/api/polkadot/wallets.ts +88 -68
- package/src/api/store.ts +6 -3
- package/src/api/types.ts +71 -54
- package/src/api/wallets.ts +16 -14
- package/src/index.ts +0 -2
- package/src/utils/{AccountId.ts → WalletAccountId.ts} +5 -5
- package/src/utils/WalletId.ts +1 -1
- package/src/utils/createStore.ts +1 -1
- package/src/utils/getAccountAddressType.ts +2 -1
- package/src/utils/getCachedObservable.ts +12 -0
- package/src/utils/getQuery.ts +72 -0
- package/src/utils/index.ts +1 -3
- package/src/utils/isEthereumAddress.ts +3 -1
- package/src/utils/isSs58Address.ts +2 -2
- package/src/utils/isWalletPlatform.ts +1 -1
- package/src/utils/logObservable.ts +21 -0
- package/src/utils/polkadotExtensions.ts +21 -0
- package/src/utils/sortAccounts.ts +36 -0
- package/src/utils/sortWallets.ts +14 -0
- package/src/utils/isTruthy.ts +0 -3
- package/src/utils/types.ts +0 -5
package/dist/index.js
CHANGED
|
@@ -20,23 +20,58 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
getKheopskit$: () => getKheopskit
|
|
23
|
+
getKheopskit$: () => getKheopskit$,
|
|
24
|
+
resolveConfig: () => resolveConfig
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(index_exports);
|
|
26
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
|
+
|
|
27
38
|
// src/api/kheopskit.ts
|
|
28
|
-
var
|
|
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
|
+
};
|
|
29
64
|
|
|
30
65
|
// src/api/accounts.ts
|
|
31
|
-
var
|
|
66
|
+
var import_rxjs5 = require("rxjs");
|
|
32
67
|
|
|
33
68
|
// src/utils/createStore.ts
|
|
34
|
-
var
|
|
69
|
+
var import_rxjs2 = require("rxjs");
|
|
35
70
|
var createStore = (key, defaultValue) => {
|
|
36
|
-
const subject = new
|
|
37
|
-
(0,
|
|
38
|
-
(0,
|
|
39
|
-
(0,
|
|
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))
|
|
40
75
|
).subscribe((newValue) => subject.next(newValue));
|
|
41
76
|
const update = (val) => {
|
|
42
77
|
setStoredData(key, val);
|
|
@@ -66,7 +101,8 @@ var setStoredData = (key, val) => {
|
|
|
66
101
|
};
|
|
67
102
|
|
|
68
103
|
// src/utils/isEthereumAddress.ts
|
|
69
|
-
var
|
|
104
|
+
var import_viem = require("viem");
|
|
105
|
+
var isEthereumAddress = (address) => (0, import_viem.isAddress)(address);
|
|
70
106
|
|
|
71
107
|
// src/utils/isSs58Address.ts
|
|
72
108
|
var import_polkadot_api = require("polkadot-api");
|
|
@@ -76,7 +112,7 @@ var isSs58Address = (address) => {
|
|
|
76
112
|
if (!address) return false;
|
|
77
113
|
accountIdEncoder(address);
|
|
78
114
|
return true;
|
|
79
|
-
} catch
|
|
115
|
+
} catch {
|
|
80
116
|
return false;
|
|
81
117
|
}
|
|
82
118
|
};
|
|
@@ -86,8 +122,8 @@ var isValidAddress = (address) => {
|
|
|
86
122
|
return address.startsWith("0x") ? isEthereumAddress(address) : isSs58Address(address);
|
|
87
123
|
};
|
|
88
124
|
|
|
89
|
-
// src/utils/
|
|
90
|
-
var
|
|
125
|
+
// src/utils/WalletAccountId.ts
|
|
126
|
+
var getWalletAccountId = (walletId, address) => {
|
|
91
127
|
if (!walletId) throw new Error("Missing walletId");
|
|
92
128
|
if (!isValidAddress(address)) throw new Error("Invalid address");
|
|
93
129
|
return `${walletId}::${address}`;
|
|
@@ -96,12 +132,302 @@ var getAccountId = (walletId, address) => {
|
|
|
96
132
|
// src/utils/isWalletPlatform.ts
|
|
97
133
|
var isWalletPlatform = (platform) => typeof platform === "string" && ["polkadot", "ethereum"].includes(platform);
|
|
98
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
|
+
|
|
99
142
|
// src/api/ethereum/accounts.ts
|
|
100
143
|
var import_rxjs3 = require("rxjs");
|
|
101
|
-
var
|
|
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
|
+
};
|
|
102
273
|
|
|
103
|
-
// src/api/
|
|
104
|
-
var
|
|
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");
|
|
105
431
|
|
|
106
432
|
// src/utils/WalletId.ts
|
|
107
433
|
var getWalletId = (platform, identifier) => {
|
|
@@ -118,6 +444,7 @@ var parseWalletId = (walletId) => {
|
|
|
118
444
|
};
|
|
119
445
|
|
|
120
446
|
// src/api/store.ts
|
|
447
|
+
var import_lodash = require("lodash");
|
|
121
448
|
var LOCAL_STORAGE_KEY = "kheopskit";
|
|
122
449
|
var DEFAULT_SETTINGS = {};
|
|
123
450
|
var storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);
|
|
@@ -144,8 +471,94 @@ var store = {
|
|
|
144
471
|
|
|
145
472
|
// src/api/ethereum/wallets.ts
|
|
146
473
|
var import_mipd = require("mipd");
|
|
147
|
-
var
|
|
148
|
-
|
|
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+PC9jbGlwUGF0aD48ZyBjbGlwLXBhdGg9InVybCgjYSkiPjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgZmlsbD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i4wODcgNy43NDggMHoiIGZpbGw9IiNmZmYiLz48L2c+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(
|
|
149
562
|
(subscriber) => {
|
|
150
563
|
const store2 = (0, import_mipd.createStore)();
|
|
151
564
|
const unsubscribe = store2.subscribe((providerDetails2) => {
|
|
@@ -158,17 +571,14 @@ var providersDetails$ = new import_rxjs2.Observable(
|
|
|
158
571
|
store2.destroy();
|
|
159
572
|
};
|
|
160
573
|
}
|
|
161
|
-
).pipe((0,
|
|
162
|
-
|
|
163
|
-
console.count("[kheopskit] providers$ emit");
|
|
164
|
-
});
|
|
165
|
-
var ethereumWallets$ = new import_rxjs2.Observable(
|
|
574
|
+
).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
575
|
+
var ethereumInjectedWallets$ = new import_rxjs7.Observable(
|
|
166
576
|
(subscriber) => {
|
|
167
|
-
const enabledWalletIds$ = new
|
|
577
|
+
const enabledWalletIds$ = new import_rxjs7.BehaviorSubject(/* @__PURE__ */ new Set());
|
|
168
578
|
const connectWallet = async (walletId, provider) => {
|
|
169
579
|
if (enabledWalletIds$.value.has(walletId))
|
|
170
580
|
throw new Error(`Extension ${walletId} already connected`);
|
|
171
|
-
provider.request({
|
|
581
|
+
await provider.request({
|
|
172
582
|
method: "eth_requestAccounts"
|
|
173
583
|
});
|
|
174
584
|
const newSet = new Set(enabledWalletIds$.value);
|
|
@@ -176,7 +586,7 @@ var ethereumWallets$ = new import_rxjs2.Observable(
|
|
|
176
586
|
enabledWalletIds$.next(newSet);
|
|
177
587
|
store.addEnabledWalletId(walletId);
|
|
178
588
|
};
|
|
179
|
-
const disconnectWallet = async (walletId
|
|
589
|
+
const disconnectWallet = async (walletId) => {
|
|
180
590
|
if (!enabledWalletIds$.value.has(walletId))
|
|
181
591
|
throw new Error(`Extension ${walletId} is not connected`);
|
|
182
592
|
const newSet = new Set(enabledWalletIds$.value);
|
|
@@ -184,21 +594,22 @@ var ethereumWallets$ = new import_rxjs2.Observable(
|
|
|
184
594
|
enabledWalletIds$.next(newSet);
|
|
185
595
|
store.removeEnabledWalletId(walletId);
|
|
186
596
|
};
|
|
187
|
-
const sub = (0,
|
|
188
|
-
(0,
|
|
597
|
+
const sub = (0, import_rxjs7.combineLatest)([providersDetails$, enabledWalletIds$]).pipe(
|
|
598
|
+
(0, import_rxjs7.map)(([providerDetails, enabledWalletIds]) => {
|
|
189
599
|
return providerDetails.map((pd) => {
|
|
190
600
|
const walletId = getWalletId("ethereum", pd.info.rdns);
|
|
191
601
|
const provider = pd.provider;
|
|
192
602
|
return {
|
|
193
603
|
platform: "ethereum",
|
|
604
|
+
type: "injected",
|
|
194
605
|
id: walletId,
|
|
195
606
|
name: pd.info.name,
|
|
196
607
|
icon: pd.info.icon,
|
|
197
608
|
provider,
|
|
198
|
-
|
|
609
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
199
610
|
providerId: pd.info.rdns,
|
|
200
611
|
connect: () => connectWallet(walletId, provider),
|
|
201
|
-
disconnect: () => disconnectWallet(walletId
|
|
612
|
+
disconnect: () => disconnectWallet(walletId)
|
|
202
613
|
};
|
|
203
614
|
});
|
|
204
615
|
})
|
|
@@ -207,221 +618,149 @@ var ethereumWallets$ = new import_rxjs2.Observable(
|
|
|
207
618
|
sub.unsubscribe();
|
|
208
619
|
};
|
|
209
620
|
}
|
|
210
|
-
).pipe((0,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
id: getAccountId(wallet.id, address),
|
|
221
|
-
platform: "ethereum",
|
|
222
|
-
provider: wallet.provider,
|
|
223
|
-
address: (0, import_viem.getAddress)(address),
|
|
224
|
-
walletName: wallet.name,
|
|
225
|
-
walletId: wallet.id,
|
|
226
|
-
isWalletDefault: i === 0
|
|
227
|
-
});
|
|
228
|
-
const listener = (addresses) => {
|
|
229
|
-
subscriber.next(addresses.map(getAccount));
|
|
230
|
-
};
|
|
231
|
-
wallet.provider.on("accountsChanged", listener);
|
|
232
|
-
wallet.provider.request({ method: "eth_accounts" }).then((addresses) => {
|
|
233
|
-
subscriber.next(addresses.map(getAccount));
|
|
234
|
-
}).catch((err) => {
|
|
235
|
-
console.error("Failed to get accounts", err);
|
|
236
|
-
subscriber.next([]);
|
|
237
|
-
});
|
|
238
|
-
return () => {
|
|
239
|
-
wallet.provider.removeListener("accountsChanged", listener);
|
|
240
|
-
};
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
var ethereumAccounts$ = new import_rxjs3.Observable(
|
|
244
|
-
(subscriber) => {
|
|
245
|
-
const sub = ethereumWallets$.pipe(
|
|
246
|
-
(0, import_rxjs3.map)((wallets) => wallets.filter((w) => w.isEnabled)),
|
|
247
|
-
(0, import_rxjs3.switchMap)(
|
|
248
|
-
(wallets) => wallets.length ? (0, import_rxjs3.combineLatest)(wallets.map(getWalletAccounts$)) : (0, import_rxjs3.of)([])
|
|
249
|
-
),
|
|
250
|
-
(0, import_rxjs3.map)((accounts) => accounts.flat())
|
|
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
|
+
)
|
|
251
631
|
).subscribe(subscriber);
|
|
252
632
|
return () => {
|
|
253
|
-
|
|
633
|
+
subscription.unsubscribe();
|
|
254
634
|
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
ethereumAccounts$.subscribe(() => {
|
|
258
|
-
console.count("[kheopskit] ethereumAccounts$ emit");
|
|
259
|
-
});
|
|
635
|
+
}).pipe((0, import_rxjs7.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
636
|
+
};
|
|
260
637
|
|
|
261
|
-
// src/
|
|
262
|
-
var
|
|
638
|
+
// src/utils/polkadotExtensions.ts
|
|
639
|
+
var POLKADOT_EXTENSIONS = {
|
|
640
|
+
talisman: {
|
|
641
|
+
name: "Talisman",
|
|
642
|
+
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTI4IiBoZWlnaHQ9IjEyOCIgdmlld0JveD0iMCAwIDEyOCAxMjgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBmaWxsPSIjZGRmZTc2IiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0wIDcwLjI1YzAgMjEuMjU1IDAgMzEuODgzIDQuNDYzIDM5Ljg1MmEzNSAzNSAwIDAgMCAxMy40MzUgMTMuNDM1QzI1Ljg2NyAxMjggMzYuNDk1IDEyOCA1Ny43NSAxMjhoMTIuNWMyMS4yNTUgMCAzMS44ODMgMCAzOS44NTItNC40NjNhMzUgMzUgMCAwIDAgMTMuNDM1LTEzLjQzNUMxMjggMTAyLjEzMyAxMjggOTEuNTA1IDEyOCA3MC4yNXYtMTIuNWMwLTIxLjI1NSAwLTMxLjg4My00LjQ2My0zOS44NTJhMzUgMzUgMCAwIDAtMTMuNDM1LTEzLjQzNUMxMDIuMTMzIDAgOTEuNTA1IDAgNzAuMjUgMGgtMTIuNUMzNi40OTUgMCAyNS44NjcgMCAxNy44OTggNC40NjNBMzUgMzUgMCAwIDAgNC40NjMgMTcuODk4QzAgMjUuODY3IDAgMzYuNDk1IDAgNTcuNzVaIi8+CiAgICA8cGF0aCBmaWxsPSIjZWE1NzUwIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGQ9Im0zMy44NzkgMzUuMTE3LS41IDE5LjE2NWM4LjEwNyA0LjE2OCAxNS43NSA0LjA3NSAyNC43NCAyLjA2MyAzLjU2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A4MTIgMTguOTMwNyAxNy4wMDU3IDE3LjAwNjJaTTQwLjE0NzkgMzMuNTQyM0g2MC45MTU3QzY0LjQ1OCAzMy41NDIzIDY3LjMyOTUgMzYuNDEzOCA2Ny4zMjk1IDM5Ljk1NjFWNDEuNjgxNkM2Ny4zMjk1IDQ1LjIyMzggNjQuNDU4IDQ4LjA5NTQgNjAuOTE1NyA0OC4wOTU0SDQwLjE0NzlDMzYuNjA1NyA0OC4wOTU0IDMzLjczNDEgNDUuMjIzOCAzMy43MzQxIDQxLjY4MTZWMzkuOTU2MUMzMy43MzQxIDM2LjQxMzggMzYuNjA1NyAzMy41NDIzIDQwLjE0NzkgMzMuNTQyM1oiIGZpbGw9InVybCgjcGFpbnQwX2xpbmVhcl8yODdfMjM1OSkiLz4KPGRlZnM+CjxsaW5lYXJHcmFkaWVudCBpZD0icGFpbnQwX2xpbmVhcl8yODdfMjM1OSIgeDE9IjE5LjM2MDIiIHkxPSIxNCIgeDI9IjU2Ljc2OTYiIHkyPSI2OS44MDA1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNDNTQ5RkYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjNjU0QkZGIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg=="
|
|
655
|
+
}
|
|
656
|
+
};
|
|
263
657
|
|
|
264
658
|
// src/api/polkadot/wallets.ts
|
|
265
659
|
var import_lodash2 = require("lodash");
|
|
266
|
-
var
|
|
267
|
-
var
|
|
268
|
-
var getInjectedWalletsIds = () => (0,
|
|
269
|
-
var polkadotInjectedWallets$ = new
|
|
270
|
-
(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
+
)
|
|
318
725
|
).subscribe(subscriber);
|
|
319
726
|
return () => {
|
|
320
727
|
subscription.unsubscribe();
|
|
321
728
|
};
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
console.count("[kheopskit] polkadotWallets$ emit");
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// src/api/polkadot/accounts.ts
|
|
330
|
-
var getWalletAccounts$2 = (wallet) => {
|
|
331
|
-
if (!wallet.isEnabled) return (0, import_rxjs5.of)([]);
|
|
332
|
-
return new import_rxjs5.Observable((subscriber) => {
|
|
333
|
-
const getAccount = (account) => ({
|
|
334
|
-
id: getAccountId(wallet.id, account.address),
|
|
335
|
-
...account,
|
|
336
|
-
platform: "polkadot",
|
|
337
|
-
walletName: wallet.name,
|
|
338
|
-
walletId: wallet.id
|
|
339
|
-
});
|
|
340
|
-
const unsubscribe = wallet.extension.subscribe((accounts) => {
|
|
341
|
-
subscriber.next(accounts.map(getAccount));
|
|
342
|
-
});
|
|
343
|
-
subscriber.next(wallet.extension.getAccounts().map(getAccount));
|
|
344
|
-
return () => {
|
|
345
|
-
return unsubscribe();
|
|
346
|
-
};
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
var polkadotAccounts$ = new import_rxjs5.Observable(
|
|
350
|
-
(subscriber) => {
|
|
351
|
-
const sub = polkadotWallets$.pipe(
|
|
352
|
-
(0, import_rxjs5.map)((wallets) => wallets.filter((w) => w.isEnabled)),
|
|
353
|
-
(0, import_rxjs5.switchMap)(
|
|
354
|
-
(wallets) => wallets.length ? (0, import_rxjs5.combineLatest)(wallets.map(getWalletAccounts$2)) : (0, import_rxjs5.of)([])
|
|
355
|
-
),
|
|
356
|
-
(0, import_rxjs5.map)((accounts) => accounts.flat())
|
|
357
|
-
).subscribe(subscriber);
|
|
358
|
-
return () => {
|
|
359
|
-
sub.unsubscribe();
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
).pipe((0, import_rxjs5.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
363
|
-
polkadotAccounts$.subscribe(() => {
|
|
364
|
-
console.count("[kheopskit] polkadotAccounts$ emit");
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
// src/api/accounts.ts
|
|
368
|
-
var getAccounts$ = (config) => {
|
|
369
|
-
return new import_rxjs6.Observable((subscriber) => {
|
|
370
|
-
const observables = config.platforms.map(
|
|
371
|
-
(platform) => {
|
|
372
|
-
switch (platform) {
|
|
373
|
-
case "polkadot":
|
|
374
|
-
return polkadotAccounts$;
|
|
375
|
-
case "ethereum":
|
|
376
|
-
return ethereumAccounts$;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
);
|
|
380
|
-
const accounts$ = observables.length ? (0, import_rxjs6.combineLatest)(observables).pipe((0, import_rxjs6.map)((accounts) => accounts.flat())) : (0, import_rxjs6.of)([]);
|
|
381
|
-
const sub = accounts$.subscribe(subscriber);
|
|
382
|
-
return () => {
|
|
383
|
-
sub.unsubscribe();
|
|
384
|
-
};
|
|
385
|
-
}).pipe((0, import_rxjs6.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
// src/api/config.ts
|
|
389
|
-
var DEFAULT_CONFIG = {
|
|
390
|
-
autoReconnect: true,
|
|
391
|
-
platforms: ["polkadot"]
|
|
392
|
-
};
|
|
393
|
-
var resolveConfig = (config) => {
|
|
394
|
-
return Object.assign({}, DEFAULT_CONFIG, config);
|
|
729
|
+
}).pipe(
|
|
730
|
+
// logObservable("getPolkadotWallets$"),
|
|
731
|
+
(0, import_rxjs8.shareReplay)({ refCount: true, bufferSize: 1 })
|
|
732
|
+
);
|
|
395
733
|
};
|
|
396
734
|
|
|
397
735
|
// src/api/wallets.ts
|
|
398
|
-
var import_rxjs7 = require("rxjs");
|
|
399
736
|
var autoReconnectWalletIds$ = store.observable.pipe(
|
|
400
|
-
(0,
|
|
401
|
-
(0,
|
|
402
|
-
(0,
|
|
737
|
+
(0, import_rxjs9.map)((s) => s.autoReconnect ?? []),
|
|
738
|
+
(0, import_rxjs9.take)(1),
|
|
739
|
+
(0, import_rxjs9.shareReplay)(1)
|
|
403
740
|
);
|
|
404
741
|
var getWallets$ = (config) => {
|
|
405
|
-
return new
|
|
742
|
+
return new import_rxjs9.Observable((subscriber) => {
|
|
406
743
|
const observables = config.platforms.map(
|
|
407
744
|
(platform) => {
|
|
408
745
|
switch (platform) {
|
|
409
746
|
case "polkadot":
|
|
410
|
-
return
|
|
747
|
+
return getPolkadotWallets$(config);
|
|
411
748
|
case "ethereum":
|
|
412
|
-
return
|
|
749
|
+
return getEthereumWallets$(config);
|
|
413
750
|
}
|
|
414
751
|
}
|
|
415
752
|
);
|
|
416
|
-
const wallets$ = observables.length ? (0,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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)(
|
|
420
759
|
([wallets, walletIds]) => wallets.filter((wallet) => walletIds?.includes(wallet.id))
|
|
421
760
|
),
|
|
422
|
-
(0,
|
|
761
|
+
(0, import_rxjs9.distinct)((w) => w.id)
|
|
423
762
|
).subscribe(async (wallet) => {
|
|
424
|
-
if (wallet.
|
|
763
|
+
if (wallet.isConnected) {
|
|
425
764
|
console.warn("Wallet %s already connected", wallet.id);
|
|
426
765
|
return;
|
|
427
766
|
}
|
|
@@ -436,23 +775,31 @@ var getWallets$ = (config) => {
|
|
|
436
775
|
subAutoReconnect.unsubscribe();
|
|
437
776
|
subWallets.unsubscribe();
|
|
438
777
|
};
|
|
439
|
-
}).pipe((0,
|
|
778
|
+
}).pipe((0, import_rxjs9.shareReplay)({ refCount: true, bufferSize: 1 }));
|
|
440
779
|
};
|
|
441
780
|
|
|
442
781
|
// src/api/kheopskit.ts
|
|
443
782
|
var getKheopskit$ = (config) => {
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
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
|
+
);
|
|
453
799
|
};
|
|
454
800
|
// Annotate the CommonJS export names for ESM import in node:
|
|
455
801
|
0 && (module.exports = {
|
|
456
|
-
getKheopskit
|
|
802
|
+
getKheopskit$,
|
|
803
|
+
resolveConfig
|
|
457
804
|
});
|
|
458
805
|
//# sourceMappingURL=index.js.map
|