@rango-dev/widget-embedded 0.37.1-next.2 → 0.38.0

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 (156) hide show
  1. package/dist/QueueManager.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  4. package/dist/components/Layout/Layout.d.ts.map +1 -1
  5. package/dist/components/Quote/Quote.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.styles.d.ts +1 -1
  7. package/dist/components/Quote/Quote.types.d.ts +0 -2
  8. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  9. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  10. package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
  11. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  12. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  13. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
  14. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  15. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
  16. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  17. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  18. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  19. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +1 -2
  20. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  21. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  22. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
  23. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  24. package/dist/constants/quote.d.ts +0 -10
  25. package/dist/constants/quote.d.ts.map +1 -1
  26. package/dist/constants/warnings.d.ts +3 -0
  27. package/dist/constants/warnings.d.ts.map +1 -0
  28. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  29. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  30. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  31. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  32. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  33. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  34. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +3 -3
  35. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  36. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  37. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +4 -6
  38. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  39. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
  40. package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
  41. package/dist/hooks/useObserveBalanceChanges/index.d.ts +2 -0
  42. package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +1 -0
  43. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +4 -0
  44. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +1 -0
  45. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +1 -2
  46. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  47. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +5 -3
  48. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  49. package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
  50. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  51. package/dist/hooks/useWalletList.d.ts.map +1 -1
  52. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +3 -2
  53. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  54. package/dist/index.d.ts +1 -1
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +2 -2
  57. package/dist/index.js.map +4 -4
  58. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  59. package/dist/pages/Home.d.ts.map +1 -1
  60. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  61. package/dist/store/app.d.ts +4 -2
  62. package/dist/store/app.d.ts.map +1 -1
  63. package/dist/store/quote.d.ts.map +1 -1
  64. package/dist/store/slices/config.d.ts +0 -4
  65. package/dist/store/slices/config.d.ts.map +1 -1
  66. package/dist/store/slices/data.d.ts.map +1 -1
  67. package/dist/store/ui.d.ts +0 -4
  68. package/dist/store/ui.d.ts.map +1 -1
  69. package/dist/store/wallets.d.ts +66 -0
  70. package/dist/store/wallets.d.ts.map +1 -0
  71. package/dist/types/config.d.ts +9 -7
  72. package/dist/types/config.d.ts.map +1 -1
  73. package/dist/types/quote.d.ts +17 -8
  74. package/dist/types/quote.d.ts.map +1 -1
  75. package/dist/types/wallets.d.ts +7 -3
  76. package/dist/types/wallets.d.ts.map +1 -1
  77. package/dist/utils/providers.d.ts +9 -8
  78. package/dist/utils/providers.d.ts.map +1 -1
  79. package/dist/utils/quote.d.ts +6 -5
  80. package/dist/utils/quote.d.ts.map +1 -1
  81. package/dist/utils/settings.d.ts +0 -1
  82. package/dist/utils/settings.d.ts.map +1 -1
  83. package/dist/utils/swap.d.ts +5 -5
  84. package/dist/utils/swap.d.ts.map +1 -1
  85. package/dist/utils/wallets.d.ts +14 -12
  86. package/dist/utils/wallets.d.ts.map +1 -1
  87. package/dist/widget-embedded.build.json +1 -1
  88. package/package.json +9 -9
  89. package/src/QueueManager.tsx +11 -17
  90. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +24 -5
  91. package/src/components/ConfirmWalletsModal/WalletList.tsx +7 -10
  92. package/src/components/Layout/Layout.tsx +3 -1
  93. package/src/components/Quote/Quote.tsx +3 -22
  94. package/src/components/Quote/Quote.types.ts +0 -2
  95. package/src/components/Quote/QuoteCostDetails.styles.ts +1 -0
  96. package/src/components/Quote/QuoteCostDetails.tsx +4 -23
  97. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +22 -42
  98. package/src/components/Quotes/Quotes.tsx +3 -2
  99. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
  100. package/src/components/SwapDetails/SwapDetails.tsx +6 -14
  101. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  102. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +13 -26
  103. package/src/components/TokenList/TokenList.tsx +27 -4
  104. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +1 -2
  105. package/src/components/WalletStatefulConnect/Namespaces.tsx +38 -31
  106. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
  107. package/src/constants/quote.ts +0 -25
  108. package/src/constants/warnings.ts +26 -0
  109. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +0 -1
  110. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
  111. package/src/containers/Inputs/Inputs.tsx +7 -20
  112. package/src/containers/QuoteInfo/QuoteInfo.tsx +9 -3
  113. package/src/containers/Wallets/Wallets.tsx +16 -82
  114. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  115. package/src/containers/WidgetInfo/WidgetInfo.tsx +8 -10
  116. package/src/containers/WidgetInfo/WidgetInfo.types.ts +3 -3
  117. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +66 -29
  118. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +15 -10
  119. package/src/hooks/useFetchApiConfig.ts +1 -5
  120. package/src/hooks/useFetchCustomToken.ts +0 -5
  121. package/src/hooks/useObserveBalanceChanges/index.ts +1 -0
  122. package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +68 -0
  123. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +17 -50
  124. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +5 -3
  125. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +6 -7
  126. package/src/hooks/useSwapInput.ts +11 -3
  127. package/src/hooks/useWalletList.ts +8 -6
  128. package/src/hooks/useWalletProviders/useWalletProviders.ts +12 -8
  129. package/src/index.ts +1 -1
  130. package/src/pages/ConfirmSwapPage.tsx +15 -7
  131. package/src/pages/Home.tsx +3 -5
  132. package/src/pages/SelectSwapItemsPage.tsx +2 -1
  133. package/src/store/app.ts +4 -4
  134. package/src/store/quote.ts +13 -3
  135. package/src/store/slices/config.ts +0 -76
  136. package/src/store/slices/data.test.ts +1 -23
  137. package/src/store/slices/data.ts +2 -3
  138. package/src/store/ui.ts +0 -6
  139. package/src/store/wallets.ts +268 -0
  140. package/src/types/config.ts +9 -8
  141. package/src/types/quote.ts +24 -10
  142. package/src/types/wallets.ts +7 -3
  143. package/src/utils/providers.ts +36 -88
  144. package/src/utils/quote.ts +45 -57
  145. package/src/utils/settings.ts +0 -4
  146. package/src/utils/swap.ts +37 -56
  147. package/src/utils/wallets.ts +141 -79
  148. package/dist/store/slices/types.d.ts +0 -6
  149. package/dist/store/slices/types.d.ts.map +0 -1
  150. package/dist/store/slices/wallets.d.ts +0 -80
  151. package/dist/store/slices/wallets.d.ts.map +0 -1
  152. package/dist/store/utils/wallets.d.ts +0 -17
  153. package/dist/store/utils/wallets.d.ts.map +0 -1
  154. package/src/store/slices/types.ts +0 -9
  155. package/src/store/slices/wallets.ts +0 -577
  156. package/src/store/utils/wallets.ts +0 -111
@@ -15,9 +15,11 @@ import {
15
15
  Typography,
16
16
  VirtualizedList,
17
17
  } from '@rango-dev/ui';
18
- import React from 'react';
18
+ import React, { useEffect, useState } from 'react';
19
19
 
20
+ import { useObserveBalanceChanges } from '../../hooks/useObserveBalanceChanges';
20
21
  import { useAppStore } from '../../store/AppStore';
22
+ import { useWalletsStore } from '../../store/wallets';
21
23
  import { createTintsAndShades } from '../../utils/colors';
22
24
  import { formatBalance } from '../../utils/wallets';
23
25
 
@@ -91,7 +93,7 @@ const renderDesc = (props: RenderDescProps) => {
91
93
 
92
94
  export function TokenList(props: PropTypes) {
93
95
  const {
94
- list: tokens,
96
+ list,
95
97
  searchedFor = '',
96
98
  onChange,
97
99
  selectedBlockchain,
@@ -99,10 +101,29 @@ export function TokenList(props: PropTypes) {
99
101
  action,
100
102
  } = props;
101
103
 
104
+ const [tokens, setTokens] = useState<Token[]>(list);
102
105
  const fetchStatus = useAppStore().fetchStatus;
103
106
  const blockchains = useAppStore().blockchains();
104
- const { getBalanceFor, fetchingWallets: loadingWallet } = useAppStore();
107
+ const [hasNextPage, setHasNextPage] = useState<boolean>(true);
108
+ const { getBalanceFor, loading: loadingWallet } = useWalletsStore();
105
109
  const { isTokenPinned } = useAppStore();
110
+ /**
111
+ * We can create the key by hashing the list of tokens,
112
+ * but if the list is large, the memory usage and cost of comparisons may be high.
113
+ */
114
+ const { balanceKey } = useObserveBalanceChanges(selectedBlockchain);
115
+
116
+ const loadNextPage = () => {
117
+ setTokens(list.slice(0, tokens.length + PAGE_SIZE));
118
+ };
119
+
120
+ useEffect(() => {
121
+ setHasNextPage(list.length > tokens.length);
122
+ }, [tokens.length]);
123
+
124
+ useEffect(() => {
125
+ setTokens(list.slice(0, PAGE_SIZE));
126
+ }, [list.length, selectedBlockchain, balanceKey]);
106
127
 
107
128
  const endRenderer = (token: Token) => {
108
129
  const tokenBalance = formatBalance(getBalanceFor(token));
@@ -139,9 +160,11 @@ export function TokenList(props: PropTypes) {
139
160
  )
140
161
  );
141
162
  };
163
+
142
164
  const renderList = () => {
143
165
  return (
144
166
  <VirtualizedList
167
+ endReached={hasNextPage ? loadNextPage : undefined}
145
168
  itemContent={(index) => {
146
169
  const token = tokens[index];
147
170
  const address = token.address || '';
@@ -235,7 +258,7 @@ export function TokenList(props: PropTypes) {
235
258
  );
236
259
  }}
237
260
  totalCount={tokens.length}
238
- key={`${selectedBlockchain}-${searchedFor}`}
261
+ key={`${selectedBlockchain}-${searchedFor}-${balanceKey}`}
239
262
  />
240
263
  );
241
264
  };
@@ -1,5 +1,4 @@
1
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
- import type { DerivationPath } from '@rango-dev/wallets-shared';
1
+ import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
3
2
 
4
3
  import { namespaces } from '@rango-dev/wallets-shared';
5
4
 
@@ -1,5 +1,5 @@
1
1
  import type { PropTypes } from './Namespaces.types';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
+ import type { Namespace } from '@rango-dev/wallets-shared';
3
3
 
4
4
  import { i18n } from '@lingui/core';
5
5
  import {
@@ -12,7 +12,8 @@ import {
12
12
  Radio,
13
13
  RadioRoot,
14
14
  } from '@rango-dev/ui';
15
- import React, { useState } from 'react';
15
+ import { namespaces } from '@rango-dev/wallets-shared';
16
+ import React, { useMemo, useState } from 'react';
16
17
 
17
18
  import { useAppStore } from '../../store/AppStore';
18
19
  import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
@@ -22,14 +23,25 @@ import { getBlockchainLogo } from './Namespaces.helpers';
22
23
  import { NamespaceList } from './Namespaces.styles';
23
24
 
24
25
  export function Namespaces(props: PropTypes) {
25
- const { targetWallet } = props.value;
26
- const singleNamespace = targetWallet.needsNamespace?.selection === 'single';
27
- const providerImage = targetWallet.image;
26
+ const { singleNamespace, availableNamespaces, providerImage } = props.value;
28
27
 
29
28
  const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
30
29
 
31
30
  const blockchains = useAppStore().blockchains();
32
31
 
32
+ const namespacesInfo = useMemo(
33
+ () =>
34
+ availableNamespaces?.map((namespace) => ({
35
+ name: namespace,
36
+ logo: getBlockchainLogo(
37
+ blockchains,
38
+ namespaces[namespace].mainBlockchain
39
+ ),
40
+ title: namespaces[namespace].title,
41
+ })),
42
+ [availableNamespaces]
43
+ );
44
+
33
45
  const onSelect = (namespace: Namespace) => {
34
46
  if (singleNamespace) {
35
47
  setSelectedNamespaces([namespace]);
@@ -71,33 +83,28 @@ export function Namespaces(props: PropTypes) {
71
83
  <NamespaceList>
72
84
  {wrapRadioRoot(
73
85
  <>
74
- {targetWallet.needsNamespace?.data.map((ns) => {
75
- return (
76
- <ListItemButton
77
- key={ns.id}
78
- id={ns.id}
79
- title={ns.label}
80
- hasDivider
81
- style={{ height: 60 }}
82
- onClick={() => onSelect(ns.value)}
83
- start={
84
- <Image
85
- src={getBlockchainLogo(blockchains, ns.id)}
86
- size={22}
86
+ {namespacesInfo?.map((namespaceInfoItem) => (
87
+ <ListItemButton
88
+ key={namespaceInfoItem.name}
89
+ id={namespaceInfoItem.name}
90
+ title={namespaceInfoItem.title}
91
+ hasDivider
92
+ style={{ height: 60 }}
93
+ onClick={() => onSelect(namespaceInfoItem.name)}
94
+ start={<Image src={namespaceInfoItem.logo} size={22} />}
95
+ end={
96
+ singleNamespace ? (
97
+ <Radio value={namespaceInfoItem.name} />
98
+ ) : (
99
+ <Checkbox
100
+ checked={selectedNamespaces.includes(
101
+ namespaceInfoItem.name
102
+ )}
87
103
  />
88
- }
89
- end={
90
- singleNamespace ? (
91
- <Radio value={ns.value} />
92
- ) : (
93
- <Checkbox
94
- checked={selectedNamespaces.includes(ns.value)}
95
- />
96
- )
97
- }
98
- />
99
- );
100
- })}
104
+ )
105
+ }
106
+ />
107
+ ))}
101
108
  </>
102
109
  )}
103
110
  </NamespaceList>
@@ -1,5 +1,5 @@
1
1
  import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
2
- import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
+ import type { Namespace } from '@rango-dev/wallets-shared';
3
3
 
4
4
  export interface PropTypes {
5
5
  onConfirm: (namespaces: Namespace[]) => void;
@@ -32,29 +32,4 @@ export const HIGH_PRIORITY_TAGS: TagValue[] = [
32
32
  'HIGH_IMPACT',
33
33
  ];
34
34
 
35
- export type Criteria = {
36
- threshold: number;
37
- minInput: number;
38
- };
39
-
40
- export const PERCENT_MULTIPLIER = 100;
41
35
  export const GAS_FEE_MAX = 30;
42
- export const ROUTE_TIME_MAX = 15;
43
- export const SECONDS_IN_MINUTE = 60;
44
- export const HIGH_FEE_THRESHOLD_USD = 30;
45
-
46
- export const HIGH_VALUE_LOSS_CRITERIA: Criteria[] = [
47
- { threshold: -10, minInput: 400 },
48
- { threshold: -5, minInput: 1000 },
49
- ];
50
-
51
- export const OUTPUT_CHANGE_WARNING_CRITERIA: Criteria[] = [
52
- {
53
- threshold: -1,
54
- minInput: 1000,
55
- },
56
- {
57
- threshold: -2,
58
- minInput: 500,
59
- },
60
- ];
@@ -0,0 +1,26 @@
1
+ import type { QuoteUpdateWarning } from '../types';
2
+
3
+ import { i18n } from '@lingui/core';
4
+
5
+ import { QuoteUpdateType } from '../types';
6
+
7
+ export function getQuoteUpdateWarningMessage(warning: QuoteUpdateWarning) {
8
+ switch (warning.type) {
9
+ case QuoteUpdateType.QUOTE_UPDATED:
10
+ return i18n.t('Route has been updated.');
11
+ case QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED:
12
+ return i18n.t(
13
+ 'Output amount changed to {newOutputAmount} ({percentageChange}% change).',
14
+ {
15
+ newOutputAmount: warning.newOutputAmount,
16
+ percentageChange: warning.percentageChange,
17
+ }
18
+ );
19
+ case QuoteUpdateType.QUOTE_SWAPPERS_UPDATED:
20
+ return i18n.t('Route swappers has been updated.');
21
+ case QuoteUpdateType.QUOTE_COINS_UPDATED:
22
+ return i18n.t('Route internal coins has been updated.');
23
+ default:
24
+ return '';
25
+ }
26
+ }
@@ -4,7 +4,6 @@ export const Container = styled('div', {
4
4
  transition: 'width 0.2s, opacity 0.2s, margin-left 0.2s',
5
5
  height: '700px',
6
6
  width: '390px',
7
- position: 'relative',
8
7
  opacity: 1,
9
8
  marginLeft: '$16',
10
9
  backgroundColor: '$neutral100',
@@ -64,7 +64,7 @@ export function ExpandedQuotes(props: PropTypes) {
64
64
  />
65
65
  <Content>
66
66
  <Quotes
67
- showModalFee={true}
67
+ showModalFee={false}
68
68
  fetch={fetch}
69
69
  hasSort={false}
70
70
  loading={loading}
@@ -2,12 +2,10 @@ import type { PropTypes } from './Inputs.types';
2
2
 
3
3
  import { i18n } from '@lingui/core';
4
4
  import { SwapInput } from '@rango-dev/ui';
5
- import BigNumber from 'bignumber.js';
6
5
  import React from 'react';
7
6
 
8
7
  import { SwitchFromAndToButton } from '../../components/SwitchFromAndTo';
9
8
  import { errorMessages } from '../../constants/errors';
10
- import { ZERO } from '../../constants/numbers';
11
9
  import {
12
10
  PERCENTAGE_CHANGE_MAX_DECIMALS,
13
11
  PERCENTAGE_CHANGE_MIN_DECIMALS,
@@ -16,8 +14,8 @@ import {
16
14
  USD_VALUE_MAX_DECIMALS,
17
15
  USD_VALUE_MIN_DECIMALS,
18
16
  } from '../../constants/routing';
19
- import { useAppStore } from '../../store/AppStore';
20
17
  import { useQuoteStore } from '../../store/quote';
18
+ import { useWalletsStore } from '../../store/wallets';
21
19
  import { getContainer } from '../../utils/common';
22
20
  import { numberToString } from '../../utils/numbers';
23
21
  import { getPriceImpact, getPriceImpactLevel } from '../../utils/quote';
@@ -40,16 +38,15 @@ export function Inputs(props: PropTypes) {
40
38
  outputUsdValue,
41
39
  selectedQuote,
42
40
  } = useQuoteStore();
43
- const { connectedWallets, getBalanceFor } = useAppStore();
41
+ const { connectedWallets, getBalanceFor } = useWalletsStore();
44
42
  const fromTokenBalance = fromToken ? getBalanceFor(fromToken) : null;
45
43
  const fromTokenFormattedBalance =
46
44
  formatBalance(fromTokenBalance)?.amount ?? '0';
47
45
 
48
- const fromBalanceAmount = fromTokenBalance
49
- ? new BigNumber(fromTokenBalance.amount).shiftedBy(
50
- -fromTokenBalance.decimals
51
- )
52
- : ZERO;
46
+ const tokenBalanceReal =
47
+ !!fromBlockchain && !!fromToken
48
+ ? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
49
+ : '0';
53
50
 
54
51
  const fetchingBalance =
55
52
  !!fromBlockchain &&
@@ -110,17 +107,7 @@ export function Inputs(props: PropTypes) {
110
107
  loadingBalance={fetchingBalance}
111
108
  tooltipContainer={getContainer()}
112
109
  onSelectMaxBalance={() => {
113
- const tokenBalanceReal = numberToString(
114
- fromBalanceAmount,
115
- fromTokenBalance?.decimals
116
- );
117
-
118
- // if a token hasn't any value, we will reset the input by setting an empty string.
119
- const nextInputAmount = !!fromTokenBalance?.amount
120
- ? tokenBalanceReal
121
- : '';
122
-
123
- setInputAmount(nextInputAmount);
110
+ setInputAmount(tokenBalanceReal.split(',').join(''));
124
111
  }}
125
112
  anyWalletConnected={connectedWallets.length > 0}
126
113
  />
@@ -7,7 +7,8 @@ import { Quote } from '../../components/Quote';
7
7
  import { QuoteSkeleton } from '../../components/QuoteSkeleton';
8
8
  import { useQuoteStore } from '../../store/quote';
9
9
  import { QuoteErrorType } from '../../types';
10
- import { getUsdOutputFrom } from '../../utils/swap';
10
+ import { getQuoteToTokenUsdPrice } from '../../utils/quote';
11
+ import { calcOutputUsdValue } from '../../utils/swap';
11
12
 
12
13
  import { QuoteContainer } from './QuoteInfo.styles';
13
14
 
@@ -27,12 +28,17 @@ export function QuoteInfo(props: PropTypes) {
27
28
  fullExpandedMode = false,
28
29
  container,
29
30
  } = props;
30
- const { inputAmount, inputUsdValue } = useQuoteStore();
31
+ const { inputAmount, inputUsdValue, toToken } = useQuoteStore();
31
32
 
32
33
  const outputAmount = !!quote?.outputAmount
33
34
  ? new BigNumber(quote?.outputAmount)
34
35
  : null;
35
- const outputUsdValue = quote ? getUsdOutputFrom(quote) : null;
36
+ const outputUsdValue = !!quote?.outputAmount
37
+ ? calcOutputUsdValue(
38
+ quote?.outputAmount,
39
+ getQuoteToTokenUsdPrice(quote) || toToken?.usdPrice
40
+ )
41
+ : null;
36
42
 
37
43
  const noResult =
38
44
  error &&
@@ -7,10 +7,6 @@ import type { ProvidersOptions } from '../../utils/providers';
7
7
  import type { LegacyEventHandler as EventHandler } from '@rango-dev/wallets-core/legacy';
8
8
  import type { PropsWithChildren } from 'react';
9
9
 
10
- import {
11
- legacyFormatAddressWithNetwork as formatAddressWithNetwork,
12
- legacyReadAccountAddress as readAccountAddress,
13
- } from '@rango-dev/wallets-core/legacy';
14
10
  import { Events, Provider } from '@rango-dev/wallets-react';
15
11
  import { type Network } from '@rango-dev/wallets-shared';
16
12
  import { isEvmBlockchain } from 'rango-sdk';
@@ -19,7 +15,7 @@ import React, { createContext, useEffect, useMemo, useRef } from 'react';
19
15
  import { useWalletProviders } from '../../hooks/useWalletProviders';
20
16
  import { AppStoreProvider, useAppStore } from '../../store/AppStore';
21
17
  import { useUiStore } from '../../store/ui';
22
- import { isFeatureEnabled } from '../../utils/settings';
18
+ import { useWalletsStore } from '../../store/wallets';
23
19
  import {
24
20
  prepareAccountsForWalletStore,
25
21
  walletAndSupportedChainsNames,
@@ -40,11 +36,9 @@ function Main(props: PropsWithChildren<PropTypes>) {
40
36
  updateSettings,
41
37
  fetch: fetchMeta,
42
38
  fetchStatus,
43
- removeBalancesForWallet,
44
39
  } = useAppStore();
45
40
  const blockchains = useAppStore().blockchains();
46
- const { newWalletConnected, disconnectWallet, connectedWallets } =
47
- useAppStore();
41
+ const { findToken } = useAppStore();
48
42
  const config = useAppStore().config;
49
43
 
50
44
  const walletOptions: ProvidersOptions = {
@@ -54,9 +48,9 @@ function Main(props: PropsWithChildren<PropTypes>) {
54
48
  walletConnectListedDesktopWalletLink:
55
49
  props.config.__UNSTABLE_OR_INTERNAL__
56
50
  ?.walletConnectListedDesktopWalletLink,
57
- experimentalWallet: props.config.features?.experimentalWallet,
58
51
  };
59
52
  const { providers } = useWalletProviders(config.wallets, walletOptions);
53
+ const { connectWallet, disconnectWallet } = useWalletsStore();
60
54
  const onConnectWalletHandler = useRef<OnWalletConnectionChange>();
61
55
  const onDisconnectWalletHandler = useRef<OnWalletConnectionChange>();
62
56
 
@@ -81,62 +75,9 @@ function Main(props: PropsWithChildren<PropTypes>) {
81
75
 
82
76
  const onUpdateState: EventHandler = (type, event, value, state, meta) => {
83
77
  if (event === Events.ACCOUNTS) {
84
- const supportedChainNames: Network[] | null =
85
- walletAndSupportedChainsNames(meta.supportedBlockchains);
86
-
87
- /*
88
- * When a wallet is connecting to an evm account, we will consider it as the account exists on other evm-compatible blockchains
89
- * To get their balances.
90
- *
91
- * The logic here is for handling switching account functionality in wallets. when a wallet is switching to another account
92
- * we need to clean the balances for old accounts.
93
- */
94
- const evmAccounts: string[] = [];
95
- const nonEvmAccounts: string[] = [];
96
-
97
- value?.forEach((account: string) => {
98
- const { network } = readAccountAddress(account);
99
- if (evmBasedChainNames.includes(network)) {
100
- evmAccounts.push(account);
101
- } else {
102
- nonEvmAccounts.push(account);
103
- }
104
- });
105
-
106
- const previousAccounts = connectedWallets
107
- .filter((wallet) => wallet.walletType === type)
108
- .map((wallet) =>
109
- formatAddressWithNetwork(wallet.address, wallet.chain)
110
- );
111
-
112
- if (previousAccounts.length > 0) {
113
- if (evmAccounts.length > 0) {
114
- // We use same logic for removing as we use for adding.
115
- const data = prepareAccountsForWalletStore(
116
- type,
117
- evmAccounts,
118
- evmBasedChainNames,
119
- supportedChainNames,
120
- meta.isContractWallet
121
- );
122
-
123
- removeBalancesForWallet(type, {
124
- chains: data.map((account) => account.chain),
125
- });
126
- }
127
-
128
- if (nonEvmAccounts.length > 0) {
129
- removeBalancesForWallet(type, {
130
- chains: nonEvmAccounts.map((account) => {
131
- const { network } = readAccountAddress(account);
132
- return network;
133
- }),
134
- });
135
- }
136
- }
137
-
138
- // After cleaning up balances, it's time to add new accounts.
139
78
  if (value) {
79
+ const supportedChainNames: Network[] | null =
80
+ walletAndSupportedChainsNames(meta.supportedBlockchains);
140
81
  const data = prepareAccountsForWalletStore(
141
82
  type,
142
83
  value,
@@ -145,7 +86,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
145
86
  meta.isContractWallet
146
87
  );
147
88
  if (data.length) {
148
- void newWalletConnected(data);
89
+ connectWallet(data, findToken);
149
90
  }
150
91
  } else {
151
92
  disconnectWallet(type);
@@ -158,17 +99,17 @@ function Main(props: PropsWithChildren<PropTypes>) {
158
99
  }
159
100
  }
160
101
  }
161
- if (
162
- (event === Events.ACCOUNTS && state.connected) ||
163
- // Hub works differently, and this check should be enough.
164
- (event === Events.ACCOUNTS && meta.isHub)
165
- ) {
102
+ if (event === Events.ACCOUNTS && state.connected) {
166
103
  const key = `${type}-${state.network}-${value}`;
167
104
 
168
- if (!!onConnectWalletHandler.current) {
169
- onConnectWalletHandler.current(key);
170
- } else {
171
- console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
105
+ if (state.connected) {
106
+ if (!!onConnectWalletHandler.current) {
107
+ onConnectWalletHandler.current(key);
108
+ } else {
109
+ console.warn(
110
+ `onConnectWallet handler hasn't been set. Are you sure?`
111
+ );
112
+ }
172
113
  }
173
114
  }
174
115
 
@@ -206,14 +147,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
206
147
  allBlockChains={blockchains}
207
148
  providers={providers}
208
149
  onUpdateState={onUpdateState}
209
- autoConnect={!!isActiveTab}
210
- configs={{
211
- wallets: config.wallets,
212
- isExperimentalEnabled: isFeatureEnabled(
213
- 'experimentalWallet',
214
- config.features
215
- ),
216
- }}>
150
+ autoConnect={!!isActiveTab}>
217
151
  {props.children}
218
152
  </Provider>
219
153
  </WidgetContext.Provider>
@@ -5,7 +5,7 @@ import type { PendingSwap } from 'rango-types/lib';
5
5
 
6
6
  import {
7
7
  cancelSwap,
8
- getCurrentNamespaceOfOrNull,
8
+ getCurrentBlockchainOfOrNull,
9
9
  getCurrentStep,
10
10
  getRelatedWalletOrNull,
11
11
  } from '@rango-dev/queue-manager-rango-preset';
@@ -66,7 +66,7 @@ export class WidgetHistory {
66
66
  step: currentStep,
67
67
  wallet: currentStep ? getRelatedWalletOrNull(swap, currentStep) : null,
68
68
  network: currentStep
69
- ? getCurrentNamespaceOfOrNull(swap, currentStep)?.network
69
+ ? getCurrentBlockchainOfOrNull(swap, currentStep)
70
70
  : null,
71
71
  };
72
72
  }
@@ -9,6 +9,7 @@ import { useAppStore } from '../../store/AppStore';
9
9
  import { useNotificationStore } from '../../store/notification';
10
10
  import { useQuoteStore } from '../../store/quote';
11
11
  import { tabManager, useUiStore } from '../../store/ui';
12
+ import { useWalletsStore } from '../../store/wallets';
12
13
  import { calculateWalletUsdValue } from '../../utils/wallets';
13
14
 
14
15
  import { WidgetHistory } from './WidgetInfo.helpers';
@@ -21,16 +22,13 @@ export function WidgetInfo(props: React.PropsWithChildren) {
21
22
  const { manager } = useManager();
22
23
  const isActiveTab = useUiStore.use.isActiveTab();
23
24
  const retrySwap = useQuoteStore.use.retry();
24
- const {
25
- findToken,
26
- getBalances,
27
- getConnectedWalletsDetails,
28
- fetchBalances: refetch,
29
- } = useAppStore();
25
+ const { findToken } = useAppStore();
30
26
 
31
27
  const history = new WidgetHistory(manager, { retrySwap, findToken });
32
- const { fetchingWallets: isLoading } = useAppStore();
33
- const totalBalance = calculateWalletUsdValue(getBalances());
28
+ const details = useWalletsStore.use.connectedWallets();
29
+ const isLoading = useWalletsStore.use.loading();
30
+ const totalBalance = calculateWalletUsdValue(details);
31
+ const refetch = useWalletsStore.use.getWalletsDetails();
34
32
  const blockchains = useAppStore().blockchains();
35
33
  const tokens = useAppStore().tokens();
36
34
  const swappers = useAppStore().swappers();
@@ -49,9 +47,9 @@ export function WidgetInfo(props: React.PropsWithChildren) {
49
47
  history,
50
48
  wallets: {
51
49
  isLoading,
52
- details: getConnectedWalletsDetails(),
50
+ details,
53
51
  totalBalance,
54
- refetch: async (accounts) => refetch(accounts),
52
+ refetch: (accounts) => refetch(accounts, findToken),
55
53
  },
56
54
  meta: {
57
55
  blockchains,
@@ -1,6 +1,6 @@
1
1
  import type { WidgetHistory } from './WidgetInfo.helpers';
2
2
  import type { FetchStatus, FindToken } from '../../store/slices/data';
3
- import type { DeprecatedWalletDetail } from '../../store/slices/wallets';
3
+ import type { ConnectedWallet } from '../../store/wallets';
4
4
  import type { QuoteInputs, UpdateQuoteInputs, Wallet } from '../../types';
5
5
  import type { Notification } from '../../types/notification';
6
6
  import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
@@ -10,10 +10,10 @@ export interface WidgetInfoContextInterface {
10
10
  setCurrentTabAsActive: () => void;
11
11
  history: WidgetHistory;
12
12
  wallets: {
13
- details: DeprecatedWalletDetail[];
13
+ details: ConnectedWallet[];
14
14
  totalBalance: string;
15
15
  isLoading: boolean;
16
- refetch: (accounts: Wallet[]) => void;
16
+ refetch: (accounts: Wallet[], tokens: Token[]) => void;
17
17
  };
18
18
  meta: {
19
19
  blockchains: BlockchainMeta[];