@rango-dev/wallets-core 0.40.1-next.11 → 0.40.1-next.13

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 (43) hide show
  1. package/dist/hub/store/events.d.ts +54 -0
  2. package/dist/hub/store/events.d.ts.map +1 -0
  3. package/dist/hub/store/extend.d.ts +14 -0
  4. package/dist/hub/store/extend.d.ts.map +1 -0
  5. package/dist/hub/store/mod.d.ts +3 -1
  6. package/dist/hub/store/mod.d.ts.map +1 -1
  7. package/dist/hub/store/mod.js +2 -0
  8. package/dist/hub/store/mod.js.map +7 -0
  9. package/dist/hub/store/namespaces.d.ts +10 -7
  10. package/dist/hub/store/namespaces.d.ts.map +1 -1
  11. package/dist/hub/store/providers.d.ts +9 -5
  12. package/dist/hub/store/providers.d.ts.map +1 -1
  13. package/dist/hub/store/store.d.ts +2 -1
  14. package/dist/hub/store/store.d.ts.map +1 -1
  15. package/dist/legacy/mod.js +1 -1
  16. package/dist/legacy/mod.js.map +2 -2
  17. package/dist/legacy/types.d.ts +18 -15
  18. package/dist/legacy/types.d.ts.map +1 -1
  19. package/dist/legacy/wallet.d.ts +5 -3
  20. package/dist/legacy/wallet.d.ts.map +1 -1
  21. package/dist/mod.js +1 -1
  22. package/dist/mod.js.map +4 -4
  23. package/dist/namespaces/common/mod.js +1 -1
  24. package/dist/namespaces/common/mod.js.map +1 -1
  25. package/dist/namespaces/evm/builders.d.ts.map +1 -1
  26. package/dist/namespaces/evm/mod.js +1 -1
  27. package/dist/namespaces/evm/mod.js.map +3 -3
  28. package/dist/namespaces/solana/builders.d.ts.map +1 -1
  29. package/dist/namespaces/solana/mod.js +1 -1
  30. package/dist/namespaces/solana/mod.js.map +3 -3
  31. package/dist/wallets-core.build.json +1 -1
  32. package/package.json +6 -2
  33. package/src/hub/store/events.ts +89 -0
  34. package/src/hub/store/extend.ts +125 -0
  35. package/src/hub/store/mod.ts +14 -1
  36. package/src/hub/store/namespaces.ts +102 -19
  37. package/src/hub/store/providers.ts +33 -9
  38. package/src/hub/store/store.test.ts +1 -1
  39. package/src/hub/store/store.ts +6 -2
  40. package/src/legacy/types.ts +24 -17
  41. package/src/legacy/wallet.ts +12 -6
  42. package/src/namespaces/evm/builders.ts +6 -2
  43. package/src/namespaces/solana/builders.ts +6 -2
@@ -0,0 +1,125 @@
1
+ import type {
2
+ Event,
3
+ ProviderConnectedEvent,
4
+ ProviderConnectingEvent,
5
+ ProviderDisconnectedEvent,
6
+ } from './events.js';
7
+ import type { RawStore, State } from './store.js';
8
+
9
+ import { guessProviderStateSelector } from './selectors.js';
10
+
11
+ export interface Store extends Omit<RawStore, 'subscribe'> {
12
+ subscribe(listener: (event: Event, state: State, prevState: State) => void): {
13
+ flushEvents(): void;
14
+ };
15
+ }
16
+
17
+ /**
18
+ * Zustand's store provides a set of built-in functionalities,
19
+ * but it may not meet all our requirements.
20
+ * This function modifies the interface and adds or updates the available methods.
21
+ */
22
+ export function extend(store: RawStore): Store {
23
+ const extendedSubscribe: (store: RawStore) => Store['subscribe'] =
24
+ (store) => (listener) => {
25
+ const executeListener = (
26
+ events: Event[],
27
+ state: State,
28
+ prevState: State
29
+ ) => {
30
+ for (const ev of events) {
31
+ listener(ev, state, prevState);
32
+ }
33
+ };
34
+
35
+ /*
36
+ * only known changes will fire event for lib users
37
+ * so all the changes in store won't trigger a user-face event
38
+ */
39
+ store.subscribe((state, prevState) => {
40
+ const eventsLike = getEventsLike(state, prevState);
41
+ const events = tryConsumeEvents(state);
42
+ const allQueuedEvents = [...events, ...eventsLike];
43
+ executeListener(allQueuedEvents, state, prevState);
44
+ });
45
+
46
+ return {
47
+ /**
48
+ * Manually run pending events.
49
+ * This useful when use `subscribe` method after sometime and when store initialized.
50
+ *
51
+ * Note: Please consider both current and previous state will be same and we don't have access to previous state in a such scenario.
52
+ */
53
+ flushEvents: () => {
54
+ const state = store.getState();
55
+ const events = tryConsumeEvents(state);
56
+ executeListener(events, state, state);
57
+ },
58
+ };
59
+ };
60
+
61
+ return new Proxy(store, {
62
+ get: function (target, prop, receiver) {
63
+ if (prop === 'subscribe') {
64
+ return extendedSubscribe(target);
65
+ }
66
+ return Reflect.get(target, prop, receiver);
67
+ },
68
+ }) as unknown as Store;
69
+ }
70
+
71
+ /**
72
+ * Retrieves the ConsumableEvent from the store and returns its values.
73
+ * The values will be consumed by iterating over the field.
74
+ */
75
+ function tryConsumeEvents(state: State): Event[] {
76
+ return [...state.providers.events, ...state.namespaces.events];
77
+ }
78
+
79
+ /**
80
+ * In certain cases, adding events to the store is not possible (e.g., namespace or provider layer).
81
+ * In these cases, we observe store changes and treat specific patterns as events when detected.
82
+ *
83
+ * Note: This approach should be avoided in most cases. It is used here to maintain backward compatibility
84
+ * with the provider's legacy interface.
85
+ */
86
+ function getEventsLike(state: State, prevState: State): Event[] {
87
+ const events: Event[] = [];
88
+
89
+ for (const providerId of Object.keys(state.providers.list)) {
90
+ const currentProviderState = guessProviderStateSelector(state, providerId);
91
+ const previousProviderState = guessProviderStateSelector(
92
+ prevState,
93
+ providerId
94
+ );
95
+
96
+ if (previousProviderState.connecting !== currentProviderState.connecting) {
97
+ const ev: ProviderConnectingEvent = {
98
+ type: 'provider_connecting',
99
+ provider: providerId,
100
+ value: currentProviderState.connecting,
101
+ };
102
+ events.push(ev);
103
+ }
104
+
105
+ if (!previousProviderState.connected && currentProviderState.connected) {
106
+ const ev: ProviderConnectedEvent = {
107
+ type: 'provider_connected',
108
+ provider: providerId,
109
+ };
110
+
111
+ events.push(ev);
112
+ }
113
+
114
+ if (previousProviderState.connected && !currentProviderState.connected) {
115
+ const ev: ProviderDisconnectedEvent = {
116
+ type: 'provider_disconnected',
117
+ provider: providerId,
118
+ };
119
+
120
+ events.push(ev);
121
+ }
122
+ }
123
+
124
+ return events;
125
+ }
@@ -2,7 +2,20 @@ export {
2
2
  guessProviderStateSelector,
3
3
  namespaceStateSelector,
4
4
  } from './selectors.js';
5
- export type { Store, State } from './store.js';
5
+ export type { Store } from './extend.js';
6
+ export type { State } from './store.js';
7
+ export type {
8
+ Event,
9
+ // Providers
10
+ ProviderDetectedEvent,
11
+ ProviderConnectingEvent,
12
+ ProviderConnectedEvent,
13
+ ProviderDisconnectedEvent,
14
+ // Namespaces
15
+ NamespaceDisconnectedEvent,
16
+ NamespaceConnectedEvent,
17
+ NamespaceSwitchedAccountEvent,
18
+ } from './events.js';
6
19
  export type { ProviderInfo, ProviderConfig } from './providers.js';
7
20
  export type { NamespaceConfig, NamespaceData } from './namespaces.js';
8
21
  export { createStore } from './store.js';
@@ -4,12 +4,17 @@ import type { StateCreator } from 'zustand';
4
4
 
5
5
  import { produce } from 'immer';
6
6
 
7
+ import {
8
+ ConsumableEvents,
9
+ type NamespaceConnectedEvent,
10
+ type NamespaceDisconnectedEvent,
11
+ type NamespaceSwitchedAccountEvent,
12
+ type NamespaceSwitchedNetworkEvent,
13
+ } from './events.js';
7
14
  import { namespaceStateSelector, type State } from './mod.js';
8
15
 
9
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
10
- export interface NamespaceConfig {
11
- // Currently, namespace doesn't has any config.
12
- }
16
+ // Currently, namespace doesn't has any config.
17
+ export type NamespaceConfig = object;
13
18
 
14
19
  export interface NamespaceData {
15
20
  accounts: null | string[];
@@ -23,15 +28,15 @@ interface NamespaceInfo {
23
28
  namespaceId: string;
24
29
  }
25
30
 
31
+ interface NamespaceItem {
32
+ info: NamespaceInfo;
33
+ data: NamespaceData;
34
+ error: unknown;
35
+ }
36
+
26
37
  type NamespaceState = {
27
- list: Record<
28
- string,
29
- {
30
- info: NamespaceInfo;
31
- data: NamespaceData;
32
- error: unknown;
33
- }
34
- >;
38
+ events: InstanceType<typeof ConsumableEvents>;
39
+ list: Record<string, NamespaceItem>;
35
40
  };
36
41
 
37
42
  interface NamespaceActions {
@@ -41,6 +46,13 @@ interface NamespaceActions {
41
46
  key: K,
42
47
  value: NamespaceData[K]
43
48
  ) => void;
49
+
50
+ _produceEventsWhenUpdatingStatus: <K extends keyof NamespaceData>(
51
+ namespace: NamespaceItem,
52
+ id: string,
53
+ key: K,
54
+ value: NamespaceData[K]
55
+ ) => void;
44
56
  }
45
57
  interface NamespaceSelectors {
46
58
  getNamespaceData(storeId: string): NamespaceData;
@@ -52,15 +64,19 @@ export type NamespaceStore = NamespaceState &
52
64
  type NamespaceStateCreator = StateCreator<State, [], [], NamespaceStore>;
53
65
 
54
66
  const namespacesStore: NamespaceStateCreator = (set, get) => ({
67
+ events: new ConsumableEvents(),
68
+
55
69
  list: {},
56
70
  addNamespace: (id, info) => {
71
+ const data: NamespaceData = {
72
+ accounts: null,
73
+ network: null,
74
+ connected: false,
75
+ connecting: false,
76
+ };
77
+
57
78
  const item = {
58
- data: {
59
- accounts: null,
60
- network: null,
61
- connected: false,
62
- connecting: false,
63
- },
79
+ data,
64
80
  error: '',
65
81
  info,
66
82
  };
@@ -72,10 +88,14 @@ const namespacesStore: NamespaceStateCreator = (set, get) => ({
72
88
  );
73
89
  },
74
90
  updateStatus: (id, key, value) => {
75
- if (!get().namespaces.list[id]) {
91
+ const ns = get().namespaces.list[id];
92
+ if (!ns) {
76
93
  throw new Error(`No namespace with '${id}' found.`);
77
94
  }
78
95
 
96
+ get().namespaces._produceEventsWhenUpdatingStatus(ns, id, key, value);
97
+
98
+ // Updating state
79
99
  set(
80
100
  produce((state: State) => {
81
101
  state.namespaces.list[id].data[key] = value;
@@ -85,6 +105,69 @@ const namespacesStore: NamespaceStateCreator = (set, get) => ({
85
105
  getNamespaceData(storeId) {
86
106
  return namespaceStateSelector(get(), storeId);
87
107
  },
108
+
109
+ _produceEventsWhenUpdatingStatus: (namespace, id, key, value) => {
110
+ if (key === 'accounts') {
111
+ // check for both null and empty array
112
+ const isAccountsEmpty =
113
+ Object.is(value, null) || (Array.isArray(value) && value.length === 0);
114
+
115
+ if (isAccountsEmpty) {
116
+ const currentConnectedStatus = get().namespaces.list[id].data.connected;
117
+ if (currentConnectedStatus) {
118
+ const event: NamespaceDisconnectedEvent = {
119
+ type: 'namespace_disconnected',
120
+ provider: namespace.info.providerId,
121
+ namespace: namespace.info.namespaceId,
122
+ };
123
+
124
+ get().namespaces.events.push(event);
125
+ }
126
+ // Skip emitting disconnect event, if the `connected` is false
127
+ } else {
128
+ const currentAccounts = get().namespaces.list[id].data.accounts;
129
+
130
+ if (!currentAccounts) {
131
+ const event: NamespaceConnectedEvent = {
132
+ type: 'namespace_connected',
133
+ provider: namespace.info.providerId,
134
+ namespace: namespace.info.namespaceId,
135
+ accounts: value as string[],
136
+ };
137
+
138
+ get().namespaces.events.push(event);
139
+ } else {
140
+ const areSameAccounts =
141
+ currentAccounts.sort().toString() ===
142
+ (value as string[]).sort().toString();
143
+
144
+ if (!areSameAccounts) {
145
+ const event: NamespaceSwitchedAccountEvent = {
146
+ type: 'namespace_account_switched',
147
+ provider: namespace.info.providerId,
148
+ namespace: namespace.info.namespaceId,
149
+ previousAccounts: currentAccounts,
150
+ accounts: value as string[],
151
+ };
152
+
153
+ get().namespaces.events.push(event);
154
+ }
155
+ }
156
+ }
157
+ } else if (key === 'network') {
158
+ const currentNetwork = get().namespaces.list[id].data.network;
159
+
160
+ const event: NamespaceSwitchedNetworkEvent = {
161
+ type: 'namespace_network_switched',
162
+ provider: namespace.info.providerId,
163
+ namespace: namespace.info.namespaceId,
164
+ network: value as string,
165
+ previousNetwork: currentNetwork,
166
+ };
167
+
168
+ get().namespaces.events.push(event);
169
+ }
170
+ },
88
171
  });
89
172
 
90
173
  export { namespacesStore };
@@ -4,6 +4,7 @@ import type { StateCreator } from 'zustand';
4
4
 
5
5
  import { produce } from 'immer';
6
6
 
7
+ import { ConsumableEvents, type ProviderDetectedEvent } from './events.js';
7
8
  import { guessProviderStateSelector, type State } from './mod.js';
8
9
 
9
10
  type Browsers = 'firefox' | 'chrome' | 'edge' | 'brave' | 'homepage';
@@ -25,15 +26,15 @@ interface ProviderData {
25
26
  installed: boolean;
26
27
  }
27
28
 
29
+ interface ProviderItem {
30
+ config: ProviderConfig;
31
+ data: ProviderData;
32
+ error: unknown;
33
+ }
34
+
28
35
  type ProviderState = {
29
- list: Record<
30
- string,
31
- {
32
- config: ProviderConfig;
33
- data: ProviderData;
34
- error: unknown;
35
- }
36
- >;
36
+ events: ConsumableEvents;
37
+ list: Record<string, ProviderItem>;
37
38
  };
38
39
  interface ProviderActions {
39
40
  addProvider: (id: string, config: ProviderConfig) => void;
@@ -42,6 +43,13 @@ interface ProviderActions {
42
43
  key: K,
43
44
  value: ProviderData[K]
44
45
  ) => void;
46
+
47
+ _produceEventsWhenUpdatingStatus: <K extends keyof ProviderData>(
48
+ provider: ProviderItem,
49
+ id: string,
50
+ key: K,
51
+ value: ProviderData[K]
52
+ ) => void;
45
53
  }
46
54
 
47
55
  interface ProviderSelectors {
@@ -56,6 +64,8 @@ export type ProviderStore = ProviderState & ProviderActions & ProviderSelectors;
56
64
  type ProvidersStateCreator = StateCreator<State, [], [], ProviderStore>;
57
65
 
58
66
  const providersStore: ProvidersStateCreator = (set, get) => ({
67
+ events: new ConsumableEvents(),
68
+
59
69
  list: {},
60
70
  addProvider: (id, config) => {
61
71
  const item = {
@@ -73,10 +83,13 @@ const providersStore: ProvidersStateCreator = (set, get) => ({
73
83
  );
74
84
  },
75
85
  updateStatus: (id, key, value) => {
76
- if (!get().providers.list[id]) {
86
+ const provider = get().providers.list[id];
87
+ if (!provider) {
77
88
  throw new Error(`No namespace namespace with '${id}' found.`);
78
89
  }
79
90
 
91
+ get().providers._produceEventsWhenUpdatingStatus(provider, id, key, value);
92
+
80
93
  set(
81
94
  produce((state: State) => {
82
95
  state.providers.list[id].data[key] = value;
@@ -86,6 +99,17 @@ const providersStore: ProvidersStateCreator = (set, get) => ({
86
99
  guessNamespacesState: (providerId: string): InternalProviderState => {
87
100
  return guessProviderStateSelector(get(), providerId);
88
101
  },
102
+
103
+ _produceEventsWhenUpdatingStatus: (_provider, id, key, _value) => {
104
+ if (key === 'installed') {
105
+ const event: ProviderDetectedEvent = {
106
+ type: 'provider_detected',
107
+ provider: id,
108
+ };
109
+
110
+ get().providers.events.push(event);
111
+ }
112
+ },
89
113
  });
90
114
 
91
115
  export { providersStore };
@@ -1,4 +1,4 @@
1
- import type { Store } from './store.js';
1
+ import type { Store } from './mod.js';
2
2
 
3
3
  import { beforeEach, describe, expect, test } from 'vitest';
4
4
 
@@ -2,6 +2,7 @@ import type { StoreApi } from 'zustand/vanilla';
2
2
 
3
3
  import { createStore as createZustandStore } from 'zustand/vanilla';
4
4
 
5
+ import { extend, type Store } from './extend.js';
5
6
  import { hubStore, type HubStore } from './hub.js';
6
7
  import { namespacesStore, type NamespaceStore } from './namespaces.js';
7
8
  import { providersStore, type ProviderStore } from './providers.js';
@@ -14,13 +15,16 @@ export interface State {
14
15
  namespaces: NamespaceStore;
15
16
  }
16
17
 
17
- export type Store = StoreApi<State>;
18
+ export type RawStore = StoreApi<State>;
19
+
18
20
  export const createStore = (): Store => {
19
- return createZustandStore<State>((...api) => {
21
+ const store = createZustandStore<State>((...api) => {
20
22
  return {
21
23
  hub: hubStore(...api),
22
24
  providers: providersStore(...api),
23
25
  namespaces: namespacesStore(...api),
24
26
  };
25
27
  });
28
+
29
+ return extend(store);
26
30
  };
@@ -60,11 +60,14 @@ export enum Networks {
60
60
  UMEE = 'UMEE',
61
61
  STARKNET = 'STARKNET',
62
62
  TON = 'TON',
63
-
63
+ BASE = 'BASE',
64
64
  // Using instead of null
65
65
  Unknown = 'Unkown',
66
66
  }
67
67
 
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ type InstanceType = any;
70
+
68
71
  export type NamespaceData = {
69
72
  namespace: Namespace;
70
73
  derivationPath?: string;
@@ -127,10 +130,10 @@ export type State = {
127
130
  export type ConnectResult = {
128
131
  accounts: string[] | null;
129
132
  network: Network | null;
130
- provider: any;
133
+ provider: InstanceType;
131
134
  };
132
135
 
133
- export type Providers = { [type in WalletType]?: any };
136
+ export type Providers = { [type in WalletType]?: InstanceType };
134
137
 
135
138
  export enum Events {
136
139
  CONNECTED = 'connected',
@@ -139,6 +142,8 @@ export enum Events {
139
142
  INSTALLED = 'installed',
140
143
  ACCOUNTS = 'accounts',
141
144
  NETWORK = 'network',
145
+ // Hub only events
146
+ NAMESPACE_DISCONNECTED = 'namespace_disconnected',
142
147
  }
143
148
 
144
149
  export type ProviderConnectResult = {
@@ -148,7 +153,7 @@ export type ProviderConnectResult = {
148
153
 
149
154
  export type GetInstanceOptions = {
150
155
  network?: Network;
151
- currentProvider: any;
156
+ currentProvider: InstanceType;
152
157
  meta: BlockchainMeta[];
153
158
  getState: () => WalletState;
154
159
  /**
@@ -162,29 +167,31 @@ export type GetInstanceOptions = {
162
167
  };
163
168
 
164
169
  export type GetInstance =
165
- | (() => any)
166
- | ((options: GetInstanceOptions) => Promise<any>);
170
+ | (() => InstanceType)
171
+ | ((options: GetInstanceOptions) => Promise<InstanceType>);
167
172
 
168
173
  export type TryGetInstance =
169
- | (() => any)
170
- | ((options: Pick<GetInstanceOptions, 'force' | 'network'>) => Promise<any>);
174
+ | (() => InstanceType)
175
+ | ((
176
+ options: Pick<GetInstanceOptions, 'force' | 'network'>
177
+ ) => Promise<InstanceType>);
171
178
 
172
179
  export type Connect = (options: {
173
- instance: any;
180
+ instance: InstanceType;
174
181
  network?: Network;
175
182
  meta: BlockchainMeta[];
176
183
  namespaces?: NamespaceData[];
177
184
  }) => Promise<ProviderConnectResult | ProviderConnectResult[]>;
178
185
 
179
186
  export type Disconnect = (options: {
180
- instance: any;
187
+ instance: InstanceType;
181
188
  destroyInstance: () => void;
182
189
  }) => Promise<void>;
183
190
 
184
191
  type CleanupSubscribe = () => void;
185
192
 
186
193
  export type Subscribe = (options: {
187
- instance: any;
194
+ instance: InstanceType;
188
195
  state: WalletState;
189
196
  meta: BlockchainMeta[];
190
197
  updateChainId: (chainId: string) => void;
@@ -194,7 +201,7 @@ export type Subscribe = (options: {
194
201
  }) => CleanupSubscribe | void;
195
202
 
196
203
  export type SwitchNetwork = (options: {
197
- instance: any;
204
+ instance: InstanceType;
198
205
  network: Network;
199
206
  meta: BlockchainMeta[];
200
207
  newInstance?: TryGetInstance;
@@ -203,7 +210,7 @@ export type SwitchNetwork = (options: {
203
210
  }) => Promise<void>;
204
211
 
205
212
  export type Suggest = (options: {
206
- instance: any;
213
+ instance: InstanceType;
207
214
  network: Network;
208
215
  meta: BlockchainMeta[];
209
216
  }) => Promise<void>;
@@ -211,11 +218,11 @@ export type Suggest = (options: {
211
218
  export type CanSwitchNetwork = (options: {
212
219
  network: Network;
213
220
  meta: BlockchainMeta[];
214
- provider: any;
221
+ provider: InstanceType;
215
222
  }) => boolean;
216
223
 
217
224
  export type CanEagerConnect = (options: {
218
- instance: any;
225
+ instance: InstanceType;
219
226
  meta: BlockchainMeta[];
220
227
  }) => Promise<boolean>;
221
228
 
@@ -227,7 +234,7 @@ export type EagerConnectResult<I = unknown> = {
227
234
 
228
235
  export interface WalletActions {
229
236
  connect: Connect;
230
- getInstance: any;
237
+ getInstance: InstanceType;
231
238
  disconnect?: Disconnect;
232
239
  subscribe?: Subscribe;
233
240
  // unsubscribe, // coupled to subscribe.
@@ -235,7 +242,7 @@ export interface WalletActions {
235
242
  // Optional, but should be provided at the same time.
236
243
  suggest?: Suggest;
237
244
  switchNetwork?: SwitchNetwork;
238
- getSigners: (provider: any) => Promise<SignerFactory>;
245
+ getSigners: (provider: InstanceType) => Promise<SignerFactory>;
239
246
  canSwitchNetworkTo?: CanSwitchNetwork;
240
247
  canEagerConnect?: CanEagerConnect;
241
248
  getWalletInfo(allBlockChains: BlockchainMeta[]): WalletInfo;
@@ -7,6 +7,7 @@ import type {
7
7
  WalletConfig,
8
8
  WalletType,
9
9
  } from './types.js';
10
+ import type { Namespace } from '../namespaces/common/types.js';
10
11
  import type { BlockchainMeta } from 'rango-types';
11
12
 
12
13
  import {
@@ -20,6 +21,7 @@ import { eagerConnectHandler } from './utils.js';
20
21
  export type EventHandler = (
21
22
  type: WalletType,
22
23
  event: Events,
24
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
25
  value: any,
24
26
  coreState: State,
25
27
  info: EventInfo
@@ -28,8 +30,11 @@ export type EventHandler = (
28
30
  export type EventInfo = {
29
31
  supportedBlockchains: BlockchainMeta[];
30
32
  isContractWallet: boolean;
31
- // This is for Hub and be able to make it compatible with legacy behavior.
33
+
34
+ // Hub fields
32
35
  isHub: boolean;
36
+ // will be set alongside ACCOUNT event
37
+ namespace?: Namespace;
33
38
  };
34
39
 
35
40
  export interface State {
@@ -49,6 +54,7 @@ export interface Options {
49
54
  handler: EventHandler;
50
55
  }
51
56
 
57
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
58
  class Wallet<InstanceType = any> {
53
59
  public provider: InstanceType | null;
54
60
  private actions: WalletActions;
@@ -298,13 +304,13 @@ class Wallet<InstanceType = any> {
298
304
  });
299
305
  }
300
306
 
301
- async getSigners(provider: any) {
307
+ async getSigners(provider: InstanceType) {
302
308
  return await this.actions.getSigners(provider);
303
309
  }
304
310
  getWalletInfo(allBlockChains: BlockchainMeta[]) {
305
311
  return this.actions.getWalletInfo(allBlockChains);
306
312
  }
307
- canSwitchNetworkTo(network: Network, provider: any) {
313
+ canSwitchNetworkTo(network: Network, provider: InstanceType) {
308
314
  const switchTo = this.actions.canSwitchNetworkTo;
309
315
  if (!switchTo) {
310
316
  return false;
@@ -331,7 +337,7 @@ class Wallet<InstanceType = any> {
331
337
  this.setInstalledAs(true);
332
338
  }
333
339
  } else if (needsCheckInstallation(this.options)) {
334
- this.actions.getInstance().then((data: any) => {
340
+ this.actions.getInstance().then((data: unknown) => {
335
341
  if (data) {
336
342
  this.setInstalledAs(true);
337
343
  }
@@ -339,7 +345,7 @@ class Wallet<InstanceType = any> {
339
345
  }
340
346
  }
341
347
 
342
- setProvider(value: any) {
348
+ setProvider(value: InstanceType | null) {
343
349
  this.provider = value;
344
350
  if (!!value && !!this.actions.subscribe) {
345
351
  const cleanup = this.actions.subscribe({
@@ -395,7 +401,7 @@ class Wallet<InstanceType = any> {
395
401
  * We will notify handler after updating all the states.
396
402
  * Because when we call `handler` it will has latest states.
397
403
  */
398
- const updates: [Events, any][] = [];
404
+ const updates: [Events, unknown][] = [];
399
405
 
400
406
  if (typeof states.connected !== 'undefined') {
401
407
  this.state.connected = states.connected;
@@ -1,10 +1,14 @@
1
1
  import type { EvmActions } from './types.js';
2
2
 
3
3
  import { ActionBuilder } from '../../mod.js';
4
- import { intoConnectionFinished } from '../common/after.js';
5
- import { connectAndUpdateStateForMultiNetworks } from '../common/and.js';
4
+ import {
5
+ connectAndUpdateStateForMultiNetworks,
6
+ intoConnecting,
7
+ intoConnectionFinished,
8
+ } from '../common/mod.js';
6
9
 
7
10
  export const connect = () =>
8
11
  new ActionBuilder<EvmActions, 'connect'>('connect')
9
12
  .and(connectAndUpdateStateForMultiNetworks)
13
+ .before(intoConnecting)
10
14
  .after(intoConnectionFinished);
@@ -1,10 +1,14 @@
1
1
  import type { SolanaActions } from './types.js';
2
2
 
3
3
  import { ActionBuilder } from '../../mod.js';
4
- import { intoConnectionFinished } from '../common/after.js';
5
- import { connectAndUpdateStateForSingleNetwork } from '../common/and.js';
4
+ import {
5
+ connectAndUpdateStateForSingleNetwork,
6
+ intoConnecting,
7
+ intoConnectionFinished,
8
+ } from '../common/mod.js';
6
9
 
7
10
  export const connect = () =>
8
11
  new ActionBuilder<SolanaActions, 'connect'>('connect')
9
12
  .and(connectAndUpdateStateForSingleNetwork)
13
+ .before(intoConnecting)
10
14
  .after(intoConnectionFinished);