@rango-dev/wallets-react 0.0.0-experimental-d44b759f-20260701 → 0.0.0-experimental-a84f27a7-20260921

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 (84) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/context.d.ts.map +1 -0
  3. package/dist/helpers.d.ts +1 -1
  4. package/dist/hooks.d.ts +3 -0
  5. package/dist/hooks.d.ts.map +1 -0
  6. package/dist/hub/autoConnect.d.ts +2 -5
  7. package/dist/hub/autoConnect.d.ts.map +1 -1
  8. package/dist/hub/constants.d.ts +0 -1
  9. package/dist/hub/constants.d.ts.map +1 -1
  10. package/dist/hub/helpers.d.ts +2 -0
  11. package/dist/hub/helpers.d.ts.map +1 -1
  12. package/dist/hub/lastConnectedWallets.d.ts +1 -2
  13. package/dist/hub/lastConnectedWallets.d.ts.map +1 -1
  14. package/dist/hub/mod.d.ts +1 -1
  15. package/dist/hub/mod.d.ts.map +1 -1
  16. package/dist/hub/persistor.d.ts +11 -0
  17. package/dist/hub/persistor.d.ts.map +1 -0
  18. package/dist/{legacy → hub}/useAutoConnect.d.ts +1 -1
  19. package/dist/hub/useAutoConnect.d.ts.map +1 -0
  20. package/dist/hub/useHubAdapter.d.ts +1 -5
  21. package/dist/hub/useHubAdapter.d.ts.map +1 -1
  22. package/dist/hub/utils.d.ts +14 -15
  23. package/dist/hub/utils.d.ts.map +1 -1
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +4 -4
  28. package/dist/legacy/mod.d.ts +2 -4
  29. package/dist/legacy/mod.d.ts.map +1 -1
  30. package/dist/legacy/types.d.ts +89 -69
  31. package/dist/legacy/types.d.ts.map +1 -1
  32. package/dist/provider.d.ts +1 -1
  33. package/dist/provider.d.ts.map +1 -1
  34. package/dist/types.d.ts +39 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/package.json +15 -16
  37. package/src/{legacy/context.ts → context.ts} +0 -3
  38. package/src/helpers.ts +1 -1
  39. package/src/hooks.ts +13 -0
  40. package/src/hub/autoConnect.ts +26 -35
  41. package/src/hub/constants.ts +0 -1
  42. package/src/hub/helpers.ts +11 -4
  43. package/src/hub/lastConnectedWallets.ts +3 -51
  44. package/src/hub/mod.ts +1 -5
  45. package/src/hub/persistor.ts +19 -0
  46. package/src/{legacy → hub}/useAutoConnect.ts +2 -2
  47. package/src/hub/useHubAdapter.ts +75 -73
  48. package/src/hub/utils.ts +39 -80
  49. package/src/index.ts +2 -2
  50. package/src/legacy/mod.ts +6 -9
  51. package/src/legacy/types.ts +112 -97
  52. package/src/provider.tsx +8 -4
  53. package/src/types.ts +58 -0
  54. package/dist/helpers/index.d.ts +0 -2
  55. package/dist/helpers/index.d.ts.map +0 -1
  56. package/dist/helpers/index.js +0 -2
  57. package/dist/helpers/index.js.map +0 -7
  58. package/dist/legacy/autoConnect.d.ts +0 -8
  59. package/dist/legacy/autoConnect.d.ts.map +0 -1
  60. package/dist/legacy/context.d.ts.map +0 -1
  61. package/dist/legacy/helpers.d.ts +0 -23
  62. package/dist/legacy/helpers.d.ts.map +0 -1
  63. package/dist/legacy/hooks.d.ts +0 -10
  64. package/dist/legacy/hooks.d.ts.map +0 -1
  65. package/dist/legacy/useAutoConnect.d.ts.map +0 -1
  66. package/dist/legacy/useLegacyProviders.d.ts +0 -7
  67. package/dist/legacy/useLegacyProviders.d.ts.map +0 -1
  68. package/dist/legacy/utils.d.ts +0 -3
  69. package/dist/legacy/utils.d.ts.map +0 -1
  70. package/dist/test-utils/fixtures.d.ts +0 -14
  71. package/dist/test-utils/fixtures.d.ts.map +0 -1
  72. package/dist/useProviders.d.ts +0 -4
  73. package/dist/useProviders.d.ts.map +0 -1
  74. package/dist/wallets-react.build.json +0 -1
  75. package/helpers/package.json +0 -8
  76. package/src/helpers/index.ts +0 -1
  77. package/src/legacy/autoConnect.ts +0 -66
  78. package/src/legacy/helpers.ts +0 -183
  79. package/src/legacy/hooks.ts +0 -54
  80. package/src/legacy/useLegacyProviders.ts +0 -244
  81. package/src/legacy/utils.ts +0 -7
  82. package/src/test-utils/fixtures.ts +0 -164
  83. package/src/useProviders.ts +0 -121
  84. /package/dist/{legacy/context.d.ts → context.d.ts} +0 -0
@@ -1,11 +1,7 @@
1
1
  import type { Namespace } from '@hub3js/namespaces';
2
2
 
3
- import { Persistor } from '@rango-dev/wallets-core/legacy';
4
-
5
- import {
6
- HUB_LAST_CONNECTED_WALLETS,
7
- LEGACY_LAST_CONNECTED_WALLETS,
8
- } from './constants.js';
3
+ import { HUB_LAST_CONNECTED_WALLETS } from './constants.js';
4
+ import { Persistor } from './persistor.js';
9
5
 
10
6
  export interface NamespaceInput {
11
7
  namespace: Namespace;
@@ -16,11 +12,9 @@ export interface LastConnectedWalletsStorage {
16
12
  [providerId: string]: NamespaceInput[];
17
13
  }
18
14
 
19
- export type LegacyLastConnectedWalletsStorage = string[];
20
-
21
15
  /**
22
16
  * We are doing some certain actions on storage for `last-connected-wallets` key.
23
- * This class helps us to define them in one place and also it has support for both legacy and hub.
17
+ * This class helps us to define them in one place.
24
18
  */
25
19
  export class LastConnectedWalletsFromStorage {
26
20
  #storageKey: string;
@@ -32,24 +26,18 @@ export class LastConnectedWalletsFromStorage {
32
26
  addWallet(providerId: string, namespaces: NamespaceInput[]): void {
33
27
  if (this.#storageKey === HUB_LAST_CONNECTED_WALLETS) {
34
28
  return this.#addWalletToHub(providerId, namespaces);
35
- } else if (this.#storageKey === LEGACY_LAST_CONNECTED_WALLETS) {
36
- return this.#addWalletToLegacy(providerId);
37
29
  }
38
30
  throw new Error('Not implemented');
39
31
  }
40
32
  removeWallets(providerIds?: string[]): void {
41
33
  if (this.#storageKey === HUB_LAST_CONNECTED_WALLETS) {
42
34
  return this.#removeWalletsFromHub(providerIds);
43
- } else if (this.#storageKey === LEGACY_LAST_CONNECTED_WALLETS) {
44
- return this.#removeWalletsFromLegacy(providerIds);
45
35
  }
46
36
  throw new Error('Not implemented');
47
37
  }
48
38
  list(): LastConnectedWalletsStorage {
49
39
  if (this.#storageKey === HUB_LAST_CONNECTED_WALLETS) {
50
40
  return this.#listFromHub();
51
- } else if (this.#storageKey === LEGACY_LAST_CONNECTED_WALLETS) {
52
- return this.#listFromLegacy();
53
41
  }
54
42
  throw new Error('Not implemented');
55
43
  }
@@ -60,17 +48,6 @@ export class LastConnectedWalletsFromStorage {
60
48
  throw new Error('Not implemented');
61
49
  }
62
50
 
63
- #listFromLegacy(): LastConnectedWalletsStorage {
64
- const persistor = new Persistor<LegacyLastConnectedWalletsStorage>();
65
- const lastConnectedWallets =
66
- persistor.getItem(LEGACY_LAST_CONNECTED_WALLETS) || [];
67
- const output: LastConnectedWalletsStorage = {};
68
- lastConnectedWallets.forEach((provider) => {
69
- // Setting empty namespaces
70
- output[provider] = [];
71
- });
72
- return output;
73
- }
74
51
  #listFromHub(): LastConnectedWalletsStorage {
75
52
  const persistor = new Persistor<LastConnectedWalletsStorage>();
76
53
  const lastConnectedWallets =
@@ -102,15 +79,6 @@ export class LastConnectedWalletsFromStorage {
102
79
  [providerId]: toBeAddedNamespaces,
103
80
  });
104
81
  }
105
- #addWalletToLegacy(providerId: string): void {
106
- const storage = new Persistor<LegacyLastConnectedWalletsStorage>();
107
- const storageState = storage.getItem(this.#storageKey) || [];
108
-
109
- storage.setItem(
110
- LEGACY_LAST_CONNECTED_WALLETS,
111
- storageState.concat(providerId)
112
- );
113
- }
114
82
  #removeWalletsFromHub(providerIds?: string[]): void {
115
83
  const persistor = new Persistor<LastConnectedWalletsStorage>();
116
84
  const storageState = persistor.getItem(this.#storageKey) || {};
@@ -147,20 +115,4 @@ export class LastConnectedWalletsFromStorage {
147
115
  this.#addWalletToHub(providerId, newProviderNamespaces);
148
116
  }
149
117
  }
150
- #removeWalletsFromLegacy(providerIds?: string[]): void {
151
- const persistor = new Persistor<LegacyLastConnectedWalletsStorage>();
152
- const storageState = persistor.getItem(this.#storageKey) || [];
153
-
154
- // Remove all wallets
155
- if (!providerIds) {
156
- persistor.setItem(this.#storageKey, []);
157
- return;
158
- }
159
-
160
- // Remove some of the wallets
161
- persistor.setItem(
162
- LEGACY_LAST_CONNECTED_WALLETS,
163
- storageState.filter((wallet) => !providerIds.includes(wallet))
164
- );
165
- }
166
118
  }
package/src/hub/mod.ts CHANGED
@@ -1,6 +1,2 @@
1
- export {
2
- separateLegacyAndHubProviders,
3
- getAllLegacyProviders,
4
- findProviderByType,
5
- } from './utils.js';
1
+ export { getHubProviders, findProviderByType } from './utils.js';
6
2
  export { useHubAdapter } from './useHubAdapter.js';
@@ -0,0 +1,19 @@
1
+ export interface PersistStorage<T> {
2
+ getItem: (name: string) => T | null;
3
+ setItem: (name: string, value: T) => void;
4
+ removeItem: (name: string) => void;
5
+ }
6
+
7
+ export class Persistor<T> implements PersistStorage<T> {
8
+ getItem(name: string) {
9
+ const item = localStorage.getItem(name);
10
+ const parsedItem = item ? (JSON.parse(item) as T) : null;
11
+ return parsedItem;
12
+ }
13
+ setItem(name: string, value: T) {
14
+ localStorage.setItem(name, JSON.stringify(value));
15
+ }
16
+ removeItem(name: string) {
17
+ localStorage.removeItem(name);
18
+ }
19
+ }
@@ -1,8 +1,8 @@
1
- import type { ProviderProps } from './types.js';
1
+ import type { ProviderProps } from '../types.js';
2
2
 
3
3
  import { useEffect, useRef } from 'react';
4
4
 
5
- import { shouldTryAutoConnect } from './utils.js';
5
+ import { shouldTryAutoConnect } from './helpers.js';
6
6
 
7
7
  export function useAutoConnect(
8
8
  props: Pick<ProviderProps, 'allBlockChains' | 'autoConnect'> & {
@@ -1,30 +1,34 @@
1
1
  import type { AllProxiedNamespaces, ExtensionLink } from './types.js';
2
- import type { ProviderContext } from '../index.js';
3
- import type { Provider } from '@hub3js/core';
4
- import type { VersionedProviders } from '@hub3js/core/utils';
2
+ import type {
3
+ ConnectResult,
4
+ NamespaceInputForConnect,
5
+ WalletInfo,
6
+ } from '../legacy/mod.js';
7
+ import type { ProviderContext, ProviderProps } from '../types.js';
8
+ import type { Provider, WalletType } from '@hub3js/core';
5
9
  import type { Accounts, AccountsWithActiveChain } from '@hub3js/std/types';
6
- import type { LegacyNamespaceInputForConnect } from '@rango-dev/wallets-core/legacy';
7
10
 
8
- import { utils } from '@hub3js/evm';
9
- import { type WalletInfo, type WalletType } from '@rango-dev/wallets-shared';
11
+ import { isUserRejectionError, WalletConnectionError } from '@hub3js/std/utils';
12
+ import {
13
+ getSupportedChainsFromNamespace,
14
+ getSupportedChainsFromProvider,
15
+ } from '@rango-dev/internal-blockchains';
10
16
  import { useEffect, useRef, useState } from 'react';
11
17
  import { Ok, Result } from 'ts-results';
12
18
 
13
- import {
14
- type ConnectResult,
15
- HUB_LAST_CONNECTED_WALLETS,
16
- type ProviderProps,
17
- } from '../legacy/mod.js';
18
- import { useAutoConnect } from '../legacy/useAutoConnect.js';
19
+ import { withErrorLoggingApi } from '../helpers.js';
19
20
 
20
21
  import { autoConnect } from './autoConnect.js';
22
+ import { HUB_LAST_CONNECTED_WALLETS } from './constants.js';
21
23
  import { createQueue, fromAccountIdToLegacyAddressFormat } from './helpers.js';
22
24
  import { LastConnectedWalletsFromStorage } from './lastConnectedWallets.js';
25
+ import { useAutoConnect } from './useAutoConnect.js';
23
26
  import { useHubRefs } from './useHubRefs.js';
24
27
  import {
25
- getSupportedChainsFromProvider,
28
+ findProviderByType,
26
29
  isEvmNamespace,
27
30
  isSolanaNamespace,
31
+ isUtxoNamespace,
28
32
  mapHubEventsToLegacy,
29
33
  transformHubResultToLegacyResult,
30
34
  tryConvertNamespaceNetworkToChainInfo,
@@ -32,8 +36,6 @@ import {
32
36
 
33
37
  export type UseAdapterParams = Omit<ProviderProps, 'providers'> & {
34
38
  providers: Provider[];
35
- /** This is only will be used to access some parts of the legacy provider that doesn't exists in Hub. */
36
- allVersionedProviders: VersionedProviders[];
37
39
  };
38
40
 
39
41
  export function useHubAdapter(params: UseAdapterParams): ProviderContext {
@@ -42,28 +44,31 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
42
44
  // useEffect will run `subscribe` once, so we need a reference and mutate the value if it's changes.
43
45
  const dataRef = useRef({
44
46
  onUpdateState: params.onUpdateState,
45
- allVersionedProviders: params.allVersionedProviders,
46
47
  allBlockChains: params.allBlockChains,
47
48
  });
49
+ const hubInitiated = useRef(false);
48
50
 
49
51
  /*
50
52
  * Params of each connection attempt for each wallet type are stored here.
51
53
  * Derivation path from params is used in `mapHubEventsToLegacy` to be added to the payload of connect events.
52
54
  */
53
55
  const lastConnectAttemptParamsRef = useRef<{
54
- [type: WalletType]: LegacyNamespaceInputForConnect[];
56
+ [type: WalletType]: NamespaceInputForConnect[];
55
57
  }>({});
56
58
 
57
59
  const updateLastConnectAttemptParams = (
58
60
  type: WalletType,
59
- namespaces: LegacyNamespaceInputForConnect[] | undefined
61
+ namespaces: NamespaceInputForConnect[] | undefined
60
62
  ) => {
61
63
  lastConnectAttemptParamsRef.current[type] = namespaces || [];
62
64
  };
63
65
 
64
66
  const queueTask = createQueue({
65
67
  onError: (error, actions) => {
66
- if (utils.isUserRejectionError(error)) {
68
+ // A connection failure carries the wallet's own error, and so its code, as its cause.
69
+ const walletError =
70
+ error instanceof WalletConnectionError ? error.cause : error;
71
+ if (isUserRejectionError(walletError)) {
67
72
  actions.removeCurrentKeyFromQueue();
68
73
  }
69
74
  },
@@ -72,43 +77,11 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
72
77
  useEffect(() => {
73
78
  dataRef.current = {
74
79
  onUpdateState: params.onUpdateState,
75
- allVersionedProviders: params.allVersionedProviders,
76
80
  allBlockChains: params.allBlockChains,
77
81
  };
78
82
  }, [params]);
79
83
 
80
- // Initialize instances
81
84
  useEffect(() => {
82
- const runOnInit = () => {
83
- getHub().init(params.configs?.walletOptions);
84
-
85
- rerender((currentRender) => currentRender + 1);
86
- };
87
-
88
- // Then will call init whenever page is ready.
89
- const initHubWhenPageIsReady = (event: Event) => {
90
- // Then will call init whenever page is ready.
91
- if (
92
- event.target &&
93
- (event.target as Document).readyState === 'complete'
94
- ) {
95
- runOnInit();
96
- document.removeEventListener(
97
- 'readystatechange',
98
- initHubWhenPageIsReady
99
- );
100
- }
101
- };
102
-
103
- // Try to run, maybe it's ready.
104
- runOnInit();
105
-
106
- /*
107
- * Try again when the page has been completely loaded.
108
- * Some of wallets, take some time to be fully injected and loaded.
109
- */
110
- document.addEventListener('readystatechange', initHubWhenPageIsReady);
111
-
112
85
  getStore()
113
86
  .subscribe((event) => {
114
87
  if (dataRef.current.onUpdateState) {
@@ -131,6 +104,17 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
131
104
  .flushEvents();
132
105
  }, []);
133
106
 
107
+ // Initialize hub only after blockchain meta is available (e.g. WalletConnect needs it at init).
108
+ useEffect(() => {
109
+ if (hubInitiated.current || !params.allBlockChains?.length) {
110
+ return;
111
+ }
112
+
113
+ getHub().init(params.configs?.walletOptions);
114
+ rerender((currentRender) => currentRender + 1);
115
+ hubInitiated.current = true;
116
+ }, [params.allBlockChains, params.configs?.walletOptions]);
117
+
134
118
  useAutoConnect({
135
119
  autoConnect: params.autoConnect,
136
120
  allBlockChains: params.allBlockChains,
@@ -152,9 +136,8 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
152
136
  const provider = getHub().get(type);
153
137
 
154
138
  if (!provider) {
155
- throw new Error(
156
- `You should add ${type} to provider first then call 'canSwitchNetworkTo'.`
157
- );
139
+ // TODO: should throw an error
140
+ return false;
158
141
  }
159
142
 
160
143
  if (!namespace) {
@@ -181,21 +164,25 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
181
164
  if (!dataRef.current.allBlockChains) {
182
165
  throw new Error(`Blockchains are not available`);
183
166
  }
184
- const providerSupportedChainsOfNamespace = namespacesProperty?.value.data
185
- .find(
186
- (providerNamespace) => providerNamespace.value === namespace.namespace
187
- )
188
- ?.getSupportedChains(dataRef.current.allBlockChains);
189
167
 
190
- if (!providerSupportedChainsOfNamespace) {
168
+ const namespaceMeta = namespacesProperty?.value.data.find(
169
+ (providerNamespace) => providerNamespace.value === namespace.namespace
170
+ );
171
+
172
+ if (!namespaceMeta) {
191
173
  throw new Error(
192
174
  `NamespaceMeta is not defined for requested namespace: ${namespace.namespace}`
193
175
  );
194
176
  }
195
177
 
178
+ const supportedChains = getSupportedChainsFromNamespace(
179
+ namespaceMeta,
180
+ dataRef.current.allBlockChains
181
+ );
182
+
196
183
  return proxiedNamespace.canSwitchNetwork({
197
184
  network,
198
- supportedChains: providerSupportedChainsOfNamespace,
185
+ supportedChains,
199
186
  });
200
187
  },
201
188
  async connect(type, namespaces) {
@@ -214,7 +201,7 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
214
201
 
215
202
  // Check `namespace` and look into hub to see how it can match given namespace to hub namespace.
216
203
  const targetNamespaces: [
217
- LegacyNamespaceInputForConnect,
204
+ NamespaceInputForConnect,
218
205
  AllProxiedNamespaces
219
206
  ][] = [];
220
207
  namespaces.forEach((namespace) => {
@@ -252,6 +239,11 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
252
239
  namespace.connect(network, {
253
240
  derivationPath: namespaceInput.derivationPath,
254
241
  });
242
+ } else if (isUtxoNamespace(namespace)) {
243
+ connectNamespacePromise = async () =>
244
+ namespace.connect({
245
+ derivationPath: namespaceInput.derivationPath,
246
+ });
255
247
  } else {
256
248
  connectNamespacePromise = async () => namespace.connect();
257
249
  }
@@ -439,18 +431,22 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
439
431
  properties: metadata.properties,
440
432
  };
441
433
  },
442
- providers() {
443
- throw new Error('This method is not available on hub providers.');
444
- },
445
434
  state(type) {
446
435
  const hubState = getHub().state();
447
436
  const wallet = getHub().get(type);
448
437
  const walletState = hubState[type];
449
438
 
450
439
  if (!walletState || !wallet) {
451
- throw new Error(
452
- `It seems your requested provider doesn't exist in hub. Provider Id: ${type}`
453
- );
440
+ // TODO: should throw an error
441
+ return {
442
+ connected: false,
443
+ connecting: false,
444
+ installed: false,
445
+ reachable: false,
446
+ accounts: null,
447
+ network: null,
448
+ namespaces: new Map(),
449
+ };
454
450
  }
455
451
 
456
452
  const accounts = walletState.namespaces
@@ -504,12 +500,18 @@ export function useHubAdapter(params: UseAdapterParams): ProviderContext {
504
500
  `Suggest has not been implemented for given chain: ${namespace.network}`
505
501
  );
506
502
  },
507
- hubProvider() {
508
- throw new Error(
509
- 'Unreachable code. the method has been implemented in main adapter instance.'
510
- );
503
+ hubProvider(type) {
504
+ const provider = findProviderByType(params.providers, type);
505
+
506
+ if (!provider) {
507
+ throw new Error(
508
+ `You're trying to access ${type} provider which is not found in hub providers. it may not be registered yet.`
509
+ );
510
+ }
511
+
512
+ return provider;
511
513
  },
512
514
  };
513
515
 
514
- return api;
516
+ return withErrorLoggingApi(api);
515
517
  }
package/src/hub/utils.ts CHANGED
@@ -1,36 +1,32 @@
1
1
  import type { AllProxiedNamespaces } from './types.js';
2
- import type { Hub, Provider, ProxiedNamespace } from '@hub3js/core';
2
+ import type {
3
+ ConnectResult,
4
+ NamespaceInputForConnect,
5
+ EventHandler as WalletEventHandler,
6
+ } from '../legacy/mod.js';
7
+ import type { ProviderProps } from '../types.js';
8
+ import type { UtxoActions } from '@hub3js/bip122';
9
+ import type { Hub, Provider, ProxiedNamespace, WalletType } from '@hub3js/core';
3
10
  import type { Event } from '@hub3js/core/store';
4
- import type { EvmActions } from '@hub3js/evm';
5
- import type { SolanaActions } from '@hub3js/solana';
6
11
  import type {
7
- LegacyNamespaceInputForConnect,
8
- LegacyProviderInterface,
9
- LegacyEventHandler as WalletEventHandler,
10
- } from '@rango-dev/wallets-core/legacy';
11
- import type { SuiActions } from '@rango-dev/wallets-core/namespaces/sui';
12
- import type { UtxoActions } from '@rango-dev/wallets-core/namespaces/utxo';
12
+ Chain as AddEthereumChainParameter,
13
+ EvmActions,
14
+ } from '@hub3js/evm';
15
+ import type { SolanaActions } from '@hub3js/solana';
13
16
 
14
17
  import { pickVersion, type VersionedProviders } from '@hub3js/core/utils';
15
18
  import {
16
- LegacyEvents as Events,
17
- legacyFormatAddressWithNetwork as formatAddressWithNetwork,
18
- } from '@rango-dev/wallets-core/legacy';
19
- import {
20
- type AddEthereumChainParameter,
21
19
  convertEvmBlockchainMetaToEvmChainInfo,
20
+ formatAddressWithNetwork,
22
21
  getBlockChainNameFromId,
23
- type WalletType,
24
- } from '@rango-dev/wallets-shared';
22
+ getSupportedChainsFromProvider,
23
+ } from '@rango-dev/internal-blockchains';
25
24
  import { AccountId } from 'caip';
26
25
  import { type BlockchainMeta, isEvmBlockchain } from 'rango-types';
27
26
 
28
- import {
29
- type ConnectResult,
30
- HUB_LAST_CONNECTED_WALLETS,
31
- type ProviderProps,
32
- } from '../legacy/mod.js';
27
+ import { Events } from '../legacy/mod.js';
33
28
 
29
+ import { HUB_LAST_CONNECTED_WALLETS } from './constants.js';
34
30
  import {
35
31
  fromAccountIdToLegacyAddressFormat,
36
32
  isConnectResultEvm,
@@ -38,27 +34,16 @@ import {
38
34
  } from './helpers.js';
39
35
  import { LastConnectedWalletsFromStorage } from './lastConnectedWallets.js';
40
36
 
41
- /* Gets a list of hub and legacy providers and returns a tuple which separates them. */
42
- export function separateLegacyAndHubProviders(
43
- providers: VersionedProviders[]
44
- ): [LegacyProviderInterface[], Provider[]] {
45
- const LEGACY_VERSION = '0.0.0';
46
- const HUB_VERSION = '1.0.0';
47
-
48
- const legacyProviders: LegacyProviderInterface[] = [];
49
- const hubProviders: Provider[] = [];
50
-
51
- providers.forEach((provider) => {
37
+ export function getHubProviders(providers: VersionedProviders[]): Provider[] {
38
+ return providers.map((provider) => {
52
39
  try {
53
- const target = pickVersion(provider, HUB_VERSION);
54
- hubProviders.push(target[1]);
40
+ return pickVersion(provider, '1.0.0')[1] as Provider;
55
41
  } catch {
56
- const target = pickVersion(provider, LEGACY_VERSION);
57
- legacyProviders.push(target[1]);
42
+ throw new Error(
43
+ "Legacy providers aren't supported anymore. Expected a provider with version '1.0.0'."
44
+ );
58
45
  }
59
46
  });
60
-
61
- return [legacyProviders, hubProviders];
62
47
  }
63
48
 
64
49
  export function findProviderByType(
@@ -77,22 +62,6 @@ const lastConnectedWalletsFromStorage = new LastConnectedWalletsFromStorage(
77
62
  HUB_LAST_CONNECTED_WALLETS
78
63
  );
79
64
 
80
- export function getSupportedChainsFromProvider(
81
- provider: Provider,
82
- allBlockChains: ProviderProps['allBlockChains']
83
- ) {
84
- const namespacesProperty = provider
85
- .info()
86
- ?.metadata.properties?.find((property) => property.name === 'namespaces');
87
-
88
- const supportedChains =
89
- namespacesProperty?.value.data.flatMap((namespace) =>
90
- namespace.getSupportedChains(allBlockChains || [])
91
- ) || [];
92
-
93
- return supportedChains;
94
- }
95
-
96
65
  export function mapHubEventsToLegacy(
97
66
  hub: Hub,
98
67
  event: Event,
@@ -100,7 +69,7 @@ export function mapHubEventsToLegacy(
100
69
  metadata: {
101
70
  allBlockChains: ProviderProps['allBlockChains'];
102
71
  lastConnectAttemptParams: {
103
- [type: WalletType]: LegacyNamespaceInputForConnect[];
72
+ [type: WalletType]: NamespaceInputForConnect[];
104
73
  };
105
74
  }
106
75
  ): void {
@@ -286,29 +255,14 @@ export function mapHubEventsToLegacy(
286
255
  }
287
256
  }
288
257
 
289
- export function getAllLegacyProviders(
290
- allProviders: VersionedProviders[]
291
- ): LegacyProviderInterface[] {
292
- const LEGACY_VERSION = '0.0.0';
293
-
294
- const legacyProviders: LegacyProviderInterface[] = [];
295
-
296
- allProviders.forEach((provider) => {
297
- const target = pickVersion(provider, LEGACY_VERSION);
298
- legacyProviders.push(target[1]);
299
- });
300
-
301
- return legacyProviders;
302
- }
303
-
304
258
  /**
305
259
  * In legacy mode, for those who have switch network functionality (like evm), we are using an enum for network names
306
260
  * this enum only has meaning for us, and when we are going to connect an instance (e.g. window.ethereum) we should pass chain id.
307
261
  */
308
262
  export function convertNamespaceNetworkToEvmChainId(
309
- namespace: LegacyNamespaceInputForConnect,
263
+ namespace: NamespaceInputForConnect,
310
264
  meta: BlockchainMeta[]
311
- ) {
265
+ ): AddEthereumChainParameter | undefined {
312
266
  if (!namespace.network) {
313
267
  return undefined;
314
268
  }
@@ -324,7 +278,7 @@ export function convertNamespaceNetworkToEvmChainId(
324
278
  * This function will help us to map these strings to proper hex ids.
325
279
  */
326
280
  export function tryConvertNamespaceNetworkToChainInfo(
327
- namespace: LegacyNamespaceInputForConnect,
281
+ namespace: NamespaceInputForConnect,
328
282
  meta: BlockchainMeta[]
329
283
  ): string | AddEthereumChainParameter | undefined {
330
284
  // `undefined` means it's not evm or we couldn't find it in meta.
@@ -341,20 +295,17 @@ export function transformHubResultToLegacyResult(
341
295
  return {
342
296
  accounts: res.accounts,
343
297
  network: res.network,
344
- provider: undefined,
345
298
  };
346
299
  } else if (isConnectResultSolana(res)) {
347
300
  return {
348
301
  accounts: res,
349
302
  network: null,
350
- provider: undefined,
351
303
  };
352
304
  }
353
305
 
354
306
  return {
355
307
  accounts: [res],
356
308
  network: null,
357
- provider: undefined,
358
309
  };
359
310
  }
360
311
 
@@ -392,12 +343,20 @@ export function synchronizeHubWithConfigProviders(
392
343
  }
393
344
 
394
345
  export function isSolanaNamespace(
395
- ns: ProxiedNamespace<EvmActions | SolanaActions | SuiActions | UtxoActions>
396
- ): ns is ProxiedNamespace<SolanaActions> & { namespaceId: 'Solana' } {
346
+ ns: AllProxiedNamespaces
347
+ ): ns is AllProxiedNamespaces &
348
+ ProxiedNamespace<SolanaActions> & { namespaceId: 'Solana' } {
397
349
  return ns.namespaceId === 'Solana';
398
350
  }
399
351
  export function isEvmNamespace(
400
- ns: ProxiedNamespace<EvmActions | SolanaActions | SuiActions | UtxoActions>
401
- ): ns is ProxiedNamespace<EvmActions> & { namespaceId: 'EVM' } {
352
+ ns: AllProxiedNamespaces
353
+ ): ns is AllProxiedNamespaces &
354
+ ProxiedNamespace<EvmActions> & { namespaceId: 'EVM' } {
402
355
  return ns.namespaceId === 'EVM';
403
356
  }
357
+ export function isUtxoNamespace(
358
+ ns: AllProxiedNamespaces
359
+ ): ns is AllProxiedNamespaces &
360
+ ProxiedNamespace<UtxoActions> & { namespaceId: 'UTXO' } {
361
+ return ns.namespaceId === 'UTXO';
362
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './legacy/helpers.js';
2
1
  export { default as Provider } from './provider.js';
3
- export { useWallets } from './legacy/hooks.js';
2
+ export { useWallets } from './hooks.js';
3
+ export type * from './types.js';
4
4
  export * from './legacy/types.js';
package/src/legacy/mod.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  export type {
2
- ProviderProps,
3
- ProviderContext,
4
2
  ConnectResult,
3
+ EventHandler,
4
+ EventInfo,
5
5
  ExtendedWalletInfo,
6
+ NamespaceInputForConnect,
7
+ WalletInfo,
8
+ WalletState,
6
9
  } from './types.js';
7
- export {
8
- LEGACY_LAST_CONNECTED_WALLETS,
9
- HUB_LAST_CONNECTED_WALLETS,
10
- } from '../hub/constants.js';
11
-
12
- export { WalletContext } from './context.js';
13
- export { useLegacyProviders } from './useLegacyProviders.js';
10
+ export { Events } from './types.js';