@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,6 +1,5 @@
1
1
  import type { QuoteCostDetailsProps } from './Quote.types';
2
2
  import type { NameOfFees } from '../../constants/quote';
3
- import type BigNumber from 'bignumber.js';
4
3
 
5
4
  import { i18n } from '@lingui/core';
6
5
  import {
@@ -12,6 +11,7 @@ import {
12
11
  QuoteCost,
13
12
  Typography,
14
13
  } from '@rango-dev/ui';
14
+ import BigNumber from 'bignumber.js';
15
15
  import React, { useState } from 'react';
16
16
 
17
17
  import { getFeeLabel } from '../../constants/quote';
@@ -62,7 +62,6 @@ export function QuoteCostDetails(props: QuoteCostDetailsProps) {
62
62
  const {
63
63
  steps,
64
64
  quote,
65
- fee,
66
65
  time,
67
66
  feeWarning,
68
67
  timeWarning,
@@ -73,8 +72,20 @@ export function QuoteCostDetails(props: QuoteCostDetailsProps) {
73
72
  const container = fullExpandedMode ? getExpanded() : getContainer();
74
73
 
75
74
  const feesGroup = getFeesGroup(swaps);
75
+
76
+ /*
77
+ * The "Total Payable Fee" must reflect only the fees the user actually pays
78
+ * (feesGroup.payable). We sum the USD value of every payable fee group and use
79
+ * it for both the collapsed summary and the itemized rows in the modal, so the
80
+ * two never disagree.
81
+ */
82
+ const totalPayableFee = Object.values(feesGroup.payable).reduce(
83
+ (acc: BigNumber, fees) => acc.plus(getTotalFeesInUsd(fees)),
84
+ new BigNumber(0)
85
+ );
86
+
76
87
  const roundedFee = numberToString(
77
- fee,
88
+ totalPayableFee,
78
89
  GAS_FEE_MIN_DECIMALS,
79
90
  GAS_FEE_MAX_DECIMALS
80
91
  );
@@ -181,7 +192,7 @@ export function QuoteCostDetails(props: QuoteCostDetailsProps) {
181
192
  <Typography variant="label" size="medium">
182
193
  $
183
194
  {numberToString(
184
- fee,
195
+ totalPayableFee,
185
196
  USD_VALUE_MIN_DECIMALS,
186
197
  USD_VALUE_MAX_DECIMALS
187
198
  )}
@@ -11,6 +11,7 @@ import {
11
11
  } from '../../hooks/useStatefulConnect';
12
12
  import { useWalletList } from '../../hooks/useWalletList';
13
13
  import { getContainer } from '../../utils/common';
14
+ import { tryRefineErrorMessage } from '../../utils/errors';
14
15
  import { WatermarkedModal } from '../common/WatermarkedModal';
15
16
  import {
16
17
  ConnectStatus,
@@ -44,8 +45,13 @@ export function StatefulConnectModal(props: PropTypes) {
44
45
  const successModalTimerId = useRef<ReturnType<typeof setTimeout>>();
45
46
  const [isConnecting, setIsConnecting] = useState(false);
46
47
  const [error, setError] = useState<string>();
47
- const catchErrorOnHandle = (error: Error) => {
48
- setError(error.message);
48
+ const catchErrorOnHandle = (error?: Error) => {
49
+ setError(
50
+ tryRefineErrorMessage(
51
+ error,
52
+ error?.message || 'An unknown error happened during connecting wallet.'
53
+ )
54
+ );
49
55
  };
50
56
  const { terminateConnectingWallets } = useWalletList();
51
57
 
@@ -36,6 +36,8 @@ import { useNotificationStore } from '../../store/notification';
36
36
  import { useQuoteStore } from '../../store/quote';
37
37
  import { UiEventTypes } from '../../types';
38
38
  import { getContainer } from '../../utils/common';
39
+ import { trackConnection } from '../../utils/connectionReporting';
40
+ import { tryRefineError } from '../../utils/errors';
39
41
  import { emitUiEvent } from '../../utils/events';
40
42
  import {
41
43
  numberToString,
@@ -175,17 +177,27 @@ export function SwapDetails(props: SwapDetailsProps) {
175
177
  const handleSwitchNetwork = () => {
176
178
  if (switchNetworkIsAvailable) {
177
179
  handleShowSwitchNetworkLoading();
178
- connect(currentStepWallet.walletType, [
180
+ trackConnection(
181
+ connect(currentStepWallet.walletType, [
182
+ {
183
+ namespace: currentStepNamespace.namespace,
184
+ network: currentStepNamespace.network,
185
+ },
186
+ ]),
179
187
  {
180
- namespace: currentStepNamespace.namespace,
181
- network: currentStepNamespace.network,
182
- },
183
- ])
188
+ trigger: 'swap-details',
189
+ source: 'user',
190
+ walletType: currentStepWallet.walletType,
191
+ namespaces: [currentStepNamespace.namespace],
192
+ }
193
+ )
184
194
  .then(() => {
185
195
  handleShowSwitchNetworkSucceeded();
186
196
  })
187
197
  .catch((error: unknown) => {
188
- handleShowSwitchNetworkFailed(error as Error);
198
+ handleShowSwitchNetworkFailed(
199
+ tryRefineError(error) ?? (error as Error)
200
+ );
189
201
  });
190
202
  }
191
203
  };
@@ -16,6 +16,8 @@ import React, { useState } from 'react';
16
16
 
17
17
  import { useWalletList } from '../../hooks/useWalletList';
18
18
  import { useUiStore } from '../../store/ui';
19
+ import { trackConnection } from '../../utils/connectionReporting';
20
+ import { tryRefineError } from '../../utils/errors';
19
21
  import { getConciseAddress } from '../../utils/wallets';
20
22
  import { NamespaceItem } from '../NamespaceItem';
21
23
 
@@ -44,15 +46,12 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
44
46
  }
45
47
 
46
48
  const walletState = state(currentStepWallet.walletType);
47
- const namespaceState =
48
- wallet.isHub && namespace?.namespace
49
- ? walletState.namespaces?.get(namespace.namespace)
50
- : null;
49
+ const namespaceState = namespace?.namespace
50
+ ? walletState.namespaces?.get(namespace.namespace)
51
+ : null;
51
52
 
52
53
  const connecting = walletState.connecting || namespaceState?.connecting;
53
- const connected = wallet.isHub
54
- ? namespaceState?.connected
55
- : walletState.connected;
54
+ const connected = namespaceState?.connected;
56
55
 
57
56
  const getButtonTitle = () => {
58
57
  if (connected) {
@@ -76,20 +75,23 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
76
75
  const handleConnect = async () => {
77
76
  try {
78
77
  setError(null);
79
- await connect(
80
- wallet.type,
81
- namespace?.namespace
82
- ? [
83
- {
84
- namespace: namespace?.namespace,
85
- network: undefined,
86
- derivationPath: currentStepWallet.derivationPath,
87
- },
88
- ]
89
- : undefined
90
- );
78
+ const namespaces = namespace?.namespace
79
+ ? [
80
+ {
81
+ namespace: namespace?.namespace,
82
+ network: undefined,
83
+ derivationPath: currentStepWallet.derivationPath,
84
+ },
85
+ ]
86
+ : undefined;
87
+ await trackConnection(connect(wallet.type, namespaces), {
88
+ trigger: 'swap-details-modal',
89
+ source: 'user',
90
+ walletType: wallet.type,
91
+ namespaces: namespaces?.map((item) => item.namespace),
92
+ });
91
93
  } catch (error) {
92
- setError(error as Error);
94
+ setError(tryRefineError(error) ?? (error as Error));
93
95
  }
94
96
  };
95
97
 
@@ -106,9 +108,7 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
106
108
  if (!connected) {
107
109
  return null;
108
110
  }
109
- const firstAccountArray = wallet?.isHub
110
- ? namespaceState?.accounts?.[0]?.split(':')
111
- : walletState?.accounts?.[0]?.split(':');
111
+ const firstAccountArray = namespaceState?.accounts?.[0]?.split(':');
112
112
  const address = firstAccountArray?.[firstAccountArray?.length - 1];
113
113
 
114
114
  if (!address) {
@@ -1,9 +1,15 @@
1
1
  import type { InstallWalletContentProps } from './SwapDetailsModal.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
- import { Button, Divider, Image, MessageBox, WarningIcon } from '@rango-dev/ui';
4
+ import {
5
+ Button,
6
+ detectInstallLink,
7
+ Divider,
8
+ Image,
9
+ MessageBox,
10
+ WarningIcon,
11
+ } from '@rango-dev/ui';
5
12
  import { useWallets } from '@rango-dev/wallets-react';
6
- import { detectInstallLink } from '@rango-dev/wallets-shared';
7
13
  import React from 'react';
8
14
 
9
15
  import {
@@ -1,5 +1,5 @@
1
+ import type { WalletType } from '@hub3js/core';
1
2
  import type { TargetNamespace } from '@rango-dev/queue-manager-rango-preset';
2
- import type { LegacyWalletType } from '@rango-dev/wallets-core/legacy';
3
3
  import type { PendingSwap } from 'rango-types';
4
4
 
5
5
  export type ModalState =
@@ -60,12 +60,12 @@ export interface NetworkStateContentProps {
60
60
  }
61
61
 
62
62
  export interface InstallWalletContentProps {
63
- walletType: LegacyWalletType;
63
+ walletType: WalletType;
64
64
  }
65
65
 
66
66
  export interface ConnectWalletContentProps {
67
67
  wallet: {
68
- walletType: LegacyWalletType;
68
+ walletType: WalletType;
69
69
  address: string;
70
70
  derivationPath?: string;
71
71
  };
@@ -8,9 +8,9 @@ import { End, List } from './TokenList.styles';
8
8
  export function LoadingTokenList(props: LoadingTokenListProps) {
9
9
  return (
10
10
  <List>
11
- {Array.from(Array(props.size), (e) => (
11
+ {Array.from(Array(props.size), (_, index) => (
12
12
  <ListItem
13
- key={e}
13
+ key={index}
14
14
  hasDivider
15
15
  start={<Skeleton variant="circular" width={35} height={35} />}
16
16
  end={
@@ -0,0 +1,98 @@
1
+ import type { DerivationPathTemplate } from './DerivationPath.helpers';
2
+
3
+ import { describe, expect, it } from 'vitest';
4
+
5
+ import {
6
+ CUSTOM_DERIVATION_PATH,
7
+ getDerivationPaths,
8
+ } from './DerivationPath.helpers';
9
+
10
+ const LEDGER: DerivationPathTemplate[] = [
11
+ {
12
+ id: 'metamask',
13
+ label: `Metamask (m/44'/60'/0'/0/index)`,
14
+ namespace: 'EVM',
15
+ generateDerivationPath: (index) => `44'/60'/0'/0/${index}`,
16
+ },
17
+ {
18
+ id: 'ledgerLive',
19
+ label: `LedgerLive (m/44'/60'/index'/0/0)`,
20
+ namespace: 'EVM',
21
+ generateDerivationPath: (index) => `44'/60'/${index}'/0/0`,
22
+ },
23
+ {
24
+ id: 'legacy',
25
+ label: `Legacy (m/44'/60'/0'/index)`,
26
+ namespace: 'EVM',
27
+ generateDerivationPath: (index) => `44'/60'/0'/${index}`,
28
+ },
29
+ {
30
+ id: `(m/44'/501'/index')`,
31
+ label: `(m/44'/501'/index')`,
32
+ namespace: 'Solana',
33
+ generateDerivationPath: (index) => `44'/501'/${index}'`,
34
+ },
35
+ {
36
+ id: `(m/44'/501'/0'/index)`,
37
+ label: `(m/44'/501'/0'/index)`,
38
+ namespace: 'Solana',
39
+ generateDerivationPath: (index) => `44'/501'/0'/${index}`,
40
+ },
41
+ ];
42
+
43
+ const TREZOR_UTXO: DerivationPathTemplate[] = [
44
+ {
45
+ id: 'bitcoin-native-segwit',
46
+ label: `Native SegWit (m/84'/0'/index')`,
47
+ namespace: 'UTXO',
48
+ generateDerivationPath: (index) => `84'/0'/${index}'/0/0`,
49
+ },
50
+ {
51
+ id: 'bitcoin-taproot',
52
+ label: `Taproot (m/86'/0'/index')`,
53
+ namespace: 'UTXO',
54
+ generateDerivationPath: (index) => `86'/0'/${index}'/0/0`,
55
+ },
56
+ ];
57
+
58
+ describe('getDerivationPaths', () => {
59
+ it('returns only the templates of the selected namespace', () => {
60
+ expect(getDerivationPaths(LEDGER, 'EVM').map((path) => path.id)).toEqual([
61
+ 'metamask',
62
+ 'ledgerLive',
63
+ 'legacy',
64
+ CUSTOM_DERIVATION_PATH.id,
65
+ ]);
66
+
67
+ expect(getDerivationPaths(LEDGER, 'Solana').map((path) => path.id)).toEqual(
68
+ [
69
+ `(m/44'/501'/index')`,
70
+ `(m/44'/501'/0'/index)`,
71
+ CUSTOM_DERIVATION_PATH.id,
72
+ ]
73
+ );
74
+ });
75
+
76
+ it('appends the custom template so a user can enter a full path', () => {
77
+ const paths = getDerivationPaths(TREZOR_UTXO, 'UTXO');
78
+
79
+ expect(paths.at(-1)).toBe(CUSTOM_DERIVATION_PATH);
80
+ expect(CUSTOM_DERIVATION_PATH.generateDerivationPath(`84'/0'/3'/0/0`)).toBe(
81
+ `84'/0'/3'/0/0`
82
+ );
83
+ });
84
+
85
+ it('generates the path the wallet expects for the picked index', () => {
86
+ const evm = getDerivationPaths(LEDGER, 'EVM');
87
+ const utxo = getDerivationPaths(TREZOR_UTXO, 'UTXO');
88
+
89
+ expect(evm[0]?.generateDerivationPath('2')).toBe(`44'/60'/0'/0/2`);
90
+ expect(evm[1]?.generateDerivationPath('2')).toBe(`44'/60'/2'/0/0`);
91
+ expect(utxo[0]?.generateDerivationPath('2')).toBe(`84'/0'/2'/0/0`);
92
+ });
93
+
94
+ it('returns nothing when the provider declares no template for the namespace', () => {
95
+ expect(getDerivationPaths(LEDGER, 'UTXO')).toEqual([]);
96
+ expect(getDerivationPaths([], 'EVM')).toEqual([]);
97
+ });
98
+ });
@@ -1,24 +1,28 @@
1
+ import type { ProviderProperty } from '@hub3js/core/store';
1
2
  import type { Namespace } from '@hub3js/namespaces';
2
- import type { DerivationPath } from '@rango-dev/wallets-shared';
3
3
 
4
- import { namespaces } from '@rango-dev/wallets-shared';
4
+ export type DerivationPathTemplate = Extract<
5
+ ProviderProperty,
6
+ { name: 'derivationPath' }
7
+ >['value']['data'][number];
5
8
 
6
- export const CUSTOM_DERIVATION_PATH: DerivationPath = {
9
+ export type DerivationPathOption = Omit<DerivationPathTemplate, 'namespace'>;
10
+
11
+ export const CUSTOM_DERIVATION_PATH: DerivationPathOption = {
7
12
  id: 'custom',
8
13
  label: 'Custom',
9
14
  generateDerivationPath: (index: string) => index,
10
15
  };
11
16
 
12
17
  export function getDerivationPaths(
18
+ derivationPaths: DerivationPathTemplate[],
13
19
  selectedNamespace?: Namespace
14
- ): DerivationPath[] {
15
- const selectedNamespaceDerivationPaths = selectedNamespace
16
- ? namespaces[selectedNamespace]?.derivationPaths
17
- : null;
20
+ ): DerivationPathOption[] {
21
+ const selectedNamespaceDerivationPaths = derivationPaths.filter(
22
+ (derivationPath) => derivationPath.namespace === selectedNamespace
23
+ );
18
24
 
19
- const derivationPaths: DerivationPath[] = !!selectedNamespaceDerivationPaths
25
+ return selectedNamespaceDerivationPaths.length
20
26
  ? [...selectedNamespaceDerivationPaths, CUSTOM_DERIVATION_PATH]
21
27
  : [];
22
-
23
- return derivationPaths;
24
28
  }
@@ -1,9 +1,9 @@
1
1
  import type { PropTypes } from './DerivationPath.types';
2
- import type { DerivationPath } from '@rango-dev/wallets-shared';
3
2
 
4
3
  import { i18n } from '@lingui/core';
5
4
  import { Divider, Image, MessageBox, Select, TextField } from '@rango-dev/ui';
6
- import React, { useEffect, useState } from 'react';
5
+ import { useWallets } from '@rango-dev/wallets-react';
6
+ import React, { useEffect, useMemo, useState } from 'react';
7
7
 
8
8
  import {
9
9
  CUSTOM_DERIVATION_PATH,
@@ -26,6 +26,8 @@ export function DerivationPath(props: PropTypes) {
26
26
  providerType: type,
27
27
  } = props.value;
28
28
 
29
+ const { getWalletInfo } = useWallets();
30
+
29
31
  const [selectedDerivationPathId, setSelectedDerivationPathId] = useState<
30
32
  string | null
31
33
  >(null);
@@ -36,7 +38,14 @@ export function DerivationPath(props: PropTypes) {
36
38
  const isCustomOptionSelected =
37
39
  selectedDerivationPathId === CUSTOM_DERIVATION_PATH.id;
38
40
 
39
- const derivationPaths = getDerivationPaths(selectedNamespace);
41
+ const derivationPaths = useMemo(
42
+ () =>
43
+ getDerivationPaths(
44
+ getWalletInfo(type).needsDerivationPath?.data ?? [],
45
+ selectedNamespace
46
+ ),
47
+ [type, selectedNamespace]
48
+ );
40
49
 
41
50
  const handleDerivationPathItemClick = ({ value }: { value: string }) => {
42
51
  const selectedDerivationPath = derivationPaths?.find(
@@ -75,10 +84,8 @@ export function DerivationPath(props: PropTypes) {
75
84
  };
76
85
 
77
86
  useEffect(() => {
78
- setSelectedDerivationPathId(
79
- getDerivationPaths(selectedNamespace)[0]?.id || null
80
- );
81
- }, [selectedNamespace]);
87
+ setSelectedDerivationPathId(derivationPaths[0]?.id || null);
88
+ }, [derivationPaths]);
82
89
 
83
90
  return (
84
91
  <>
@@ -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 { trackConnection } from '../../utils/connectionReporting';
17
18
  import { NamespaceUnsupportedItem } from '../NamespaceItem/NamespaceUnsupportedItem';
18
19
 
19
20
  import { NamespacesHeader } from './Detached.styles';
@@ -57,13 +58,21 @@ export function Detached(props: PropTypes) {
57
58
  if (derivationPathProperty && options?.shouldAskForDerivationPath) {
58
59
  navigateToDerivationPath(namespace);
59
60
  } else {
60
- await connect(walletType, [
61
+ await trackConnection(
62
+ connect(walletType, [
63
+ {
64
+ namespace: namespace,
65
+ network: '',
66
+ derivationPath: options?.derivationPath ?? undefined,
67
+ },
68
+ ]),
61
69
  {
62
- namespace: namespace,
63
- network: '',
64
- derivationPath: options?.derivationPath ?? undefined,
65
- },
66
- ]);
70
+ trigger: 'wallet-modal-namespace',
71
+ source: 'user',
72
+ walletType,
73
+ namespaces: [namespace],
74
+ }
75
+ );
67
76
  }
68
77
  };
69
78
 
@@ -119,7 +128,7 @@ export function Detached(props: PropTypes) {
119
128
  );
120
129
  };
121
130
 
122
- const renderNamespaceItem = (namespace: LegacyNamespaceMeta) => {
131
+ const renderNamespaceItem = (namespace: NamespaceMeta) => {
123
132
  if (namespace.unsupported) {
124
133
  return <NamespaceUnsupportedItem namespace={namespace} />;
125
134
  }
@@ -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(
@@ -1,7 +1,7 @@
1
1
  import type { OnUpdateState } from './Wallets.types';
2
- import type { LegacyEventHandler } from '@rango-dev/wallets-core/legacy';
2
+ import type { EventHandler } from '@rango-dev/wallets-react';
3
3
 
4
- import { LegacyEvents } from '@rango-dev/wallets-core/legacy';
4
+ import { Events } from '@rango-dev/wallets-react';
5
5
 
6
6
  /*
7
7
  * propagate updates for Dapps using external wallets
@@ -10,7 +10,7 @@ import { LegacyEvents } from '@rango-dev/wallets-core/legacy';
10
10
  */
11
11
  export function propagateEvents(
12
12
  cb: OnUpdateState,
13
- eventParams: Parameters<LegacyEventHandler>
13
+ eventParams: Parameters<EventHandler>
14
14
  ): void {
15
15
  const [walletType, event, value, coreState, info] = eventParams;
16
16
 
@@ -18,7 +18,7 @@ export function propagateEvents(
18
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
19
  * so for backward-compat we need to keep the behavior of WalletEventTypes.DISCONNECT
20
20
  */
21
- if (event === LegacyEvents.PROVIDER_DISCONNECTED) {
21
+ if (event === Events.PROVIDER_DISCONNECTED) {
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}