@rango-dev/widget-embedded 0.0.0-experimental-1624fbb4-20260708 → 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 (158) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +1 -1
  4. package/dist/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts.map +1 -1
  5. package/dist/components/CustomDestination/CustomDestination.styles.d.ts +4 -4
  6. package/dist/components/CustomDestination/CustomDestination.styles.d.ts.map +1 -1
  7. package/dist/components/CustomTokenModal/CustomTokenModal.styles.d.ts +169 -169
  8. package/dist/components/CustomTokenModal/CustomTokenModal.styles.d.ts.map +1 -1
  9. package/dist/components/FilterSelector/FilterSelector.style.d.ts +1 -1
  10. package/dist/components/FilterSelector/FilterSelector.style.d.ts.map +1 -1
  11. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts +1 -1
  12. package/dist/components/HeaderButtons/HeaderButtons.styles.d.ts.map +1 -1
  13. package/dist/components/NamespaceItem/NamespaceItem.d.ts.map +1 -1
  14. package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts +1 -1
  15. package/dist/components/NamespaceItem/NamespaceItem.styles.d.ts.map +1 -1
  16. package/dist/components/NamespaceItem/NamespaceItem.types.d.ts +3 -3
  17. package/dist/components/NamespaceItem/NamespaceItem.types.d.ts.map +1 -1
  18. package/dist/components/Quote/Quote.d.ts.map +1 -1
  19. package/dist/components/Quote/Quote.styles.d.ts +171 -171
  20. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  21. package/dist/components/Quote/Quote.types.d.ts +0 -2
  22. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  23. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  24. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts +169 -169
  25. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -1
  26. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +168 -168
  27. package/dist/components/RefreshModal/RefreshModal.styles.d.ts.map +1 -1
  28. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
  29. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  30. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +1 -1
  31. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  32. package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts.map +1 -1
  33. package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts.map +1 -1
  34. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +3 -3
  35. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  36. package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts +1 -1
  37. package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts.map +1 -1
  38. package/dist/components/TokenList/TokenList.styles.d.ts +2 -2
  39. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  40. package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -1
  41. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +7 -3
  42. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  43. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.test.d.ts +2 -0
  44. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.test.d.ts.map +1 -0
  45. package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts +169 -169
  46. package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -1
  47. package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
  48. package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts.map +1 -1
  49. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  50. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +168 -168
  51. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
  52. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +3 -3
  53. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  54. package/dist/constants/errors.d.ts +1 -0
  55. package/dist/constants/errors.d.ts.map +1 -1
  56. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  57. package/dist/containers/Wallets/Wallets.helpers.d.ts +2 -2
  58. package/dist/containers/Wallets/Wallets.helpers.d.ts.map +1 -1
  59. package/dist/containers/Wallets/Wallets.types.d.ts +4 -4
  60. package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
  61. package/dist/containers/Wallets/useUpdates.d.ts +1 -1
  62. package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
  63. package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
  64. package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts +5 -0
  65. package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts.map +1 -0
  66. package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +1 -1
  67. package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -1
  68. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  69. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -4
  70. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  71. package/dist/hooks/useWalletList.d.ts.map +1 -1
  72. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -2
  73. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  74. package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts +2 -3
  75. package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts.map +1 -1
  76. package/dist/index.d.ts +10 -7
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +3 -2
  79. package/dist/index.js.map +4 -4
  80. package/dist/store/AppStore.d.ts +2 -2
  81. package/dist/store/AppStore.d.ts.map +1 -1
  82. package/dist/store/app.d.ts +2 -2
  83. package/dist/store/app.d.ts.map +1 -1
  84. package/dist/store/slices/config.d.ts +5 -5
  85. package/dist/store/slices/config.d.ts.map +1 -1
  86. package/dist/test-utils/fixtures.d.ts +2 -2
  87. package/dist/test-utils/fixtures.d.ts.map +1 -1
  88. package/dist/types/config.d.ts +25 -4
  89. package/dist/types/config.d.ts.map +1 -1
  90. package/dist/types/wallets.d.ts +1 -1
  91. package/dist/types/wallets.d.ts.map +1 -1
  92. package/dist/utils/common.d.ts +1 -0
  93. package/dist/utils/common.d.ts.map +1 -1
  94. package/dist/utils/connectionReporting.d.ts +24 -0
  95. package/dist/utils/connectionReporting.d.ts.map +1 -0
  96. package/dist/utils/connectionReporting.test.d.ts +2 -0
  97. package/dist/utils/connectionReporting.test.d.ts.map +1 -0
  98. package/dist/utils/errors.d.ts +14 -0
  99. package/dist/utils/errors.d.ts.map +1 -0
  100. package/dist/utils/errors.test.d.ts +2 -0
  101. package/dist/utils/errors.test.d.ts.map +1 -0
  102. package/dist/utils/providers.d.ts +3 -6
  103. package/dist/utils/providers.d.ts.map +1 -1
  104. package/dist/utils/swap.d.ts +1 -1
  105. package/dist/utils/swap.d.ts.map +1 -1
  106. package/dist/utils/wallets.d.ts +2 -1
  107. package/dist/utils/wallets.d.ts.map +1 -1
  108. package/package.json +16 -16
  109. package/src/QueueManager.tsx +17 -8
  110. package/src/components/NamespaceItem/NamespaceItem.styles.ts +1 -0
  111. package/src/components/NamespaceItem/NamespaceItem.tsx +5 -1
  112. package/src/components/NamespaceItem/NamespaceItem.types.ts +3 -3
  113. package/src/components/Quote/Quote.tsx +0 -2
  114. package/src/components/Quote/Quote.types.ts +0 -2
  115. package/src/components/Quote/QuoteCostDetails.tsx +15 -4
  116. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +8 -2
  117. package/src/components/SwapDetails/SwapDetails.tsx +18 -6
  118. package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +23 -23
  119. package/src/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.tsx +8 -2
  120. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +3 -3
  121. package/src/components/TokenList/LoadingTokenList.tsx +2 -2
  122. package/src/components/WalletStatefulConnect/DerivationPath.helpers.test.ts +98 -0
  123. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +14 -10
  124. package/src/components/WalletStatefulConnect/DerivationPath.tsx +14 -7
  125. package/src/components/WalletStatefulConnect/Detached.tsx +17 -8
  126. package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +2 -1
  127. package/src/components/WalletStatefulConnect/Namespaces.tsx +6 -12
  128. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +3 -3
  129. package/src/constants/errors.ts +3 -0
  130. package/src/containers/Wallets/Wallets.helpers.ts +4 -4
  131. package/src/containers/Wallets/Wallets.tsx +20 -3
  132. package/src/containers/Wallets/Wallets.types.ts +4 -7
  133. package/src/containers/Wallets/useUpdates.ts +4 -119
  134. package/src/containers/WidgetProvider/WidgetProvider.helpers.ts +10 -0
  135. package/src/containers/WidgetProvider/WidgetProvider.tsx +12 -1
  136. package/src/containers/WidgetProvider/WidgetProvider.types.ts +1 -1
  137. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +30 -31
  138. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +6 -3
  139. package/src/hooks/useWalletList.ts +10 -7
  140. package/src/hooks/useWalletProviders/useWalletProviders.helpers.ts +3 -10
  141. package/src/hooks/useWalletProviders/useWalletProviders.ts +2 -2
  142. package/src/index.ts +10 -11
  143. package/src/store/AppStore.tsx +4 -2
  144. package/src/store/app.ts +7 -2
  145. package/src/store/slices/config.ts +36 -25
  146. package/src/store/slices/data.test.ts +2 -2
  147. package/src/test-utils/fixtures.ts +6 -2
  148. package/src/types/config.ts +31 -4
  149. package/src/types/wallets.ts +1 -1
  150. package/src/utils/common.ts +6 -0
  151. package/src/utils/connectionReporting.test.ts +379 -0
  152. package/src/utils/connectionReporting.ts +94 -0
  153. package/src/utils/errors.test.ts +125 -0
  154. package/src/utils/errors.ts +88 -0
  155. package/src/utils/providers.ts +16 -50
  156. package/src/utils/swap.ts +8 -1
  157. package/src/utils/wallets.ts +12 -15
  158. package/dist/widget-embedded.build.json +0 -1
@@ -1,9 +1,6 @@
1
- import type { WidgetConfig } from '../../types';
1
+ import type { WidgetConfigWithoutLegacyProviders } from '../../types';
2
2
  import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
3
- import type {
4
- LegacyEventHandler as EventHandler,
5
- LegacyEvents,
6
- } from '@rango-dev/wallets-core/legacy';
3
+ import type { EventHandler, Events } from '@rango-dev/wallets-react';
7
4
 
8
5
  export type OnWalletConnectHandler = (wallet: LastConnectedWallet) => void;
9
6
  export type OnWalletDisconnectHandler = (walletType: string) => void;
@@ -23,7 +20,7 @@ export interface WidgetContextInterface {
23
20
  }
24
21
 
25
22
  type EventHandlerParams = Parameters<EventHandler>;
26
- type EventParam = Exclude<LegacyEvents, LegacyEvents.PROVIDER_DISCONNECTED>;
23
+ type EventParam = Exclude<Events, Events.PROVIDER_DISCONNECTED>;
27
24
 
28
25
  export type OnUpdateState = (
29
26
  type: EventHandlerParams[0],
@@ -35,5 +32,5 @@ export type OnUpdateState = (
35
32
 
36
33
  export interface PropTypes {
37
34
  onUpdateState?: OnUpdateState;
38
- config: WidgetConfig;
35
+ config: WidgetConfigWithoutLegacyProviders;
39
36
  }
@@ -2,18 +2,11 @@ import type {
2
2
  OnWalletConnectHandler,
3
3
  OnWalletDisconnectHandler,
4
4
  } from './Wallets.types';
5
+ import type { Network } from '@rango-dev/internal-blockchains';
5
6
  import type { LastConnectedWallet } from '@rango-dev/queue-manager-rango-preset';
6
- import type {
7
- LegacyEventHandler as EventHandler,
8
- LegacyEventHandler,
9
- } from '@rango-dev/wallets-core/legacy';
7
+ import type { EventHandler } from '@rango-dev/wallets-react';
10
8
 
11
- import {
12
- legacyFormatAddressWithNetwork as formatAddressWithNetwork,
13
- legacyReadAccountAddress as readAccountAddress,
14
- } from '@rango-dev/wallets-core/legacy';
15
9
  import { Events } from '@rango-dev/wallets-react';
16
- import { type Network } from '@rango-dev/wallets-shared';
17
10
  import { isEvmBlockchain } from 'rango-sdk';
18
11
 
19
12
  import { useAppStore } from '../../store/AppStore';
@@ -39,8 +32,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
39
32
  newWalletConnected,
40
33
  disconnectWallet,
41
34
  disconnectNamespaces,
42
- connectedWallets,
43
- removeBalancesForWallet,
44
35
  blockchains,
45
36
  } = useAppStore();
46
37
 
@@ -50,7 +41,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
50
41
  .map((chain) => chain.name);
51
42
 
52
43
  const onAccountsEvent = (
53
- event: Parameters<LegacyEventHandler>,
44
+ event: Parameters<EventHandler>,
54
45
  params: {
55
46
  supportedChainNames: Network[] | null;
56
47
  }
@@ -83,13 +74,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
83
74
  }
84
75
  };
85
76
 
86
- const handleUpdatesForHub: EventHandler = (
87
- type,
88
- event,
89
- value,
90
- state,
91
- info
92
- ) => {
77
+ const handler: EventHandler = (type, event, value, state, info) => {
93
78
  if (event === Events.ACCOUNTS) {
94
79
  const supportedChainNames: Network[] | null =
95
80
  walletAndSupportedChainsNames(info.supportedBlockchains);
@@ -116,97 +101,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
116
101
  if (event === Events.NAMESPACE_DISCONNECTED) {
117
102
  disconnectNamespaces(type, value);
118
103
  }
119
- };
120
104
 
121
- const handleUpdatesForLegacy: EventHandler = (
122
- type,
123
- event,
124
- value,
125
- state,
126
- info
127
- ) => {
128
- if (event === Events.ACCOUNTS) {
129
- const supportedChainNames: Network[] | null =
130
- walletAndSupportedChainsNames(info.supportedBlockchains);
131
-
132
- /*
133
- * When a wallet is connecting to an evm account, we will consider it as the account exists on other evm-compatible blockchains
134
- * To get their balances.
135
- *
136
- * The logic here is for handling switching account functionality in wallets. when a wallet is switching to another account
137
- * we need to clean the balances for old accounts.
138
- *
139
- * Note: hub will do the cleanup on namespace diconnected event.
140
- */
141
- const evmAccounts: string[] = [];
142
- const nonEvmAccounts: string[] = [];
143
-
144
- value?.forEach((account: string) => {
145
- const { network } = readAccountAddress(account);
146
- if (evmBasedChainNames.includes(network)) {
147
- evmAccounts.push(account);
148
- } else {
149
- nonEvmAccounts.push(account);
150
- }
151
- });
152
-
153
- const previousAccounts = connectedWallets
154
- .filter((wallet) => wallet.walletType === type)
155
- .map((wallet) =>
156
- formatAddressWithNetwork(wallet.address, wallet.chain)
157
- );
158
-
159
- if (previousAccounts.length > 0) {
160
- if (evmAccounts.length > 0) {
161
- // We use same logic for removing as we use for adding.
162
- const data = prepareAccountsForWalletStore(
163
- type,
164
- evmAccounts,
165
- evmBasedChainNames,
166
- supportedChainNames,
167
- info.isContractWallet
168
- );
169
-
170
- removeBalancesForWallet(type, {
171
- chains: data.map((account) => account.chain),
172
- });
173
- }
174
-
175
- if (nonEvmAccounts.length > 0) {
176
- removeBalancesForWallet(type, {
177
- chains: nonEvmAccounts.map((account) => {
178
- const { network } = readAccountAddress(account);
179
- return network;
180
- }),
181
- });
182
- }
183
- }
184
-
185
- // After cleaning up balances, it's time to add new accounts.
186
- if (value) {
187
- onAccountsEvent([type, event, value, state, info], {
188
- supportedChainNames,
189
- });
190
- } else {
191
- disconnectWallet(type);
192
- if (!!onDisconnectWalletHandler.current) {
193
- onDisconnectWalletHandler.current(type);
194
- } else {
195
- console.warn(
196
- `onDisconnectWallet handler hasn't been set. Are you sure?`
197
- );
198
- }
199
- }
200
- }
201
- };
202
-
203
- const handleUpdatesForBoth: EventHandler = (
204
- type,
205
- event,
206
- value,
207
- state,
208
- _info
209
- ) => {
210
105
  if (event === Events.CONNECTED && value) {
211
106
  const walletFromEvent: LastConnectedWallet = {
212
107
  walletType: type,
@@ -234,16 +129,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
234
129
  }
235
130
  };
236
131
 
237
- const handler: EventHandler = (type, event, value, state, info) => {
238
- if (info.isHub) {
239
- handleUpdatesForHub(type, event, value, state, info);
240
- } else {
241
- handleUpdatesForLegacy(type, event, value, state, info);
242
- }
243
-
244
- handleUpdatesForBoth(type, event, value, state, info);
245
- };
246
-
247
132
  return {
248
133
  handler,
249
134
  };
@@ -0,0 +1,10 @@
1
+ import type { WalletType } from '@hub3js/core';
2
+ import type { ProviderInterface } from '@rango-dev/wallets-react';
3
+
4
+ import { Provider } from '@hub3js/core';
5
+
6
+ export function isHubWallet(
7
+ wallet: WalletType | ProviderInterface | Provider
8
+ ): wallet is WalletType | Provider {
9
+ return typeof wallet === 'string' || wallet instanceof Provider;
10
+ }
@@ -13,9 +13,18 @@ import { getApiKeyFromEnvOrThrow } from '../../utils/env';
13
13
  import { WidgetWallets } from '../Wallets';
14
14
  import { WidgetInfo } from '../WidgetInfo';
15
15
 
16
+ import { isHubWallet } from './WidgetProvider.helpers';
17
+
16
18
  export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
17
19
  const { onUpdateState, config } = props;
18
20
 
21
+ const wallets = config?.wallets;
22
+ if (wallets && !wallets.every(isHubWallet)) {
23
+ throw new Error(
24
+ "Legacy providers aren't supported anymore. Expected a provider with version '1.0.0'."
25
+ );
26
+ }
27
+
19
28
  const fontFamily = props.config?.theme?.fontFamily;
20
29
 
21
30
  const { fetchApiConfig } = useFetchApiConfig();
@@ -45,7 +54,9 @@ export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
45
54
  }, [props.config?.signers?.customSolanaRPC]);
46
55
 
47
56
  return (
48
- <WidgetWallets config={config} onUpdateState={onUpdateState}>
57
+ <WidgetWallets
58
+ config={{ ...config, wallets }}
59
+ onUpdateState={onUpdateState}>
49
60
  <QueueManager apiKey={config.apiKey}>
50
61
  <WidgetInfo>{props.children}</WidgetInfo>
51
62
  </QueueManager>
@@ -1,5 +1,5 @@
1
1
  import type { WidgetConfig } from '../../types';
2
- import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
2
+ import type { EventHandler } from '@rango-dev/wallets-react';
3
3
 
4
4
  export type PropTypes = {
5
5
  onUpdateState?: EventHandler;
@@ -1,13 +1,17 @@
1
- import type { HandleConnectOptions, Result } from './useStatefulConnect.types';
1
+ import type {
2
+ HandleConnectOptions,
3
+ NamespaceData,
4
+ Result,
5
+ } from './useStatefulConnect.types';
2
6
  import type { WalletInfoWithExtra } from '../../types';
3
7
  import type { Namespace } from '@hub3js/namespaces';
4
- import type { NamespaceData } from '@rango-dev/wallets-shared';
5
8
 
6
9
  import { WalletState } from '@rango-dev/ui';
7
10
  import { useWallets } from '@rango-dev/wallets-react';
8
11
  import { useReducer } from 'react';
9
12
 
10
13
  import { isOnDetached } from '../../components/StatefulConnectModal';
14
+ import { trackConnection } from '../../utils/connectionReporting';
11
15
  import { type ExtendedModalWalletInfo } from '../../utils/wallets';
12
16
 
13
17
  import {
@@ -71,14 +75,14 @@ export function useStatefulConnect(): UseStatefulConnect {
71
75
  ...namespaceInput,
72
76
  network: undefined,
73
77
  }));
74
- await connect(wallet.type, legacyNamespacesInput);
78
+ await trackConnection(connect(wallet.type, legacyNamespacesInput), {
79
+ trigger: 'wallet-modal',
80
+ source: 'user',
81
+ walletType: wallet.type,
82
+ namespaces: namespaces?.map(({ namespace }) => namespace),
83
+ });
75
84
  return { status: ResultStatus.Connected };
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
- } catch (e: any) {
78
- const message = e?.message
79
- ? `Error: ${e.message}`
80
- : 'An unknown error happened during connecting wallet.';
81
-
85
+ } catch (e) {
82
86
  if (options?.disconnectOnError) {
83
87
  try {
84
88
  await handleDisconnect(wallet);
@@ -89,7 +93,7 @@ export function useStatefulConnect(): UseStatefulConnect {
89
93
  }
90
94
  }
91
95
 
92
- throw new Error(message, { cause: e });
96
+ throw e;
93
97
  }
94
98
  };
95
99
 
@@ -110,16 +114,13 @@ export function useStatefulConnect(): UseStatefulConnect {
110
114
  * 3. Target wallet contains only one namespace, in this situation we should check if that namespace needs derivation path and based on that, try to connect to the related provider or display derivation path modal.
111
115
  */
112
116
 
113
- // Legacy and hub have different structure to handle each situation.
114
- const isHub = !!wallet.isHub;
115
- const needsNamespace = isHub
116
- ? wallet.properties?.find((item) => item.name === 'namespaces')?.value
117
- : wallet.needsNamespace;
117
+ const needsNamespace = wallet.properties?.find(
118
+ (item) => item.name === 'namespaces'
119
+ )?.value;
118
120
 
119
- const needsDerivationPath = isHub
120
- ? wallet.properties?.find((item) => item.name === 'derivationPath')
121
- ?.value
122
- : wallet.needsDerivationPath;
121
+ const needsDerivationPath = wallet.properties?.find(
122
+ (item) => item.name === 'derivationPath'
123
+ )?.value;
123
124
 
124
125
  // Forced namespaces are used to bypass namespace selection flow.
125
126
  if (forceConnectToNamespaces) {
@@ -209,7 +210,7 @@ export function useStatefulConnect(): UseStatefulConnect {
209
210
  * and forced namespaces are not enabled,
210
211
  * we should display detached modal
211
212
  */
212
- if (!!wallet.isHub && !options?.forceConnectToNamespaces) {
213
+ if (!options?.forceConnectToNamespaces) {
213
214
  const needsNamespace = wallet.properties?.find(
214
215
  (item) => item.name === 'namespaces'
215
216
  )?.value;
@@ -237,14 +238,13 @@ export function useStatefulConnect(): UseStatefulConnect {
237
238
  wallet: ExtendedModalWalletInfo,
238
239
  selectedNamespaces: Namespace[]
239
240
  ): Promise<Result> => {
240
- const isHub = !!wallet.isHub;
241
- const needsNamespace = isHub
242
- ? wallet.properties?.find((item) => item.name === 'namespaces')?.value
243
- : wallet.needsNamespace;
241
+ const needsNamespace = wallet.properties?.find(
242
+ (item) => item.name === 'namespaces'
243
+ )?.value;
244
244
 
245
- const needsDerivationPath = isHub
246
- ? wallet.properties?.find((item) => item.name === 'derivationPath')?.value
247
- : wallet.needsDerivationPath;
245
+ const needsDerivationPath = wallet.properties?.find(
246
+ (item) => item.name === 'derivationPath'
247
+ )?.value;
248
248
 
249
249
  const isSingleNamespace = needsNamespace?.selection === 'single';
250
250
  const firstSelectedNamespace = selectedNamespaces[0];
@@ -320,10 +320,9 @@ export function useStatefulConnect(): UseStatefulConnect {
320
320
  const selectedNamespace = connectState.derivationPath.namespace;
321
321
  const namespaces = [{ namespace: selectedNamespace, derivationPath }];
322
322
 
323
- const isHub = !!wallet.isHub;
324
- const needsNamespace = isHub
325
- ? wallet.properties?.find((item) => item.name === 'namespaces')?.value
326
- : wallet.needsNamespace;
323
+ const needsNamespace = wallet.properties?.find(
324
+ (item) => item.name === 'namespaces'
325
+ )?.value;
327
326
 
328
327
  const namespaceIsAvailable =
329
328
  !!needsNamespace?.data && needsNamespace.data.length > 1;
@@ -1,6 +1,11 @@
1
1
  import type { ExtendedModalWalletInfo } from '../../utils/wallets';
2
2
  import type { Namespace } from '@hub3js/namespaces';
3
3
 
4
+ export interface NamespaceData {
5
+ namespace: Namespace;
6
+ derivationPath?: string;
7
+ }
8
+
4
9
  export interface HandleConnectOptions {
5
10
  // To have a switch between connect and disconnect when user is clicking on a button, this option can be helpful.
6
11
  forceConnectToNamespaces?: Namespace[];
@@ -15,9 +20,7 @@ export interface NeedsNamespacesState {
15
20
 
16
21
  export interface DetachedPayload {
17
22
  targetWallet: ExtendedModalWalletInfo;
18
- selectedNamespaces:
19
- | { namespace: Namespace; derivationPath?: string }[]
20
- | null;
23
+ selectedNamespaces: NamespaceData[] | null;
21
24
  derivationPath?: string;
22
25
  }
23
26
 
@@ -1,12 +1,13 @@
1
1
  import type { ExtendedModalWalletInfo } from '../utils/wallets';
2
2
  import type { WalletInfo } from '@rango-dev/ui';
3
3
 
4
+ import { WalletTypes } from '@rango-dev/provider-all';
4
5
  import { WalletState } from '@rango-dev/ui';
5
6
  import { useWallets } from '@rango-dev/wallets-react';
6
- import { detectMobileScreens, WalletTypes } from '@rango-dev/wallets-shared';
7
7
  import { useCallback, useEffect } from 'react';
8
8
 
9
9
  import { useAppStore } from '../store/AppStore';
10
+ import { detectMobileScreens } from '../utils/common';
10
11
  import { emitWalletDetected } from '../utils/events';
11
12
  import { configWalletsToWalletName } from '../utils/providers';
12
13
  import {
@@ -37,6 +38,12 @@ const NON_INJECTED_WALLET_TYPES = new Set<string>([
37
38
  WalletTypes.DEFAULT,
38
39
  ]);
39
40
 
41
+ const DEFAULT_EVM_WALLETS = new Set<string>([
42
+ WalletTypes.DEFAULT,
43
+ WalletTypes.WALLET_CONNECT_2,
44
+ WalletTypes.LEDGER,
45
+ ]);
46
+
40
47
  interface Params {
41
48
  chain?: string;
42
49
  }
@@ -89,7 +96,7 @@ export function useWalletList(params?: Params): API {
89
96
  if (isDetected && !detectedWalletsReported.has(wallet.type)) {
90
97
  detectedWalletsReported.add(wallet.type);
91
98
  emitWalletDetected({
92
- walletName: wallet.title,
99
+ walletName: wallet.type,
93
100
  });
94
101
  }
95
102
  });
@@ -131,11 +138,7 @@ export function useWalletList(params?: Params): API {
131
138
  const isEvmWalletInstalledExceptDefault = wallets.filter(
132
139
  (wallet) =>
133
140
  wallet.state != WalletState.NOT_INSTALLED &&
134
- ![
135
- WalletTypes.DEFAULT,
136
- WalletTypes.WALLET_CONNECT_2,
137
- WalletTypes.LEDGER,
138
- ].includes(wallet.type as WalletTypes) &&
141
+ !DEFAULT_EVM_WALLETS.has(wallet.type) &&
139
142
  getWalletInfo(wallet.type).supportedChains.filter(
140
143
  (blockchain) => blockchain.type == 'EVM'
141
144
  ).length > 0
@@ -1,19 +1,12 @@
1
- import type { ProviderInterface } from '@rango-dev/wallets-react';
1
+ import type { Provider } from '@hub3js/core';
2
2
 
3
- import { Provider } from '@hub3js/core';
4
-
5
- export function hashProviders(
6
- providers: (string | ProviderInterface | Provider)[]
7
- ): string {
3
+ export function hashProviders(providers: (string | Provider)[]): string {
8
4
  return providers
9
5
  .map((provider) => {
10
6
  if (typeof provider === 'string') {
11
7
  return provider;
12
8
  }
13
- if (provider instanceof Provider) {
14
- return provider.id;
15
- }
16
- return provider.config.type;
9
+ return provider.id;
17
10
  })
18
11
  .join('-');
19
12
  }
@@ -1,4 +1,4 @@
1
- import type { WidgetConfig } from '../../types';
1
+ import type { WidgetConfigWithoutLegacyProviders } from '../../types';
2
2
  import type { ProvidersOptions } from '../../utils/providers';
3
3
 
4
4
  import { useEffect } from 'react';
@@ -8,7 +8,7 @@ import { useAppStore } from '../../store/AppStore';
8
8
  import { hashProviders } from './useWalletProviders.helpers';
9
9
 
10
10
  export function useWalletProviders(
11
- configWallets: WidgetConfig['wallets'],
11
+ configWallets: WidgetConfigWithoutLegacyProviders['wallets'],
12
12
  options?: ProvidersOptions
13
13
  ) {
14
14
  const { clearConnectedWallet, getAvailableProviders, buildAndSetProviders } =
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import type {
14
14
  WidgetTheme,
15
15
  WidgetVariant,
16
16
  } from './types';
17
+ import type { WalletType } from '@hub3js/core';
17
18
  import type {
18
19
  PendingSwapWithQueueID,
19
20
  Route,
@@ -36,16 +37,14 @@ import type {
36
37
  StepTxExecutionUpdatedEvent,
37
38
  } from '@rango-dev/queue-manager-rango-preset';
38
39
  import type {
39
- LegacyEventHandler as HandleWalletsUpdate,
40
- LegacyProviderInterface as ProviderInterface,
41
- } from '@rango-dev/wallets-core/legacy';
42
- import type {
40
+ EventHandler as HandleWalletsUpdate,
41
+ ProviderInterface,
43
42
  WalletInfo,
44
43
  WalletState,
45
- WalletType,
46
- } from '@rango-dev/wallets-shared';
44
+ } from '@rango-dev/wallets-react';
47
45
  import type { PendingSwap, PendingSwapStep } from 'rango-types';
48
46
 
47
+ import { Networks, readAccountAddress } from '@rango-dev/internal-blockchains';
49
48
  import {
50
49
  EventSeverity,
51
50
  RouteEventType,
@@ -53,9 +52,7 @@ import {
53
52
  StepExecutionBlockedEventStatus,
54
53
  StepExecutionEventStatus,
55
54
  } from '@rango-dev/queue-manager-rango-preset';
56
- import { legacyReadAccountAddress as readAccountAddress } from '@rango-dev/wallets-core/legacy';
57
55
  import { useWallets, Events as WalletEvents } from '@rango-dev/wallets-react';
58
- import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
59
56
  import { PendingSwapNetworkStatus } from 'rango-types';
60
57
 
61
58
  import {
@@ -87,7 +84,7 @@ import {
87
84
  WalletEventTypes,
88
85
  WidgetEvents,
89
86
  } from './types';
90
- import { pickProviderVersionWithFallbackToLegacy } from './utils/providers';
87
+ import { pickProviderVersion } from './utils/providers';
91
88
  import { customizedThemeTokens } from './utils/ui';
92
89
 
93
90
  export const StatefulConnect = {
@@ -105,6 +102,9 @@ export type {
105
102
  WidgetTheme,
106
103
  WidgetColors,
107
104
  WidgetColorsKeys,
105
+ /**
106
+ * @deprecated Pass a hub `Provider` instead. This type will be removed in future versions.
107
+ */
108
108
  ProviderInterface,
109
109
  BlockchainAndTokenConfig,
110
110
  WidgetProps,
@@ -183,10 +183,9 @@ export type {
183
183
  // Internal function and enum exports for Rango
184
184
  export {
185
185
  readAccountAddress,
186
- pickProviderVersionWithFallbackToLegacy,
186
+ pickProviderVersion,
187
187
  Networks,
188
188
  WalletEvents,
189
- WalletTypes,
190
189
  PendingSwapNetworkStatus,
191
190
  EventSeverity,
192
191
  };
@@ -1,4 +1,4 @@
1
- import type { WidgetConfig } from '../types';
1
+ import type { WidgetConfigWithoutLegacyProviders } from '../types';
2
2
  import type { PropsWithChildren } from 'react';
3
3
 
4
4
  import React, { createContext, useContext, useEffect, useRef } from 'react';
@@ -6,7 +6,9 @@ import React, { createContext, useContext, useEffect, useRef } from 'react';
6
6
  import { createAppStore } from './app';
7
7
 
8
8
  type AppStore = ReturnType<typeof createAppStore>;
9
- type AppStoreProviderProps = PropsWithChildren<{ config?: WidgetConfig }>;
9
+ type AppStoreProviderProps = PropsWithChildren<{
10
+ config?: WidgetConfigWithoutLegacyProviders;
11
+ }>;
10
12
 
11
13
  export const AppStoreContext = createContext<AppStore | null>(null);
12
14
 
package/src/store/app.ts CHANGED
@@ -1,4 +1,7 @@
1
- import type { WidgetConfig } from '../types';
1
+ import type {
2
+ WidgetConfig,
3
+ WidgetConfigWithoutLegacyProviders,
4
+ } from '../types';
2
5
  import type { AppStoreState } from './slices/types';
3
6
  import type { StateCreator } from 'zustand';
4
7
 
@@ -21,7 +24,9 @@ export type StateCreatorWithInitialData<
21
24
 
22
25
  export type { AppStoreState };
23
26
 
24
- export function createAppStore(initialData?: WidgetConfig) {
27
+ export function createAppStore(
28
+ initialData?: WidgetConfigWithoutLegacyProviders
29
+ ) {
25
30
  return create<AppStoreState>()(
26
31
  persist(
27
32
  (...a) => ({