@rango-dev/widget-embedded 0.0.0-experimental-d66900c7-20260708 → 0.0.0-experimental-99f1781b-20260920

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 (194) 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 +2 -1
  29. package/dist/components/StatefulConnectModal/StatefulConnectModal.d.ts.map +1 -1
  30. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  31. package/dist/components/SwapDetails/SwapDetails.styles.d.ts +1 -1
  32. package/dist/components/SwapDetails/SwapDetails.styles.d.ts.map +1 -1
  33. package/dist/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.d.ts.map +1 -1
  34. package/dist/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.d.ts.map +1 -1
  35. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts +3 -3
  36. package/dist/components/SwapDetailsModal/SwapDetailsModal.types.d.ts.map +1 -1
  37. package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts +1 -1
  38. package/dist/components/SwapMetrics/SwapMetrics.styles.d.ts.map +1 -1
  39. package/dist/components/TokenList/TokenList.styles.d.ts +2 -2
  40. package/dist/components/TokenList/TokenList.styles.d.ts.map +1 -1
  41. package/dist/components/WalletStatefulConnect/DerivationPath.d.ts.map +1 -1
  42. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +7 -3
  43. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  44. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.test.d.ts +2 -0
  45. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.test.d.ts.map +1 -0
  46. package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts +169 -169
  47. package/dist/components/WalletStatefulConnect/DerivationPath.styles.d.ts.map +1 -1
  48. package/dist/components/WalletStatefulConnect/Detached.d.ts.map +1 -1
  49. package/dist/components/WalletStatefulConnect/Detached.types.d.ts +2 -1
  50. package/dist/components/WalletStatefulConnect/Detached.types.d.ts.map +1 -1
  51. package/dist/components/WalletStatefulConnect/NamespaceDetachedItem.d.ts.map +1 -1
  52. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  53. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts +168 -168
  54. package/dist/components/WalletStatefulConnect/Namespaces.styles.d.ts.map +1 -1
  55. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +3 -3
  56. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  57. package/dist/constants/errors.d.ts +1 -0
  58. package/dist/constants/errors.d.ts.map +1 -1
  59. package/dist/containers/Wallets/Wallets.constants.d.ts +3 -0
  60. package/dist/containers/Wallets/Wallets.constants.d.ts.map +1 -0
  61. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  62. package/dist/containers/Wallets/Wallets.helpers.d.ts +2 -2
  63. package/dist/containers/Wallets/Wallets.helpers.d.ts.map +1 -1
  64. package/dist/containers/Wallets/Wallets.helpers.test.d.ts +2 -0
  65. package/dist/containers/Wallets/Wallets.helpers.test.d.ts.map +1 -0
  66. package/dist/containers/Wallets/Wallets.types.d.ts +6 -4
  67. package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -1
  68. package/dist/containers/Wallets/useUpdates.d.ts +1 -1
  69. package/dist/containers/Wallets/useUpdates.d.ts.map +1 -1
  70. package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
  71. package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts +5 -0
  72. package/dist/containers/WidgetProvider/WidgetProvider.helpers.d.ts.map +1 -0
  73. package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +1 -1
  74. package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -1
  75. package/dist/hooks/useConnectWithLogging/index.d.ts +2 -0
  76. package/dist/hooks/useConnectWithLogging/index.d.ts.map +1 -0
  77. package/dist/hooks/useConnectWithLogging/useConnectWithLogging.d.ts +11 -0
  78. package/dist/hooks/useConnectWithLogging/useConnectWithLogging.d.ts.map +1 -0
  79. package/dist/hooks/useConnectWithLogging/useConnectWithLogging.test.d.ts +2 -0
  80. package/dist/hooks/useConnectWithLogging/useConnectWithLogging.test.d.ts.map +1 -0
  81. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +2 -1
  82. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  83. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -4
  84. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  85. package/dist/hooks/useWalletList.d.ts.map +1 -1
  86. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -2
  87. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  88. package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts +2 -3
  89. package/dist/hooks/useWalletProviders/useWalletProviders.helpers.d.ts.map +1 -1
  90. package/dist/index.d.ts +10 -7
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +3 -2
  93. package/dist/index.js.map +4 -4
  94. package/dist/libs/connectLogging/connectLogging.constants.d.ts +9 -0
  95. package/dist/libs/connectLogging/connectLogging.constants.d.ts.map +1 -0
  96. package/dist/libs/connectLogging/connectLogging.d.ts +12 -0
  97. package/dist/libs/connectLogging/connectLogging.d.ts.map +1 -0
  98. package/dist/libs/connectLogging/connectLogging.test.d.ts +2 -0
  99. package/dist/libs/connectLogging/connectLogging.test.d.ts.map +1 -0
  100. package/dist/libs/connectLogging/connectLogging.types.d.ts +57 -0
  101. package/dist/libs/connectLogging/connectLogging.types.d.ts.map +1 -0
  102. package/dist/libs/connectLogging/index.d.ts +3 -0
  103. package/dist/libs/connectLogging/index.d.ts.map +1 -0
  104. package/dist/pages/WalletsPage.d.ts.map +1 -1
  105. package/dist/store/AppStore.d.ts +2 -2
  106. package/dist/store/AppStore.d.ts.map +1 -1
  107. package/dist/store/app.d.ts +2 -2
  108. package/dist/store/app.d.ts.map +1 -1
  109. package/dist/store/slices/config.d.ts +5 -5
  110. package/dist/store/slices/config.d.ts.map +1 -1
  111. package/dist/test-utils/fixtures.d.ts +2 -2
  112. package/dist/test-utils/fixtures.d.ts.map +1 -1
  113. package/dist/types/config.d.ts +25 -4
  114. package/dist/types/config.d.ts.map +1 -1
  115. package/dist/types/event.d.ts +1 -1
  116. package/dist/types/event.d.ts.map +1 -1
  117. package/dist/types/wallets.d.ts +1 -1
  118. package/dist/types/wallets.d.ts.map +1 -1
  119. package/dist/utils/common.d.ts +1 -0
  120. package/dist/utils/common.d.ts.map +1 -1
  121. package/dist/utils/errors.d.ts +14 -0
  122. package/dist/utils/errors.d.ts.map +1 -0
  123. package/dist/utils/errors.test.d.ts +2 -0
  124. package/dist/utils/errors.test.d.ts.map +1 -0
  125. package/dist/utils/providers.d.ts +3 -6
  126. package/dist/utils/providers.d.ts.map +1 -1
  127. package/dist/utils/swap.d.ts +1 -1
  128. package/dist/utils/swap.d.ts.map +1 -1
  129. package/dist/utils/wallets.d.ts +2 -1
  130. package/dist/utils/wallets.d.ts.map +1 -1
  131. package/package.json +16 -16
  132. package/src/QueueManager.tsx +17 -16
  133. package/src/components/ConfirmWalletsModal/WalletList.tsx +2 -2
  134. package/src/components/NamespaceItem/NamespaceItem.styles.ts +1 -0
  135. package/src/components/NamespaceItem/NamespaceItem.tsx +5 -1
  136. package/src/components/NamespaceItem/NamespaceItem.types.ts +3 -3
  137. package/src/components/Quote/Quote.tsx +0 -2
  138. package/src/components/Quote/Quote.types.ts +0 -2
  139. package/src/components/Quote/QuoteCostDetails.tsx +15 -4
  140. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +4 -2
  141. package/src/components/SwapDetails/SwapDetails.tsx +17 -8
  142. package/src/components/SwapDetailsModal/SwapDetailsModal.ConnectWallet.tsx +12 -13
  143. package/src/components/SwapDetailsModal/SwapDetailsModal.InstallWallet.tsx +8 -2
  144. package/src/components/SwapDetailsModal/SwapDetailsModal.types.ts +3 -3
  145. package/src/components/TokenList/LoadingTokenList.tsx +2 -2
  146. package/src/components/WalletStatefulConnect/DerivationPath.helpers.test.ts +98 -0
  147. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +14 -10
  148. package/src/components/WalletStatefulConnect/DerivationPath.tsx +14 -7
  149. package/src/components/WalletStatefulConnect/Detached.tsx +17 -10
  150. package/src/components/WalletStatefulConnect/Detached.types.ts +2 -1
  151. package/src/components/WalletStatefulConnect/NamespaceDetachedItem.tsx +2 -1
  152. package/src/components/WalletStatefulConnect/Namespaces.tsx +6 -12
  153. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +3 -3
  154. package/src/constants/errors.ts +3 -0
  155. package/src/containers/Wallets/Wallets.constants.ts +14 -0
  156. package/src/containers/Wallets/Wallets.helpers.test.ts +67 -0
  157. package/src/containers/Wallets/Wallets.helpers.ts +9 -9
  158. package/src/containers/Wallets/Wallets.tsx +20 -3
  159. package/src/containers/Wallets/Wallets.types.ts +7 -7
  160. package/src/containers/Wallets/useUpdates.ts +7 -117
  161. package/src/containers/WidgetProvider/WidgetProvider.helpers.ts +10 -0
  162. package/src/containers/WidgetProvider/WidgetProvider.tsx +12 -1
  163. package/src/containers/WidgetProvider/WidgetProvider.types.ts +1 -1
  164. package/src/hooks/useConnectWithLogging/index.ts +1 -0
  165. package/src/hooks/useConnectWithLogging/useConnectWithLogging.test.ts +138 -0
  166. package/src/hooks/useConnectWithLogging/useConnectWithLogging.ts +36 -0
  167. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +36 -29
  168. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +6 -3
  169. package/src/hooks/useWalletList.ts +10 -8
  170. package/src/hooks/useWalletProviders/useWalletProviders.helpers.ts +3 -10
  171. package/src/hooks/useWalletProviders/useWalletProviders.ts +2 -2
  172. package/src/index.ts +10 -11
  173. package/src/libs/connectLogging/connectLogging.constants.ts +17 -0
  174. package/src/libs/connectLogging/connectLogging.test.ts +918 -0
  175. package/src/libs/connectLogging/connectLogging.ts +359 -0
  176. package/src/libs/connectLogging/connectLogging.types.ts +70 -0
  177. package/src/libs/connectLogging/index.ts +5 -0
  178. package/src/pages/WalletsPage.tsx +1 -0
  179. package/src/store/AppStore.tsx +4 -2
  180. package/src/store/app.ts +7 -2
  181. package/src/store/slices/config.ts +36 -25
  182. package/src/store/slices/data.test.ts +2 -2
  183. package/src/store/slices/wallets.ts +1 -1
  184. package/src/test-utils/fixtures.ts +6 -2
  185. package/src/types/config.ts +31 -4
  186. package/src/types/event.ts +1 -1
  187. package/src/types/wallets.ts +1 -1
  188. package/src/utils/common.ts +6 -0
  189. package/src/utils/errors.test.ts +78 -0
  190. package/src/utils/errors.ts +69 -0
  191. package/src/utils/providers.ts +16 -50
  192. package/src/utils/swap.ts +8 -1
  193. package/src/utils/wallets.ts +12 -15
  194. package/dist/widget-embedded.build.json +0 -1
@@ -0,0 +1,138 @@
1
+ import type {
2
+ ConnectResult,
3
+ NamespaceInputForConnect,
4
+ } from '@rango-dev/wallets-react';
5
+
6
+ import { WalletConnectionError } from '@hub3js/std/utils';
7
+ import { error as logError } from '@rango-dev/logging-core';
8
+ import { WalletConnectionAttemptError } from '@rango-dev/wallets-react';
9
+ import { createElement } from 'react';
10
+ import { renderToStaticMarkup } from 'react-dom/server';
11
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
12
+
13
+ import { useConnectWithLogging } from './useConnectWithLogging';
14
+
15
+ const { connect } = vi.hoisted(() => ({ connect: vi.fn() }));
16
+
17
+ vi.mock('@rango-dev/logging-core', () => ({ error: vi.fn() }));
18
+ vi.mock('@rango-dev/wallets-react', async (importOriginal) => ({
19
+ ...(await importOriginal<Record<string, unknown>>()),
20
+ useWallets: () => ({ connect }),
21
+ }));
22
+
23
+ const loggedError = vi.mocked(logError);
24
+
25
+ const THREE_MINUTES = 180_000;
26
+
27
+ const NAMESPACES: NamespaceInputForConnect[] = [
28
+ { namespace: 'EVM', network: undefined },
29
+ ];
30
+
31
+ const CONNECTED: ConnectResult[] = [{ accounts: [], network: null }];
32
+
33
+ type ConnectWithLogging = ReturnType<typeof useConnectWithLogging>;
34
+
35
+ async function pending(): Promise<ConnectResult[]> {
36
+ return new Promise<ConnectResult[]>(() => undefined);
37
+ }
38
+
39
+ function failedAttempt(): WalletConnectionAttemptError {
40
+ return new WalletConnectionAttemptError({
41
+ errors: [
42
+ new WalletConnectionError({ namespace: 'EVM', cause: new Error('boom') }),
43
+ ],
44
+ requestedNamespaces: NAMESPACES,
45
+ });
46
+ }
47
+
48
+ function renderConnect(): ConnectWithLogging {
49
+ let rendered: ConnectWithLogging | undefined;
50
+ function Probe() {
51
+ rendered = useConnectWithLogging();
52
+ return null;
53
+ }
54
+
55
+ renderToStaticMarkup(createElement(Probe));
56
+
57
+ if (!rendered) {
58
+ throw new Error('The hook was not rendered.');
59
+ }
60
+
61
+ return rendered;
62
+ }
63
+
64
+ beforeEach(() => {
65
+ loggedError.mockReset();
66
+ connect.mockReset();
67
+ connect.mockResolvedValue(CONNECTED);
68
+ vi.useFakeTimers();
69
+ });
70
+
71
+ afterEach(() => {
72
+ vi.useRealTimers();
73
+ });
74
+
75
+ describe('connecting without a trigger', () => {
76
+ it('calls connect with the same wallet type and namespaces and resolves with its result', async () => {
77
+ await expect(renderConnect()('metamask', NAMESPACES)).resolves.toBe(
78
+ CONNECTED
79
+ );
80
+
81
+ expect(connect).toHaveBeenCalledWith('metamask', NAMESPACES);
82
+ });
83
+
84
+ it('logs nothing when the attempt fails and rethrows its error unchanged', async () => {
85
+ const received = failedAttempt();
86
+ connect.mockRejectedValue(received);
87
+
88
+ await expect(renderConnect()('metamask', NAMESPACES)).rejects.toBe(
89
+ received
90
+ );
91
+
92
+ expect(loggedError).not.toHaveBeenCalled();
93
+ });
94
+
95
+ it('logs nothing when the attempt is still pending after three minutes', () => {
96
+ connect.mockReturnValue(pending());
97
+
98
+ void renderConnect()('metamask', NAMESPACES);
99
+ vi.advanceTimersByTime(THREE_MINUTES);
100
+
101
+ expect(loggedError).not.toHaveBeenCalled();
102
+ });
103
+ });
104
+
105
+ describe('connecting with a trigger', () => {
106
+ it('logs the error the attempt failed with, tagged with the trigger, and rethrows it unchanged', async () => {
107
+ const received = failedAttempt();
108
+ connect.mockRejectedValue(received);
109
+
110
+ await expect(
111
+ renderConnect()('metamask', NAMESPACES, {
112
+ trigger: 'swap-details-reconnect',
113
+ })
114
+ ).rejects.toBe(received);
115
+
116
+ expect(connect).toHaveBeenCalledWith('metamask', NAMESPACES);
117
+ expect(loggedError).toHaveBeenCalledTimes(1);
118
+ expect(loggedError.mock.calls[0]?.[0]).toBe(received);
119
+ expect(loggedError.mock.calls[0]?.[1]?.tags).toEqual({
120
+ walletType: 'metamask',
121
+ namespaces: 'EVM',
122
+ trigger: 'swap-details-reconnect',
123
+ category: 'wallet',
124
+ });
125
+ });
126
+
127
+ it('logs a timeout when the attempt is still pending after three minutes', () => {
128
+ connect.mockReturnValue(pending());
129
+
130
+ void renderConnect()('metamask', NAMESPACES, { trigger: 'wallets-page' });
131
+ vi.advanceTimersByTime(THREE_MINUTES);
132
+
133
+ expect(loggedError).toHaveBeenCalledTimes(1);
134
+ expect(loggedError.mock.calls[0]?.[1]?.tags).toEqual(
135
+ expect.objectContaining({ trigger: 'wallets-page', category: 'timeout' })
136
+ );
137
+ });
138
+ });
@@ -0,0 +1,36 @@
1
+ import type { WithConnectTrigger } from '../../libs/connectLogging';
2
+ import type { WalletType } from '@hub3js/core';
3
+ import type {
4
+ ConnectResult,
5
+ NamespaceInputForConnect,
6
+ } from '@rango-dev/wallets-react';
7
+
8
+ import { useWallets } from '@rango-dev/wallets-react';
9
+
10
+ import { runConnectWithLogging } from '../../libs/connectLogging';
11
+
12
+ type ConnectWithLogging = (
13
+ walletType: WalletType,
14
+ namespaces?: NamespaceInputForConnect[],
15
+ options?: WithConnectTrigger
16
+ ) => Promise<ConnectResult[]>;
17
+
18
+ /**
19
+ * `connect` from `useWallets`, logging the attempts that fail. Without a
20
+ * trigger it's `connect` itself: nothing is logged and no timer runs.
21
+ */
22
+ export function useConnectWithLogging(): ConnectWithLogging {
23
+ const { connect } = useWallets();
24
+
25
+ return async (walletType, namespaces, options) => {
26
+ const trigger = options?.trigger;
27
+ if (!trigger) {
28
+ return connect(walletType, namespaces);
29
+ }
30
+
31
+ return runConnectWithLogging(
32
+ { walletType, trigger, requestedNamespaces: namespaces ?? [] },
33
+ async () => connect(walletType, namespaces)
34
+ );
35
+ };
36
+ }
@@ -1,14 +1,20 @@
1
- import type { HandleConnectOptions, Result } from './useStatefulConnect.types';
1
+ import type {
2
+ HandleConnectOptions,
3
+ NamespaceData,
4
+ Result,
5
+ } from './useStatefulConnect.types';
6
+ import type { WithConnectTrigger } from '../../libs/connectLogging';
2
7
  import type { WalletInfoWithExtra } from '../../types';
3
8
  import type { Namespace } from '@hub3js/namespaces';
4
- import type { NamespaceData } from '@rango-dev/wallets-shared';
5
9
 
6
10
  import { WalletState } from '@rango-dev/ui';
7
11
  import { useWallets } from '@rango-dev/wallets-react';
8
12
  import { useReducer } from 'react';
9
13
 
10
14
  import { isOnDetached } from '../../components/StatefulConnectModal';
15
+ import { tryRefineErrorMessage } from '../../utils/errors';
11
16
  import { type ExtendedModalWalletInfo } from '../../utils/wallets';
17
+ import { useConnectWithLogging } from '../useConnectWithLogging';
12
18
 
13
19
  import {
14
20
  isStateOnDerivationPathStep,
@@ -48,8 +54,11 @@ export interface UseStatefulConnect {
48
54
  * or what derivation path should be used for.
49
55
  *
50
56
  */
51
- export function useStatefulConnect(): UseStatefulConnect {
52
- const { state, disconnect, connect } = useWallets();
57
+ export function useStatefulConnect({
58
+ trigger,
59
+ }: WithConnectTrigger = {}): UseStatefulConnect {
60
+ const { state, disconnect } = useWallets();
61
+ const connect = useConnectWithLogging();
53
62
 
54
63
  const [connectState, dispatch] = useReducer(reducer, initState);
55
64
 
@@ -71,13 +80,16 @@ export function useStatefulConnect(): UseStatefulConnect {
71
80
  ...namespaceInput,
72
81
  network: undefined,
73
82
  }));
74
- await connect(wallet.type, legacyNamespacesInput);
83
+ await connect(wallet.type, legacyNamespacesInput, { trigger });
75
84
  return { status: ResultStatus.Connected };
76
85
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
86
  } catch (e: any) {
78
- const message = e?.message
79
- ? `Error: ${e.message}`
80
- : 'An unknown error happened during connecting wallet.';
87
+ const message = tryRefineErrorMessage(
88
+ e,
89
+ e?.message
90
+ ? `Error: ${e.message}`
91
+ : 'An unknown error happened during connecting wallet.'
92
+ );
81
93
 
82
94
  if (options?.disconnectOnError) {
83
95
  try {
@@ -110,16 +122,13 @@ export function useStatefulConnect(): UseStatefulConnect {
110
122
  * 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
123
  */
112
124
 
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;
125
+ const needsNamespace = wallet.properties?.find(
126
+ (item) => item.name === 'namespaces'
127
+ )?.value;
118
128
 
119
- const needsDerivationPath = isHub
120
- ? wallet.properties?.find((item) => item.name === 'derivationPath')
121
- ?.value
122
- : wallet.needsDerivationPath;
129
+ const needsDerivationPath = wallet.properties?.find(
130
+ (item) => item.name === 'derivationPath'
131
+ )?.value;
123
132
 
124
133
  // Forced namespaces are used to bypass namespace selection flow.
125
134
  if (forceConnectToNamespaces) {
@@ -209,7 +218,7 @@ export function useStatefulConnect(): UseStatefulConnect {
209
218
  * and forced namespaces are not enabled,
210
219
  * we should display detached modal
211
220
  */
212
- if (!!wallet.isHub && !options?.forceConnectToNamespaces) {
221
+ if (!options?.forceConnectToNamespaces) {
213
222
  const needsNamespace = wallet.properties?.find(
214
223
  (item) => item.name === 'namespaces'
215
224
  )?.value;
@@ -237,14 +246,13 @@ export function useStatefulConnect(): UseStatefulConnect {
237
246
  wallet: ExtendedModalWalletInfo,
238
247
  selectedNamespaces: Namespace[]
239
248
  ): Promise<Result> => {
240
- const isHub = !!wallet.isHub;
241
- const needsNamespace = isHub
242
- ? wallet.properties?.find((item) => item.name === 'namespaces')?.value
243
- : wallet.needsNamespace;
249
+ const needsNamespace = wallet.properties?.find(
250
+ (item) => item.name === 'namespaces'
251
+ )?.value;
244
252
 
245
- const needsDerivationPath = isHub
246
- ? wallet.properties?.find((item) => item.name === 'derivationPath')?.value
247
- : wallet.needsDerivationPath;
253
+ const needsDerivationPath = wallet.properties?.find(
254
+ (item) => item.name === 'derivationPath'
255
+ )?.value;
248
256
 
249
257
  const isSingleNamespace = needsNamespace?.selection === 'single';
250
258
  const firstSelectedNamespace = selectedNamespaces[0];
@@ -320,10 +328,9 @@ export function useStatefulConnect(): UseStatefulConnect {
320
328
  const selectedNamespace = connectState.derivationPath.namespace;
321
329
  const namespaces = [{ namespace: selectedNamespace, derivationPath }];
322
330
 
323
- const isHub = !!wallet.isHub;
324
- const needsNamespace = isHub
325
- ? wallet.properties?.find((item) => item.name === 'namespaces')?.value
326
- : wallet.needsNamespace;
331
+ const needsNamespace = wallet.properties?.find(
332
+ (item) => item.name === 'namespaces'
333
+ )?.value;
327
334
 
328
335
  const namespaceIsAvailable =
329
336
  !!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,8 +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
- walletType: wallet.type,
93
- walletName: wallet.title,
99
+ walletName: wallet.type,
94
100
  });
95
101
  }
96
102
  });
@@ -132,11 +138,7 @@ export function useWalletList(params?: Params): API {
132
138
  const isEvmWalletInstalledExceptDefault = wallets.filter(
133
139
  (wallet) =>
134
140
  wallet.state != WalletState.NOT_INSTALLED &&
135
- ![
136
- WalletTypes.DEFAULT,
137
- WalletTypes.WALLET_CONNECT_2,
138
- WalletTypes.LEDGER,
139
- ].includes(wallet.type as WalletTypes) &&
141
+ !DEFAULT_EVM_WALLETS.has(wallet.type) &&
140
142
  getWalletInfo(wallet.type).supportedChains.filter(
141
143
  (blockchain) => blockchain.type == 'EVM'
142
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
  };
@@ -0,0 +1,17 @@
1
+ /** How long a wallet may leave an attempt unanswered before it's logged. */
2
+ export const CONNECT_TIMEOUT = 180_000;
3
+
4
+ export const CONNECT_TIMEOUT_MESSAGE =
5
+ 'Wallet connection still pending after 3 minutes';
6
+
7
+ export const UNREADABLE_FAILURE_MESSAGE = 'Failure could not be described';
8
+
9
+ /** No class is named like this, so it can't be mistaken for a real name. */
10
+ export const UNREADABLE_FAILURE_NAME = '(unreadable)';
11
+
12
+ export const ATTEMPT_ERROR_NAMES: readonly string[] = [
13
+ 'WalletConnectionAttemptError',
14
+ 'AutoConnectionAttemptError',
15
+ ];
16
+
17
+ export const CONNECTION_ERROR_NAME = 'WalletConnectionError';