@kheopskit/core 0.0.1-alpha.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,103 +1,123 @@
1
1
  import { store } from "@/api/store";
2
- import type { PolkadotWallet } from "@/api/types";
3
- import { getWalletId, parseWalletId, type WalletId } from "@/utils/WalletId";
2
+ import type {
3
+ KheopskitConfig,
4
+ PolkadotInjectedWallet,
5
+ PolkadotWallet,
6
+ } from "@/api/types";
7
+ import { type WalletId, getWalletId, parseWalletId } from "@/utils/WalletId";
8
+ import { POLKADOT_EXTENSIONS } from "@/utils/polkadotExtensions";
4
9
  import { isEqual } from "lodash";
5
10
  import {
11
+ type InjectedExtension,
6
12
  connectInjectedExtension,
7
13
  getInjectedExtensions,
8
- type InjectedExtension,
9
14
  } from "polkadot-api/pjs-signer";
10
15
  import {
11
16
  BehaviorSubject,
17
+ Observable,
12
18
  combineLatest,
13
19
  distinctUntilChanged,
14
20
  map,
15
21
  mergeMap,
16
- Observable,
17
22
  of,
18
23
  shareReplay,
19
24
  timer,
20
25
  } from "rxjs";
26
+ import { getAppKitWallets$ } from "../appKit";
21
27
 
22
28
  const getInjectedWalletsIds = () =>
23
29
  getInjectedExtensions().map((name) => getWalletId("polkadot", name));
24
30
 
25
- const polkadotInjectedWallets$ = new Observable<PolkadotWallet[]>(
26
- (subscriber) => {
27
- const enabledExtensions$ = new BehaviorSubject<
28
- Map<WalletId, InjectedExtension>
29
- >(new Map());
31
+ export const polkadotInjectedWallets$ = new Observable<
32
+ PolkadotInjectedWallet[]
33
+ >((subscriber) => {
34
+ const enabledExtensions$ = new BehaviorSubject<
35
+ Map<WalletId, InjectedExtension>
36
+ >(new Map());
30
37
 
31
- const connect = async (walletId: WalletId) => {
32
- if (enabledExtensions$.value.has(walletId))
33
- throw new Error(`Extension ${walletId} already connected`);
34
- const { identifier } = parseWalletId(walletId);
35
- const extension = await connectInjectedExtension(identifier);
38
+ const connect = async (walletId: WalletId) => {
39
+ if (enabledExtensions$.value.has(walletId))
40
+ throw new Error(`Extension ${walletId} already connected`);
41
+ const { identifier } = parseWalletId(walletId);
42
+ const extension = await connectInjectedExtension(identifier);
36
43
 
37
- const newMap = new Map(enabledExtensions$.value);
38
- newMap.set(walletId, extension);
39
- enabledExtensions$.next(newMap);
44
+ const newMap = new Map(enabledExtensions$.value);
45
+ newMap.set(walletId, extension);
46
+ enabledExtensions$.next(newMap);
40
47
 
41
- store.addEnabledWalletId(walletId);
42
- };
48
+ store.addEnabledWalletId(walletId);
49
+ };
43
50
 
44
- const disconnect = (walletId: WalletId) => {
45
- if (!enabledExtensions$.value.has(walletId))
46
- throw new Error(`Extension ${walletId} is not connected`);
51
+ const disconnect = (walletId: WalletId) => {
52
+ if (!enabledExtensions$.value.has(walletId))
53
+ throw new Error(`Extension ${walletId} is not connected`);
47
54
 
48
- const newMap = new Map(enabledExtensions$.value);
49
- newMap.delete(walletId);
50
- enabledExtensions$.next(newMap);
55
+ const newMap = new Map(enabledExtensions$.value);
56
+ newMap.delete(walletId);
57
+ enabledExtensions$.next(newMap);
51
58
 
52
- store.removeEnabledWalletId(walletId);
53
- };
59
+ store.removeEnabledWalletId(walletId);
60
+ };
54
61
 
55
- const walletIds$ = of(0, 200, 500, 1000) // poll for wallets that register after page load
56
- .pipe(
57
- mergeMap((time) => timer(time)),
58
- map(() => getInjectedWalletsIds()),
59
- distinctUntilChanged<WalletId[]>(isEqual)
60
- );
62
+ const walletIds$ = of(0, 200, 500, 1000) // poll for wallets that inject after page load
63
+ .pipe(
64
+ mergeMap((time) => timer(time)),
65
+ map(() => getInjectedWalletsIds()),
66
+ distinctUntilChanged<WalletId[]>(isEqual),
67
+ );
61
68
 
62
- const subscription = combineLatest([walletIds$, enabledExtensions$])
63
- .pipe(
64
- map(([walletIds, enabledExtensions]) => {
65
- return walletIds.map((id): PolkadotWallet => {
66
- const { identifier } = parseWalletId(id);
67
- const extension = enabledExtensions.get(id);
69
+ const subscription = combineLatest([walletIds$, enabledExtensions$])
70
+ .pipe(
71
+ map(([walletIds, enabledExtensions]) => {
72
+ return walletIds.map((id): PolkadotInjectedWallet => {
73
+ const { identifier } = parseWalletId(id);
74
+ const extension = enabledExtensions.get(id);
75
+ const extInfo = POLKADOT_EXTENSIONS[identifier];
76
+
77
+ return {
78
+ id,
79
+ type: "injected",
80
+ platform: "polkadot",
81
+ name: extInfo?.name ?? identifier,
82
+ icon: extInfo?.icon ?? "",
83
+ extensionId: identifier,
84
+ extension,
85
+ isConnected: !!extension,
86
+ connect: () => connect(id),
87
+ disconnect: () => disconnect(id),
88
+ };
89
+ });
90
+ }),
91
+ )
92
+ .subscribe(subscriber);
93
+
94
+ return () => {
95
+ // console.log("Unsubscribing from polkadotInjectedWallets$");
96
+ subscription.unsubscribe();
97
+ };
98
+ }).pipe(
99
+ // logObservable("polkadotInjectedWallets$"),
100
+ shareReplay({ refCount: true, bufferSize: 1 }),
101
+ );
68
102
 
69
- return extension
70
- ? {
71
- id,
72
- platform: "polkadot",
73
- name: identifier,
74
- extensionId: identifier,
75
- isEnabled: true,
76
- extension,
77
- disconnect: () => disconnect(id),
78
- }
79
- : {
80
- id,
81
- platform: "polkadot",
82
- name: identifier,
83
- extensionId: identifier,
84
- isEnabled: false,
85
- connect: () => connect(id),
86
- };
87
- });
88
- })
103
+ export const getPolkadotWallets$ = (config: KheopskitConfig) => {
104
+ return new Observable<PolkadotWallet[]>((subscriber) => {
105
+ const subscription = combineLatest([
106
+ polkadotInjectedWallets$,
107
+ getAppKitWallets$(config)?.pipe(map((w) => w.polkadot)),
108
+ ])
109
+ .pipe(
110
+ map(([injectedWallets, appKitWallet]) =>
111
+ appKitWallet ? [...injectedWallets, appKitWallet] : injectedWallets,
112
+ ),
89
113
  )
90
114
  .subscribe(subscriber);
91
115
 
92
116
  return () => {
93
117
  subscription.unsubscribe();
94
118
  };
95
- }
96
- ).pipe(shareReplay({ refCount: true, bufferSize: 1 }));
97
-
98
- // TODO merge with wallet connect
99
- export const polkadotWallets$ = polkadotInjectedWallets$;
100
-
101
- polkadotWallets$.subscribe(() => {
102
- console.count("[kheopskit] polkadotWallets$ emit");
103
- });
119
+ }).pipe(
120
+ // logObservable("getPolkadotWallets$"),
121
+ shareReplay({ refCount: true, bufferSize: 1 }),
122
+ );
123
+ };
package/src/api/store.ts CHANGED
@@ -1,10 +1,13 @@
1
+ import { type WalletId, parseWalletId } from "@/utils/WalletId";
1
2
  import { createStore } from "@/utils/createStore";
2
- import type { KheopskitStoreData } from "./types";
3
3
  import { uniq } from "lodash";
4
- import { parseWalletId, type WalletId } from "@/utils/WalletId";
5
4
 
6
5
  const LOCAL_STORAGE_KEY = "kheopskit";
7
6
 
7
+ export type KheopskitStoreData = {
8
+ autoReconnect?: WalletId[];
9
+ };
10
+
8
11
  const DEFAULT_SETTINGS: KheopskitStoreData = {};
9
12
 
10
13
  const storage = createStore(LOCAL_STORAGE_KEY, DEFAULT_SETTINGS);
@@ -21,7 +24,7 @@ export const removeEnabledWalletId = (walletId: WalletId) => {
21
24
  storage.mutate((prev) => ({
22
25
  ...prev,
23
26
  autoReconnect: uniq(
24
- (prev.autoReconnect ?? []).filter((id) => id !== walletId)
27
+ (prev.autoReconnect ?? []).filter((id) => id !== walletId),
25
28
  ),
26
29
  }));
27
30
  };
package/src/api/types.ts CHANGED
@@ -1,92 +1,109 @@
1
+ import type { WalletAccountId } from "@/utils";
1
2
  import type { WalletId } from "@/utils/WalletId";
2
- import type { EIP1193Provider } from "viem";
3
+ import type { AppKit } from "@reown/appkit/core";
4
+ import type { AppKitNetwork } from "@reown/appkit/networks";
5
+ import type { Metadata } from "@walletconnect/universal-provider";
3
6
  import type {
4
- InjectedAccount,
5
7
  InjectedExtension,
6
- PolkadotSigner,
8
+ InjectedPolkadotAccount,
7
9
  } from "polkadot-api/pjs-signer";
8
- import type { PolkadotAccount } from "./polkadot/accounts";
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
- };
39
-
40
- export type KheopskitStoreData = {
41
- // polkadot?: PlatformData<PolkadotAccountStorage>;
42
- // ethereum?: PlatformData<EthereumAccountStorage>;
43
- autoReconnect?: WalletId[];
44
- };
10
+ import type {
11
+ Account,
12
+ CustomTransport,
13
+ EIP1193Provider,
14
+ WalletClient,
15
+ } from "viem";
45
16
 
46
17
  export type KheopskitConfig = {
47
- autoReconnect?: boolean;
18
+ autoReconnect: boolean;
48
19
  platforms: WalletPlatform[];
20
+ walletConnect?: {
21
+ projectId: string;
22
+ metadata: Metadata;
23
+ /** Defaults to wss://relay.walletconnect.com */
24
+ relayUrl?: string;
25
+ /**
26
+ * list of CAIP-13 ids of polkadot-sdk chains
27
+ * see https://docs.reown.com/advanced/multichain/polkadot/dapp-integration-guide#walletconnect-code%2Fcomponent-setup
28
+ */
29
+ networks: [AppKitNetwork, ...AppKitNetwork[]];
30
+ };
31
+ debug: boolean;
49
32
  };
50
33
 
51
- export type PolkadotDisabledInjectedWallet = {
34
+ export type PolkadotInjectedWallet = {
52
35
  id: WalletId;
53
36
  platform: "polkadot";
37
+ type: "injected";
54
38
  extensionId: string;
39
+ extension: InjectedExtension | undefined;
55
40
  name: string;
56
- isEnabled: false;
41
+ icon: string;
42
+ isConnected: boolean;
57
43
  connect: () => Promise<void>;
44
+ disconnect: () => void;
58
45
  };
59
46
 
60
- export type PolkadotEnabledInjectedWallet = {
47
+ export type PolkadotAppKitWallet = {
61
48
  id: WalletId;
62
49
  platform: "polkadot";
63
- extensionId: string;
64
- extension: InjectedExtension;
50
+ type: "appKit";
51
+ appKit: AppKit;
65
52
  name: string;
66
- isEnabled: true;
53
+ icon: string;
54
+ isConnected: boolean;
55
+ connect: () => Promise<void>;
67
56
  disconnect: () => void;
68
57
  };
69
58
 
70
- // TODO export type PolkadotWalletConnectWallet = {}
71
-
72
- export type PolkadotWallet =
73
- | PolkadotDisabledInjectedWallet
74
- | PolkadotEnabledInjectedWallet;
59
+ export type PolkadotWallet = PolkadotInjectedWallet | PolkadotAppKitWallet;
75
60
 
76
- export type EthereumWallet = {
61
+ export type EthereumInjectedWallet = {
77
62
  platform: "ethereum";
63
+ type: "injected";
78
64
  id: WalletId;
79
65
  providerId: string;
80
66
  provider: EIP1193Provider;
81
67
  name: string;
82
68
  icon: string;
83
- isEnabled: boolean;
69
+ isConnected: boolean;
70
+ connect: () => Promise<void>;
71
+ disconnect: () => void;
72
+ };
73
+
74
+ export type EthereumAppKitWallet = {
75
+ platform: "ethereum";
76
+ type: "appKit";
77
+ id: WalletId;
78
+ appKit: AppKit;
79
+ name: string;
80
+ icon: string;
81
+ isConnected: boolean;
84
82
  connect: () => Promise<void>;
85
83
  disconnect: () => void;
86
84
  };
87
85
 
86
+ export type EthereumWallet = EthereumInjectedWallet | EthereumAppKitWallet;
87
+
88
88
  export type Wallet = PolkadotWallet | EthereumWallet;
89
89
 
90
90
  export type WalletPlatform = Wallet["platform"];
91
91
 
92
+ export type PolkadotAccount = InjectedPolkadotAccount & {
93
+ id: WalletAccountId;
94
+ platform: "polkadot";
95
+ walletName: string;
96
+ walletId: string;
97
+ };
98
+
99
+ export type EthereumAccount = {
100
+ id: WalletAccountId;
101
+ platform: "ethereum";
102
+ client: WalletClient<CustomTransport, undefined, Account, undefined>; // let consumer knows chain is unknown
103
+ address: `0x${string}`;
104
+ walletName: string;
105
+ walletId: string;
106
+ isWalletDefault: boolean;
107
+ };
108
+
92
109
  export type WalletAccount = PolkadotAccount | EthereumAccount;
@@ -1,54 +1,56 @@
1
+ import { sortWallets } from "@/utils/sortWallets";
1
2
  import {
3
+ Observable,
2
4
  combineLatest,
3
5
  distinct,
4
6
  filter,
5
7
  map,
6
8
  mergeMap,
7
- Observable,
8
9
  of,
9
10
  shareReplay,
10
11
  take,
11
12
  } from "rxjs";
12
- import type { ResolvedConfig } from "./config";
13
- import { ethereumWallets$ } from "./ethereum/wallets";
14
- import { polkadotWallets$ } from "./polkadot/wallets";
13
+ import { getEthereumWallets$ } from "./ethereum/wallets";
14
+ import { getPolkadotWallets$ } from "./polkadot/wallets";
15
15
  import { store } from "./store";
16
- import type { Wallet } from "./types";
16
+ import type { KheopskitConfig, Wallet } from "./types";
17
17
 
18
18
  // lock the list of wallets to auto reconnect on first call
19
19
  const autoReconnectWalletIds$ = store.observable.pipe(
20
20
  map((s) => s.autoReconnect ?? []),
21
21
  take(1),
22
- shareReplay(1)
22
+ shareReplay(1),
23
23
  );
24
24
 
25
- export const getWallets$ = (config: ResolvedConfig) => {
25
+ export const getWallets$ = (config: KheopskitConfig) => {
26
26
  return new Observable<Wallet[]>((subscriber) => {
27
27
  const observables = config.platforms.map<Observable<Wallet[]>>(
28
28
  (platform) => {
29
29
  switch (platform) {
30
30
  case "polkadot":
31
- return polkadotWallets$;
31
+ return getPolkadotWallets$(config);
32
32
  case "ethereum":
33
- return ethereumWallets$;
33
+ return getEthereumWallets$(config);
34
34
  }
35
- }
35
+ },
36
36
  );
37
37
 
38
38
  const wallets$ = observables.length
39
- ? combineLatest(observables).pipe(map((wallets) => wallets.flat()))
39
+ ? combineLatest(observables).pipe(
40
+ map((wallets) => wallets.flat().sort(sortWallets)),
41
+ )
40
42
  : of([]);
41
43
 
42
44
  const subAutoReconnect = combineLatest([wallets$, autoReconnectWalletIds$])
43
45
  .pipe(
44
46
  filter(([, walletIds]) => config.autoReconnect && !!walletIds?.length),
45
47
  mergeMap(([wallets, walletIds]) =>
46
- wallets.filter((wallet) => walletIds?.includes(wallet.id))
48
+ wallets.filter((wallet) => walletIds?.includes(wallet.id)),
47
49
  ),
48
- distinct((w) => w.id)
50
+ distinct((w) => w.id),
49
51
  )
50
52
  .subscribe(async (wallet) => {
51
- if (wallet.isEnabled) {
53
+ if (wallet.isConnected) {
52
54
  console.warn("Wallet %s already connected", wallet.id);
53
55
  return;
54
56
  }
package/src/index.ts CHANGED
@@ -1,3 +1 @@
1
1
  export * from "./api";
2
-
3
- export type { KheopskitConfig } from "./api/types";
@@ -2,18 +2,18 @@ import type { SS58String } from "polkadot-api";
2
2
 
3
3
  import { isValidAddress } from "./isValidAddress";
4
4
 
5
- export type AccountId = string;
5
+ export type WalletAccountId = string;
6
6
 
7
- export const getAccountId = (
7
+ export const getWalletAccountId = (
8
8
  walletId: string,
9
- address: SS58String
10
- ): AccountId => {
9
+ address: SS58String,
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 parseAccountId = (accountId: string) => {
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");
@@ -5,7 +5,7 @@ export type WalletId = string;
5
5
 
6
6
  export const getWalletId = (
7
7
  platform: WalletPlatform,
8
- identifier: string
8
+ identifier: string,
9
9
  ): WalletId => {
10
10
  if (!isWalletPlatform(platform)) throw new Error("Invalid platform");
11
11
  if (!identifier) throw new Error("Invalid name");
@@ -7,7 +7,7 @@ export const createStore = <T>(key: string, defaultValue: T) => {
7
7
  fromEvent<StorageEvent>(window, "storage")
8
8
  .pipe(
9
9
  filter((event) => event.key === key),
10
- map((event) => parseData(event.newValue, defaultValue))
10
+ map((event) => parseData(event.newValue, defaultValue)),
11
11
  )
12
12
  .subscribe((newValue) => subject.next(newValue));
13
13
 
@@ -1,6 +1,7 @@
1
1
  import { isEthereumAddress } from "./isEthereumAddress";
2
2
  import { isSs58Address } from "./isSs58Address";
3
- import type { AccountAddressType } from "./types";
3
+
4
+ export type AccountAddressType = "ss58" | "ethereum";
4
5
 
5
6
  export const getAccountAddressType = (address: string): AccountAddressType => {
6
7
  if (address.startsWith("0x")) {
@@ -0,0 +1,12 @@
1
+ import type { Observable } from "rxjs";
2
+
3
+ const CACHE = new Map<string, Observable<unknown>>();
4
+
5
+ export const getCachedObservable$ = <T, Obs = Observable<T>>(
6
+ key: string,
7
+ create: () => Obs,
8
+ ): Obs => {
9
+ if (!CACHE.has(key)) CACHE.set(key, create() as Observable<unknown>);
10
+
11
+ return CACHE.get(key) as Obs;
12
+ };
@@ -0,0 +1,72 @@
1
+ import { isEqual } from "lodash";
2
+ import {
3
+ BehaviorSubject,
4
+ Observable,
5
+ distinctUntilChanged,
6
+ shareReplay,
7
+ } from "rxjs";
8
+
9
+ import { getCachedObservable$ } from "./getCachedObservable";
10
+
11
+ export type QueryStatus = "loading" | "loaded" | "error";
12
+
13
+ export type QueryResult<
14
+ T,
15
+ S extends QueryStatus = "loading" | "loaded" | "error",
16
+ > = S extends "loading"
17
+ ? { status: "loading"; data: T | undefined; error: undefined }
18
+ : S extends "loaded"
19
+ ? { status: "loaded"; data: T; error: undefined }
20
+ : { status: "error"; data: undefined; error: unknown };
21
+
22
+ type QueryOptions<T> = {
23
+ queryKey: string;
24
+ queryFn: () => Promise<T>;
25
+ defaultValue?: T;
26
+ refreshInterval?: number;
27
+ };
28
+
29
+ export const getQuery$ = <T>({
30
+ queryKey,
31
+ queryFn,
32
+ defaultValue,
33
+ refreshInterval,
34
+ }: QueryOptions<T>): Observable<QueryResult<T>> => {
35
+ return getCachedObservable$(queryKey, () =>
36
+ new Observable<QueryResult<T>>((subscriber) => {
37
+ const result = new BehaviorSubject<QueryResult<T>>({
38
+ status: "loading",
39
+ data: defaultValue,
40
+ error: undefined,
41
+ });
42
+
43
+ // result subscription
44
+ const sub = result
45
+ .pipe(distinctUntilChanged<QueryResult<T>>(isEqual))
46
+ .subscribe(subscriber);
47
+
48
+ let timeout: ReturnType<typeof setTimeout> | undefined = undefined;
49
+
50
+ // fetch result subscription
51
+ const run = () => {
52
+ queryFn()
53
+ .then((data) => {
54
+ result.next({ status: "loaded", data, error: undefined });
55
+ })
56
+ .catch((error) => {
57
+ result.next({ status: "error", data: undefined, error });
58
+ })
59
+ .finally(() => {
60
+ if (refreshInterval) timeout = setTimeout(run, refreshInterval);
61
+ });
62
+ };
63
+
64
+ run();
65
+
66
+ return () => {
67
+ sub.unsubscribe();
68
+ if (timeout) clearTimeout(timeout);
69
+ };
70
+ }).pipe(shareReplay({ refCount: true, bufferSize: 1 })),
71
+ );
72
+ };
@@ -1,12 +1,10 @@
1
1
  // export all modules from this folder, except exports.ts
2
2
  export * from "./createStore";
3
3
  export * from "./getAccountAddressType";
4
- export * from "./AccountId";
4
+ export * from "./WalletAccountId";
5
5
  export * from "./isEthereumAddress";
6
6
  export * from "./isSs58Address";
7
- export * from "./isTruthy";
8
7
  export * from "./isValidAddress";
9
8
  export * from "./sleep";
10
9
  export * from "./throwAfter";
11
- export * from "./types";
12
10
  export * from "./isWalletPlatform";
@@ -1,2 +1,4 @@
1
+ import { isAddress } from "viem";
2
+
1
3
  export const isEthereumAddress = (address: string): boolean =>
2
- /^0x[a-fA-F0-9]{40}$/.test(address);
4
+ isAddress(address);
@@ -3,13 +3,13 @@ import { AccountId, type SS58String } from "polkadot-api";
3
3
  const accountIdEncoder = AccountId().enc;
4
4
 
5
5
  export const isSs58Address = (
6
- address: SS58String | string
6
+ address: SS58String | string,
7
7
  ): address is SS58String => {
8
8
  try {
9
9
  if (!address) return false;
10
10
  accountIdEncoder(address);
11
11
  return true;
12
- } catch (_err) {
12
+ } catch {
13
13
  return false;
14
14
  }
15
15
  };
@@ -1,7 +1,7 @@
1
1
  import type { WalletPlatform } from "@/api/types";
2
2
 
3
3
  export const isWalletPlatform = (
4
- platform: unknown
4
+ platform: unknown,
5
5
  ): platform is WalletPlatform =>
6
6
  typeof platform === "string" &&
7
7
  ["polkadot", "ethereum"].includes(platform as WalletPlatform);
@@ -0,0 +1,21 @@
1
+ import { type MonoTypeOperatorFunction, tap } from "rxjs";
2
+
3
+ type Opts = {
4
+ printValue?: boolean;
5
+ enabled?: boolean;
6
+ };
7
+
8
+ export const logObservable = <T>(
9
+ label: string,
10
+ opts?: Opts,
11
+ ): MonoTypeOperatorFunction<T> =>
12
+ tap((value) => {
13
+ const { printValue = false, enabled = true } = opts || {};
14
+
15
+ if (!label || !enabled) return;
16
+
17
+ const text = `[kheopskit] observable ${label} emit`;
18
+
19
+ if (printValue) console.debug(text, value);
20
+ else console.debug(text);
21
+ });