@rango-dev/widget-embedded 0.1.10 → 0.1.11-next.4

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 (76) hide show
  1. package/dist/App.d.ts +3 -3
  2. package/dist/App.d.ts.map +1 -1
  3. package/dist/components/AppRouter.d.ts +1 -7
  4. package/dist/components/AppRouter.d.ts.map +1 -1
  5. package/dist/components/AppRoutes.d.ts +2 -2
  6. package/dist/components/AppRoutes.d.ts.map +1 -1
  7. package/dist/components/Layout.d.ts +3 -3
  8. package/dist/components/Layout.d.ts.map +1 -1
  9. package/dist/components/PercentageChange.d.ts +9 -0
  10. package/dist/components/PercentageChange.d.ts.map +1 -0
  11. package/dist/components/TokenInfo.d.ts.map +1 -1
  12. package/dist/components/TokenPreview.d.ts +2 -1
  13. package/dist/components/TokenPreview.d.ts.map +1 -1
  14. package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
  15. package/dist/hooks/useTheme.d.ts +2 -5
  16. package/dist/hooks/useTheme.d.ts.map +1 -1
  17. package/dist/lib.d.ts +2 -2
  18. package/dist/lib.d.ts.map +1 -1
  19. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  20. package/dist/pages/Home.d.ts +1 -7
  21. package/dist/pages/Home.d.ts.map +1 -1
  22. package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
  23. package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
  24. package/dist/pages/SelectChainPage.d.ts +1 -2
  25. package/dist/pages/SelectChainPage.d.ts.map +1 -1
  26. package/dist/pages/SelectTokenPage.d.ts +2 -2
  27. package/dist/pages/SelectTokenPage.d.ts.map +1 -1
  28. package/dist/pages/SettingsPage.d.ts +1 -2
  29. package/dist/pages/SettingsPage.d.ts.map +1 -1
  30. package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
  31. package/dist/pages/WalletsPage.d.ts +1 -1
  32. package/dist/pages/WalletsPage.d.ts.map +1 -1
  33. package/dist/store/bestRoute.d.ts +1 -0
  34. package/dist/store/bestRoute.d.ts.map +1 -1
  35. package/dist/store/settings.d.ts +2 -0
  36. package/dist/store/settings.d.ts.map +1 -1
  37. package/dist/types/config.d.ts +26 -29
  38. package/dist/types/config.d.ts.map +1 -1
  39. package/dist/types/routing.d.ts +14 -1
  40. package/dist/types/routing.d.ts.map +1 -1
  41. package/dist/utils/routing.d.ts +2 -2
  42. package/dist/utils/routing.d.ts.map +1 -1
  43. package/dist/utils/swap.d.ts +2 -6
  44. package/dist/utils/swap.d.ts.map +1 -1
  45. package/dist/widget-embedded.cjs.development.js +181 -193
  46. package/dist/widget-embedded.cjs.development.js.map +1 -1
  47. package/dist/widget-embedded.cjs.production.min.js +181 -193
  48. package/dist/widget-embedded.cjs.production.min.js.map +1 -1
  49. package/dist/widget-embedded.esm.js +181 -193
  50. package/dist/widget-embedded.esm.js.map +1 -1
  51. package/package.json +6 -4
  52. package/readme.md +1 -1
  53. package/src/App.tsx +21 -13
  54. package/src/components/AppRouter.tsx +7 -16
  55. package/src/components/AppRoutes.tsx +13 -32
  56. package/src/components/Layout.tsx +32 -23
  57. package/src/components/PercentageChange.tsx +33 -0
  58. package/src/components/TokenInfo.tsx +20 -4
  59. package/src/components/TokenPreview.tsx +16 -8
  60. package/src/hooks/useConfirmSwap.ts +5 -4
  61. package/src/hooks/useTheme.ts +15 -9
  62. package/src/lib.tsx +30 -36
  63. package/src/pages/ConfirmSwapPage.tsx +14 -7
  64. package/src/pages/Home.tsx +10 -22
  65. package/src/pages/LiquiditySourcesPage.tsx +3 -6
  66. package/src/pages/SelectChainPage.tsx +6 -6
  67. package/src/pages/SelectTokenPage.tsx +16 -18
  68. package/src/pages/SettingsPage.tsx +8 -18
  69. package/src/pages/SwapDetailsPage.tsx +2 -4
  70. package/src/pages/WalletsPage.tsx +2 -2
  71. package/src/store/bestRoute.ts +38 -8
  72. package/src/store/settings.ts +7 -0
  73. package/src/types/config.ts +27 -29
  74. package/src/types/routing.ts +17 -1
  75. package/src/utils/routing.ts +29 -23
  76. package/src/utils/swap.ts +5 -97
package/src/lib.tsx CHANGED
@@ -15,35 +15,31 @@ import { Layout } from './components/Layout';
15
15
  import { globalFont, globalStyles } from './globalStyles';
16
16
  import { useTheme } from './hooks/useTheme';
17
17
  import { isEvmBlockchain } from 'rango-sdk';
18
- import { Configs } from './types';
19
- import { useSettingsStore } from './store/settings';
18
+ import { WidgetConfig } from './types';
20
19
  import useSelectLanguage from './hooks/useSelectLanguage';
21
20
  import './i18n';
22
21
  import QueueManager from './QueueManager';
22
+ import { useUiStore } from './store/ui';
23
+ import { navigationRoutes } from './constants/navigationRoutes';
23
24
 
24
25
  export type WidgetProps = {
25
- configs: Configs;
26
+ config?: WidgetConfig;
26
27
  };
27
28
 
28
- export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
29
+ export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
29
30
  globalStyles();
30
- globalFont(configs?.fontFamily || 'Roboto');
31
+ globalFont(config?.theme?.fontFamily || 'Roboto');
31
32
 
32
- const { activeTheme } = useTheme({
33
- ...configs.colors,
34
- borderRadius: configs?.borderRadius,
35
- fontFamily: configs?.fontFamily,
36
- });
33
+ const { activeTheme } = useTheme({ ...config?.theme });
37
34
  const { blockchains } = useMetaStore.use.meta();
38
35
  const disconnectWallet = useWalletsStore.use.disconnectWallet();
39
36
  const connectWallet = useWalletsStore.use.connectWallet();
40
- const setTheme = useSettingsStore.use.setTheme();
41
37
  const { changeLanguage } = useSelectLanguage();
42
38
  const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
43
-
44
39
  const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
45
40
  useState<string>('');
46
41
  const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
42
+ const currentPage = useUiStore.use.currentPage();
47
43
 
48
44
  const evmBasedChainNames = blockchains
49
45
  .filter(isEvmBlockchain)
@@ -71,7 +67,6 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
71
67
  disconnectWallet(type);
72
68
  }
73
69
  }
74
-
75
70
  if (event === Events.ACCOUNTS && state.connected) {
76
71
  const key = `${type}-${state.network}-${value}`;
77
72
 
@@ -88,24 +83,19 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
88
83
  let providers = allProviders();
89
84
 
90
85
  useEffect(() => {
91
- if (configs.theme !== 'auto') setTheme(configs.theme);
92
- }, [configs.theme]);
93
-
94
- useEffect(() => {
95
- const wallets = configs.wallets;
86
+ const wallets = config?.wallets;
96
87
  clearConnectedWallet();
97
- providers =
98
- wallets === 'all'
99
- ? allProviders()
100
- : allProviders().filter((provider) => {
101
- const type = provider.config.type;
102
- return wallets.find((w) => w === type);
103
- });
104
- }, [configs?.wallets]);
88
+ providers = !wallets
89
+ ? allProviders()
90
+ : allProviders().filter((provider) => {
91
+ const type = provider.config.type;
92
+ return wallets.find((w) => w === type);
93
+ });
94
+ }, [config?.wallets]);
105
95
 
106
96
  useEffect(() => {
107
- changeLanguage(configs?.languege);
108
- }, [configs?.languege]);
97
+ changeLanguage(config?.language || 'en');
98
+ }, [config?.language]);
109
99
 
110
100
  return (
111
101
  <Provider
@@ -116,22 +106,26 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
116
106
  <div id="pageContainer" className={activeTheme}>
117
107
  <QueueManager>
118
108
  <SwapContainer
119
- style={{
120
- width: configs?.width || 'auto',
121
- height: configs?.height || 'auto',
122
- }}
109
+ fixedHeight={currentPage !== navigationRoutes.home}
110
+ // style={
111
+ // currentPage !== navigationRoutes.home && config?.theme?.height
112
+ // ? {
113
+ // height: config?.theme?.height,
114
+ // width: config?.theme?.width || 'auto',
115
+ // }
116
+ // : {
117
+ // width: config?.theme?.width || 'auto',
118
+ // }
119
+ // }
123
120
  >
124
121
  <AppRouter
125
- title={configs.title}
126
- titleSize={configs.titleSize}
127
- titleWeight={configs.titleWeight}
128
122
  lastConnectedWallet={lastConnectedWalletWithNetwork}
129
123
  disconnectedWallet={disconnectedWallet}
130
124
  clearDisconnectedWallet={() => {
131
125
  setDisconnectedWallet(undefined);
132
126
  }}
133
127
  >
134
- <Layout configs={configs} />
128
+ <Layout config={config} />
135
129
  </AppRouter>
136
130
  </SwapContainer>
137
131
  </QueueManager>
@@ -10,11 +10,7 @@ import {
10
10
  getSelectableWallets,
11
11
  isExperimentalChain,
12
12
  } from '../utils/wallets';
13
- import {
14
- calcOutputUsdValue,
15
- getTotalFeeInUsd,
16
- requiredWallets,
17
- } from '../utils/swap';
13
+ import { getTotalFeeInUsd, requiredWallets } from '../utils/swap';
18
14
  import { decimalNumber, numberToString } from '../utils/numbers';
19
15
  import { useMetaStore } from '../store/meta';
20
16
  import { Network, WalletType } from '@rango-dev/wallets-shared';
@@ -33,6 +29,7 @@ import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
33
29
  import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
34
30
  import { ConfirmSwapExtraMessages } from '../components/warnings/ConfirmSwapExtraMessages';
35
31
  import { getBestRouteStatus } from '../utils/routing';
32
+ import { PercentageChange } from '../components/PercentageChange';
36
33
 
37
34
  export function ConfirmSwapPage() {
38
35
  const navigate = useNavigate();
@@ -48,6 +45,8 @@ export function ConfirmSwapPage() {
48
45
  const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
49
46
  const slippage = useSettingsStore.use.slippage();
50
47
  const customSlippage = useSettingsStore.use.customSlippage();
48
+ const inputUsdValue = useBestRouteStore.use.inputUsdValue();
49
+ const outputUsdValue = useBestRouteStore.use.outputUsdValue();
51
50
 
52
51
  const bestRouteloadingStatus = getBestRouteStatus(
53
52
  fetchingBestRoute,
@@ -97,6 +96,7 @@ export function ConfirmSwapPage() {
97
96
 
98
97
  return (
99
98
  <ConfirmSwap
99
+ // @ts-ignore
100
100
  requiredWallets={getRequiredChains(bestRoute)}
101
101
  selectableWallets={selectableWallets}
102
102
  onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
@@ -106,6 +106,7 @@ export function ConfirmSwapPage() {
106
106
  manager?.create(
107
107
  'swap',
108
108
  { swapDetails: swap },
109
+ // @ts-ignore
109
110
  { id: swap.requestId }
110
111
  );
111
112
  setSelectedSwap(swap.requestId);
@@ -134,7 +135,7 @@ export function ConfirmSwapPage() {
134
135
  symbol: firstStep?.from.symbol || '',
135
136
  image: firstStep?.from.logo || '',
136
137
  }}
137
- usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
138
+ usdValue={inputUsdValue}
138
139
  amount={fromAmount}
139
140
  label={t('From')}
140
141
  loadingStatus={bestRouteloadingStatus}
@@ -149,10 +150,16 @@ export function ConfirmSwapPage() {
149
150
  symbol: lastStep?.to.symbol || '',
150
151
  image: lastStep?.to.logo || '',
151
152
  }}
152
- usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
153
+ usdValue={outputUsdValue}
153
154
  amount={toAmount}
154
155
  label={t('To')}
155
156
  loadingStatus={bestRouteloadingStatus}
157
+ percentageChange={
158
+ <PercentageChange
159
+ inputUsdValue={inputUsdValue}
160
+ outputUsdValue={outputUsdValue}
161
+ />
162
+ }
156
163
  />
157
164
  </>
158
165
  }
@@ -63,14 +63,8 @@ const Alerts = styled('div', {
63
63
  width: '100%',
64
64
  paddingTop: '$16',
65
65
  });
66
- interface PropTypes {
67
- title?: string;
68
- titleSize?: number;
69
- titleWeight?: number;
70
- }
71
- export function Home(props: PropTypes) {
72
- const { title = 'SWAP' } = props;
73
66
 
67
+ export function Home() {
74
68
  const isRouterInContext = useInRouterContext();
75
69
  const navigate = useNavigate();
76
70
  const [count, setCount] = useState(0);
@@ -78,10 +72,6 @@ export function Home(props: PropTypes) {
78
72
  const fromToken = useBestRouteStore.use.fromToken();
79
73
  const toChain = useBestRouteStore.use.toChain();
80
74
  const toToken = useBestRouteStore.use.toToken();
81
- const setFromChain = useBestRouteStore.use.setFromChain();
82
- const setFromToken = useBestRouteStore.use.setFromToken();
83
- const setToChain = useBestRouteStore.use.setToChain();
84
- const setToToken = useBestRouteStore.use.setToToken();
85
75
  const setInputAmount = useBestRouteStore.use.setInputAmount();
86
76
  const inputUsdValue = useBestRouteStore.use.inputUsdValue();
87
77
  const inputAmount = useBestRouteStore.use.inputAmount();
@@ -94,15 +84,7 @@ export function Home(props: PropTypes) {
94
84
  const loadingMetaStatus = useMetaStore.use.loadingStatus();
95
85
  const accounts = useWalletsStore.use.accounts();
96
86
  const setCurrentPage = useUiStore.use.setCurrentPage();
97
-
98
- const swithFromAndTo = () => {
99
- setFromChain(toChain);
100
- setFromToken(toToken);
101
- setToChain(fromChain);
102
- setToToken(fromToken);
103
- setInputAmount(outputAmount?.toString() || '');
104
- setCount((prev) => prev + 1);
105
- };
87
+ const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
106
88
 
107
89
  const errorMessage =
108
90
  loadingMetaStatus === 'failed'
@@ -154,7 +136,7 @@ export function Home(props: PropTypes) {
154
136
  return (
155
137
  <Container>
156
138
  <Header
157
- title={title}
139
+ title="SWAP"
158
140
  suffix={
159
141
  <HeaderButtons
160
142
  onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
@@ -170,7 +152,13 @@ export function Home(props: PropTypes) {
170
152
  inputAmount={inputAmount}
171
153
  />
172
154
  <SwitchButtonContainer>
173
- <Button variant="ghost" onClick={swithFromAndTo}>
155
+ <Button
156
+ variant="ghost"
157
+ onClick={() => {
158
+ switchFromAndTo();
159
+ setCount((prev) => prev + 1);
160
+ }}
161
+ >
174
162
  <VerticalSwapIcon size={32} />
175
163
  {isRouterInContext && <SwithFromAndTo count={count} />}
176
164
  </Button>
@@ -4,10 +4,9 @@ import { navigationRoutes } from '../constants/navigationRoutes';
4
4
  import { useNavigateBack } from '../hooks/useNavigateBack';
5
5
  import { useMetaStore } from '../store/meta';
6
6
  import { useSettingsStore } from '../store/settings';
7
- import { Source } from '../types';
8
7
  import { removeDuplicateFrom } from '../utils/common';
9
8
  interface PropTypes {
10
- supportedSwappers: 'all' | Source[];
9
+ supportedSwappers?: string[];
11
10
  }
12
11
  export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
13
12
  const swappers = useMetaStore.use.meta().swappers;
@@ -47,12 +46,10 @@ export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
47
46
  <LiquiditySourcesSelector
48
47
  toggleAll={toggleAllLiquiditySources}
49
48
  list={
50
- supportedSwappers !== 'all'
49
+ supportedSwappers
51
50
  ? uniqueSwappersGroups.filter(
52
51
  (item) =>
53
- supportedSwappers.filter(
54
- (s) => s.title === item.title && s.type === item.type
55
- ).length > 0
52
+ supportedSwappers.filter((s) => s === item.title).length > 0
56
53
  )
57
54
  : uniqueSwappersGroups
58
55
  }
@@ -4,19 +4,19 @@ import { useBestRouteStore } from '../store/bestRoute';
4
4
  import { useMetaStore } from '../store/meta';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { navigationRoutes } from '../constants/navigationRoutes';
7
- import { BlockchainMeta } from 'rango-sdk';
8
7
 
9
8
  interface PropTypes {
10
9
  type: 'from' | 'to';
11
- supportedChains: 'all' | BlockchainMeta[];
10
+ supportedChains?: string[];
12
11
  }
13
12
 
14
13
  export function SelectChainPage(props: PropTypes) {
15
14
  const { type, supportedChains } = props;
16
- const blockchains =
17
- supportedChains === 'all'
18
- ? useMetaStore.use.meta().blockchains
19
- : supportedChains;
15
+ const blockchains = supportedChains
16
+ ? useMetaStore.use
17
+ .meta()
18
+ .blockchains.filter((chain) => supportedChains.includes(chain.name))
19
+ : useMetaStore.use.meta().blockchains;
20
20
  const loadingStatus = useMetaStore.use.loadingStatus();
21
21
  const fromChain = useBestRouteStore.use.fromChain();
22
22
  const toChain = useBestRouteStore.use.toChain();
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { TokenSelector } from '@rango-dev/ui';
3
3
  import { useBestRouteStore } from '../store/bestRoute';
4
- import { Token } from 'rango-sdk';
4
+ import { Asset, Token } from 'rango-sdk';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { navigationRoutes } from '../constants/navigationRoutes';
7
7
  import { tokensAreEqual } from '../utils/wallets';
@@ -9,7 +9,7 @@ import { useMetaStore } from '../store/meta';
9
9
 
10
10
  interface PropTypes {
11
11
  type: 'from' | 'to';
12
- supportedTokens: 'all' | Token[];
12
+ supportedTokens?: Asset[];
13
13
  }
14
14
 
15
15
  export interface TokenWithBalance extends Token {
@@ -25,23 +25,21 @@ export function SelectTokenPage(props: PropTypes) {
25
25
  const { type, supportedTokens } = props;
26
26
  const sourceTokens = useBestRouteStore.use.sourceTokens();
27
27
  const destinationTokens = useBestRouteStore.use.destinationTokens();
28
- const supportedSourceTokens =
29
- supportedTokens === 'all'
30
- ? sourceTokens
31
- : sourceTokens.filter((token) =>
32
- supportedTokens.some((supportedToken) =>
33
- tokensAreEqual(supportedToken, token)
34
- )
35
- );
28
+ const supportedSourceTokens = supportedTokens
29
+ ? sourceTokens.filter((token) =>
30
+ supportedTokens.some((supportedToken) =>
31
+ tokensAreEqual(supportedToken, token)
32
+ )
33
+ )
34
+ : sourceTokens;
36
35
 
37
- const supportedDestinationTokens =
38
- supportedTokens === 'all'
39
- ? destinationTokens
40
- : destinationTokens.filter((token) =>
41
- supportedTokens.some((supportedToken) =>
42
- tokensAreEqual(supportedToken, token)
43
- )
44
- );
36
+ const supportedDestinationTokens = supportedTokens
37
+ ? destinationTokens.filter((token) =>
38
+ supportedTokens.some((supportedToken) =>
39
+ tokensAreEqual(supportedToken, token)
40
+ )
41
+ )
42
+ : destinationTokens;
45
43
 
46
44
  const fromToken = useBestRouteStore.use.fromToken();
47
45
  const toToken = useBestRouteStore.use.toToken();
@@ -5,7 +5,6 @@ import { useMetaStore } from '../store/meta';
5
5
  import { useNavigate } from 'react-router-dom';
6
6
  import { navigationRoutes } from '../constants/navigationRoutes';
7
7
  import { removeDuplicateFrom } from '../utils/common';
8
- import { Source } from '../types';
9
8
  import {
10
9
  MAX_SLIPPAGE,
11
10
  MIN_SLIPPGAE,
@@ -13,7 +12,7 @@ import {
13
12
  } from '../constants/swapSettings';
14
13
  import { useNavigateBack } from '../hooks/useNavigateBack';
15
14
  interface PropTypes {
16
- supportedSwappers: 'all' | Source[];
15
+ supportedSwappers?: string[];
17
16
  }
18
17
  export function SettingsPage({ supportedSwappers }: PropTypes) {
19
18
  const slippage = useSettingsStore.use.slippage();
@@ -45,8 +44,6 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
45
44
  .find((s) => {
46
45
  if (s) {
47
46
  for (const type of s.types) {
48
- if (supportedSwappers !== 'all') {
49
- }
50
47
  uniqueSwappersGroups.push({
51
48
  title: s.swapperGroup,
52
49
  logo: s.logo,
@@ -56,23 +53,16 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
56
53
  }
57
54
  }
58
55
  });
59
- supportedSwappers !== 'all' &&
56
+ supportedSwappers &&
60
57
  uniqueSwappersGroups.filter(
61
- (item) =>
62
- supportedSwappers.filter(
63
- (s) => s.title === item.title && s.type === item.type
64
- ).length > 0
58
+ (item) => supportedSwappers.filter((s) => s === item.title).length > 0
65
59
  );
66
60
 
67
- const supportedUniqueSwappersGroups =
68
- supportedSwappers !== 'all'
69
- ? uniqueSwappersGroups.filter(
70
- (item) =>
71
- supportedSwappers.filter(
72
- (s) => s.title === item.title && s.type === item.type
73
- ).length > 0
74
- )
75
- : uniqueSwappersGroups;
61
+ const supportedUniqueSwappersGroups = supportedSwappers
62
+ ? uniqueSwappersGroups.filter(
63
+ (item) => supportedSwappers.filter((s) => s === item.title).length > 0
64
+ )
65
+ : uniqueSwappersGroups;
76
66
 
77
67
  return (
78
68
  <Settings
@@ -4,7 +4,7 @@ import useCopyToClipboard from '../hooks/useCopyToClipboard';
4
4
  import { useManager } from '@rango-dev/queue-manager-react';
5
5
  import { useNavigateBack } from '../hooks/useNavigateBack';
6
6
  import { getPendingSwaps } from '../utils/queue';
7
- import { SwapHistory } from '@rango-dev/ui';
7
+ import { SwapHistory, Spacer } from '@rango-dev/ui';
8
8
  import { useUiStore } from '../store/ui';
9
9
  import {
10
10
  cancelSwap,
@@ -26,7 +26,6 @@ import {
26
26
  shouldRetrySwap,
27
27
  } from '../utils/swap';
28
28
  import { TokenPreview } from '../components/TokenPreview';
29
- import { Spacer } from '@rango-dev/ui';
30
29
  import { numberToString } from '../utils/numbers';
31
30
  //@ts-ignore
32
31
  import { t } from 'i18next';
@@ -127,7 +126,7 @@ export function SwapDetailsPage() {
127
126
  <TokenPreview
128
127
  chain={{
129
128
  displayName: lastStep?.toBlockchain || '',
130
- // @ts-ignore
129
+ //@ts-ignore
131
130
  logo: lastStep?.toBlockchainLogo || '',
132
131
  }}
133
132
  token={{
@@ -141,7 +140,6 @@ export function SwapDetailsPage() {
141
140
  </>
142
141
  }
143
142
  //todo: move PendingSwap type to rango-types
144
- //@ts-ignore
145
143
  pendingSwap={swap}
146
144
  onCopy={handleCopy}
147
145
  isCopied={isCopied}
@@ -20,7 +20,7 @@ import { Spinner } from '@rango-dev/ui';
20
20
  import { LoadingFailedAlert } from '@rango-dev/ui';
21
21
 
22
22
  interface PropTypes {
23
- supportedWallets: 'all' | WalletType[];
23
+ supportedWallets?: WalletType[];
24
24
  multiWallets: boolean;
25
25
  }
26
26
 
@@ -50,7 +50,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
50
50
  const wallets = getlistWallet(
51
51
  state,
52
52
  getWalletInfo,
53
- supportedWallets === 'all' ? Object.values(WalletType) : supportedWallets
53
+ supportedWallets || Object.values(WalletType)
54
54
  );
55
55
  const walletsRef = useRef<WalletInfo[]>();
56
56
 
@@ -49,6 +49,7 @@ export interface RouteState {
49
49
  bestRoute: BestRouteResponse | null;
50
50
  setBestRoute: (bestRoute: BestRouteResponse | null) => void;
51
51
  retry: (pendingSwap: PendingSwap) => void;
52
+ switchFromAndTo: () => void;
52
53
  }
53
54
 
54
55
  export const useBestRouteStore = createSelectors(
@@ -146,7 +147,6 @@ export const useBestRouteStore = createSelectors(
146
147
  toToken: token,
147
148
  })),
148
149
  setInputAmount: (amount) => {
149
- console.log(amount, typeof amount);
150
150
  set((state) => ({
151
151
  inputAmount: amount,
152
152
  ...(!amount && {
@@ -224,6 +224,20 @@ export const useBestRouteStore = createSelectors(
224
224
  destinationTokens: sortedDestinationTokens,
225
225
  });
226
226
  },
227
+ switchFromAndTo: () =>
228
+ set((state) => ({
229
+ fromChain: state.toChain,
230
+ fromToken: state.toToken,
231
+ toChain: state.fromChain,
232
+ toToken: state.fromToken,
233
+ sourceTokens: state.destinationTokens,
234
+ destinationTokens: state.sourceTokens,
235
+ inputAmount: state.outputAmount?.toString() || '',
236
+ inputUsdValue: getUsdValue(
237
+ state.toToken,
238
+ state.outputAmount?.toString() || ''
239
+ ),
240
+ })),
227
241
  }))
228
242
  )
229
243
  );
@@ -235,7 +249,7 @@ const bestRoute = (
235
249
  let abortController: AbortController | null = null;
236
250
  const fetchBestRoute = () => {
237
251
  const { fromToken, toToken, inputAmount } = bestRouteStore.getState();
238
- const { slippage, customSlippage, disabledLiquiditySources } =
252
+ const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
239
253
  settingsStore.getState();
240
254
  if (!fromToken || !toToken || !inputAmount || inputAmount === '0') return;
241
255
  abortController?.abort();
@@ -249,7 +263,8 @@ const bestRoute = (
249
263
  [],
250
264
  disabledLiquiditySources,
251
265
  userSlippage,
252
- false
266
+ false,
267
+ affiliateRef
253
268
  );
254
269
  if (!bestRouteStore.getState().loading)
255
270
  bestRouteStore.setState({
@@ -282,7 +297,7 @@ const bestRoute = (
282
297
  const bestRouteParamsListener = () => {
283
298
  const { fromToken, toToken, inputAmount, inputUsdValue } =
284
299
  useBestRouteStore.getState();
285
- if (!inputAmount || inputAmount === '0') return;
300
+ if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0)) return;
286
301
 
287
302
  if (tokensAreEqual(fromToken, toToken))
288
303
  return bestRouteStore.setState({
@@ -312,8 +327,15 @@ const bestRoute = (
312
327
  }),
313
328
  bestRouteParamsListener,
314
329
  {
315
- equalityFn: (prevState, state) => {
316
- if (isRouteParametersChanged(prevState, state)) return false;
330
+ equalityFn: (prevState, currentState) => {
331
+ if (
332
+ isRouteParametersChanged({
333
+ store: 'bestRoute',
334
+ prevState,
335
+ currentState,
336
+ })
337
+ )
338
+ return false;
317
339
  else return true;
318
340
  },
319
341
  }
@@ -324,11 +346,19 @@ const bestRoute = (
324
346
  slippage: state.slippage,
325
347
  customSlippage: state.customSlippage,
326
348
  disabledLiquiditySources: state.disabledLiquiditySources,
349
+ infiniteApprove: state.infiniteApprove,
327
350
  }),
328
351
  bestRouteParamsListener,
329
352
  {
330
- equalityFn: (prevState, state) => {
331
- if (isRouteParametersChanged(prevState, state)) return false;
353
+ equalityFn: (prevState, currentState) => {
354
+ if (
355
+ isRouteParametersChanged({
356
+ store: 'settings',
357
+ prevState,
358
+ currentState,
359
+ })
360
+ )
361
+ return false;
332
362
  else return true;
333
363
  },
334
364
  }
@@ -13,12 +13,14 @@ export interface SettingsState {
13
13
  infiniteApprove: boolean;
14
14
  disabledLiquiditySources: string[];
15
15
  theme: Theme;
16
+ affiliateRef: string | null;
16
17
  setSlippage: (slippage: number) => void;
17
18
  setCustomSlippage: (customSlippage: number | null) => void;
18
19
  toggleInfiniteApprove: () => void;
19
20
  toggleLiquiditySource: (name: string) => void;
20
21
  setTheme: (theme: Theme) => void;
21
22
  toggleAllLiquiditySources: () => void;
23
+ setAffiliateRef: (affiliateRef: string | null) => void;
22
24
  }
23
25
 
24
26
  export const useSettingsStore = createSelectors(
@@ -28,6 +30,7 @@ export const useSettingsStore = createSelectors(
28
30
  slippage: DEFAULT_SLIPPAGE,
29
31
  customSlippage: null,
30
32
  infiniteApprove: false,
33
+ affiliateRef: null,
31
34
  disabledLiquiditySources: [],
32
35
  theme: 'auto',
33
36
  setSlippage: (slippage) =>
@@ -38,6 +41,10 @@ export const useSettingsStore = createSelectors(
38
41
  set(() => ({
39
42
  customSlippage: customSlippage,
40
43
  })),
44
+ setAffiliateRef: (affiliateRef) =>
45
+ set(() => ({
46
+ affiliateRef,
47
+ })),
41
48
  toggleAllLiquiditySources: () =>
42
49
  set((state) => {
43
50
  const { swappers } = useMetaStore.getState().meta;