@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
@@ -1,6 +1,6 @@
1
1
  import type { PropTypes } from './Detached.types';
2
2
  import type { Namespace } from '@hub3js/namespaces';
3
- import type { LegacyNamespaceMeta } from '@rango-dev/wallets-core/legacy';
3
+ import type { NamespaceMeta } from '@rango-dev/wallets-react';
4
4
 
5
5
  import { i18n } from '@lingui/core';
6
6
  import {
@@ -14,6 +14,7 @@ import {
14
14
  import { useWallets } from '@rango-dev/wallets-react';
15
15
  import React from 'react';
16
16
 
17
+ import { useConnectWithLogging } from '../../hooks/useConnectWithLogging';
17
18
  import { NamespaceUnsupportedItem } from '../NamespaceItem/NamespaceUnsupportedItem';
18
19
 
19
20
  import { NamespacesHeader } from './Detached.styles';
@@ -28,10 +29,12 @@ export function Detached(props: PropTypes) {
28
29
  confirmText = i18n.t('Done'),
29
30
  onDisconnectWallet,
30
31
  navigateToDerivationPath,
32
+ trigger,
31
33
  } = props;
32
34
  const { targetWallet } = value;
33
35
 
34
- const { connect, disconnect, state } = useWallets();
36
+ const { disconnect, state } = useWallets();
37
+ const connect = useConnectWithLogging();
35
38
  const walletType = targetWallet.type;
36
39
  const walletState = state(walletType);
37
40
  const namespacesProperty = targetWallet.properties?.find(
@@ -57,13 +60,17 @@ export function Detached(props: PropTypes) {
57
60
  if (derivationPathProperty && options?.shouldAskForDerivationPath) {
58
61
  navigateToDerivationPath(namespace);
59
62
  } else {
60
- await connect(walletType, [
61
- {
62
- namespace: namespace,
63
- network: '',
64
- derivationPath: options?.derivationPath ?? undefined,
65
- },
66
- ]);
63
+ await connect(
64
+ walletType,
65
+ [
66
+ {
67
+ namespace: namespace,
68
+ network: '',
69
+ derivationPath: options?.derivationPath ?? undefined,
70
+ },
71
+ ],
72
+ { trigger }
73
+ );
67
74
  }
68
75
  };
69
76
 
@@ -119,7 +126,7 @@ export function Detached(props: PropTypes) {
119
126
  );
120
127
  };
121
128
 
122
- const renderNamespaceItem = (namespace: LegacyNamespaceMeta) => {
129
+ const renderNamespaceItem = (namespace: NamespaceMeta) => {
123
130
  if (namespace.unsupported) {
124
131
  return <NamespaceUnsupportedItem namespace={namespace} />;
125
132
  }
@@ -1,7 +1,8 @@
1
1
  import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
2
+ import type { WithConnectTrigger } from '../../libs/connectLogging';
2
3
  import type { Namespace } from '@hub3js/namespaces';
3
4
 
4
- export interface PropTypes {
5
+ export interface PropTypes extends WithConnectTrigger {
5
6
  value: NeedsNamespacesState;
6
7
  onConfirm: () => void;
7
8
  confirmText?: string;
@@ -4,6 +4,7 @@ import { i18n } from '@lingui/core';
4
4
  import { Button, Spinner } from '@rango-dev/ui';
5
5
  import React, { useLayoutEffect, useRef, useState } from 'react';
6
6
 
7
+ import { tryRefineError } from '../../utils/errors';
7
8
  import { getConciseAddress } from '../../utils/wallets';
8
9
  import { NamespaceItem } from '../NamespaceItem';
9
10
 
@@ -39,7 +40,7 @@ export function NamespaceDetachedItem(props: NamespaceDetachedItemPropTypes) {
39
40
  processingConnectAttempt.current = true;
40
41
  await handleConnect(options);
41
42
  } catch (error) {
42
- setError(error as Error);
43
+ setError(tryRefineError(error) ?? (error as Error));
43
44
  } finally {
44
45
  processingConnectAttempt.current = false;
45
46
  }
@@ -2,6 +2,7 @@ import type { PropTypes } from './Namespaces.types';
2
2
  import type { Namespace } from '@hub3js/namespaces';
3
3
 
4
4
  import { i18n } from '@lingui/core';
5
+ import { getSupportedChainsFromNamespace } from '@rango-dev/internal-blockchains';
5
6
  import {
6
7
  Alert,
7
8
  Button,
@@ -24,13 +25,8 @@ export function Namespaces(props: PropTypes) {
24
25
  const namespacesProperty = targetWallet.properties?.find(
25
26
  (property) => property.name === 'namespaces'
26
27
  );
27
- const isHub = targetWallet.isHub;
28
- const singleNamespace = targetWallet.isHub
29
- ? namespacesProperty?.value.selection === 'single'
30
- : targetWallet.needsNamespace?.selection === 'single';
31
- const needsNamespace = isHub
32
- ? namespacesProperty?.value
33
- : targetWallet.needsNamespace;
28
+ const singleNamespace = namespacesProperty?.value.selection === 'single';
29
+ const needsNamespace = namespacesProperty?.value;
34
30
  const providerImage = targetWallet.image;
35
31
 
36
32
  const blockchains = useAppStore().blockchains();
@@ -83,11 +79,9 @@ export function Namespaces(props: PropTypes) {
83
79
  if (!!props.value.defaultSelectedChains?.length) {
84
80
  const namespacesContainingDefaultSelectedChains =
85
81
  supportedNamespaces.filter((namespace) =>
86
- namespace
87
- .getSupportedChains(blockchains)
88
- .some((chain) =>
89
- props.value.defaultSelectedChains?.includes(chain.name)
90
- )
82
+ getSupportedChainsFromNamespace(namespace, blockchains).some(
83
+ (chain) => props.value.defaultSelectedChains?.includes(chain.name)
84
+ )
91
85
  );
92
86
  setSelectedNamespaces(
93
87
  namespacesContainingDefaultSelectedChains.map(
@@ -1,7 +1,7 @@
1
1
  import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
2
2
  import type { NamespaceData } from '@hub3js/core/store';
3
3
  import type { Namespace } from '@hub3js/namespaces';
4
- import type { LegacyNamespaceMeta } from '@rango-dev/wallets-core/legacy';
4
+ import type { NamespaceMeta } from '@rango-dev/wallets-react';
5
5
 
6
6
  export interface PropTypes {
7
7
  onConfirm: (namespaces: Namespace[]) => void;
@@ -11,7 +11,7 @@ export interface PropTypes {
11
11
  interface NamespaceItemSharedPropTypes {
12
12
  onClick: () => void;
13
13
  type: 'radio' | 'checkbox';
14
- namespace: LegacyNamespaceMeta;
14
+ namespace: NamespaceMeta;
15
15
  }
16
16
 
17
17
  interface RadioNamespaceItemPropTypes extends NamespaceItemSharedPropTypes {
@@ -28,7 +28,7 @@ export type NamespaceItemPropTypes =
28
28
  | CheckboxNamespaceItemPropTypes;
29
29
 
30
30
  export type NamespaceDetachedItemPropTypes = {
31
- namespace: LegacyNamespaceMeta;
31
+ namespace: NamespaceMeta;
32
32
  state: NamespaceData;
33
33
  initialConnect?: boolean;
34
34
  disabled?: boolean;
@@ -7,6 +7,9 @@ import { QuoteErrorType } from '../types';
7
7
  export const errorMessages = () => {
8
8
  return {
9
9
  genericServerError: i18n.t('Failed Network, Please retry your swap.'),
10
+ moduleLoadError: i18n.t(
11
+ 'A network error occurred while processing your request. Please check your internet connection or refresh the page and try again.'
12
+ ),
10
13
  liquiditySourcesError: {
11
14
  title: i18n.t('Please reset your liquidity sources.'),
12
15
  description: i18n.t(
@@ -0,0 +1,14 @@
1
+ import { Events } from '@rango-dev/wallets-react';
2
+
3
+ /*
4
+ * Events the widget keeps to itself, never passed on to `onUpdateState`.
5
+ *
6
+ * PROVIDER_DISCONNECTED has conflict with WalletEventTypes.DISCONNECT since they are doing samething, the first one is using only for Hub, the second one is what we exposed to the lib users.
7
+ * so for backward-compat we need to keep the behavior of WalletEventTypes.DISCONNECT
8
+ *
9
+ * AUTO_CONNECT_FAILED only exists so the widget can log it.
10
+ */
11
+ export const INTERNAL_EVENTS = [
12
+ Events.PROVIDER_DISCONNECTED,
13
+ Events.AUTO_CONNECT_FAILED,
14
+ ] as const;
@@ -0,0 +1,67 @@
1
+ import type { EventInfo, WalletState } from '@rango-dev/wallets-react';
2
+
3
+ import { AutoConnectionAttemptError, Events } from '@rango-dev/wallets-react';
4
+ import { describe, expect, it, vi } from 'vitest';
5
+
6
+ import { propagateEvents } from './Wallets.helpers';
7
+
8
+ const CORE_STATE: WalletState = {
9
+ connected: false,
10
+ connecting: false,
11
+ reachable: false,
12
+ installed: true,
13
+ accounts: null,
14
+ network: null,
15
+ };
16
+
17
+ const INFO: EventInfo = {
18
+ supportedBlockchains: [],
19
+ isContractWallet: false,
20
+ isHub: true,
21
+ };
22
+
23
+ describe('propagating events to the integrator', () => {
24
+ it('passes an event on, unchanged', () => {
25
+ const onUpdateState = vi.fn();
26
+
27
+ propagateEvents(onUpdateState, [
28
+ 'metamask',
29
+ Events.CONNECTED,
30
+ true,
31
+ CORE_STATE,
32
+ INFO,
33
+ ]);
34
+
35
+ expect(onUpdateState).toHaveBeenCalledWith(
36
+ 'metamask',
37
+ Events.CONNECTED,
38
+ true,
39
+ CORE_STATE,
40
+ INFO
41
+ );
42
+ });
43
+
44
+ it('keeps provider disconnected and auto-connect failed events from the integrator', () => {
45
+ const onUpdateState = vi.fn();
46
+
47
+ propagateEvents(onUpdateState, [
48
+ 'metamask',
49
+ Events.PROVIDER_DISCONNECTED,
50
+ undefined,
51
+ CORE_STATE,
52
+ INFO,
53
+ ]);
54
+ propagateEvents(onUpdateState, [
55
+ 'metamask',
56
+ Events.AUTO_CONNECT_FAILED,
57
+ new AutoConnectionAttemptError({
58
+ errors: [new Error('boom')],
59
+ requestedNamespaces: [{ namespace: 'EVM', network: undefined }],
60
+ }),
61
+ CORE_STATE,
62
+ INFO,
63
+ ]);
64
+
65
+ expect(onUpdateState).not.toHaveBeenCalled();
66
+ });
67
+ });
@@ -1,7 +1,11 @@
1
- import type { OnUpdateState } from './Wallets.types';
2
- import type { LegacyEventHandler } from '@rango-dev/wallets-core/legacy';
1
+ import type { InternalEvent, OnUpdateState } from './Wallets.types';
2
+ import type { EventHandler, Events } from '@rango-dev/wallets-react';
3
3
 
4
- import { LegacyEvents } from '@rango-dev/wallets-core/legacy';
4
+ import { INTERNAL_EVENTS } from './Wallets.constants';
5
+
6
+ function isInternalEvent(event: Events): event is InternalEvent {
7
+ return (INTERNAL_EVENTS as readonly Events[]).includes(event);
8
+ }
5
9
 
6
10
  /*
7
11
  * propagate updates for Dapps using external wallets
@@ -10,15 +14,11 @@ import { LegacyEvents } from '@rango-dev/wallets-core/legacy';
10
14
  */
11
15
  export function propagateEvents(
12
16
  cb: OnUpdateState,
13
- eventParams: Parameters<LegacyEventHandler>
17
+ eventParams: Parameters<EventHandler>
14
18
  ): void {
15
19
  const [walletType, event, value, coreState, info] = eventParams;
16
20
 
17
- /*
18
- * PROVIDER_DISCONNECTED has conflict with WalletEventTypes.DISCONNECT since they are doing samething, the first one is using only for Hub, the second one is what we exposed to the lib users.
19
- * so for backward-compat we need to keep the behavior of WalletEventTypes.DISCONNECT
20
- */
21
- if (event === LegacyEvents.PROVIDER_DISCONNECTED) {
21
+ if (isInternalEvent(event)) {
22
22
  return;
23
23
  }
24
24
 
@@ -5,11 +5,11 @@ import type {
5
5
  WidgetContextInterface,
6
6
  } from './Wallets.types';
7
7
  import type { ProvidersOptions } from '../../utils/providers';
8
- import type { LegacyEventHandler } from '@rango-dev/wallets-core/legacy';
8
+ import type { EventHandler } from '@rango-dev/wallets-react';
9
9
  import type { PropsWithChildren } from 'react';
10
10
 
11
+ import { WalletTypes } from '@rango-dev/provider-all';
11
12
  import { Provider } from '@rango-dev/wallets-react';
12
- import { WalletTypes } from '@rango-dev/wallets-shared';
13
13
  import React, { createContext, useEffect, useMemo, useRef } from 'react';
14
14
 
15
15
  import { useWalletProviders } from '../../hooks/useWalletProviders';
@@ -89,7 +89,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
89
89
  allBlockChains={blockchains}
90
90
  providers={providers}
91
91
  onUpdateState={(type, event, value, state, info) => {
92
- const eventParams: Parameters<LegacyEventHandler> = [
92
+ const eventParams: Parameters<EventHandler> = [
93
93
  type,
94
94
  event,
95
95
  value,
@@ -109,9 +109,26 @@ function Main(props: PropsWithChildren<PropTypes>) {
109
109
  [WalletTypes.TON_CONNECT]: {
110
110
  provider: { manifestUrl: config.tonConnect?.manifestUrl },
111
111
  },
112
+ [WalletTypes.OKX]: {
113
+ provider: {
114
+ tonConnectManifestUrl: config.tonConnect?.manifestUrl,
115
+ },
116
+ },
112
117
  [WalletTypes.TREZOR]: {
113
118
  provider: { manifest: config.trezorManifest },
114
119
  },
120
+ [WalletTypes.WALLET_CONNECT_2]: {
121
+ provider: {
122
+ WC_PROJECT_ID: config.walletConnectProjectId || '',
123
+ DISABLE_MODAL_AND_OPEN_LINK:
124
+ config.__UNSTABLE_OR_INTERNAL__
125
+ ?.walletConnectListedDesktopWalletLink,
126
+ meta: blockchains,
127
+ },
128
+ },
129
+ [WalletTypes.LEDGER_WALLET]: {
130
+ provider: config.ledgerWallet,
131
+ },
115
132
  },
116
133
  }}>
117
134
  {props.children}
@@ -1,9 +1,7 @@
1
- import type { WidgetConfig } from '../../types';
1
+ import type { INTERNAL_EVENTS } from './Wallets.constants';
2
+ import type { WidgetConfigWithoutLegacyProviders } from '../../types';
2
3
  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';
4
+ import type { EventHandler, Events } from '@rango-dev/wallets-react';
7
5
 
8
6
  export type OnWalletConnectHandler = (wallet: LastConnectedWallet) => void;
9
7
  export type OnWalletDisconnectHandler = (walletType: string) => void;
@@ -22,8 +20,10 @@ export interface WidgetContextInterface {
22
20
  onDisconnectWallet(handler: OnWalletDisconnectHandler): void;
23
21
  }
24
22
 
23
+ export type InternalEvent = (typeof INTERNAL_EVENTS)[number];
24
+
25
25
  type EventHandlerParams = Parameters<EventHandler>;
26
- type EventParam = Exclude<LegacyEvents, LegacyEvents.PROVIDER_DISCONNECTED>;
26
+ type EventParam = Exclude<Events, InternalEvent>;
27
27
 
28
28
  export type OnUpdateState = (
29
29
  type: EventHandlerParams[0],
@@ -35,5 +35,5 @@ export type OnUpdateState = (
35
35
 
36
36
  export interface PropTypes {
37
37
  onUpdateState?: OnUpdateState;
38
- config: WidgetConfig;
38
+ config: WidgetConfigWithoutLegacyProviders;
39
39
  }
@@ -2,20 +2,14 @@ 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
 
12
+ import { logAutoConnectFailure } from '../../libs/connectLogging';
19
13
  import { useAppStore } from '../../store/AppStore';
20
14
  import {
21
15
  prepareAccountsForWalletStore,
@@ -39,8 +33,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
39
33
  newWalletConnected,
40
34
  disconnectWallet,
41
35
  disconnectNamespaces,
42
- connectedWallets,
43
- removeBalancesForWallet,
44
36
  blockchains,
45
37
  } = useAppStore();
46
38
 
@@ -50,7 +42,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
50
42
  .map((chain) => chain.name);
51
43
 
52
44
  const onAccountsEvent = (
53
- event: Parameters<LegacyEventHandler>,
45
+ event: Parameters<EventHandler>,
54
46
  params: {
55
47
  supportedChainNames: Network[] | null;
56
48
  }
@@ -83,13 +75,7 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
83
75
  }
84
76
  };
85
77
 
86
- const handleUpdatesForHub: EventHandler = (
87
- type,
88
- event,
89
- value,
90
- state,
91
- info
92
- ) => {
78
+ const handler: EventHandler = (type, event, value, state, info) => {
93
79
  if (event === Events.ACCOUNTS) {
94
80
  const supportedChainNames: Network[] | null =
95
81
  walletAndSupportedChainsNames(info.supportedBlockchains);
@@ -116,97 +102,11 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
116
102
  if (event === Events.NAMESPACE_DISCONNECTED) {
117
103
  disconnectNamespaces(type, value);
118
104
  }
119
- };
120
-
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
105
 
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
- }
106
+ if (event === Events.AUTO_CONNECT_FAILED) {
107
+ logAutoConnectFailure(type, value);
200
108
  }
201
- };
202
109
 
203
- const handleUpdatesForBoth: EventHandler = (
204
- type,
205
- event,
206
- value,
207
- state,
208
- _info
209
- ) => {
210
110
  if (event === Events.CONNECTED && value) {
211
111
  const walletFromEvent: LastConnectedWallet = {
212
112
  walletType: type,
@@ -234,16 +134,6 @@ export function useUpdates(params: UseUpdatesParams): UseUpdates {
234
134
  }
235
135
  };
236
136
 
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
137
  return {
248
138
  handler,
249
139
  };
@@ -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;
@@ -0,0 +1 @@
1
+ export { useConnectWithLogging } from './useConnectWithLogging';