@kheopskit/core 0.0.1-alpha.0 → 0.0.1-alpha.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 +6 -0
- package/dist/index.d.mts +21 -46
- package/dist/index.d.ts +21 -46
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/ethereum/accounts.ts +5 -15
- package/src/api/ethereum/wallets.ts +1 -1
- package/src/api/polkadot/accounts.ts +5 -12
- package/src/api/polkadot/wallets.ts +2 -2
- package/src/api/types.ts +22 -38
- package/src/api/wallets.ts +1 -1
- package/src/utils/AccountId.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @kheopskit/core
|
|
2
2
|
|
|
3
|
+
## 0.0.1-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4f378f9`](https://github.com/0xKheops/kheopskit-alpha/commit/4f378f9b61e555b7b66ef3bfaf107ab8e6ac62b1) Thanks [@0xKheops](https://github.com/0xKheops)! - refactor property names
|
|
8
|
+
|
|
3
9
|
## 0.0.1-alpha.0
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,51 +1,11 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { EIP1193Provider } from 'viem';
|
|
3
|
-
import {
|
|
3
|
+
import { InjectedExtension, InjectedPolkadotAccount } from 'polkadot-api/pjs-signer';
|
|
4
4
|
|
|
5
5
|
type WalletId = string;
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type WalletAccountId = string;
|
|
8
8
|
|
|
9
|
-
type PolkadotAccount = InjectedPolkadotAccount & {
|
|
10
|
-
id: AccountId;
|
|
11
|
-
platform: "polkadot";
|
|
12
|
-
walletName: string;
|
|
13
|
-
walletId: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type EthereumAccount = {
|
|
17
|
-
id: AccountId;
|
|
18
|
-
platform: "ethereum";
|
|
19
|
-
provider: EIP1193Provider;
|
|
20
|
-
address: `0x${string}`;
|
|
21
|
-
walletName: string;
|
|
22
|
-
walletId: string;
|
|
23
|
-
isWalletDefault: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type AccountStorageBase = {
|
|
27
|
-
wallet: string;
|
|
28
|
-
address: string;
|
|
29
|
-
};
|
|
30
|
-
type EthereumAccountStorage = AccountStorageBase & {
|
|
31
|
-
platform: "ethereum";
|
|
32
|
-
};
|
|
33
|
-
type PolkadotAccountStorage = AccountStorageBase & {
|
|
34
|
-
platform: "polkadot";
|
|
35
|
-
name: InjectedAccount["name"];
|
|
36
|
-
type: InjectedAccount["type"];
|
|
37
|
-
genesisHash: InjectedAccount["genesisHash"];
|
|
38
|
-
};
|
|
39
|
-
type AccountStorage = PolkadotAccountStorage | EthereumAccountStorage;
|
|
40
|
-
type Account<T extends AccountStorage> = T & {
|
|
41
|
-
id: string;
|
|
42
|
-
signer: T extends PolkadotAccountStorage ? PolkadotSigner : null;
|
|
43
|
-
};
|
|
44
|
-
type PlatformData<T extends AccountStorageBase> = {
|
|
45
|
-
enabledExtensionIds: string[];
|
|
46
|
-
accounts: T[];
|
|
47
|
-
defaultAccountId: string | null;
|
|
48
|
-
};
|
|
49
9
|
type KheopskitStoreData = {
|
|
50
10
|
autoReconnect?: WalletId[];
|
|
51
11
|
};
|
|
@@ -58,7 +18,7 @@ type PolkadotDisabledInjectedWallet = {
|
|
|
58
18
|
platform: "polkadot";
|
|
59
19
|
extensionId: string;
|
|
60
20
|
name: string;
|
|
61
|
-
|
|
21
|
+
isConnected: false;
|
|
62
22
|
connect: () => Promise<void>;
|
|
63
23
|
};
|
|
64
24
|
type PolkadotEnabledInjectedWallet = {
|
|
@@ -67,7 +27,7 @@ type PolkadotEnabledInjectedWallet = {
|
|
|
67
27
|
extensionId: string;
|
|
68
28
|
extension: InjectedExtension;
|
|
69
29
|
name: string;
|
|
70
|
-
|
|
30
|
+
isConnected: true;
|
|
71
31
|
disconnect: () => void;
|
|
72
32
|
};
|
|
73
33
|
type PolkadotWallet = PolkadotDisabledInjectedWallet | PolkadotEnabledInjectedWallet;
|
|
@@ -78,12 +38,27 @@ type EthereumWallet = {
|
|
|
78
38
|
provider: EIP1193Provider;
|
|
79
39
|
name: string;
|
|
80
40
|
icon: string;
|
|
81
|
-
|
|
41
|
+
isConnected: boolean;
|
|
82
42
|
connect: () => Promise<void>;
|
|
83
43
|
disconnect: () => void;
|
|
84
44
|
};
|
|
85
45
|
type Wallet = PolkadotWallet | EthereumWallet;
|
|
86
46
|
type WalletPlatform = Wallet["platform"];
|
|
47
|
+
type PolkadotAccount = InjectedPolkadotAccount & {
|
|
48
|
+
id: WalletAccountId;
|
|
49
|
+
platform: "polkadot";
|
|
50
|
+
walletName: string;
|
|
51
|
+
walletId: string;
|
|
52
|
+
};
|
|
53
|
+
type EthereumAccount = {
|
|
54
|
+
id: WalletAccountId;
|
|
55
|
+
platform: "ethereum";
|
|
56
|
+
provider: EIP1193Provider;
|
|
57
|
+
address: `0x${string}`;
|
|
58
|
+
walletName: string;
|
|
59
|
+
walletId: string;
|
|
60
|
+
isWalletDefault: boolean;
|
|
61
|
+
};
|
|
87
62
|
type WalletAccount = PolkadotAccount | EthereumAccount;
|
|
88
63
|
|
|
89
64
|
declare const getKheopskit$: (config: KheopskitConfig) => Observable<{
|
|
@@ -91,4 +66,4 @@ declare const getKheopskit$: (config: KheopskitConfig) => Observable<{
|
|
|
91
66
|
accounts: WalletAccount[];
|
|
92
67
|
}>;
|
|
93
68
|
|
|
94
|
-
export { type
|
|
69
|
+
export { type EthereumAccount, type EthereumWallet, type KheopskitConfig, type KheopskitStoreData, type PolkadotAccount, type PolkadotDisabledInjectedWallet, type PolkadotEnabledInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, getKheopskit$ };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,51 +1,11 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
import { EIP1193Provider } from 'viem';
|
|
3
|
-
import {
|
|
3
|
+
import { InjectedExtension, InjectedPolkadotAccount } from 'polkadot-api/pjs-signer';
|
|
4
4
|
|
|
5
5
|
type WalletId = string;
|
|
6
6
|
|
|
7
|
-
type
|
|
7
|
+
type WalletAccountId = string;
|
|
8
8
|
|
|
9
|
-
type PolkadotAccount = InjectedPolkadotAccount & {
|
|
10
|
-
id: AccountId;
|
|
11
|
-
platform: "polkadot";
|
|
12
|
-
walletName: string;
|
|
13
|
-
walletId: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type EthereumAccount = {
|
|
17
|
-
id: AccountId;
|
|
18
|
-
platform: "ethereum";
|
|
19
|
-
provider: EIP1193Provider;
|
|
20
|
-
address: `0x${string}`;
|
|
21
|
-
walletName: string;
|
|
22
|
-
walletId: string;
|
|
23
|
-
isWalletDefault: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type AccountStorageBase = {
|
|
27
|
-
wallet: string;
|
|
28
|
-
address: string;
|
|
29
|
-
};
|
|
30
|
-
type EthereumAccountStorage = AccountStorageBase & {
|
|
31
|
-
platform: "ethereum";
|
|
32
|
-
};
|
|
33
|
-
type PolkadotAccountStorage = AccountStorageBase & {
|
|
34
|
-
platform: "polkadot";
|
|
35
|
-
name: InjectedAccount["name"];
|
|
36
|
-
type: InjectedAccount["type"];
|
|
37
|
-
genesisHash: InjectedAccount["genesisHash"];
|
|
38
|
-
};
|
|
39
|
-
type AccountStorage = PolkadotAccountStorage | EthereumAccountStorage;
|
|
40
|
-
type Account<T extends AccountStorage> = T & {
|
|
41
|
-
id: string;
|
|
42
|
-
signer: T extends PolkadotAccountStorage ? PolkadotSigner : null;
|
|
43
|
-
};
|
|
44
|
-
type PlatformData<T extends AccountStorageBase> = {
|
|
45
|
-
enabledExtensionIds: string[];
|
|
46
|
-
accounts: T[];
|
|
47
|
-
defaultAccountId: string | null;
|
|
48
|
-
};
|
|
49
9
|
type KheopskitStoreData = {
|
|
50
10
|
autoReconnect?: WalletId[];
|
|
51
11
|
};
|
|
@@ -58,7 +18,7 @@ type PolkadotDisabledInjectedWallet = {
|
|
|
58
18
|
platform: "polkadot";
|
|
59
19
|
extensionId: string;
|
|
60
20
|
name: string;
|
|
61
|
-
|
|
21
|
+
isConnected: false;
|
|
62
22
|
connect: () => Promise<void>;
|
|
63
23
|
};
|
|
64
24
|
type PolkadotEnabledInjectedWallet = {
|
|
@@ -67,7 +27,7 @@ type PolkadotEnabledInjectedWallet = {
|
|
|
67
27
|
extensionId: string;
|
|
68
28
|
extension: InjectedExtension;
|
|
69
29
|
name: string;
|
|
70
|
-
|
|
30
|
+
isConnected: true;
|
|
71
31
|
disconnect: () => void;
|
|
72
32
|
};
|
|
73
33
|
type PolkadotWallet = PolkadotDisabledInjectedWallet | PolkadotEnabledInjectedWallet;
|
|
@@ -78,12 +38,27 @@ type EthereumWallet = {
|
|
|
78
38
|
provider: EIP1193Provider;
|
|
79
39
|
name: string;
|
|
80
40
|
icon: string;
|
|
81
|
-
|
|
41
|
+
isConnected: boolean;
|
|
82
42
|
connect: () => Promise<void>;
|
|
83
43
|
disconnect: () => void;
|
|
84
44
|
};
|
|
85
45
|
type Wallet = PolkadotWallet | EthereumWallet;
|
|
86
46
|
type WalletPlatform = Wallet["platform"];
|
|
47
|
+
type PolkadotAccount = InjectedPolkadotAccount & {
|
|
48
|
+
id: WalletAccountId;
|
|
49
|
+
platform: "polkadot";
|
|
50
|
+
walletName: string;
|
|
51
|
+
walletId: string;
|
|
52
|
+
};
|
|
53
|
+
type EthereumAccount = {
|
|
54
|
+
id: WalletAccountId;
|
|
55
|
+
platform: "ethereum";
|
|
56
|
+
provider: EIP1193Provider;
|
|
57
|
+
address: `0x${string}`;
|
|
58
|
+
walletName: string;
|
|
59
|
+
walletId: string;
|
|
60
|
+
isWalletDefault: boolean;
|
|
61
|
+
};
|
|
87
62
|
type WalletAccount = PolkadotAccount | EthereumAccount;
|
|
88
63
|
|
|
89
64
|
declare const getKheopskit$: (config: KheopskitConfig) => Observable<{
|
|
@@ -91,4 +66,4 @@ declare const getKheopskit$: (config: KheopskitConfig) => Observable<{
|
|
|
91
66
|
accounts: WalletAccount[];
|
|
92
67
|
}>;
|
|
93
68
|
|
|
94
|
-
export { type
|
|
69
|
+
export { type EthereumAccount, type EthereumWallet, type KheopskitConfig, type KheopskitStoreData, type PolkadotAccount, type PolkadotDisabledInjectedWallet, type PolkadotEnabledInjectedWallet, type PolkadotWallet, type Wallet, type WalletAccount, type WalletPlatform, getKheopskit$ };
|
package/dist/index.js
CHANGED
|
@@ -87,7 +87,7 @@ var isValidAddress = (address) => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
// src/utils/AccountId.ts
|
|
90
|
-
var
|
|
90
|
+
var getWalletAccountId = (walletId, address) => {
|
|
91
91
|
if (!walletId) throw new Error("Missing walletId");
|
|
92
92
|
if (!isValidAddress(address)) throw new Error("Invalid address");
|
|
93
93
|
return `${walletId}::${address}`;
|
|
@@ -195,7 +195,7 @@ var ethereumWallets$ = new import_rxjs2.Observable(
|
|
|
195
195
|
name: pd.info.name,
|
|
196
196
|
icon: pd.info.icon,
|
|
197
197
|
provider,
|
|
198
|
-
|
|
198
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
199
199
|
providerId: pd.info.rdns,
|
|
200
200
|
connect: () => connectWallet(walletId, provider),
|
|
201
201
|
disconnect: () => disconnectWallet(walletId, provider)
|
|
@@ -214,10 +214,10 @@ ethereumWallets$.subscribe(() => {
|
|
|
214
214
|
|
|
215
215
|
// src/api/ethereum/accounts.ts
|
|
216
216
|
var getWalletAccounts$ = (wallet) => {
|
|
217
|
-
if (!wallet.
|
|
217
|
+
if (!wallet.isConnected) return (0, import_rxjs3.of)([]);
|
|
218
218
|
return new import_rxjs3.Observable((subscriber) => {
|
|
219
219
|
const getAccount = (address, i) => ({
|
|
220
|
-
id:
|
|
220
|
+
id: getWalletAccountId(wallet.id, address),
|
|
221
221
|
platform: "ethereum",
|
|
222
222
|
provider: wallet.provider,
|
|
223
223
|
address: (0, import_viem.getAddress)(address),
|
|
@@ -243,7 +243,7 @@ var getWalletAccounts$ = (wallet) => {
|
|
|
243
243
|
var ethereumAccounts$ = new import_rxjs3.Observable(
|
|
244
244
|
(subscriber) => {
|
|
245
245
|
const sub = ethereumWallets$.pipe(
|
|
246
|
-
(0, import_rxjs3.map)((wallets) => wallets.filter((w) => w.
|
|
246
|
+
(0, import_rxjs3.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
247
247
|
(0, import_rxjs3.switchMap)(
|
|
248
248
|
(wallets) => wallets.length ? (0, import_rxjs3.combineLatest)(wallets.map(getWalletAccounts$)) : (0, import_rxjs3.of)([])
|
|
249
249
|
),
|
|
@@ -302,7 +302,7 @@ var polkadotInjectedWallets$ = new import_rxjs4.Observable(
|
|
|
302
302
|
platform: "polkadot",
|
|
303
303
|
name: identifier,
|
|
304
304
|
extensionId: identifier,
|
|
305
|
-
|
|
305
|
+
isConnected: true,
|
|
306
306
|
extension,
|
|
307
307
|
disconnect: () => disconnect(id)
|
|
308
308
|
} : {
|
|
@@ -310,7 +310,7 @@ var polkadotInjectedWallets$ = new import_rxjs4.Observable(
|
|
|
310
310
|
platform: "polkadot",
|
|
311
311
|
name: identifier,
|
|
312
312
|
extensionId: identifier,
|
|
313
|
-
|
|
313
|
+
isConnected: false,
|
|
314
314
|
connect: () => connect(id)
|
|
315
315
|
};
|
|
316
316
|
});
|
|
@@ -328,10 +328,10 @@ polkadotWallets$.subscribe(() => {
|
|
|
328
328
|
|
|
329
329
|
// src/api/polkadot/accounts.ts
|
|
330
330
|
var getWalletAccounts$2 = (wallet) => {
|
|
331
|
-
if (!wallet.
|
|
331
|
+
if (!wallet.isConnected) return (0, import_rxjs5.of)([]);
|
|
332
332
|
return new import_rxjs5.Observable((subscriber) => {
|
|
333
333
|
const getAccount = (account) => ({
|
|
334
|
-
id:
|
|
334
|
+
id: getWalletAccountId(wallet.id, account.address),
|
|
335
335
|
...account,
|
|
336
336
|
platform: "polkadot",
|
|
337
337
|
walletName: wallet.name,
|
|
@@ -349,7 +349,7 @@ var getWalletAccounts$2 = (wallet) => {
|
|
|
349
349
|
var polkadotAccounts$ = new import_rxjs5.Observable(
|
|
350
350
|
(subscriber) => {
|
|
351
351
|
const sub = polkadotWallets$.pipe(
|
|
352
|
-
(0, import_rxjs5.map)((wallets) => wallets.filter((w) => w.
|
|
352
|
+
(0, import_rxjs5.map)((wallets) => wallets.filter((w) => w.isConnected)),
|
|
353
353
|
(0, import_rxjs5.switchMap)(
|
|
354
354
|
(wallets) => wallets.length ? (0, import_rxjs5.combineLatest)(wallets.map(getWalletAccounts$2)) : (0, import_rxjs5.of)([])
|
|
355
355
|
),
|
|
@@ -421,7 +421,7 @@ var getWallets$ = (config) => {
|
|
|
421
421
|
),
|
|
422
422
|
(0, import_rxjs7.distinct)((w) => w.id)
|
|
423
423
|
).subscribe(async (wallet) => {
|
|
424
|
-
if (wallet.
|
|
424
|
+
if (wallet.isConnected) {
|
|
425
425
|
console.warn("Wallet %s already connected", wallet.id);
|
|
426
426
|
return;
|
|
427
427
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/api/kheopskit.ts","../src/api/accounts.ts","../src/utils/createStore.ts","../src/utils/isEthereumAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/AccountId.ts","../src/utils/isWalletPlatform.ts","../src/api/ethereum/accounts.ts","../src/api/store.ts","../src/utils/WalletId.ts","../src/api/ethereum/wallets.ts","../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/config.ts","../src/api/wallets.ts"],"sourcesContent":["export * from \"./api\";\n\nexport type { KheopskitConfig } from \"./api/types\";\n","import { combineLatest, map, Observable, shareReplay } from \"rxjs\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport type { KheopskitConfig, Wallet, WalletAccount } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig } from \"./types\";\n\nexport const getKheopskit$ = (config: KheopskitConfig) => {\n const c = resolveConfig(config);\n\n return new Observable<{ wallets: Wallet[]; accounts: WalletAccount[] }>(\n (subscriber) => {\n const subscription = combineLatest([getWallets$(c), getAccounts$(c)])\n .pipe(map(([wallets, accounts]) => ({ wallets, accounts })))\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n ).pipe(shareReplay({ bufferSize: 1, refCount: true }));\n};\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumAccounts$ } from \"./ethereum/accounts\";\nimport { polkadotAccounts$ } from \"./polkadot/accounts\";\nimport type { WalletAccount } from \"./types\";\n\nexport const getAccounts$ = (config: ResolvedConfig) => {\n return new Observable<WalletAccount[]>((subscriber) => {\n const observables = config.platforms.map<Observable<WalletAccount[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotAccounts$;\n case \"ethereum\":\n return ethereumAccounts$;\n }\n }\n );\n\n const accounts$ = observables.length\n ? combineLatest(observables).pipe(map((accounts) => accounts.flat()))\n : of([]);\n\n const sub = accounts$.subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import { BehaviorSubject, filter, fromEvent, map } from \"rxjs\";\n\nexport const createStore = <T>(key: string, defaultValue: T) => {\n const subject = new BehaviorSubject<T>(getStoredData(key, defaultValue));\n\n // Cross-tab sync via 'storage' event (won't fire if key is updated from same tab)\n fromEvent<StorageEvent>(window, \"storage\")\n .pipe(\n filter((event) => event.key === key),\n map((event) => parseData(event.newValue, defaultValue))\n )\n .subscribe((newValue) => subject.next(newValue));\n\n const update = (val: T) => {\n setStoredData(key, val);\n subject.next(val);\n };\n\n return {\n observable: subject.asObservable(),\n set: (val: T) => update(val),\n mutate: (transform: (prev: T) => T) =>\n update(transform(subject.getValue())),\n get: () => structuredClone(subject.getValue()),\n };\n};\n\nconst parseData = <T>(str: string | null, defaultValue: T): T => {\n try {\n if (str) return JSON.parse(str);\n } catch {\n // invalid data\n }\n return defaultValue;\n};\n\nconst getStoredData = <T>(key: string, defaultValue: T): T => {\n const str = localStorage.getItem(key);\n return parseData(str, defaultValue);\n};\n\nconst setStoredData = <T>(key: string, val: T) => {\n const str = JSON.stringify(val);\n localStorage.setItem(key, str);\n};\n","export const isEthereumAddress = (address: string): boolean =>\n /^0x[a-fA-F0-9]{40}$/.test(address);\n","import { AccountId, type SS58String } from \"polkadot-api\";\n\nconst accountIdEncoder = AccountId().enc;\n\nexport const isSs58Address = (\n address: SS58String | string\n): address is SS58String => {\n try {\n if (!address) return false;\n accountIdEncoder(address);\n return true;\n } catch (_err) {\n return false;\n }\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n return address.startsWith(\"0x\")\n ? isEthereumAddress(address)\n : isSs58Address(address);\n};\n","import type { SS58String } from \"polkadot-api\";\n\nimport { isValidAddress } from \"./isValidAddress\";\n\nexport type AccountId = string;\n\nexport const getAccountId = (\n walletId: string,\n address: SS58String\n): AccountId => {\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!isValidAddress(address)) throw new Error(\"Invalid address\");\n return `${walletId}::${address}`;\n};\n\nexport const parseAccountId = (accountId: string) => {\n if (!accountId) throw new Error(\"Invalid walletAccountId\");\n const [walletId, address] = accountId.split(\"::\");\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n return { walletId, address };\n};\n","import type { WalletPlatform } from \"@/api/types\";\n\nexport const isWalletPlatform = (\n platform: unknown\n): platform is WalletPlatform =>\n typeof platform === \"string\" &&\n [\"polkadot\", \"ethereum\"].includes(platform as WalletPlatform);\n","import type { EthereumWallet } from \"@/api/types\";\nimport { getAccountId, type AccountId } from \"@/utils\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { getAddress, type EIP1193Provider } from \"viem\";\nimport { ethereumWallets$ } from \"./wallets\";\n\nexport type EthereumAccount = {\n id: AccountId;\n platform: \"ethereum\";\n provider: EIP1193Provider;\n address: `0x${string}`;\n walletName: string;\n walletId: string;\n isWalletDefault: boolean;\n};\n\nconst getWalletAccounts$ = (\n wallet: EthereumWallet\n): Observable<EthereumAccount[]> => {\n if (!wallet.isEnabled) return of([]);\n\n return new Observable<EthereumAccount[]>((subscriber) => {\n const getAccount = (address: string, i: number): EthereumAccount => ({\n id: getAccountId(wallet.id, address),\n platform: \"ethereum\",\n provider: wallet.provider as EIP1193Provider,\n address: getAddress(address),\n walletName: wallet.name,\n walletId: wallet.id,\n isWalletDefault: i === 0,\n });\n\n const listener = (addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n };\n\n // subscribe to changes\n wallet.provider.on(\"accountsChanged\", listener);\n\n // initial value\n wallet.provider\n .request({ method: \"eth_accounts\" })\n .then((addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n })\n .catch((err) => {\n console.error(\"Failed to get accounts\", err);\n subscriber.next([]);\n });\n\n return () => {\n wallet.provider.removeListener(\"accountsChanged\", listener);\n };\n });\n};\n\nexport const ethereumAccounts$ = new Observable<EthereumAccount[]>(\n (subscriber) => {\n const sub = ethereumWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isEnabled)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumAccounts$.subscribe(() => {\n console.count(\"[kheopskit] ethereumAccounts$ emit\");\n});\n","import { createStore } from \"@/utils/createStore\";\nimport type { KheopskitStoreData } from \"./types\";\nimport { uniq } from \"lodash\";\nimport { parseWalletId, type WalletId } from \"@/utils/WalletId\";\n\nconst LOCAL_STORAGE_KEY = \"kheopskit\";\n\nconst DEFAULT_SETTINGS: KheopskitStoreData = {};\n\nconst storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);\n\nexport const addEnabledWalletId = (walletId: WalletId) => {\n parseWalletId(walletId); // validate walletId\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq((prev.autoReconnect ?? []).concat(walletId)),\n }));\n};\n\nexport const removeEnabledWalletId = (walletId: WalletId) => {\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq(\n (prev.autoReconnect ?? []).filter((id) => id !== walletId)\n ),\n }));\n};\n\nexport const store = {\n observable: storage.observable,\n addEnabledWalletId,\n removeEnabledWalletId,\n};\n","import type { WalletPlatform } from \"@/api/types\";\nimport { isWalletPlatform } from \"./isWalletPlatform\";\n\nexport type WalletId = string;\n\nexport const getWalletId = (\n platform: WalletPlatform,\n identifier: string\n): WalletId => {\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid name\");\n return `${platform}:${identifier}`;\n};\n\nexport const parseWalletId = (walletId: string) => {\n if (!walletId) throw new Error(\"Invalid walletId\");\n const [platform, identifier] = walletId.split(\":\");\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid address\");\n return { platform, identifier };\n};\n","import { store } from \"@/api/store\";\nimport type { EthereumWallet } from \"@/api/types\";\nimport { getWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { createStore, type EIP6963ProviderDetail } from \"mipd\";\nimport {\n BehaviorSubject,\n combineLatest,\n map,\n Observable,\n shareReplay,\n} from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\n\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n (subscriber) => {\n const store = createStore();\n\n const unsubscribe = store.subscribe((providerDetails) => {\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n });\n\n const providerDetails = store.getProviders();\n\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n return () => {\n unsubscribe();\n store.destroy();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nprovidersDetails$.subscribe(() => {\n console.count(\"[kheopskit] providers$ emit\");\n});\n\nexport const ethereumWallets$ = new Observable<EthereumWallet[]>(\n (subscriber) => {\n const enabledWalletIds$ = new BehaviorSubject<Set<WalletId>>(new Set());\n\n const connectWallet = async (\n walletId: WalletId,\n provider: EIP1193Provider\n ) => {\n if (enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n\n provider.request({\n method: \"eth_requestAccounts\",\n });\n\n const newSet = new Set(enabledWalletIds$.value);\n newSet.add(walletId);\n enabledWalletIds$.next(newSet);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnectWallet = async (\n walletId: WalletId,\n _provider: EIP1193Provider\n ) => {\n if (!enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n const newSet = new Set(enabledWalletIds$.value);\n newSet.delete(walletId);\n enabledWalletIds$.next(newSet);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const sub = combineLatest([providersDetails$, enabledWalletIds$])\n .pipe(\n map(([providerDetails, enabledWalletIds]) => {\n return providerDetails.map((pd): EthereumWallet => {\n const walletId = getWalletId(\"ethereum\", pd.info.rdns);\n const provider = pd.provider as EIP1193Provider;\n\n return {\n platform: \"ethereum\",\n id: walletId,\n name: pd.info.name,\n icon: pd.info.icon,\n provider,\n isEnabled: enabledWalletIds.has(walletId),\n providerId: pd.info.rdns,\n connect: () => connectWallet(walletId, provider),\n disconnect: () => disconnectWallet(walletId, provider),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumWallets$.subscribe(() => {\n console.count(\"[kheopskit] ethereumWallets$ emit\");\n});\n","import type { PolkadotWallet } from \"@/api/types\";\nimport { getAccountId, type AccountId } from \"@/utils\";\nimport type { InjectedPolkadotAccount } from \"polkadot-api/pjs-signer\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { polkadotWallets$ } from \"./wallets\";\n\nexport type PolkadotAccount = InjectedPolkadotAccount & {\n id: AccountId;\n platform: \"polkadot\";\n walletName: string;\n walletId: string;\n};\n\nconst getWalletAccounts$ = (\n wallet: PolkadotWallet\n): Observable<PolkadotAccount[]> => {\n if (!wallet.isEnabled) return of([]);\n\n return new Observable<PolkadotAccount[]>((subscriber) => {\n const getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n id: getAccountId(wallet.id, account.address),\n ...account,\n platform: \"polkadot\",\n walletName: wallet.name,\n walletId: wallet.id,\n });\n\n // subscribe to changes\n const unsubscribe = wallet.extension.subscribe((accounts) => {\n subscriber.next(accounts.map(getAccount));\n });\n\n // initial value\n subscriber.next(wallet.extension.getAccounts().map(getAccount));\n\n return () => {\n return unsubscribe();\n };\n });\n};\n\nexport const polkadotAccounts$ = new Observable<PolkadotAccount[]>(\n (subscriber) => {\n const sub = polkadotWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isEnabled)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\npolkadotAccounts$.subscribe(() => {\n console.count(\"[kheopskit] polkadotAccounts$ emit\");\n});\n","import { store } from \"@/api/store\";\nimport type { PolkadotWallet } from \"@/api/types\";\nimport { getWalletId, parseWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { isEqual } from \"lodash\";\nimport {\n connectInjectedExtension,\n getInjectedExtensions,\n type InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport {\n BehaviorSubject,\n combineLatest,\n distinctUntilChanged,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n timer,\n} from \"rxjs\";\n\nconst getInjectedWalletsIds = () =>\n getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\nconst polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(\n (subscriber) => {\n const enabledExtensions$ = new BehaviorSubject<\n Map<WalletId, InjectedExtension>\n >(new Map());\n\n const connect = async (walletId: WalletId) => {\n if (enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n const { identifier } = parseWalletId(walletId);\n const extension = await connectInjectedExtension(identifier);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.set(walletId, extension);\n enabledExtensions$.next(newMap);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnect = (walletId: WalletId) => {\n if (!enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.delete(walletId);\n enabledExtensions$.next(newMap);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const walletIds$ = of(0, 200, 500, 1000) // poll for wallets that register after page load\n .pipe(\n mergeMap((time) => timer(time)),\n map(() => getInjectedWalletsIds()),\n distinctUntilChanged<WalletId[]>(isEqual)\n );\n\n const subscription = combineLatest([walletIds$, enabledExtensions$])\n .pipe(\n map(([walletIds, enabledExtensions]) => {\n return walletIds.map((id): PolkadotWallet => {\n const { identifier } = parseWalletId(id);\n const extension = enabledExtensions.get(id);\n\n return extension\n ? {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isEnabled: true,\n extension,\n disconnect: () => disconnect(id),\n }\n : {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isEnabled: false,\n connect: () => connect(id),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// TODO merge with wallet connect\nexport const polkadotWallets$ = polkadotInjectedWallets$;\n\npolkadotWallets$.subscribe(() => {\n console.count(\"[kheopskit] polkadotWallets$ emit\");\n});\n","import type { KheopskitConfig } from \"./types\";\n\nexport type ResolvedConfig = Required<KheopskitConfig>;\n\nexport const DEFAULT_CONFIG: ResolvedConfig = {\n autoReconnect: true,\n platforms: [\"polkadot\"],\n};\n\nexport const resolveConfig = (config: KheopskitConfig): ResolvedConfig => {\n return Object.assign({}, DEFAULT_CONFIG, config);\n};\n","import {\n combineLatest,\n distinct,\n filter,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n take,\n} from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumWallets$ } from \"./ethereum/wallets\";\nimport { polkadotWallets$ } from \"./polkadot/wallets\";\nimport { store } from \"./store\";\nimport type { Wallet } from \"./types\";\n\n// lock the list of wallets to auto reconnect on first call\nconst autoReconnectWalletIds$ = store.observable.pipe(\n map((s) => s.autoReconnect ?? []),\n take(1),\n shareReplay(1)\n);\n\nexport const getWallets$ = (config: ResolvedConfig) => {\n return new Observable<Wallet[]>((subscriber) => {\n const observables = config.platforms.map<Observable<Wallet[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotWallets$;\n case \"ethereum\":\n return ethereumWallets$;\n }\n }\n );\n\n const wallets$ = observables.length\n ? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n : of([]);\n\n const subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n .pipe(\n filter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n mergeMap(([wallets, walletIds]) =>\n wallets.filter((wallet) => walletIds?.includes(wallet.id))\n ),\n distinct((w) => w.id)\n )\n .subscribe(async (wallet) => {\n if (wallet.isEnabled) {\n console.warn(\"Wallet %s already connected\", wallet.id);\n return;\n }\n\n try {\n await wallet.connect();\n } catch (err) {\n console.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n }\n });\n\n const subWallets = wallets$.subscribe(subscriber);\n\n return () => {\n subAutoReconnect.unsubscribe();\n subWallets.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAA4D;;;ACA5D,IAAAC,eAAgE;;;ACAhE,kBAAwD;AAEjD,IAAM,cAAc,CAAI,KAAa,iBAAoB;AAC9D,QAAM,UAAU,IAAI,4BAAmB,cAAc,KAAK,YAAY,CAAC;AAGvE,6BAAwB,QAAQ,SAAS,EACtC;AAAA,QACC,oBAAO,CAAC,UAAU,MAAM,QAAQ,GAAG;AAAA,QACnC,iBAAI,CAAC,UAAU,UAAU,MAAM,UAAU,YAAY,CAAC;AAAA,EACxD,EACC,UAAU,CAAC,aAAa,QAAQ,KAAK,QAAQ,CAAC;AAEjD,QAAM,SAAS,CAAC,QAAW;AACzB,kBAAc,KAAK,GAAG;AACtB,YAAQ,KAAK,GAAG;AAAA,EAClB;AAEA,SAAO;AAAA,IACL,YAAY,QAAQ,aAAa;AAAA,IACjC,KAAK,CAAC,QAAW,OAAO,GAAG;AAAA,IAC3B,QAAQ,CAAC,cACP,OAAO,UAAU,QAAQ,SAAS,CAAC,CAAC;AAAA,IACtC,KAAK,MAAM,gBAAgB,QAAQ,SAAS,CAAC;AAAA,EAC/C;AACF;AAEA,IAAM,YAAY,CAAI,KAAoB,iBAAuB;AAC/D,MAAI;AACF,QAAI,IAAK,QAAO,KAAK,MAAM,GAAG;AAAA,EAChC,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAEA,IAAM,gBAAgB,CAAI,KAAa,iBAAuB;AAC5D,QAAM,MAAM,aAAa,QAAQ,GAAG;AACpC,SAAO,UAAU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,OAAO,QAAQ;AAAA,MACvB,SAAS,KAAK;AACZ,gBAAQ,MAAM,iCAAiC,OAAO,IAAI,EAAE,IAAI,CAAC;AAAA,MACnE;AAAA,IACF,CAAC;AAEH,UAAM,aAAa,SAAS,UAAU,UAAU;AAEhD,WAAO,MAAM;AACX,uBAAiB,YAAY;AAC7B,iBAAW,YAAY;AAAA,IACzB;AAAA,EACF,CAAC,EAAE,SAAK,0BAAY,EAAE,UAAU,MAAM,YAAY,EAAE,CAAC,CAAC;AACxD;;;Af7DO,IAAM,gBAAgB,CAAC,WAA4B;AACxD,QAAM,IAAI,cAAc,MAAM;AAE9B,SAAO,IAAI;AAAA,IACT,CAAC,eAAe;AACd,YAAM,mBAAe,4BAAc,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EACjE,SAAK,kBAAI,CAAC,CAAC,SAAS,QAAQ,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC,EAC1D,UAAU,UAAU;AAEvB,aAAO,MAAM;AACX,qBAAa,YAAY;AAAA,MAC3B;AAAA,IACF;AAAA,EACF,EAAE,SAAK,0BAAY,EAAE,YAAY,GAAG,UAAU,KAAK,CAAC,CAAC;AACvD;","names":["import_rxjs","import_rxjs","import_rxjs","import_rxjs","store","providerDetails","import_rxjs","import_lodash","import_rxjs","getWalletAccounts$","import_rxjs"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api/kheopskit.ts","../src/api/accounts.ts","../src/utils/createStore.ts","../src/utils/isEthereumAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/AccountId.ts","../src/utils/isWalletPlatform.ts","../src/api/ethereum/accounts.ts","../src/api/store.ts","../src/utils/WalletId.ts","../src/api/ethereum/wallets.ts","../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/config.ts","../src/api/wallets.ts"],"sourcesContent":["export * from \"./api\";\n\nexport type { KheopskitConfig } from \"./api/types\";\n","import { combineLatest, map, Observable, shareReplay } from \"rxjs\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport type { KheopskitConfig, Wallet, WalletAccount } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig } from \"./types\";\n\nexport const getKheopskit$ = (config: KheopskitConfig) => {\n const c = resolveConfig(config);\n\n return new Observable<{ wallets: Wallet[]; accounts: WalletAccount[] }>(\n (subscriber) => {\n const subscription = combineLatest([getWallets$(c), getAccounts$(c)])\n .pipe(map(([wallets, accounts]) => ({ wallets, accounts })))\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n ).pipe(shareReplay({ bufferSize: 1, refCount: true }));\n};\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumAccounts$ } from \"./ethereum/accounts\";\nimport { polkadotAccounts$ } from \"./polkadot/accounts\";\nimport type { WalletAccount } from \"./types\";\n\nexport const getAccounts$ = (config: ResolvedConfig) => {\n return new Observable<WalletAccount[]>((subscriber) => {\n const observables = config.platforms.map<Observable<WalletAccount[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotAccounts$;\n case \"ethereum\":\n return ethereumAccounts$;\n }\n }\n );\n\n const accounts$ = observables.length\n ? combineLatest(observables).pipe(map((accounts) => accounts.flat()))\n : of([]);\n\n const sub = accounts$.subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import { BehaviorSubject, filter, fromEvent, map } from \"rxjs\";\n\nexport const createStore = <T>(key: string, defaultValue: T) => {\n const subject = new BehaviorSubject<T>(getStoredData(key, defaultValue));\n\n // Cross-tab sync via 'storage' event (won't fire if key is updated from same tab)\n fromEvent<StorageEvent>(window, \"storage\")\n .pipe(\n filter((event) => event.key === key),\n map((event) => parseData(event.newValue, defaultValue))\n )\n .subscribe((newValue) => subject.next(newValue));\n\n const update = (val: T) => {\n setStoredData(key, val);\n subject.next(val);\n };\n\n return {\n observable: subject.asObservable(),\n set: (val: T) => update(val),\n mutate: (transform: (prev: T) => T) =>\n update(transform(subject.getValue())),\n get: () => structuredClone(subject.getValue()),\n };\n};\n\nconst parseData = <T>(str: string | null, defaultValue: T): T => {\n try {\n if (str) return JSON.parse(str);\n } catch {\n // invalid data\n }\n return defaultValue;\n};\n\nconst getStoredData = <T>(key: string, defaultValue: T): T => {\n const str = localStorage.getItem(key);\n return parseData(str, defaultValue);\n};\n\nconst setStoredData = <T>(key: string, val: T) => {\n const str = JSON.stringify(val);\n localStorage.setItem(key, str);\n};\n","export const isEthereumAddress = (address: string): boolean =>\n /^0x[a-fA-F0-9]{40}$/.test(address);\n","import { AccountId, type SS58String } from \"polkadot-api\";\n\nconst accountIdEncoder = AccountId().enc;\n\nexport const isSs58Address = (\n address: SS58String | string\n): address is SS58String => {\n try {\n if (!address) return false;\n accountIdEncoder(address);\n return true;\n } catch (_err) {\n return false;\n }\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n return address.startsWith(\"0x\")\n ? isEthereumAddress(address)\n : isSs58Address(address);\n};\n","import type { SS58String } from \"polkadot-api\";\n\nimport { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n walletId: string,\n address: SS58String\n): WalletAccountId => {\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!isValidAddress(address)) throw new Error(\"Invalid address\");\n return `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n if (!accountId) throw new Error(\"Invalid walletAccountId\");\n const [walletId, address] = accountId.split(\"::\");\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n return { walletId, address };\n};\n","import type { WalletPlatform } from \"@/api/types\";\n\nexport const isWalletPlatform = (\n platform: unknown\n): platform is WalletPlatform =>\n typeof platform === \"string\" &&\n [\"polkadot\", \"ethereum\"].includes(platform as WalletPlatform);\n","import type { EthereumAccount, EthereumWallet } from \"@/api/types\";\nimport { getWalletAccountId } from \"@/utils\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { getAddress, type EIP1193Provider } from \"viem\";\nimport { ethereumWallets$ } from \"./wallets\";\n\nconst getWalletAccounts$ = (\n wallet: EthereumWallet\n): Observable<EthereumAccount[]> => {\n if (!wallet.isConnected) return of([]);\n\n return new Observable<EthereumAccount[]>((subscriber) => {\n const getAccount = (address: string, i: number): EthereumAccount => ({\n id: getWalletAccountId(wallet.id, address),\n platform: \"ethereum\",\n provider: wallet.provider as EIP1193Provider,\n address: getAddress(address),\n walletName: wallet.name,\n walletId: wallet.id,\n isWalletDefault: i === 0,\n });\n\n const listener = (addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n };\n\n // subscribe to changes\n wallet.provider.on(\"accountsChanged\", listener);\n\n // initial value\n wallet.provider\n .request({ method: \"eth_accounts\" })\n .then((addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n })\n .catch((err) => {\n console.error(\"Failed to get accounts\", err);\n subscriber.next([]);\n });\n\n return () => {\n wallet.provider.removeListener(\"accountsChanged\", listener);\n };\n });\n};\n\nexport const ethereumAccounts$ = new Observable<EthereumAccount[]>(\n (subscriber) => {\n const sub = ethereumWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isConnected)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumAccounts$.subscribe(() => {\n console.count(\"[kheopskit] ethereumAccounts$ emit\");\n});\n","import { createStore } from \"@/utils/createStore\";\nimport type { KheopskitStoreData } from \"./types\";\nimport { uniq } from \"lodash\";\nimport { parseWalletId, type WalletId } from \"@/utils/WalletId\";\n\nconst LOCAL_STORAGE_KEY = \"kheopskit\";\n\nconst DEFAULT_SETTINGS: KheopskitStoreData = {};\n\nconst storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);\n\nexport const addEnabledWalletId = (walletId: WalletId) => {\n parseWalletId(walletId); // validate walletId\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq((prev.autoReconnect ?? []).concat(walletId)),\n }));\n};\n\nexport const removeEnabledWalletId = (walletId: WalletId) => {\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq(\n (prev.autoReconnect ?? []).filter((id) => id !== walletId)\n ),\n }));\n};\n\nexport const store = {\n observable: storage.observable,\n addEnabledWalletId,\n removeEnabledWalletId,\n};\n","import type { WalletPlatform } from \"@/api/types\";\nimport { isWalletPlatform } from \"./isWalletPlatform\";\n\nexport type WalletId = string;\n\nexport const getWalletId = (\n platform: WalletPlatform,\n identifier: string\n): WalletId => {\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid name\");\n return `${platform}:${identifier}`;\n};\n\nexport const parseWalletId = (walletId: string) => {\n if (!walletId) throw new Error(\"Invalid walletId\");\n const [platform, identifier] = walletId.split(\":\");\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid address\");\n return { platform, identifier };\n};\n","import { store } from \"@/api/store\";\nimport type { EthereumWallet } from \"@/api/types\";\nimport { getWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { createStore, type EIP6963ProviderDetail } from \"mipd\";\nimport {\n BehaviorSubject,\n combineLatest,\n map,\n Observable,\n shareReplay,\n} from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\n\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n (subscriber) => {\n const store = createStore();\n\n const unsubscribe = store.subscribe((providerDetails) => {\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n });\n\n const providerDetails = store.getProviders();\n\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n return () => {\n unsubscribe();\n store.destroy();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nprovidersDetails$.subscribe(() => {\n console.count(\"[kheopskit] providers$ emit\");\n});\n\nexport const ethereumWallets$ = new Observable<EthereumWallet[]>(\n (subscriber) => {\n const enabledWalletIds$ = new BehaviorSubject<Set<WalletId>>(new Set());\n\n const connectWallet = async (\n walletId: WalletId,\n provider: EIP1193Provider\n ) => {\n if (enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n\n provider.request({\n method: \"eth_requestAccounts\",\n });\n\n const newSet = new Set(enabledWalletIds$.value);\n newSet.add(walletId);\n enabledWalletIds$.next(newSet);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnectWallet = async (\n walletId: WalletId,\n _provider: EIP1193Provider\n ) => {\n if (!enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n const newSet = new Set(enabledWalletIds$.value);\n newSet.delete(walletId);\n enabledWalletIds$.next(newSet);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const sub = combineLatest([providersDetails$, enabledWalletIds$])\n .pipe(\n map(([providerDetails, enabledWalletIds]) => {\n return providerDetails.map((pd): EthereumWallet => {\n const walletId = getWalletId(\"ethereum\", pd.info.rdns);\n const provider = pd.provider as EIP1193Provider;\n\n return {\n platform: \"ethereum\",\n id: walletId,\n name: pd.info.name,\n icon: pd.info.icon,\n provider,\n isConnected: enabledWalletIds.has(walletId),\n providerId: pd.info.rdns,\n connect: () => connectWallet(walletId, provider),\n disconnect: () => disconnectWallet(walletId, provider),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumWallets$.subscribe(() => {\n console.count(\"[kheopskit] ethereumWallets$ emit\");\n});\n","import type { PolkadotAccount, PolkadotWallet } from \"@/api/types\";\nimport { getWalletAccountId } from \"@/utils\";\nimport type { InjectedPolkadotAccount } from \"polkadot-api/pjs-signer\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { polkadotWallets$ } from \"./wallets\";\n\nconst getWalletAccounts$ = (\n wallet: PolkadotWallet\n): Observable<PolkadotAccount[]> => {\n if (!wallet.isConnected) return of([]);\n\n return new Observable<PolkadotAccount[]>((subscriber) => {\n const getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n id: getWalletAccountId(wallet.id, account.address),\n ...account,\n platform: \"polkadot\",\n walletName: wallet.name,\n walletId: wallet.id,\n });\n\n // subscribe to changes\n const unsubscribe = wallet.extension.subscribe((accounts) => {\n subscriber.next(accounts.map(getAccount));\n });\n\n // initial value\n subscriber.next(wallet.extension.getAccounts().map(getAccount));\n\n return () => {\n return unsubscribe();\n };\n });\n};\n\nexport const polkadotAccounts$ = new Observable<PolkadotAccount[]>(\n (subscriber) => {\n const sub = polkadotWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isConnected)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\npolkadotAccounts$.subscribe(() => {\n console.count(\"[kheopskit] polkadotAccounts$ emit\");\n});\n","import { store } from \"@/api/store\";\nimport type { PolkadotWallet } from \"@/api/types\";\nimport { getWalletId, parseWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { isEqual } from \"lodash\";\nimport {\n connectInjectedExtension,\n getInjectedExtensions,\n type InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport {\n BehaviorSubject,\n combineLatest,\n distinctUntilChanged,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n timer,\n} from \"rxjs\";\n\nconst getInjectedWalletsIds = () =>\n getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\nconst polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(\n (subscriber) => {\n const enabledExtensions$ = new BehaviorSubject<\n Map<WalletId, InjectedExtension>\n >(new Map());\n\n const connect = async (walletId: WalletId) => {\n if (enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n const { identifier } = parseWalletId(walletId);\n const extension = await connectInjectedExtension(identifier);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.set(walletId, extension);\n enabledExtensions$.next(newMap);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnect = (walletId: WalletId) => {\n if (!enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.delete(walletId);\n enabledExtensions$.next(newMap);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const walletIds$ = of(0, 200, 500, 1000) // poll for wallets that register after page load\n .pipe(\n mergeMap((time) => timer(time)),\n map(() => getInjectedWalletsIds()),\n distinctUntilChanged<WalletId[]>(isEqual)\n );\n\n const subscription = combineLatest([walletIds$, enabledExtensions$])\n .pipe(\n map(([walletIds, enabledExtensions]) => {\n return walletIds.map((id): PolkadotWallet => {\n const { identifier } = parseWalletId(id);\n const extension = enabledExtensions.get(id);\n\n return extension\n ? {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isConnected: true,\n extension,\n disconnect: () => disconnect(id),\n }\n : {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isConnected: false,\n connect: () => connect(id),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// TODO merge with wallet connect\nexport const polkadotWallets$ = polkadotInjectedWallets$;\n\npolkadotWallets$.subscribe(() => {\n console.count(\"[kheopskit] polkadotWallets$ emit\");\n});\n","import type { KheopskitConfig } from \"./types\";\n\nexport type ResolvedConfig = Required<KheopskitConfig>;\n\nexport const DEFAULT_CONFIG: ResolvedConfig = {\n autoReconnect: true,\n platforms: [\"polkadot\"],\n};\n\nexport const resolveConfig = (config: KheopskitConfig): ResolvedConfig => {\n return Object.assign({}, DEFAULT_CONFIG, config);\n};\n","import {\n combineLatest,\n distinct,\n filter,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n take,\n} from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumWallets$ } from \"./ethereum/wallets\";\nimport { polkadotWallets$ } from \"./polkadot/wallets\";\nimport { store } from \"./store\";\nimport type { Wallet } from \"./types\";\n\n// lock the list of wallets to auto reconnect on first call\nconst autoReconnectWalletIds$ = store.observable.pipe(\n map((s) => s.autoReconnect ?? []),\n take(1),\n shareReplay(1)\n);\n\nexport const getWallets$ = (config: ResolvedConfig) => {\n return new Observable<Wallet[]>((subscriber) => {\n const observables = config.platforms.map<Observable<Wallet[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotWallets$;\n case \"ethereum\":\n return ethereumWallets$;\n }\n }\n );\n\n const wallets$ = observables.length\n ? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n : of([]);\n\n const subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n .pipe(\n filter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n mergeMap(([wallets, walletIds]) =>\n wallets.filter((wallet) => walletIds?.includes(wallet.id))\n ),\n distinct((w) => w.id)\n )\n .subscribe(async (wallet) => {\n if (wallet.isConnected) {\n console.warn(\"Wallet %s already connected\", wallet.id);\n return;\n }\n\n try {\n await wallet.connect();\n } catch (err) {\n console.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n }\n });\n\n const subWallets = wallets$.subscribe(subscriber);\n\n return () => {\n subAutoReconnect.unsubscribe();\n subWallets.unsubscribe();\n };\n }).pipe(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iBAAW,YAAY;AAAA,IACzB;AAAA,EACF,CAAC,EAAE,SAAK,0BAAY,EAAE,UAAU,MAAM,YAAY,EAAE,CAAC,CAAC;AACxD;;;Af7DO,IAAM,gBAAgB,CAAC,WAA4B;AACxD,QAAM,IAAI,cAAc,MAAM;AAE9B,SAAO,IAAI;AAAA,IACT,CAAC,eAAe;AACd,YAAM,mBAAe,4BAAc,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EACjE,SAAK,kBAAI,CAAC,CAAC,SAAS,QAAQ,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC,EAC1D,UAAU,UAAU;AAEvB,aAAO,MAAM;AACX,qBAAa,YAAY;AAAA,MAC3B;AAAA,IACF;AAAA,EACF,EAAE,SAAK,0BAAY,EAAE,YAAY,GAAG,UAAU,KAAK,CAAC,CAAC;AACvD;","names":["import_rxjs","import_rxjs","import_rxjs","import_rxjs","store","providerDetails","import_rxjs","import_lodash","import_rxjs","getWalletAccounts$","import_rxjs"]}
|
package/dist/index.mjs
CHANGED
|
@@ -61,7 +61,7 @@ var isValidAddress = (address) => {
|
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
// src/utils/AccountId.ts
|
|
64
|
-
var
|
|
64
|
+
var getWalletAccountId = (walletId, address) => {
|
|
65
65
|
if (!walletId) throw new Error("Missing walletId");
|
|
66
66
|
if (!isValidAddress(address)) throw new Error("Invalid address");
|
|
67
67
|
return `${walletId}::${address}`;
|
|
@@ -182,7 +182,7 @@ var ethereumWallets$ = new Observable(
|
|
|
182
182
|
name: pd.info.name,
|
|
183
183
|
icon: pd.info.icon,
|
|
184
184
|
provider,
|
|
185
|
-
|
|
185
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
186
186
|
providerId: pd.info.rdns,
|
|
187
187
|
connect: () => connectWallet(walletId, provider),
|
|
188
188
|
disconnect: () => disconnectWallet(walletId, provider)
|
|
@@ -201,10 +201,10 @@ ethereumWallets$.subscribe(() => {
|
|
|
201
201
|
|
|
202
202
|
// src/api/ethereum/accounts.ts
|
|
203
203
|
var getWalletAccounts$ = (wallet) => {
|
|
204
|
-
if (!wallet.
|
|
204
|
+
if (!wallet.isConnected) return of([]);
|
|
205
205
|
return new Observable2((subscriber) => {
|
|
206
206
|
const getAccount = (address, i) => ({
|
|
207
|
-
id:
|
|
207
|
+
id: getWalletAccountId(wallet.id, address),
|
|
208
208
|
platform: "ethereum",
|
|
209
209
|
provider: wallet.provider,
|
|
210
210
|
address: getAddress(address),
|
|
@@ -230,7 +230,7 @@ var getWalletAccounts$ = (wallet) => {
|
|
|
230
230
|
var ethereumAccounts$ = new Observable2(
|
|
231
231
|
(subscriber) => {
|
|
232
232
|
const sub = ethereumWallets$.pipe(
|
|
233
|
-
map3((wallets) => wallets.filter((w) => w.
|
|
233
|
+
map3((wallets) => wallets.filter((w) => w.isConnected)),
|
|
234
234
|
switchMap(
|
|
235
235
|
(wallets) => wallets.length ? combineLatest2(wallets.map(getWalletAccounts$)) : of([])
|
|
236
236
|
),
|
|
@@ -309,7 +309,7 @@ var polkadotInjectedWallets$ = new Observable3(
|
|
|
309
309
|
platform: "polkadot",
|
|
310
310
|
name: identifier,
|
|
311
311
|
extensionId: identifier,
|
|
312
|
-
|
|
312
|
+
isConnected: true,
|
|
313
313
|
extension,
|
|
314
314
|
disconnect: () => disconnect(id)
|
|
315
315
|
} : {
|
|
@@ -317,7 +317,7 @@ var polkadotInjectedWallets$ = new Observable3(
|
|
|
317
317
|
platform: "polkadot",
|
|
318
318
|
name: identifier,
|
|
319
319
|
extensionId: identifier,
|
|
320
|
-
|
|
320
|
+
isConnected: false,
|
|
321
321
|
connect: () => connect(id)
|
|
322
322
|
};
|
|
323
323
|
});
|
|
@@ -335,10 +335,10 @@ polkadotWallets$.subscribe(() => {
|
|
|
335
335
|
|
|
336
336
|
// src/api/polkadot/accounts.ts
|
|
337
337
|
var getWalletAccounts$2 = (wallet) => {
|
|
338
|
-
if (!wallet.
|
|
338
|
+
if (!wallet.isConnected) return of3([]);
|
|
339
339
|
return new Observable4((subscriber) => {
|
|
340
340
|
const getAccount = (account) => ({
|
|
341
|
-
id:
|
|
341
|
+
id: getWalletAccountId(wallet.id, account.address),
|
|
342
342
|
...account,
|
|
343
343
|
platform: "polkadot",
|
|
344
344
|
walletName: wallet.name,
|
|
@@ -356,7 +356,7 @@ var getWalletAccounts$2 = (wallet) => {
|
|
|
356
356
|
var polkadotAccounts$ = new Observable4(
|
|
357
357
|
(subscriber) => {
|
|
358
358
|
const sub = polkadotWallets$.pipe(
|
|
359
|
-
map5((wallets) => wallets.filter((w) => w.
|
|
359
|
+
map5((wallets) => wallets.filter((w) => w.isConnected)),
|
|
360
360
|
switchMap2(
|
|
361
361
|
(wallets) => wallets.length ? combineLatest4(wallets.map(getWalletAccounts$2)) : of3([])
|
|
362
362
|
),
|
|
@@ -438,7 +438,7 @@ var getWallets$ = (config) => {
|
|
|
438
438
|
),
|
|
439
439
|
distinct((w) => w.id)
|
|
440
440
|
).subscribe(async (wallet) => {
|
|
441
|
-
if (wallet.
|
|
441
|
+
if (wallet.isConnected) {
|
|
442
442
|
console.warn("Wallet %s already connected", wallet.id);
|
|
443
443
|
return;
|
|
444
444
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/api/kheopskit.ts","../src/api/accounts.ts","../src/utils/createStore.ts","../src/utils/isEthereumAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/AccountId.ts","../src/utils/isWalletPlatform.ts","../src/api/ethereum/accounts.ts","../src/api/store.ts","../src/utils/WalletId.ts","../src/api/ethereum/wallets.ts","../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/config.ts","../src/api/wallets.ts"],"sourcesContent":["import { combineLatest, map, Observable, shareReplay } from \"rxjs\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport type { KheopskitConfig, Wallet, WalletAccount } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig } from \"./types\";\n\nexport const getKheopskit$ = (config: KheopskitConfig) => {\n const c = resolveConfig(config);\n\n return new Observable<{ wallets: Wallet[]; accounts: WalletAccount[] }>(\n (subscriber) => {\n const subscription = combineLatest([getWallets$(c), getAccounts$(c)])\n .pipe(map(([wallets, accounts]) => ({ wallets, accounts })))\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n ).pipe(shareReplay({ bufferSize: 1, refCount: true }));\n};\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumAccounts$ } from \"./ethereum/accounts\";\nimport { polkadotAccounts$ } from \"./polkadot/accounts\";\nimport type { WalletAccount } from \"./types\";\n\nexport const getAccounts$ = (config: ResolvedConfig) => {\n return new Observable<WalletAccount[]>((subscriber) => {\n const observables = config.platforms.map<Observable<WalletAccount[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotAccounts$;\n case \"ethereum\":\n return ethereumAccounts$;\n }\n }\n );\n\n const accounts$ = observables.length\n ? combineLatest(observables).pipe(map((accounts) => accounts.flat()))\n : of([]);\n\n const sub = accounts$.subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import { BehaviorSubject, filter, fromEvent, map } from \"rxjs\";\n\nexport const createStore = <T>(key: string, defaultValue: T) => {\n const subject = new BehaviorSubject<T>(getStoredData(key, defaultValue));\n\n // Cross-tab sync via 'storage' event (won't fire if key is updated from same tab)\n fromEvent<StorageEvent>(window, \"storage\")\n .pipe(\n filter((event) => event.key === key),\n map((event) => parseData(event.newValue, defaultValue))\n )\n .subscribe((newValue) => subject.next(newValue));\n\n const update = (val: T) => {\n setStoredData(key, val);\n subject.next(val);\n };\n\n return {\n observable: subject.asObservable(),\n set: (val: T) => update(val),\n mutate: (transform: (prev: T) => T) =>\n update(transform(subject.getValue())),\n get: () => structuredClone(subject.getValue()),\n };\n};\n\nconst parseData = <T>(str: string | null, defaultValue: T): T => {\n try {\n if (str) return JSON.parse(str);\n } catch {\n // invalid data\n }\n return defaultValue;\n};\n\nconst getStoredData = <T>(key: string, defaultValue: T): T => {\n const str = localStorage.getItem(key);\n return parseData(str, defaultValue);\n};\n\nconst setStoredData = <T>(key: string, val: T) => {\n const str = JSON.stringify(val);\n localStorage.setItem(key, str);\n};\n","export const isEthereumAddress = (address: string): boolean =>\n /^0x[a-fA-F0-9]{40}$/.test(address);\n","import { AccountId, type SS58String } from \"polkadot-api\";\n\nconst accountIdEncoder = AccountId().enc;\n\nexport const isSs58Address = (\n address: SS58String | string\n): address is SS58String => {\n try {\n if (!address) return false;\n accountIdEncoder(address);\n return true;\n } catch (_err) {\n return false;\n }\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n return address.startsWith(\"0x\")\n ? isEthereumAddress(address)\n : isSs58Address(address);\n};\n","import type { SS58String } from \"polkadot-api\";\n\nimport { isValidAddress } from \"./isValidAddress\";\n\nexport type AccountId = string;\n\nexport const getAccountId = (\n walletId: string,\n address: SS58String\n): AccountId => {\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!isValidAddress(address)) throw new Error(\"Invalid address\");\n return `${walletId}::${address}`;\n};\n\nexport const parseAccountId = (accountId: string) => {\n if (!accountId) throw new Error(\"Invalid walletAccountId\");\n const [walletId, address] = accountId.split(\"::\");\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n return { walletId, address };\n};\n","import type { WalletPlatform } from \"@/api/types\";\n\nexport const isWalletPlatform = (\n platform: unknown\n): platform is WalletPlatform =>\n typeof platform === \"string\" &&\n [\"polkadot\", \"ethereum\"].includes(platform as WalletPlatform);\n","import type { EthereumWallet } from \"@/api/types\";\nimport { getAccountId, type AccountId } from \"@/utils\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { getAddress, type EIP1193Provider } from \"viem\";\nimport { ethereumWallets$ } from \"./wallets\";\n\nexport type EthereumAccount = {\n id: AccountId;\n platform: \"ethereum\";\n provider: EIP1193Provider;\n address: `0x${string}`;\n walletName: string;\n walletId: string;\n isWalletDefault: boolean;\n};\n\nconst getWalletAccounts$ = (\n wallet: EthereumWallet\n): Observable<EthereumAccount[]> => {\n if (!wallet.isEnabled) return of([]);\n\n return new Observable<EthereumAccount[]>((subscriber) => {\n const getAccount = (address: string, i: number): EthereumAccount => ({\n id: getAccountId(wallet.id, address),\n platform: \"ethereum\",\n provider: wallet.provider as EIP1193Provider,\n address: getAddress(address),\n walletName: wallet.name,\n walletId: wallet.id,\n isWalletDefault: i === 0,\n });\n\n const listener = (addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n };\n\n // subscribe to changes\n wallet.provider.on(\"accountsChanged\", listener);\n\n // initial value\n wallet.provider\n .request({ method: \"eth_accounts\" })\n .then((addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n })\n .catch((err) => {\n console.error(\"Failed to get accounts\", err);\n subscriber.next([]);\n });\n\n return () => {\n wallet.provider.removeListener(\"accountsChanged\", listener);\n };\n });\n};\n\nexport const ethereumAccounts$ = new Observable<EthereumAccount[]>(\n (subscriber) => {\n const sub = ethereumWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isEnabled)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumAccounts$.subscribe(() => {\n console.count(\"[kheopskit] ethereumAccounts$ emit\");\n});\n","import { createStore } from \"@/utils/createStore\";\nimport type { KheopskitStoreData } from \"./types\";\nimport { uniq } from \"lodash\";\nimport { parseWalletId, type WalletId } from \"@/utils/WalletId\";\n\nconst LOCAL_STORAGE_KEY = \"kheopskit\";\n\nconst DEFAULT_SETTINGS: KheopskitStoreData = {};\n\nconst storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);\n\nexport const addEnabledWalletId = (walletId: WalletId) => {\n parseWalletId(walletId); // validate walletId\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq((prev.autoReconnect ?? []).concat(walletId)),\n }));\n};\n\nexport const removeEnabledWalletId = (walletId: WalletId) => {\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq(\n (prev.autoReconnect ?? []).filter((id) => id !== walletId)\n ),\n }));\n};\n\nexport const store = {\n observable: storage.observable,\n addEnabledWalletId,\n removeEnabledWalletId,\n};\n","import type { WalletPlatform } from \"@/api/types\";\nimport { isWalletPlatform } from \"./isWalletPlatform\";\n\nexport type WalletId = string;\n\nexport const getWalletId = (\n platform: WalletPlatform,\n identifier: string\n): WalletId => {\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid name\");\n return `${platform}:${identifier}`;\n};\n\nexport const parseWalletId = (walletId: string) => {\n if (!walletId) throw new Error(\"Invalid walletId\");\n const [platform, identifier] = walletId.split(\":\");\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid address\");\n return { platform, identifier };\n};\n","import { store } from \"@/api/store\";\nimport type { EthereumWallet } from \"@/api/types\";\nimport { getWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { createStore, type EIP6963ProviderDetail } from \"mipd\";\nimport {\n BehaviorSubject,\n combineLatest,\n map,\n Observable,\n shareReplay,\n} from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\n\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n (subscriber) => {\n const store = createStore();\n\n const unsubscribe = store.subscribe((providerDetails) => {\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n });\n\n const providerDetails = store.getProviders();\n\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n return () => {\n unsubscribe();\n store.destroy();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nprovidersDetails$.subscribe(() => {\n console.count(\"[kheopskit] providers$ emit\");\n});\n\nexport const ethereumWallets$ = new Observable<EthereumWallet[]>(\n (subscriber) => {\n const enabledWalletIds$ = new BehaviorSubject<Set<WalletId>>(new Set());\n\n const connectWallet = async (\n walletId: WalletId,\n provider: EIP1193Provider\n ) => {\n if (enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n\n provider.request({\n method: \"eth_requestAccounts\",\n });\n\n const newSet = new Set(enabledWalletIds$.value);\n newSet.add(walletId);\n enabledWalletIds$.next(newSet);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnectWallet = async (\n walletId: WalletId,\n _provider: EIP1193Provider\n ) => {\n if (!enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n const newSet = new Set(enabledWalletIds$.value);\n newSet.delete(walletId);\n enabledWalletIds$.next(newSet);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const sub = combineLatest([providersDetails$, enabledWalletIds$])\n .pipe(\n map(([providerDetails, enabledWalletIds]) => {\n return providerDetails.map((pd): EthereumWallet => {\n const walletId = getWalletId(\"ethereum\", pd.info.rdns);\n const provider = pd.provider as EIP1193Provider;\n\n return {\n platform: \"ethereum\",\n id: walletId,\n name: pd.info.name,\n icon: pd.info.icon,\n provider,\n isEnabled: enabledWalletIds.has(walletId),\n providerId: pd.info.rdns,\n connect: () => connectWallet(walletId, provider),\n disconnect: () => disconnectWallet(walletId, provider),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumWallets$.subscribe(() => {\n console.count(\"[kheopskit] ethereumWallets$ emit\");\n});\n","import type { PolkadotWallet } from \"@/api/types\";\nimport { getAccountId, type AccountId } from \"@/utils\";\nimport type { InjectedPolkadotAccount } from \"polkadot-api/pjs-signer\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { polkadotWallets$ } from \"./wallets\";\n\nexport type PolkadotAccount = InjectedPolkadotAccount & {\n id: AccountId;\n platform: \"polkadot\";\n walletName: string;\n walletId: string;\n};\n\nconst getWalletAccounts$ = (\n wallet: PolkadotWallet\n): Observable<PolkadotAccount[]> => {\n if (!wallet.isEnabled) return of([]);\n\n return new Observable<PolkadotAccount[]>((subscriber) => {\n const getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n id: getAccountId(wallet.id, account.address),\n ...account,\n platform: \"polkadot\",\n walletName: wallet.name,\n walletId: wallet.id,\n });\n\n // subscribe to changes\n const unsubscribe = wallet.extension.subscribe((accounts) => {\n subscriber.next(accounts.map(getAccount));\n });\n\n // initial value\n subscriber.next(wallet.extension.getAccounts().map(getAccount));\n\n return () => {\n return unsubscribe();\n };\n });\n};\n\nexport const polkadotAccounts$ = new Observable<PolkadotAccount[]>(\n (subscriber) => {\n const sub = polkadotWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isEnabled)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\npolkadotAccounts$.subscribe(() => {\n console.count(\"[kheopskit] polkadotAccounts$ emit\");\n});\n","import { store } from \"@/api/store\";\nimport type { PolkadotWallet } from \"@/api/types\";\nimport { getWalletId, parseWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { isEqual } from \"lodash\";\nimport {\n connectInjectedExtension,\n getInjectedExtensions,\n type InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport {\n BehaviorSubject,\n combineLatest,\n distinctUntilChanged,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n timer,\n} from \"rxjs\";\n\nconst getInjectedWalletsIds = () =>\n getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\nconst polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(\n (subscriber) => {\n const enabledExtensions$ = new BehaviorSubject<\n Map<WalletId, InjectedExtension>\n >(new Map());\n\n const connect = async (walletId: WalletId) => {\n if (enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n const { identifier } = parseWalletId(walletId);\n const extension = await connectInjectedExtension(identifier);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.set(walletId, extension);\n enabledExtensions$.next(newMap);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnect = (walletId: WalletId) => {\n if (!enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.delete(walletId);\n enabledExtensions$.next(newMap);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const walletIds$ = of(0, 200, 500, 1000) // poll for wallets that register after page load\n .pipe(\n mergeMap((time) => timer(time)),\n map(() => getInjectedWalletsIds()),\n distinctUntilChanged<WalletId[]>(isEqual)\n );\n\n const subscription = combineLatest([walletIds$, enabledExtensions$])\n .pipe(\n map(([walletIds, enabledExtensions]) => {\n return walletIds.map((id): PolkadotWallet => {\n const { identifier } = parseWalletId(id);\n const extension = enabledExtensions.get(id);\n\n return extension\n ? {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isEnabled: true,\n extension,\n disconnect: () => disconnect(id),\n }\n : {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isEnabled: false,\n connect: () => connect(id),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// TODO merge with wallet connect\nexport const polkadotWallets$ = polkadotInjectedWallets$;\n\npolkadotWallets$.subscribe(() => {\n console.count(\"[kheopskit] polkadotWallets$ emit\");\n});\n","import type { KheopskitConfig } from \"./types\";\n\nexport type ResolvedConfig = Required<KheopskitConfig>;\n\nexport const DEFAULT_CONFIG: ResolvedConfig = {\n autoReconnect: true,\n platforms: [\"polkadot\"],\n};\n\nexport const resolveConfig = (config: KheopskitConfig): ResolvedConfig => {\n return Object.assign({}, DEFAULT_CONFIG, config);\n};\n","import {\n combineLatest,\n distinct,\n filter,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n take,\n} from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumWallets$ } from \"./ethereum/wallets\";\nimport { polkadotWallets$ } from \"./polkadot/wallets\";\nimport { store } from \"./store\";\nimport type { Wallet } from \"./types\";\n\n// lock the list of wallets to auto reconnect on first call\nconst autoReconnectWalletIds$ = store.observable.pipe(\n map((s) => s.autoReconnect ?? []),\n take(1),\n shareReplay(1)\n);\n\nexport const getWallets$ = (config: ResolvedConfig) => {\n return new Observable<Wallet[]>((subscriber) => {\n const observables = config.platforms.map<Observable<Wallet[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotWallets$;\n case \"ethereum\":\n return ethereumWallets$;\n }\n }\n );\n\n const wallets$ = observables.length\n ? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n : of([]);\n\n const subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n .pipe(\n filter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n mergeMap(([wallets, walletIds]) =>\n wallets.filter((wallet) => walletIds?.includes(wallet.id))\n ),\n distinct((w) => w.id)\n )\n .subscribe(async (wallet) => {\n if (wallet.isEnabled) {\n console.warn(\"Wallet %s already connected\", wallet.id);\n return;\n }\n\n try {\n await wallet.connect();\n } catch (err) {\n console.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n }\n });\n\n const subWallets = wallets$.subscribe(subscriber);\n\n return () => {\n subAutoReconnect.unsubscribe();\n subWallets.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n"],"mappings":";AAAA,SAAS,iBAAAA,gBAAe,OAAAC,MAAK,cAAAC,aAAY,eAAAC,oBAAmB;;;ACA5D,SAAS,iBAAAC,gBAAe,OAAAC,MAAK,cAAAC,aAAY,MAAAC,KAAI,eAAAC,oBAAmB;;;ACAhE,SAAS,iBAAiB,QAAQ,WAAW,WAAW;AAEjD,IAAM,cAAc,CAAI,KAAa,iBAAoB;AAC9D,QAAM,UAAU,IAAI,gBAAmB,cAAc,KAAK,YAAY,CAAC;AAGvE,YAAwB,QAAQ,SAAS,EACtC;AAAA,IACC,OAAO,CAAC,UAAU,MAAM,QAAQ,GAAG;AAAA,IACnC,IAAI,CAAC,UAAU,UAAU,MAAM,UAAU,YAAY,CAAC;AAAA,EACxD,EACC,UAAU,CAAC,aAAa,QAAQ,KAAK,QAAQ,CAAC;AAEjD,QAAM,SAAS,CAAC,QAAW;AACzB,kBAAc,KAAK,GAAG;AACtB,YAAQ,KAAK,GAAG;AAAA,EAClB;AAEA,SAAO;AAAA,IACL,YAAY,QAAQ,aAAa;AAAA,IACjC,KAAK,CAAC,QAAW,OAAO,GAAG;AAAA,IAC3B,QAAQ,CAAC,cACP,OAAO,UAAU,QAAQ,SAAS,CAAC,CAAC;AAAA,IACtC,KAAK,MAAM,gBAAgB,QAAQ,SAAS,CAAC;AAAA,EAC/C;AACF;AAEA,IAAM,YAAY,CAAI,KAAoB,iBAAuB;AAC/D,MAAI;AACF,QAAI,IAAK,QAAO,KAAK,MAAM,GAAG;AAAA,EAChC,QAAQ;AAAA,EAER;AACA,SAAO;AACT;AAEA,IAAM,gBAAgB,CAAI,KAAa,iBAAuB;AAC5D,QAAM,MAAM,aAAa,QAAQ,GAAG;AACpC,SAAO,UAAU,KAAK,YAAY;AACpC;AAEA,IAAM,gBAAgB,CAAI,KAAa,QAAW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YAAY,GAAG,UAAU,KAAK,CAAC,CAAC;AACvD;","names":["combineLatest","map","Observable","shareReplay","combineLatest","map","Observable","of","shareReplay","combineLatest","map","Observable","shareReplay","createStore","BehaviorSubject","map","store","providerDetails","Observable","map","combineLatest","shareReplay","combineLatest","map","Observable","of","shareReplay","switchMap","BehaviorSubject","combineLatest","map","Observable","of","shareReplay","getWalletAccounts$","of","Observable","map","switchMap","combineLatest","shareReplay","Observable","combineLatest","map","of","shareReplay","combineLatest","filter","map","mergeMap","Observable","of","shareReplay","map","shareReplay","Observable","combineLatest","of","filter","mergeMap","Observable","combineLatest","map","shareReplay"]}
|
|
1
|
+
{"version":3,"sources":["../src/api/kheopskit.ts","../src/api/accounts.ts","../src/utils/createStore.ts","../src/utils/isEthereumAddress.ts","../src/utils/isSs58Address.ts","../src/utils/isValidAddress.ts","../src/utils/AccountId.ts","../src/utils/isWalletPlatform.ts","../src/api/ethereum/accounts.ts","../src/api/store.ts","../src/utils/WalletId.ts","../src/api/ethereum/wallets.ts","../src/api/polkadot/accounts.ts","../src/api/polkadot/wallets.ts","../src/api/config.ts","../src/api/wallets.ts"],"sourcesContent":["import { combineLatest, map, Observable, shareReplay } from \"rxjs\";\nimport { getAccounts$ } from \"./accounts\";\nimport { resolveConfig } from \"./config\";\nimport type { KheopskitConfig, Wallet, WalletAccount } from \"./types\";\nimport { getWallets$ } from \"./wallets\";\n\nexport type { KheopskitConfig } from \"./types\";\n\nexport const getKheopskit$ = (config: KheopskitConfig) => {\n const c = resolveConfig(config);\n\n return new Observable<{ wallets: Wallet[]; accounts: WalletAccount[] }>(\n (subscriber) => {\n const subscription = combineLatest([getWallets$(c), getAccounts$(c)])\n .pipe(map(([wallets, accounts]) => ({ wallets, accounts })))\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n ).pipe(shareReplay({ bufferSize: 1, refCount: true }));\n};\n","import { combineLatest, map, Observable, of, shareReplay } from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumAccounts$ } from \"./ethereum/accounts\";\nimport { polkadotAccounts$ } from \"./polkadot/accounts\";\nimport type { WalletAccount } from \"./types\";\n\nexport const getAccounts$ = (config: ResolvedConfig) => {\n return new Observable<WalletAccount[]>((subscriber) => {\n const observables = config.platforms.map<Observable<WalletAccount[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotAccounts$;\n case \"ethereum\":\n return ethereumAccounts$;\n }\n }\n );\n\n const accounts$ = observables.length\n ? combineLatest(observables).pipe(map((accounts) => accounts.flat()))\n : of([]);\n\n const sub = accounts$.subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n","import { BehaviorSubject, filter, fromEvent, map } from \"rxjs\";\n\nexport const createStore = <T>(key: string, defaultValue: T) => {\n const subject = new BehaviorSubject<T>(getStoredData(key, defaultValue));\n\n // Cross-tab sync via 'storage' event (won't fire if key is updated from same tab)\n fromEvent<StorageEvent>(window, \"storage\")\n .pipe(\n filter((event) => event.key === key),\n map((event) => parseData(event.newValue, defaultValue))\n )\n .subscribe((newValue) => subject.next(newValue));\n\n const update = (val: T) => {\n setStoredData(key, val);\n subject.next(val);\n };\n\n return {\n observable: subject.asObservable(),\n set: (val: T) => update(val),\n mutate: (transform: (prev: T) => T) =>\n update(transform(subject.getValue())),\n get: () => structuredClone(subject.getValue()),\n };\n};\n\nconst parseData = <T>(str: string | null, defaultValue: T): T => {\n try {\n if (str) return JSON.parse(str);\n } catch {\n // invalid data\n }\n return defaultValue;\n};\n\nconst getStoredData = <T>(key: string, defaultValue: T): T => {\n const str = localStorage.getItem(key);\n return parseData(str, defaultValue);\n};\n\nconst setStoredData = <T>(key: string, val: T) => {\n const str = JSON.stringify(val);\n localStorage.setItem(key, str);\n};\n","export const isEthereumAddress = (address: string): boolean =>\n /^0x[a-fA-F0-9]{40}$/.test(address);\n","import { AccountId, type SS58String } from \"polkadot-api\";\n\nconst accountIdEncoder = AccountId().enc;\n\nexport const isSs58Address = (\n address: SS58String | string\n): address is SS58String => {\n try {\n if (!address) return false;\n accountIdEncoder(address);\n return true;\n } catch (_err) {\n return false;\n }\n};\n","import { isEthereumAddress } from \"./isEthereumAddress\";\nimport { isSs58Address } from \"./isSs58Address\";\n\nexport const isValidAddress = (address: string): boolean => {\n return address.startsWith(\"0x\")\n ? isEthereumAddress(address)\n : isSs58Address(address);\n};\n","import type { SS58String } from \"polkadot-api\";\n\nimport { isValidAddress } from \"./isValidAddress\";\n\nexport type WalletAccountId = string;\n\nexport const getWalletAccountId = (\n walletId: string,\n address: SS58String\n): WalletAccountId => {\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!isValidAddress(address)) throw new Error(\"Invalid address\");\n return `${walletId}::${address}`;\n};\n\nexport const parseWalletAccountId = (accountId: string) => {\n if (!accountId) throw new Error(\"Invalid walletAccountId\");\n const [walletId, address] = accountId.split(\"::\");\n if (!walletId) throw new Error(\"Missing walletId\");\n if (!address || !isValidAddress(address)) throw new Error(\"Invalid address\");\n return { walletId, address };\n};\n","import type { WalletPlatform } from \"@/api/types\";\n\nexport const isWalletPlatform = (\n platform: unknown\n): platform is WalletPlatform =>\n typeof platform === \"string\" &&\n [\"polkadot\", \"ethereum\"].includes(platform as WalletPlatform);\n","import type { EthereumAccount, EthereumWallet } from \"@/api/types\";\nimport { getWalletAccountId } from \"@/utils\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { getAddress, type EIP1193Provider } from \"viem\";\nimport { ethereumWallets$ } from \"./wallets\";\n\nconst getWalletAccounts$ = (\n wallet: EthereumWallet\n): Observable<EthereumAccount[]> => {\n if (!wallet.isConnected) return of([]);\n\n return new Observable<EthereumAccount[]>((subscriber) => {\n const getAccount = (address: string, i: number): EthereumAccount => ({\n id: getWalletAccountId(wallet.id, address),\n platform: \"ethereum\",\n provider: wallet.provider as EIP1193Provider,\n address: getAddress(address),\n walletName: wallet.name,\n walletId: wallet.id,\n isWalletDefault: i === 0,\n });\n\n const listener = (addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n };\n\n // subscribe to changes\n wallet.provider.on(\"accountsChanged\", listener);\n\n // initial value\n wallet.provider\n .request({ method: \"eth_accounts\" })\n .then((addresses: string[]) => {\n subscriber.next(addresses.map(getAccount));\n })\n .catch((err) => {\n console.error(\"Failed to get accounts\", err);\n subscriber.next([]);\n });\n\n return () => {\n wallet.provider.removeListener(\"accountsChanged\", listener);\n };\n });\n};\n\nexport const ethereumAccounts$ = new Observable<EthereumAccount[]>(\n (subscriber) => {\n const sub = ethereumWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isConnected)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumAccounts$.subscribe(() => {\n console.count(\"[kheopskit] ethereumAccounts$ emit\");\n});\n","import { createStore } from \"@/utils/createStore\";\nimport type { KheopskitStoreData } from \"./types\";\nimport { uniq } from \"lodash\";\nimport { parseWalletId, type WalletId } from \"@/utils/WalletId\";\n\nconst LOCAL_STORAGE_KEY = \"kheopskit\";\n\nconst DEFAULT_SETTINGS: KheopskitStoreData = {};\n\nconst storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);\n\nexport const addEnabledWalletId = (walletId: WalletId) => {\n parseWalletId(walletId); // validate walletId\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq((prev.autoReconnect ?? []).concat(walletId)),\n }));\n};\n\nexport const removeEnabledWalletId = (walletId: WalletId) => {\n storage.mutate((prev) => ({\n ...prev,\n autoReconnect: uniq(\n (prev.autoReconnect ?? []).filter((id) => id !== walletId)\n ),\n }));\n};\n\nexport const store = {\n observable: storage.observable,\n addEnabledWalletId,\n removeEnabledWalletId,\n};\n","import type { WalletPlatform } from \"@/api/types\";\nimport { isWalletPlatform } from \"./isWalletPlatform\";\n\nexport type WalletId = string;\n\nexport const getWalletId = (\n platform: WalletPlatform,\n identifier: string\n): WalletId => {\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid name\");\n return `${platform}:${identifier}`;\n};\n\nexport const parseWalletId = (walletId: string) => {\n if (!walletId) throw new Error(\"Invalid walletId\");\n const [platform, identifier] = walletId.split(\":\");\n if (!isWalletPlatform(platform)) throw new Error(\"Invalid platform\");\n if (!identifier) throw new Error(\"Invalid address\");\n return { platform, identifier };\n};\n","import { store } from \"@/api/store\";\nimport type { EthereumWallet } from \"@/api/types\";\nimport { getWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { createStore, type EIP6963ProviderDetail } from \"mipd\";\nimport {\n BehaviorSubject,\n combineLatest,\n map,\n Observable,\n shareReplay,\n} from \"rxjs\";\nimport type { EIP1193Provider } from \"viem\";\n\nconst providersDetails$ = new Observable<EIP6963ProviderDetail[]>(\n (subscriber) => {\n const store = createStore();\n\n const unsubscribe = store.subscribe((providerDetails) => {\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n });\n\n const providerDetails = store.getProviders();\n\n subscriber.next(providerDetails as EIP6963ProviderDetail[]);\n\n return () => {\n unsubscribe();\n store.destroy();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nprovidersDetails$.subscribe(() => {\n console.count(\"[kheopskit] providers$ emit\");\n});\n\nexport const ethereumWallets$ = new Observable<EthereumWallet[]>(\n (subscriber) => {\n const enabledWalletIds$ = new BehaviorSubject<Set<WalletId>>(new Set());\n\n const connectWallet = async (\n walletId: WalletId,\n provider: EIP1193Provider\n ) => {\n if (enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n\n provider.request({\n method: \"eth_requestAccounts\",\n });\n\n const newSet = new Set(enabledWalletIds$.value);\n newSet.add(walletId);\n enabledWalletIds$.next(newSet);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnectWallet = async (\n walletId: WalletId,\n _provider: EIP1193Provider\n ) => {\n if (!enabledWalletIds$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n const newSet = new Set(enabledWalletIds$.value);\n newSet.delete(walletId);\n enabledWalletIds$.next(newSet);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const sub = combineLatest([providersDetails$, enabledWalletIds$])\n .pipe(\n map(([providerDetails, enabledWalletIds]) => {\n return providerDetails.map((pd): EthereumWallet => {\n const walletId = getWalletId(\"ethereum\", pd.info.rdns);\n const provider = pd.provider as EIP1193Provider;\n\n return {\n platform: \"ethereum\",\n id: walletId,\n name: pd.info.name,\n icon: pd.info.icon,\n provider,\n isConnected: enabledWalletIds.has(walletId),\n providerId: pd.info.rdns,\n connect: () => connectWallet(walletId, provider),\n disconnect: () => disconnectWallet(walletId, provider),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\nethereumWallets$.subscribe(() => {\n console.count(\"[kheopskit] ethereumWallets$ emit\");\n});\n","import type { PolkadotAccount, PolkadotWallet } from \"@/api/types\";\nimport { getWalletAccountId } from \"@/utils\";\nimport type { InjectedPolkadotAccount } from \"polkadot-api/pjs-signer\";\nimport {\n combineLatest,\n map,\n Observable,\n of,\n shareReplay,\n switchMap,\n} from \"rxjs\";\nimport { polkadotWallets$ } from \"./wallets\";\n\nconst getWalletAccounts$ = (\n wallet: PolkadotWallet\n): Observable<PolkadotAccount[]> => {\n if (!wallet.isConnected) return of([]);\n\n return new Observable<PolkadotAccount[]>((subscriber) => {\n const getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({\n id: getWalletAccountId(wallet.id, account.address),\n ...account,\n platform: \"polkadot\",\n walletName: wallet.name,\n walletId: wallet.id,\n });\n\n // subscribe to changes\n const unsubscribe = wallet.extension.subscribe((accounts) => {\n subscriber.next(accounts.map(getAccount));\n });\n\n // initial value\n subscriber.next(wallet.extension.getAccounts().map(getAccount));\n\n return () => {\n return unsubscribe();\n };\n });\n};\n\nexport const polkadotAccounts$ = new Observable<PolkadotAccount[]>(\n (subscriber) => {\n const sub = polkadotWallets$\n .pipe(\n map((wallets) => wallets.filter((w) => w.isConnected)),\n switchMap((wallets) =>\n wallets.length\n ? combineLatest(wallets.map(getWalletAccounts$))\n : of([])\n ),\n map((accounts) => accounts.flat())\n )\n .subscribe(subscriber);\n\n return () => {\n sub.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\npolkadotAccounts$.subscribe(() => {\n console.count(\"[kheopskit] polkadotAccounts$ emit\");\n});\n","import { store } from \"@/api/store\";\nimport type { PolkadotWallet } from \"@/api/types\";\nimport { getWalletId, parseWalletId, type WalletId } from \"@/utils/WalletId\";\nimport { isEqual } from \"lodash\";\nimport {\n connectInjectedExtension,\n getInjectedExtensions,\n type InjectedExtension,\n} from \"polkadot-api/pjs-signer\";\nimport {\n BehaviorSubject,\n combineLatest,\n distinctUntilChanged,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n timer,\n} from \"rxjs\";\n\nconst getInjectedWalletsIds = () =>\n getInjectedExtensions().map((name) => getWalletId(\"polkadot\", name));\n\nconst polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(\n (subscriber) => {\n const enabledExtensions$ = new BehaviorSubject<\n Map<WalletId, InjectedExtension>\n >(new Map());\n\n const connect = async (walletId: WalletId) => {\n if (enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} already connected`);\n const { identifier } = parseWalletId(walletId);\n const extension = await connectInjectedExtension(identifier);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.set(walletId, extension);\n enabledExtensions$.next(newMap);\n\n store.addEnabledWalletId(walletId);\n };\n\n const disconnect = (walletId: WalletId) => {\n if (!enabledExtensions$.value.has(walletId))\n throw new Error(`Extension ${walletId} is not connected`);\n\n const newMap = new Map(enabledExtensions$.value);\n newMap.delete(walletId);\n enabledExtensions$.next(newMap);\n\n store.removeEnabledWalletId(walletId);\n };\n\n const walletIds$ = of(0, 200, 500, 1000) // poll for wallets that register after page load\n .pipe(\n mergeMap((time) => timer(time)),\n map(() => getInjectedWalletsIds()),\n distinctUntilChanged<WalletId[]>(isEqual)\n );\n\n const subscription = combineLatest([walletIds$, enabledExtensions$])\n .pipe(\n map(([walletIds, enabledExtensions]) => {\n return walletIds.map((id): PolkadotWallet => {\n const { identifier } = parseWalletId(id);\n const extension = enabledExtensions.get(id);\n\n return extension\n ? {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isConnected: true,\n extension,\n disconnect: () => disconnect(id),\n }\n : {\n id,\n platform: \"polkadot\",\n name: identifier,\n extensionId: identifier,\n isConnected: false,\n connect: () => connect(id),\n };\n });\n })\n )\n .subscribe(subscriber);\n\n return () => {\n subscription.unsubscribe();\n };\n }\n).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n\n// TODO merge with wallet connect\nexport const polkadotWallets$ = polkadotInjectedWallets$;\n\npolkadotWallets$.subscribe(() => {\n console.count(\"[kheopskit] polkadotWallets$ emit\");\n});\n","import type { KheopskitConfig } from \"./types\";\n\nexport type ResolvedConfig = Required<KheopskitConfig>;\n\nexport const DEFAULT_CONFIG: ResolvedConfig = {\n autoReconnect: true,\n platforms: [\"polkadot\"],\n};\n\nexport const resolveConfig = (config: KheopskitConfig): ResolvedConfig => {\n return Object.assign({}, DEFAULT_CONFIG, config);\n};\n","import {\n combineLatest,\n distinct,\n filter,\n map,\n mergeMap,\n Observable,\n of,\n shareReplay,\n take,\n} from \"rxjs\";\nimport type { ResolvedConfig } from \"./config\";\nimport { ethereumWallets$ } from \"./ethereum/wallets\";\nimport { polkadotWallets$ } from \"./polkadot/wallets\";\nimport { store } from \"./store\";\nimport type { Wallet } from \"./types\";\n\n// lock the list of wallets to auto reconnect on first call\nconst autoReconnectWalletIds$ = store.observable.pipe(\n map((s) => s.autoReconnect ?? []),\n take(1),\n shareReplay(1)\n);\n\nexport const getWallets$ = (config: ResolvedConfig) => {\n return new Observable<Wallet[]>((subscriber) => {\n const observables = config.platforms.map<Observable<Wallet[]>>(\n (platform) => {\n switch (platform) {\n case \"polkadot\":\n return polkadotWallets$;\n case \"ethereum\":\n return ethereumWallets$;\n }\n }\n );\n\n const wallets$ = observables.length\n ? combineLatest(observables).pipe(map((wallets) => wallets.flat()))\n : of([]);\n\n const subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])\n .pipe(\n filter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),\n mergeMap(([wallets, walletIds]) =>\n wallets.filter((wallet) => walletIds?.includes(wallet.id))\n ),\n distinct((w) => w.id)\n )\n .subscribe(async (wallet) => {\n if (wallet.isConnected) {\n console.warn(\"Wallet %s already connected\", wallet.id);\n return;\n }\n\n try {\n await wallet.connect();\n } catch (err) {\n console.error(\"Failed to reconnect wallet %s\", wallet.id, { err });\n }\n });\n\n const subWallets = wallets$.subscribe(subscriber);\n\n return () => {\n subAutoReconnect.unsubscribe();\n subWallets.unsubscribe();\n };\n }).pipe(shareReplay({ refCount: true, bufferSize: 1 }));\n};\n"],"mappings":";AAAA,SAAS,iBAAAA,gBAAe,OAAAC,MAAK,cAAAC,aAAY,eAAAC,oBAAmB;;;ACA5D,SAAS,iBAAAC,gBAAe,OAAAC,MAAK,cAAAC,aAAY,MAAAC,KAAI,eAAAC,oBAAmB;;;ACAhE,SAAS,iBAAiB,QAAQ,WAAW,WAAW;AAEjD,IAAM,cAAc,CAAI,KAAa,iBAAoB;AAC9D,QAAM,UAAU,IAAI,gBAAmB,cAAc,KAAK,YAAY,CAAC;AAGvE,YAAwB,QAAQ,SAAS,EACtC;AAAA,IACC,OAAO,CAAC,UAAU,MAAM,QAAQ,GAAG;AAAA,IACnC,IAAI,CAAC,UAAU,UAAU,MAAM,UAAU,YAAY,CAAC;AAAA,EACxD,EACC,U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Z,gBAAQ,MAAM,iCAAiC,OAAO,IAAI,EAAE,IAAI,CAAC;AAAA,MACnE;AAAA,IACF,CAAC;AAEH,UAAM,aAAa,SAAS,UAAU,UAAU;AAEhD,WAAO,MAAM;AACX,uBAAiB,YAAY;AAC7B,iBAAW,YAAY;AAAA,IACzB;AAAA,EACF,CAAC,EAAE,KAAKL,aAAY,EAAE,UAAU,MAAM,YAAY,EAAE,CAAC,CAAC;AACxD;;;Af7DO,IAAM,gBAAgB,CAAC,WAA4B;AACxD,QAAM,IAAI,cAAc,MAAM;AAE9B,SAAO,IAAIM;AAAA,IACT,CAAC,eAAe;AACd,YAAM,eAAeC,eAAc,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,EACjE,KAAKC,KAAI,CAAC,CAAC,SAAS,QAAQ,OAAO,EAAE,SAAS,SAAS,EAAE,CAAC,EAC1D,UAAU,UAAU;AAEvB,aAAO,MAAM;AACX,qBAAa,YAAY;AAAA,MAC3B;AAAA,IACF;AAAA,EACF,EAAE,KAAKC,aAAY,EAAE,YAAY,GAAG,UAAU,KAAK,CAAC,CAAC;AACvD;","names":["combineLatest","map","Observable","shareReplay","combineLatest","map","Observable","of","shareReplay","combineLatest","map","Observable","shareReplay","createStore","BehaviorSubject","map","store","providerDetails","Observable","map","combineLatest","shareReplay","combineLatest","map","Observable","of","shareReplay","switchMap","BehaviorSubject","combineLatest","map","Observable","of","shareReplay","getWalletAccounts$","of","Observable","map","switchMap","combineLatest","shareReplay","Observable","combineLatest","map","of","shareReplay","combineLatest","filter","map","mergeMap","Observable","of","shareReplay","map","shareReplay","Observable","combineLatest","of","filter","mergeMap","Observable","combineLatest","map","shareReplay"]}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EthereumWallet } from "@/api/types";
|
|
2
|
-
import {
|
|
1
|
+
import type { EthereumAccount, EthereumWallet } from "@/api/types";
|
|
2
|
+
import { getWalletAccountId } from "@/utils";
|
|
3
3
|
import {
|
|
4
4
|
combineLatest,
|
|
5
5
|
map,
|
|
@@ -11,24 +11,14 @@ import {
|
|
|
11
11
|
import { getAddress, type EIP1193Provider } from "viem";
|
|
12
12
|
import { ethereumWallets$ } from "./wallets";
|
|
13
13
|
|
|
14
|
-
export type EthereumAccount = {
|
|
15
|
-
id: AccountId;
|
|
16
|
-
platform: "ethereum";
|
|
17
|
-
provider: EIP1193Provider;
|
|
18
|
-
address: `0x${string}`;
|
|
19
|
-
walletName: string;
|
|
20
|
-
walletId: string;
|
|
21
|
-
isWalletDefault: boolean;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
14
|
const getWalletAccounts$ = (
|
|
25
15
|
wallet: EthereumWallet
|
|
26
16
|
): Observable<EthereumAccount[]> => {
|
|
27
|
-
if (!wallet.
|
|
17
|
+
if (!wallet.isConnected) return of([]);
|
|
28
18
|
|
|
29
19
|
return new Observable<EthereumAccount[]>((subscriber) => {
|
|
30
20
|
const getAccount = (address: string, i: number): EthereumAccount => ({
|
|
31
|
-
id:
|
|
21
|
+
id: getWalletAccountId(wallet.id, address),
|
|
32
22
|
platform: "ethereum",
|
|
33
23
|
provider: wallet.provider as EIP1193Provider,
|
|
34
24
|
address: getAddress(address),
|
|
@@ -65,7 +55,7 @@ export const ethereumAccounts$ = new Observable<EthereumAccount[]>(
|
|
|
65
55
|
(subscriber) => {
|
|
66
56
|
const sub = ethereumWallets$
|
|
67
57
|
.pipe(
|
|
68
|
-
map((wallets) => wallets.filter((w) => w.
|
|
58
|
+
map((wallets) => wallets.filter((w) => w.isConnected)),
|
|
69
59
|
switchMap((wallets) =>
|
|
70
60
|
wallets.length
|
|
71
61
|
? combineLatest(wallets.map(getWalletAccounts$))
|
|
@@ -82,7 +82,7 @@ export const ethereumWallets$ = new Observable<EthereumWallet[]>(
|
|
|
82
82
|
name: pd.info.name,
|
|
83
83
|
icon: pd.info.icon,
|
|
84
84
|
provider,
|
|
85
|
-
|
|
85
|
+
isConnected: enabledWalletIds.has(walletId),
|
|
86
86
|
providerId: pd.info.rdns,
|
|
87
87
|
connect: () => connectWallet(walletId, provider),
|
|
88
88
|
disconnect: () => disconnectWallet(walletId, provider),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PolkadotWallet } from "@/api/types";
|
|
2
|
-
import {
|
|
1
|
+
import type { PolkadotAccount, PolkadotWallet } from "@/api/types";
|
|
2
|
+
import { getWalletAccountId } from "@/utils";
|
|
3
3
|
import type { InjectedPolkadotAccount } from "polkadot-api/pjs-signer";
|
|
4
4
|
import {
|
|
5
5
|
combineLatest,
|
|
@@ -11,21 +11,14 @@ import {
|
|
|
11
11
|
} from "rxjs";
|
|
12
12
|
import { polkadotWallets$ } from "./wallets";
|
|
13
13
|
|
|
14
|
-
export type PolkadotAccount = InjectedPolkadotAccount & {
|
|
15
|
-
id: AccountId;
|
|
16
|
-
platform: "polkadot";
|
|
17
|
-
walletName: string;
|
|
18
|
-
walletId: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
14
|
const getWalletAccounts$ = (
|
|
22
15
|
wallet: PolkadotWallet
|
|
23
16
|
): Observable<PolkadotAccount[]> => {
|
|
24
|
-
if (!wallet.
|
|
17
|
+
if (!wallet.isConnected) return of([]);
|
|
25
18
|
|
|
26
19
|
return new Observable<PolkadotAccount[]>((subscriber) => {
|
|
27
20
|
const getAccount = (account: InjectedPolkadotAccount): PolkadotAccount => ({
|
|
28
|
-
id:
|
|
21
|
+
id: getWalletAccountId(wallet.id, account.address),
|
|
29
22
|
...account,
|
|
30
23
|
platform: "polkadot",
|
|
31
24
|
walletName: wallet.name,
|
|
@@ -50,7 +43,7 @@ export const polkadotAccounts$ = new Observable<PolkadotAccount[]>(
|
|
|
50
43
|
(subscriber) => {
|
|
51
44
|
const sub = polkadotWallets$
|
|
52
45
|
.pipe(
|
|
53
|
-
map((wallets) => wallets.filter((w) => w.
|
|
46
|
+
map((wallets) => wallets.filter((w) => w.isConnected)),
|
|
54
47
|
switchMap((wallets) =>
|
|
55
48
|
wallets.length
|
|
56
49
|
? combineLatest(wallets.map(getWalletAccounts$))
|
|
@@ -72,7 +72,7 @@ const polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(
|
|
|
72
72
|
platform: "polkadot",
|
|
73
73
|
name: identifier,
|
|
74
74
|
extensionId: identifier,
|
|
75
|
-
|
|
75
|
+
isConnected: true,
|
|
76
76
|
extension,
|
|
77
77
|
disconnect: () => disconnect(id),
|
|
78
78
|
}
|
|
@@ -81,7 +81,7 @@ const polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(
|
|
|
81
81
|
platform: "polkadot",
|
|
82
82
|
name: identifier,
|
|
83
83
|
extensionId: identifier,
|
|
84
|
-
|
|
84
|
+
isConnected: false,
|
|
85
85
|
connect: () => connect(id),
|
|
86
86
|
};
|
|
87
87
|
});
|
package/src/api/types.ts
CHANGED
|
@@ -1,45 +1,12 @@
|
|
|
1
1
|
import type { WalletId } from "@/utils/WalletId";
|
|
2
2
|
import type { EIP1193Provider } from "viem";
|
|
3
3
|
import type {
|
|
4
|
-
InjectedAccount,
|
|
5
4
|
InjectedExtension,
|
|
6
|
-
|
|
5
|
+
InjectedPolkadotAccount,
|
|
7
6
|
} from "polkadot-api/pjs-signer";
|
|
8
|
-
import type {
|
|
9
|
-
import type { EthereumAccount } from "./ethereum/accounts";
|
|
10
|
-
|
|
11
|
-
type AccountStorageBase = {
|
|
12
|
-
wallet: string;
|
|
13
|
-
address: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type EthereumAccountStorage = AccountStorageBase & {
|
|
17
|
-
platform: "ethereum";
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type PolkadotAccountStorage = AccountStorageBase & {
|
|
21
|
-
platform: "polkadot";
|
|
22
|
-
name: InjectedAccount["name"];
|
|
23
|
-
type: InjectedAccount["type"]; // required, right?
|
|
24
|
-
genesisHash: InjectedAccount["genesisHash"];
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type AccountStorage = PolkadotAccountStorage | EthereumAccountStorage;
|
|
28
|
-
|
|
29
|
-
export type Account<T extends AccountStorage> = T & {
|
|
30
|
-
id: string;
|
|
31
|
-
signer: T extends PolkadotAccountStorage ? PolkadotSigner : null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export type PlatformData<T extends AccountStorageBase> = {
|
|
35
|
-
enabledExtensionIds: string[];
|
|
36
|
-
accounts: T[];
|
|
37
|
-
defaultAccountId: string | null;
|
|
38
|
-
};
|
|
7
|
+
import type { WalletAccountId } from "@/utils";
|
|
39
8
|
|
|
40
9
|
export type KheopskitStoreData = {
|
|
41
|
-
// polkadot?: PlatformData<PolkadotAccountStorage>;
|
|
42
|
-
// ethereum?: PlatformData<EthereumAccountStorage>;
|
|
43
10
|
autoReconnect?: WalletId[];
|
|
44
11
|
};
|
|
45
12
|
|
|
@@ -53,7 +20,7 @@ export type PolkadotDisabledInjectedWallet = {
|
|
|
53
20
|
platform: "polkadot";
|
|
54
21
|
extensionId: string;
|
|
55
22
|
name: string;
|
|
56
|
-
|
|
23
|
+
isConnected: false;
|
|
57
24
|
connect: () => Promise<void>;
|
|
58
25
|
};
|
|
59
26
|
|
|
@@ -63,7 +30,7 @@ export type PolkadotEnabledInjectedWallet = {
|
|
|
63
30
|
extensionId: string;
|
|
64
31
|
extension: InjectedExtension;
|
|
65
32
|
name: string;
|
|
66
|
-
|
|
33
|
+
isConnected: true;
|
|
67
34
|
disconnect: () => void;
|
|
68
35
|
};
|
|
69
36
|
|
|
@@ -80,7 +47,7 @@ export type EthereumWallet = {
|
|
|
80
47
|
provider: EIP1193Provider;
|
|
81
48
|
name: string;
|
|
82
49
|
icon: string;
|
|
83
|
-
|
|
50
|
+
isConnected: boolean;
|
|
84
51
|
connect: () => Promise<void>;
|
|
85
52
|
disconnect: () => void;
|
|
86
53
|
};
|
|
@@ -89,4 +56,21 @@ export type Wallet = PolkadotWallet | EthereumWallet;
|
|
|
89
56
|
|
|
90
57
|
export type WalletPlatform = Wallet["platform"];
|
|
91
58
|
|
|
59
|
+
export type PolkadotAccount = InjectedPolkadotAccount & {
|
|
60
|
+
id: WalletAccountId;
|
|
61
|
+
platform: "polkadot";
|
|
62
|
+
walletName: string;
|
|
63
|
+
walletId: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type EthereumAccount = {
|
|
67
|
+
id: WalletAccountId;
|
|
68
|
+
platform: "ethereum";
|
|
69
|
+
provider: EIP1193Provider;
|
|
70
|
+
address: `0x${string}`;
|
|
71
|
+
walletName: string;
|
|
72
|
+
walletId: string;
|
|
73
|
+
isWalletDefault: boolean;
|
|
74
|
+
};
|
|
75
|
+
|
|
92
76
|
export type WalletAccount = PolkadotAccount | EthereumAccount;
|
package/src/api/wallets.ts
CHANGED
package/src/utils/AccountId.ts
CHANGED
|
@@ -2,18 +2,18 @@ import type { SS58String } from "polkadot-api";
|
|
|
2
2
|
|
|
3
3
|
import { isValidAddress } from "./isValidAddress";
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type WalletAccountId = string;
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const getWalletAccountId = (
|
|
8
8
|
walletId: string,
|
|
9
9
|
address: SS58String
|
|
10
|
-
):
|
|
10
|
+
): WalletAccountId => {
|
|
11
11
|
if (!walletId) throw new Error("Missing walletId");
|
|
12
12
|
if (!isValidAddress(address)) throw new Error("Invalid address");
|
|
13
13
|
return `${walletId}::${address}`;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const parseWalletAccountId = (accountId: string) => {
|
|
17
17
|
if (!accountId) throw new Error("Invalid walletAccountId");
|
|
18
18
|
const [walletId, address] = accountId.split("::");
|
|
19
19
|
if (!walletId) throw new Error("Missing walletId");
|