@rango-dev/widget-embedded 0.37.0 → 0.37.1-next.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 (157) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/QueueManager.d.ts.map +1 -1
  3. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  4. package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
  5. package/dist/components/Layout/Layout.d.ts.map +1 -1
  6. package/dist/components/Quote/Quote.d.ts.map +1 -1
  7. package/dist/components/Quote/Quote.styles.d.ts +1 -1
  8. package/dist/components/Quote/Quote.types.d.ts +2 -0
  9. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  10. package/dist/components/Quote/QuoteCostDetails.d.ts.map +1 -1
  11. package/dist/components/Quote/QuoteCostDetails.styles.d.ts.map +1 -1
  12. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  13. package/dist/components/Quotes/Quotes.d.ts.map +1 -1
  14. package/dist/components/RefreshModal/RefreshModal.styles.d.ts +1 -1
  15. package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
  16. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts +1 -1
  17. package/dist/components/SwapDetailsAlerts/SwapDetailsAlerts.types.d.ts.map +1 -1
  18. package/dist/components/SwapDetailsModal/SwapDetailsCompleteModal.d.ts.map +1 -1
  19. package/dist/components/TokenList/TokenList.d.ts.map +1 -1
  20. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts +2 -1
  21. package/dist/components/WalletStatefulConnect/DerivationPath.helpers.d.ts.map +1 -1
  22. package/dist/components/WalletStatefulConnect/Namespaces.d.ts.map +1 -1
  23. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts +1 -1
  24. package/dist/components/WalletStatefulConnect/Namespaces.types.d.ts.map +1 -1
  25. package/dist/constants/quote.d.ts +10 -0
  26. package/dist/constants/quote.d.ts.map +1 -1
  27. package/dist/containers/ExpandedQuotes/ExpandedQuotes.styles.d.ts.map +1 -1
  28. package/dist/containers/Inputs/Inputs.d.ts.map +1 -1
  29. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  30. package/dist/containers/Wallets/Wallets.d.ts.map +1 -1
  31. package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -1
  32. package/dist/containers/WidgetInfo/WidgetInfo.helpers.d.ts +1 -1
  33. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +2 -2
  34. package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -1
  35. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  36. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +6 -4
  37. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  38. package/dist/hooks/useFetchApiConfig.d.ts.map +1 -1
  39. package/dist/hooks/useFetchCustomToken.d.ts.map +1 -1
  40. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts +2 -1
  41. package/dist/hooks/useStatefulConnect/useStatefulConnect.d.ts.map +1 -1
  42. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts +3 -5
  43. package/dist/hooks/useStatefulConnect/useStatefulConnect.types.d.ts.map +1 -1
  44. package/dist/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.d.ts.map +1 -1
  45. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  46. package/dist/hooks/useWalletList.d.ts.map +1 -1
  47. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts +2 -3
  48. package/dist/hooks/useWalletProviders/useWalletProviders.d.ts.map +1 -1
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +2 -2
  52. package/dist/index.js.map +4 -4
  53. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  54. package/dist/pages/Home.d.ts.map +1 -1
  55. package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
  56. package/dist/store/app.d.ts +2 -4
  57. package/dist/store/app.d.ts.map +1 -1
  58. package/dist/store/quote.d.ts.map +1 -1
  59. package/dist/store/slices/config.d.ts +4 -0
  60. package/dist/store/slices/config.d.ts.map +1 -1
  61. package/dist/store/slices/data.d.ts.map +1 -1
  62. package/dist/store/slices/types.d.ts +6 -0
  63. package/dist/store/slices/types.d.ts.map +1 -0
  64. package/dist/store/slices/wallets.d.ts +60 -0
  65. package/dist/store/slices/wallets.d.ts.map +1 -0
  66. package/dist/store/ui.d.ts +4 -0
  67. package/dist/store/ui.d.ts.map +1 -1
  68. package/dist/store/utils/wallets.d.ts +17 -0
  69. package/dist/store/utils/wallets.d.ts.map +1 -0
  70. package/dist/types/config.d.ts +6 -3
  71. package/dist/types/config.d.ts.map +1 -1
  72. package/dist/types/quote.d.ts +8 -17
  73. package/dist/types/quote.d.ts.map +1 -1
  74. package/dist/types/wallets.d.ts +3 -7
  75. package/dist/types/wallets.d.ts.map +1 -1
  76. package/dist/utils/providers.d.ts +8 -9
  77. package/dist/utils/providers.d.ts.map +1 -1
  78. package/dist/utils/quote.d.ts +5 -6
  79. package/dist/utils/quote.d.ts.map +1 -1
  80. package/dist/utils/settings.d.ts +1 -0
  81. package/dist/utils/settings.d.ts.map +1 -1
  82. package/dist/utils/swap.d.ts +5 -5
  83. package/dist/utils/swap.d.ts.map +1 -1
  84. package/dist/utils/wallets.d.ts +12 -14
  85. package/dist/utils/wallets.d.ts.map +1 -1
  86. package/dist/widget-embedded.build.json +1 -1
  87. package/package.json +8 -8
  88. package/src/QueueManager.tsx +17 -11
  89. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +5 -24
  90. package/src/components/ConfirmWalletsModal/WalletList.tsx +10 -7
  91. package/src/components/Layout/Layout.tsx +1 -3
  92. package/src/components/Quote/Quote.tsx +22 -3
  93. package/src/components/Quote/Quote.types.ts +2 -0
  94. package/src/components/Quote/QuoteCostDetails.styles.ts +0 -1
  95. package/src/components/Quote/QuoteCostDetails.tsx +23 -4
  96. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +42 -22
  97. package/src/components/Quotes/Quotes.tsx +2 -3
  98. package/src/components/StatefulConnectModal/StatefulConnectModal.tsx +1 -1
  99. package/src/components/SwapDetails/SwapDetails.tsx +14 -6
  100. package/src/components/SwapDetailsAlerts/SwapDetailsAlerts.types.ts +1 -1
  101. package/src/components/SwapDetailsModal/SwapDetailsCompleteModal.tsx +26 -13
  102. package/src/components/TokenList/TokenList.tsx +4 -27
  103. package/src/components/WalletStatefulConnect/DerivationPath.helpers.ts +2 -1
  104. package/src/components/WalletStatefulConnect/Namespaces.tsx +31 -38
  105. package/src/components/WalletStatefulConnect/Namespaces.types.tsx +1 -1
  106. package/src/constants/quote.ts +25 -0
  107. package/src/containers/ExpandedQuotes/ExpandedQuotes.styles.ts +1 -0
  108. package/src/containers/ExpandedQuotes/ExpandedQuotes.tsx +1 -1
  109. package/src/containers/Inputs/Inputs.tsx +20 -7
  110. package/src/containers/QuoteInfo/QuoteInfo.tsx +3 -9
  111. package/src/containers/Wallets/Wallets.tsx +82 -16
  112. package/src/containers/WidgetInfo/WidgetInfo.helpers.ts +2 -2
  113. package/src/containers/WidgetInfo/WidgetInfo.tsx +10 -8
  114. package/src/containers/WidgetInfo/WidgetInfo.types.ts +2 -2
  115. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +29 -66
  116. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +10 -15
  117. package/src/hooks/useFetchApiConfig.ts +5 -1
  118. package/src/hooks/useFetchCustomToken.ts +5 -0
  119. package/src/hooks/useStatefulConnect/useStatefulConnect.ts +50 -17
  120. package/src/hooks/useStatefulConnect/useStatefulConnect.types.ts +3 -5
  121. package/src/hooks/useSubscribeToWidgetEvents/useSubscribeToWidgetEvents.ts +7 -6
  122. package/src/hooks/useSwapInput.ts +3 -11
  123. package/src/hooks/useWalletList.ts +6 -8
  124. package/src/hooks/useWalletProviders/useWalletProviders.ts +8 -12
  125. package/src/index.ts +1 -1
  126. package/src/pages/ConfirmSwapPage.tsx +7 -15
  127. package/src/pages/Home.tsx +5 -3
  128. package/src/pages/SelectSwapItemsPage.tsx +1 -2
  129. package/src/store/app.ts +4 -4
  130. package/src/store/quote.ts +3 -13
  131. package/src/store/slices/config.ts +76 -0
  132. package/src/store/slices/data.test.ts +23 -1
  133. package/src/store/slices/data.ts +3 -2
  134. package/src/store/slices/types.ts +9 -0
  135. package/src/store/slices/wallets.ts +488 -0
  136. package/src/store/ui.ts +6 -0
  137. package/src/store/utils/wallets.ts +108 -0
  138. package/src/types/config.ts +7 -3
  139. package/src/types/quote.ts +10 -24
  140. package/src/types/wallets.ts +3 -7
  141. package/src/utils/providers.ts +88 -36
  142. package/src/utils/quote.ts +57 -45
  143. package/src/utils/settings.ts +4 -0
  144. package/src/utils/swap.ts +56 -37
  145. package/src/utils/wallets.ts +76 -141
  146. package/dist/constants/warnings.d.ts +0 -3
  147. package/dist/constants/warnings.d.ts.map +0 -1
  148. package/dist/hooks/useObserveBalanceChanges/index.d.ts +0 -2
  149. package/dist/hooks/useObserveBalanceChanges/index.d.ts.map +0 -1
  150. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts +0 -4
  151. package/dist/hooks/useObserveBalanceChanges/useObserveBalanceChanges.d.ts.map +0 -1
  152. package/dist/store/wallets.d.ts +0 -66
  153. package/dist/store/wallets.d.ts.map +0 -1
  154. package/src/constants/warnings.ts +0 -26
  155. package/src/hooks/useObserveBalanceChanges/index.ts +0 -1
  156. package/src/hooks/useObserveBalanceChanges/useObserveBalanceChanges.ts +0 -68
  157. package/src/store/wallets.ts +0 -268
@@ -15,11 +15,9 @@ import {
15
15
  Typography,
16
16
  VirtualizedList,
17
17
  } from '@rango-dev/ui';
18
- import React, { useEffect, useState } from 'react';
18
+ import React from 'react';
19
19
 
20
- import { useObserveBalanceChanges } from '../../hooks/useObserveBalanceChanges';
21
20
  import { useAppStore } from '../../store/AppStore';
22
- import { useWalletsStore } from '../../store/wallets';
23
21
  import { createTintsAndShades } from '../../utils/colors';
24
22
  import { formatBalance } from '../../utils/wallets';
25
23
 
@@ -93,7 +91,7 @@ const renderDesc = (props: RenderDescProps) => {
93
91
 
94
92
  export function TokenList(props: PropTypes) {
95
93
  const {
96
- list,
94
+ list: tokens,
97
95
  searchedFor = '',
98
96
  onChange,
99
97
  selectedBlockchain,
@@ -101,29 +99,10 @@ export function TokenList(props: PropTypes) {
101
99
  action,
102
100
  } = props;
103
101
 
104
- const [tokens, setTokens] = useState<Token[]>(list);
105
102
  const fetchStatus = useAppStore().fetchStatus;
106
103
  const blockchains = useAppStore().blockchains();
107
- const [hasNextPage, setHasNextPage] = useState<boolean>(true);
108
- const { getBalanceFor, loading: loadingWallet } = useWalletsStore();
104
+ const { getBalanceFor, fetchingWallets: loadingWallet } = useAppStore();
109
105
  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]);
127
106
 
128
107
  const endRenderer = (token: Token) => {
129
108
  const tokenBalance = formatBalance(getBalanceFor(token));
@@ -160,11 +139,9 @@ export function TokenList(props: PropTypes) {
160
139
  )
161
140
  );
162
141
  };
163
-
164
142
  const renderList = () => {
165
143
  return (
166
144
  <VirtualizedList
167
- endReached={hasNextPage ? loadNextPage : undefined}
168
145
  itemContent={(index) => {
169
146
  const token = tokens[index];
170
147
  const address = token.address || '';
@@ -258,7 +235,7 @@ export function TokenList(props: PropTypes) {
258
235
  );
259
236
  }}
260
237
  totalCount={tokens.length}
261
- key={`${selectedBlockchain}-${searchedFor}-${balanceKey}`}
238
+ key={`${selectedBlockchain}-${searchedFor}`}
262
239
  />
263
240
  );
264
241
  };
@@ -1,4 +1,5 @@
1
- import type { DerivationPath, Namespace } from '@rango-dev/wallets-shared';
1
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
2
+ import type { DerivationPath } from '@rango-dev/wallets-shared';
2
3
 
3
4
  import { namespaces } from '@rango-dev/wallets-shared';
4
5
 
@@ -1,5 +1,5 @@
1
1
  import type { PropTypes } from './Namespaces.types';
2
- import type { Namespace } from '@rango-dev/wallets-shared';
2
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
3
 
4
4
  import { i18n } from '@lingui/core';
5
5
  import {
@@ -12,8 +12,7 @@ import {
12
12
  Radio,
13
13
  RadioRoot,
14
14
  } from '@rango-dev/ui';
15
- import { namespaces } from '@rango-dev/wallets-shared';
16
- import React, { useMemo, useState } from 'react';
15
+ import React, { useState } from 'react';
17
16
 
18
17
  import { useAppStore } from '../../store/AppStore';
19
18
  import { WalletImageContainer } from '../HeaderButtons/HeaderButtons.styles';
@@ -23,25 +22,14 @@ import { getBlockchainLogo } from './Namespaces.helpers';
23
22
  import { NamespaceList } from './Namespaces.styles';
24
23
 
25
24
  export function Namespaces(props: PropTypes) {
26
- const { singleNamespace, availableNamespaces, providerImage } = props.value;
25
+ const { targetWallet } = props.value;
26
+ const singleNamespace = targetWallet.needsNamespace?.selection === 'single';
27
+ const providerImage = targetWallet.image;
27
28
 
28
29
  const [selectedNamespaces, setSelectedNamespaces] = useState<Namespace[]>([]);
29
30
 
30
31
  const blockchains = useAppStore().blockchains();
31
32
 
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
-
45
33
  const onSelect = (namespace: Namespace) => {
46
34
  if (singleNamespace) {
47
35
  setSelectedNamespaces([namespace]);
@@ -83,28 +71,33 @@ export function Namespaces(props: PropTypes) {
83
71
  <NamespaceList>
84
72
  {wrapRadioRoot(
85
73
  <>
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
- )}
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}
103
87
  />
104
- )
105
- }
106
- />
107
- ))}
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
+ })}
108
101
  </>
109
102
  )}
110
103
  </NamespaceList>
@@ -1,5 +1,5 @@
1
1
  import type { NeedsNamespacesState } from '../../hooks/useStatefulConnect';
2
- import type { Namespace } from '@rango-dev/wallets-shared';
2
+ import type { Namespace } from '@rango-dev/wallets-core/namespaces/common';
3
3
 
4
4
  export interface PropTypes {
5
5
  onConfirm: (namespaces: Namespace[]) => void;
@@ -32,4 +32,29 @@ 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;
35
41
  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
+ ];
@@ -4,6 +4,7 @@ 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',
7
8
  opacity: 1,
8
9
  marginLeft: '$16',
9
10
  backgroundColor: '$neutral100',
@@ -64,7 +64,7 @@ export function ExpandedQuotes(props: PropTypes) {
64
64
  />
65
65
  <Content>
66
66
  <Quotes
67
- showModalFee={false}
67
+ showModalFee={true}
68
68
  fetch={fetch}
69
69
  hasSort={false}
70
70
  loading={loading}
@@ -2,10 +2,12 @@ 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';
5
6
  import React from 'react';
6
7
 
7
8
  import { SwitchFromAndToButton } from '../../components/SwitchFromAndTo';
8
9
  import { errorMessages } from '../../constants/errors';
10
+ import { ZERO } from '../../constants/numbers';
9
11
  import {
10
12
  PERCENTAGE_CHANGE_MAX_DECIMALS,
11
13
  PERCENTAGE_CHANGE_MIN_DECIMALS,
@@ -14,8 +16,8 @@ import {
14
16
  USD_VALUE_MAX_DECIMALS,
15
17
  USD_VALUE_MIN_DECIMALS,
16
18
  } from '../../constants/routing';
19
+ import { useAppStore } from '../../store/AppStore';
17
20
  import { useQuoteStore } from '../../store/quote';
18
- import { useWalletsStore } from '../../store/wallets';
19
21
  import { getContainer } from '../../utils/common';
20
22
  import { numberToString } from '../../utils/numbers';
21
23
  import { getPriceImpact, getPriceImpactLevel } from '../../utils/quote';
@@ -38,15 +40,16 @@ export function Inputs(props: PropTypes) {
38
40
  outputUsdValue,
39
41
  selectedQuote,
40
42
  } = useQuoteStore();
41
- const { connectedWallets, getBalanceFor } = useWalletsStore();
43
+ const { connectedWallets, getBalanceFor } = useAppStore();
42
44
  const fromTokenBalance = fromToken ? getBalanceFor(fromToken) : null;
43
45
  const fromTokenFormattedBalance =
44
46
  formatBalance(fromTokenBalance)?.amount ?? '0';
45
47
 
46
- const tokenBalanceReal =
47
- !!fromBlockchain && !!fromToken
48
- ? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
49
- : '0';
48
+ const fromBalanceAmount = fromTokenBalance
49
+ ? new BigNumber(fromTokenBalance.amount).shiftedBy(
50
+ -fromTokenBalance.decimals
51
+ )
52
+ : ZERO;
50
53
 
51
54
  const fetchingBalance =
52
55
  !!fromBlockchain &&
@@ -107,7 +110,17 @@ export function Inputs(props: PropTypes) {
107
110
  loadingBalance={fetchingBalance}
108
111
  tooltipContainer={getContainer()}
109
112
  onSelectMaxBalance={() => {
110
- setInputAmount(tokenBalanceReal.split(',').join(''));
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);
111
124
  }}
112
125
  anyWalletConnected={connectedWallets.length > 0}
113
126
  />
@@ -7,8 +7,7 @@ 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 { getQuoteToTokenUsdPrice } from '../../utils/quote';
11
- import { calcOutputUsdValue } from '../../utils/swap';
10
+ import { getUsdOutputFrom } from '../../utils/swap';
12
11
 
13
12
  import { QuoteContainer } from './QuoteInfo.styles';
14
13
 
@@ -28,17 +27,12 @@ export function QuoteInfo(props: PropTypes) {
28
27
  fullExpandedMode = false,
29
28
  container,
30
29
  } = props;
31
- const { inputAmount, inputUsdValue, toToken } = useQuoteStore();
30
+ const { inputAmount, inputUsdValue } = useQuoteStore();
32
31
 
33
32
  const outputAmount = !!quote?.outputAmount
34
33
  ? new BigNumber(quote?.outputAmount)
35
34
  : null;
36
- const outputUsdValue = !!quote?.outputAmount
37
- ? calcOutputUsdValue(
38
- quote?.outputAmount,
39
- getQuoteToTokenUsdPrice(quote) || toToken?.usdPrice
40
- )
41
- : null;
35
+ const outputUsdValue = quote ? getUsdOutputFrom(quote) : null;
42
36
 
43
37
  const noResult =
44
38
  error &&
@@ -7,6 +7,10 @@ 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';
10
14
  import { Events, Provider } from '@rango-dev/wallets-react';
11
15
  import { type Network } from '@rango-dev/wallets-shared';
12
16
  import { isEvmBlockchain } from 'rango-sdk';
@@ -15,7 +19,7 @@ import React, { createContext, useEffect, useMemo, useRef } from 'react';
15
19
  import { useWalletProviders } from '../../hooks/useWalletProviders';
16
20
  import { AppStoreProvider, useAppStore } from '../../store/AppStore';
17
21
  import { useUiStore } from '../../store/ui';
18
- import { useWalletsStore } from '../../store/wallets';
22
+ import { isFeatureEnabled } from '../../utils/settings';
19
23
  import {
20
24
  prepareAccountsForWalletStore,
21
25
  walletAndSupportedChainsNames,
@@ -36,9 +40,11 @@ function Main(props: PropsWithChildren<PropTypes>) {
36
40
  updateSettings,
37
41
  fetch: fetchMeta,
38
42
  fetchStatus,
43
+ removeBalancesForWallet,
39
44
  } = useAppStore();
40
45
  const blockchains = useAppStore().blockchains();
41
- const { findToken } = useAppStore();
46
+ const { newWalletConnected, disconnectWallet, connectedWallets } =
47
+ useAppStore();
42
48
  const config = useAppStore().config;
43
49
 
44
50
  const walletOptions: ProvidersOptions = {
@@ -48,9 +54,9 @@ function Main(props: PropsWithChildren<PropTypes>) {
48
54
  walletConnectListedDesktopWalletLink:
49
55
  props.config.__UNSTABLE_OR_INTERNAL__
50
56
  ?.walletConnectListedDesktopWalletLink,
57
+ experimentalWallet: props.config.features?.experimentalWallet,
51
58
  };
52
59
  const { providers } = useWalletProviders(config.wallets, walletOptions);
53
- const { connectWallet, disconnectWallet } = useWalletsStore();
54
60
  const onConnectWalletHandler = useRef<OnWalletConnectionChange>();
55
61
  const onDisconnectWalletHandler = useRef<OnWalletConnectionChange>();
56
62
 
@@ -75,9 +81,62 @@ function Main(props: PropsWithChildren<PropTypes>) {
75
81
 
76
82
  const onUpdateState: EventHandler = (type, event, value, state, meta) => {
77
83
  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.
78
139
  if (value) {
79
- const supportedChainNames: Network[] | null =
80
- walletAndSupportedChainsNames(meta.supportedBlockchains);
81
140
  const data = prepareAccountsForWalletStore(
82
141
  type,
83
142
  value,
@@ -86,7 +145,7 @@ function Main(props: PropsWithChildren<PropTypes>) {
86
145
  meta.isContractWallet
87
146
  );
88
147
  if (data.length) {
89
- connectWallet(data, findToken);
148
+ void newWalletConnected(data);
90
149
  }
91
150
  } else {
92
151
  disconnectWallet(type);
@@ -99,17 +158,17 @@ function Main(props: PropsWithChildren<PropTypes>) {
99
158
  }
100
159
  }
101
160
  }
102
- if (event === Events.ACCOUNTS && state.connected) {
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
+ ) {
103
166
  const key = `${type}-${state.network}-${value}`;
104
167
 
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
- }
168
+ if (!!onConnectWalletHandler.current) {
169
+ onConnectWalletHandler.current(key);
170
+ } else {
171
+ console.warn(`onConnectWallet handler hasn't been set. Are you sure?`);
113
172
  }
114
173
  }
115
174
 
@@ -147,7 +206,14 @@ function Main(props: PropsWithChildren<PropTypes>) {
147
206
  allBlockChains={blockchains}
148
207
  providers={providers}
149
208
  onUpdateState={onUpdateState}
150
- autoConnect={!!isActiveTab}>
209
+ autoConnect={!!isActiveTab}
210
+ configs={{
211
+ wallets: config.wallets,
212
+ isExperimentalEnabled: isFeatureEnabled(
213
+ 'experimentalWallet',
214
+ config.features
215
+ ),
216
+ }}>
151
217
  {props.children}
152
218
  </Provider>
153
219
  </WidgetContext.Provider>
@@ -5,7 +5,7 @@ import type { PendingSwap } from 'rango-types/lib';
5
5
 
6
6
  import {
7
7
  cancelSwap,
8
- getCurrentBlockchainOfOrNull,
8
+ getCurrentNamespaceOfOrNull,
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
- ? getCurrentBlockchainOfOrNull(swap, currentStep)
69
+ ? getCurrentNamespaceOfOrNull(swap, currentStep)?.network
70
70
  : null,
71
71
  };
72
72
  }
@@ -9,7 +9,6 @@ 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';
13
12
  import { calculateWalletUsdValue } from '../../utils/wallets';
14
13
 
15
14
  import { WidgetHistory } from './WidgetInfo.helpers';
@@ -22,13 +21,16 @@ export function WidgetInfo(props: React.PropsWithChildren) {
22
21
  const { manager } = useManager();
23
22
  const isActiveTab = useUiStore.use.isActiveTab();
24
23
  const retrySwap = useQuoteStore.use.retry();
25
- const { findToken } = useAppStore();
24
+ const {
25
+ findToken,
26
+ connectedWallets,
27
+ getBalances,
28
+ fetchBalances: refetch,
29
+ } = useAppStore();
26
30
 
27
31
  const history = new WidgetHistory(manager, { retrySwap, findToken });
28
- const details = useWalletsStore.use.connectedWallets();
29
- const isLoading = useWalletsStore.use.loading();
30
- const totalBalance = calculateWalletUsdValue(details);
31
- const refetch = useWalletsStore.use.getWalletsDetails();
32
+ const { fetchingWallets: isLoading } = useAppStore();
33
+ const totalBalance = calculateWalletUsdValue(getBalances());
32
34
  const blockchains = useAppStore().blockchains();
33
35
  const tokens = useAppStore().tokens();
34
36
  const swappers = useAppStore().swappers();
@@ -47,9 +49,9 @@ export function WidgetInfo(props: React.PropsWithChildren) {
47
49
  history,
48
50
  wallets: {
49
51
  isLoading,
50
- details,
52
+ details: connectedWallets,
51
53
  totalBalance,
52
- refetch: (accounts) => refetch(accounts, findToken),
54
+ refetch: async (accounts) => refetch(accounts),
53
55
  },
54
56
  meta: {
55
57
  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 { ConnectedWallet } from '../../store/wallets';
3
+ import type { ConnectedWallet } from '../../store/slices/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';
@@ -13,7 +13,7 @@ export interface WidgetInfoContextInterface {
13
13
  details: ConnectedWallet[];
14
14
  totalBalance: string;
15
15
  isLoading: boolean;
16
- refetch: (accounts: Wallet[], tokens: Token[]) => void;
16
+ refetch: (accounts: Wallet[]) => void;
17
17
  };
18
18
  meta: {
19
19
  blockchains: BlockchainMeta[];