@hub3js/core 0.61.1 → 0.61.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/builders/namespace.d.ts +2 -2
  2. package/dist/builders/namespace.d.ts.map +1 -1
  3. package/dist/builders/provider.d.ts +2 -1
  4. package/dist/builders/provider.d.ts.map +1 -1
  5. package/dist/hub/helpers.d.ts +2 -1
  6. package/dist/hub/helpers.d.ts.map +1 -1
  7. package/dist/hub/hub.d.ts +8 -7
  8. package/dist/hub/hub.d.ts.map +1 -1
  9. package/dist/hub/mod.d.ts +2 -2
  10. package/dist/hub/mod.d.ts.map +1 -1
  11. package/dist/hub/namespaces/namespace.d.ts +3 -3
  12. package/dist/hub/namespaces/namespace.d.ts.map +1 -1
  13. package/dist/hub/provider/provider.d.ts +3 -3
  14. package/dist/hub/provider/provider.d.ts.map +1 -1
  15. package/dist/hub/store/events.d.ts +9 -8
  16. package/dist/hub/store/events.d.ts.map +1 -1
  17. package/dist/hub/store/mod.d.ts +1 -1
  18. package/dist/hub/store/mod.d.ts.map +1 -1
  19. package/dist/hub/store/mod.js +1 -1
  20. package/dist/hub/store/mod.js.map +2 -2
  21. package/dist/hub/store/namespaces.d.ts +2 -1
  22. package/dist/hub/store/namespaces.d.ts.map +1 -1
  23. package/dist/hub/store/providers.d.ts +7 -6
  24. package/dist/hub/store/providers.d.ts.map +1 -1
  25. package/dist/hub/store/selectors.d.ts +2 -1
  26. package/dist/hub/store/selectors.d.ts.map +1 -1
  27. package/dist/hub/types.d.ts +1 -0
  28. package/dist/hub/types.d.ts.map +1 -1
  29. package/dist/mod.d.ts +1 -1
  30. package/dist/mod.d.ts.map +1 -1
  31. package/dist/mod.js +1 -1
  32. package/dist/mod.js.map +2 -2
  33. package/package.json +1 -1
  34. package/src/builders/namespace.ts +3 -3
  35. package/src/builders/provider.ts +3 -2
  36. package/src/hub/helpers.ts +3 -1
  37. package/src/hub/hub.ts +9 -8
  38. package/src/hub/mod.ts +8 -2
  39. package/src/hub/namespaces/namespace.ts +3 -2
  40. package/src/hub/provider/provider.ts +3 -3
  41. package/src/hub/store/events.ts +10 -8
  42. package/src/hub/store/mod.ts +2 -0
  43. package/src/hub/store/namespaces.ts +2 -1
  44. package/src/hub/store/providers.ts +8 -7
  45. package/src/hub/store/selectors.ts +2 -1
  46. package/src/hub/types.ts +2 -0
  47. package/src/mod.ts +3 -0
package/src/hub/hub.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { Namespace, State as NamespaceState } from './namespaces/mod.js';
2
2
  import type { Provider, State as ProviderState } from './provider/mod.js';
3
3
  import type { Store } from './store/mod.js';
4
+ import type { WalletType } from './types.js';
4
5
 
5
6
  /**
6
7
  * Hub stores providers with heterogeneous `TNS` shapes. `Provider<TNS>` is
@@ -20,19 +21,19 @@ import type { Store } from './store/mod.js';
20
21
  type AnyProvider = Provider<any>;
21
22
 
22
23
  type HubState = {
23
- [key in string]: ProviderState & {
24
+ [key in WalletType]: ProviderState & {
24
25
  namespaces: NamespaceState[];
25
26
  };
26
27
  };
27
28
 
28
29
  type RunAllResult = {
29
- id: string;
30
+ id: WalletType;
30
31
  provider: unknown;
31
32
  namespaces: unknown[];
32
33
  };
33
34
 
34
35
  type RunAllArgs = {
35
- [providerId: string]: {
36
+ [providerId: WalletType]: {
36
37
  provider?: unknown;
37
38
  namespaces?: {
38
39
  [namespaceId: string]: unknown;
@@ -45,7 +46,7 @@ interface HubOptions {
45
46
  }
46
47
 
47
48
  export class Hub {
48
- #providers = new Map<string, AnyProvider>();
49
+ #providers = new Map<WalletType, AnyProvider>();
49
50
  #options: HubOptions;
50
51
 
51
52
  constructor(options?: HubOptions) {
@@ -103,7 +104,7 @@ export class Hub {
103
104
  return output;
104
105
  }
105
106
 
106
- add(id: string, provider: AnyProvider): this {
107
+ add(id: WalletType, provider: AnyProvider): this {
107
108
  if (this.#options.store) {
108
109
  provider.store(this.#options.store);
109
110
  }
@@ -111,7 +112,7 @@ export class Hub {
111
112
  return this;
112
113
  }
113
114
 
114
- remove(id: string): this {
115
+ remove(id: WalletType): this {
115
116
  const providerToRemove = this.#providers.get(id);
116
117
 
117
118
  if (!providerToRemove) {
@@ -124,11 +125,11 @@ export class Hub {
124
125
  return this;
125
126
  }
126
127
 
127
- get(providerId: string): AnyProvider | undefined {
128
+ get(providerId: WalletType): AnyProvider | undefined {
128
129
  return this.#providers.get(providerId);
129
130
  }
130
131
 
131
- getAll(): Map<string, AnyProvider> {
132
+ getAll(): Map<WalletType, AnyProvider> {
132
133
  return this.#providers;
133
134
  }
134
135
 
package/src/hub/mod.ts CHANGED
@@ -10,7 +10,13 @@ export { Provider } from './provider/mod.js';
10
10
  export type { RegisteredNamespaces } from './provider/mod.js';
11
11
 
12
12
  export { Hub } from './hub.js';
13
- export type { Store, State, ProviderMetadata } from './store/mod.js';
13
+ export type {
14
+ Store,
15
+ State,
16
+ ProviderMetadata,
17
+ NamespacesProperty,
18
+ DerivationPathProperty,
19
+ } from './store/mod.js';
14
20
  export {
15
21
  createStore,
16
22
  guessProviderStateSelector,
@@ -18,4 +24,4 @@ export {
18
24
  } from './store/mod.js';
19
25
  export { generateStoreId } from './helpers.js';
20
26
  export type { CanEagerConnect } from './namespaces/types.js';
21
- export type { FunctionWithContext, AnyFunction } from './types.js';
27
+ export type { FunctionWithContext, AnyFunction, WalletType } from './types.js';
@@ -13,6 +13,7 @@ import type {
13
13
  AndFunction,
14
14
  AnyFunction,
15
15
  FunctionWithContext,
16
+ WalletType,
16
17
  } from '../types.js';
17
18
 
18
19
  import { generateStoreId, isAsync } from '../helpers.js';
@@ -42,7 +43,7 @@ class Namespace<T extends Actions<T>> {
42
43
  /** it will be used for `store` and accessing to store by its id mainly. */
43
44
  public readonly namespaceId: string;
44
45
  /** it will be used for `store` and accessing to store by its id mainly. */
45
- public readonly providerId: string;
46
+ public readonly providerId: WalletType;
46
47
 
47
48
  #actions: RegisteredActions<T>;
48
49
  #andOperators: Operators<T> = new Map();
@@ -59,7 +60,7 @@ class Namespace<T extends Actions<T>> {
59
60
 
60
61
  constructor(
61
62
  id: string,
62
- providerId: string,
63
+ providerId: WalletType,
63
64
  options: {
64
65
  store?: Store;
65
66
  configs?: NamespaceConfig;
@@ -8,7 +8,7 @@ import type {
8
8
  } from './types.js';
9
9
  import type { FindProxiedNamespace } from '../../builders/mod.js';
10
10
  import type { ProviderConfig, ProviderInfo, Store } from '../store/mod.js';
11
- import type { AnyFunction, FunctionWithContext } from '../types.js';
11
+ import type { AnyFunction, FunctionWithContext, WalletType } from '../types.js';
12
12
 
13
13
  const VERSION = '1.0';
14
14
 
@@ -23,7 +23,7 @@ const VERSION = '1.0';
23
23
  * to pass via `new Provider<MyNamespaces>(...)`.
24
24
  */
25
25
  export class Provider<TNS = unknown> {
26
- public readonly id: string;
26
+ public readonly id: WalletType;
27
27
  public readonly version = VERSION;
28
28
 
29
29
  #namespaces: RegisteredNamespaces<TNS>;
@@ -33,7 +33,7 @@ export class Provider<TNS = unknown> {
33
33
  #configs: ProviderConfig<TNS>;
34
34
 
35
35
  constructor(
36
- id: string,
36
+ id: WalletType,
37
37
  namespaces: RegisteredNamespaces<TNS>,
38
38
  configs: ProviderConfig<TNS>,
39
39
  options?: {
@@ -1,19 +1,21 @@
1
+ import type { WalletType } from '../types.js';
2
+
1
3
  export type NamespaceDisconnectedEvent = {
2
4
  type: 'namespace_disconnected';
3
- provider: string;
5
+ provider: WalletType;
4
6
  namespace: string;
5
7
  };
6
8
 
7
9
  export type NamespaceConnectedEvent = {
8
10
  type: 'namespace_connected';
9
- provider: string;
11
+ provider: WalletType;
10
12
  namespace: string;
11
13
  accounts: string[];
12
14
  };
13
15
 
14
16
  export type NamespaceSwitchedAccountEvent = {
15
17
  type: 'namespace_account_switched';
16
- provider: string;
18
+ provider: WalletType;
17
19
  namespace: string;
18
20
  accounts: string[];
19
21
  previousAccounts: string[];
@@ -21,7 +23,7 @@ export type NamespaceSwitchedAccountEvent = {
21
23
 
22
24
  export type NamespaceSwitchedNetworkEvent = {
23
25
  type: 'namespace_network_switched';
24
- provider: string;
26
+ provider: WalletType;
25
27
  namespace: string;
26
28
  network: string;
27
29
  previousNetwork: string | null;
@@ -29,23 +31,23 @@ export type NamespaceSwitchedNetworkEvent = {
29
31
 
30
32
  export type ProviderDetectedEvent = {
31
33
  type: 'provider_detected';
32
- provider: string;
34
+ provider: WalletType;
33
35
  };
34
36
 
35
37
  export type ProviderConnectingEvent = {
36
38
  type: 'provider_connecting';
37
- provider: string;
39
+ provider: WalletType;
38
40
  value: boolean;
39
41
  };
40
42
 
41
43
  export type ProviderConnectedEvent = {
42
44
  type: 'provider_connected';
43
- provider: string;
45
+ provider: WalletType;
44
46
  };
45
47
 
46
48
  export type ProviderDisconnectedEvent = {
47
49
  type: 'provider_disconnected';
48
- provider: string;
50
+ provider: WalletType;
49
51
  };
50
52
 
51
53
  export type Event =
@@ -21,6 +21,8 @@ export type {
21
21
  ProviderConfig,
22
22
  ProviderInfo,
23
23
  ProviderProperty,
24
+ NamespacesProperty,
25
+ DerivationPathProperty,
24
26
  } from './providers.js';
25
27
  export type { NamespaceConfig, NamespaceData } from './namespaces.js';
26
28
  export { createStore } from './store.js';
@@ -1,5 +1,6 @@
1
1
  /************ Namespace ************/
2
2
 
3
+ import type { WalletType } from '../types.js';
3
4
  import type { StateCreator } from 'zustand';
4
5
 
5
6
  import { produce } from 'immer';
@@ -26,7 +27,7 @@ export interface NamespaceData {
26
27
  }
27
28
 
28
29
  interface NamespaceInfo {
29
- providerId: string;
30
+ providerId: WalletType;
30
31
  namespaceId: string;
31
32
  }
32
33
 
@@ -1,4 +1,5 @@
1
1
  import type { State as InternalProviderState } from '../provider/mod.js';
2
+ import type { WalletType } from '../types.js';
2
3
  import type { SignerFactory } from 'rango-types';
3
4
  import type { StateCreator } from 'zustand';
4
5
 
@@ -94,20 +95,20 @@ interface ProviderItem {
94
95
 
95
96
  type ProviderState = {
96
97
  events: ConsumableEvents;
97
- list: Record<string, ProviderItem>;
98
+ list: Record<WalletType, ProviderItem>;
98
99
  };
99
100
  interface ProviderActions {
100
- addProvider: (id: string, config: ProviderConfig) => void;
101
- removeProvider: (id: string) => void;
101
+ addProvider: (id: WalletType, config: ProviderConfig) => void;
102
+ removeProvider: (id: WalletType) => void;
102
103
  updateStatus: <K extends keyof ProviderData>(
103
- id: string,
104
+ id: WalletType,
104
105
  key: K,
105
106
  value: ProviderData[K],
106
107
  ) => void;
107
108
 
108
109
  _produceEventsWhenUpdatingStatus: <K extends keyof ProviderData>(
109
110
  provider: ProviderItem,
110
- id: string,
111
+ id: WalletType,
111
112
  key: K,
112
113
  value: ProviderData[K],
113
114
  ) => void;
@@ -118,7 +119,7 @@ interface ProviderSelectors {
118
119
  * Provider has a limited state to itself, to be compatible with legacy, we try to produce same object as legacy
119
120
  * which includes namespace state as well.
120
121
  */
121
- guessNamespacesState: (id: string) => InternalProviderState;
122
+ guessNamespacesState: (id: WalletType) => InternalProviderState;
122
123
  }
123
124
 
124
125
  export type ProviderStore = ProviderState & ProviderActions & ProviderSelectors;
@@ -164,7 +165,7 @@ const providersStore: ProvidersStateCreator = (set, get) => ({
164
165
  }),
165
166
  );
166
167
  },
167
- guessNamespacesState: (providerId: string): InternalProviderState => {
168
+ guessNamespacesState: (providerId: WalletType): InternalProviderState => {
168
169
  return guessProviderStateSelector(get(), providerId);
169
170
  },
170
171
 
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { State } from '../mod.js';
8
8
  import type { State as InternalProviderState } from '../provider/mod.js';
9
+ import type { WalletType } from '../types.js';
9
10
 
10
11
  /**
11
12
  * Legacy provider state includes `connecting` and `connected` values. It hadn't a separation layer for `namespaces`.
@@ -16,7 +17,7 @@ import type { State as InternalProviderState } from '../provider/mod.js';
16
17
  */
17
18
  export function guessProviderStateSelector(
18
19
  state: State,
19
- providerId: string,
20
+ providerId: WalletType,
20
21
  ): InternalProviderState {
21
22
  /*
22
23
  * We keep namespaces in a separate branch than providers.
package/src/hub/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export type WalletType = string;
2
+
1
3
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
4
  export type AnyFunction = (...args: any[]) => any;
3
5
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
package/src/mod.ts CHANGED
@@ -4,6 +4,9 @@ export type {
4
4
  Store,
5
5
  State,
6
6
  ProviderMetadata,
7
+ NamespacesProperty,
8
+ DerivationPathProperty,
9
+ WalletType,
7
10
  Subscriber,
8
11
  SubscriberCleanUp,
9
12
  Context,