@rango-dev/widget-embedded 0.17.1-next.17 → 0.17.1-next.19

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 (60) hide show
  1. package/dist/components/AppRouter.d.ts.map +1 -1
  2. package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
  3. package/dist/components/NotificationContent/NotificationContent.d.ts.map +1 -1
  4. package/dist/components/Quote/Quote.d.ts.map +1 -1
  5. package/dist/components/Quote/Quote.styles.d.ts +159 -0
  6. package/dist/components/Quote/Quote.styles.d.ts.map +1 -1
  7. package/dist/components/Quote/Quote.types.d.ts +0 -1
  8. package/dist/components/Quote/Quote.types.d.ts.map +1 -1
  9. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -1
  10. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -1
  11. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +1 -0
  12. package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -1
  13. package/dist/constants/errors.d.ts.map +1 -1
  14. package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -1
  15. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +316 -0
  16. package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -1
  17. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +3 -0
  18. package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -1
  19. package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -1
  20. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +6 -3
  21. package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -1
  22. package/dist/hooks/useSwapInput.d.ts.map +1 -1
  23. package/dist/index.js +1 -1
  24. package/dist/index.js.map +4 -4
  25. package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
  26. package/dist/pages/Home.d.ts.map +1 -1
  27. package/dist/types/swap.d.ts +3 -13
  28. package/dist/types/swap.d.ts.map +1 -1
  29. package/dist/utils/meta.d.ts +2 -1
  30. package/dist/utils/meta.d.ts.map +1 -1
  31. package/dist/utils/quote.d.ts.map +1 -1
  32. package/dist/utils/swap.d.ts +12 -4
  33. package/dist/utils/swap.d.ts.map +1 -1
  34. package/package.json +2 -2
  35. package/src/components/AppRouter.tsx +2 -27
  36. package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +9 -3
  37. package/src/components/NoResult/NoResult.helpers.ts +12 -12
  38. package/src/components/NotificationContent/NotificationContent.tsx +2 -1
  39. package/src/components/Quote/Quote.styles.ts +20 -0
  40. package/src/components/Quote/Quote.tsx +98 -30
  41. package/src/components/Quote/Quote.types.ts +0 -1
  42. package/src/components/Quote/QuoteSkeleton.tsx +1 -1
  43. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +11 -4
  44. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +13 -13
  45. package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +1 -0
  46. package/src/components/SwapDetails/SwapDetails.tsx +2 -2
  47. package/src/components/SwapDetailsModal/SwapDetailsModal.Cancel.tsx +2 -2
  48. package/src/constants/errors.ts +9 -5
  49. package/src/containers/QuoteInfo/QuoteInfo.styles.ts +17 -1
  50. package/src/containers/QuoteInfo/QuoteInfo.tsx +44 -43
  51. package/src/containers/QuoteInfo/QuoteInfo.types.ts +3 -0
  52. package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +15 -11
  53. package/src/hooks/useConfirmSwap/useConfirmSwap.ts +16 -17
  54. package/src/hooks/useSwapInput.ts +79 -25
  55. package/src/pages/ConfirmSwapPage.tsx +29 -6
  56. package/src/pages/Home.tsx +36 -45
  57. package/src/types/swap.ts +3 -12
  58. package/src/utils/meta.ts +8 -1
  59. package/src/utils/quote.ts +6 -6
  60. package/src/utils/swap.ts +44 -35
@@ -3,9 +3,7 @@ import type { PropTypes } from './QuoteWarningsAndErrors.types';
3
3
  import { i18n } from '@lingui/core';
4
4
  import { Alert, Button, InfoIcon } from '@rango-dev/ui';
5
5
  import React from 'react';
6
- import { useNavigate } from 'react-router-dom';
7
6
 
8
- import { navigationRoutes } from '../../constants/navigationRoutes';
9
7
  import { QuoteErrorType, QuoteWarningType } from '../../types';
10
8
  import { NoResult } from '../NoResult';
11
9
 
@@ -24,10 +22,9 @@ export function QuoteWarningsAndErrors(props: PropTypes) {
24
22
  onOpenWarningModal,
25
23
  onCloseWarningModal,
26
24
  onConfirmWarningModal,
25
+ onChangeSettings,
27
26
  } = props;
28
27
 
29
- const navigate = useNavigate();
30
-
31
28
  const warningModalHandlers = {
32
29
  open: showWarningModal,
33
30
  onClose: onCloseWarningModal,
@@ -58,20 +55,23 @@ export function QuoteWarningsAndErrors(props: PropTypes) {
58
55
  title={alertInfo.title}
59
56
  type={alertInfo.alertType}
60
57
  variant="alarm"
61
- action={
62
- alertInfo.action === 'show-info' ? (
58
+ {...(alertInfo.action === 'show-info' && {
59
+ action: (
63
60
  <Action onClick={onOpenWarningModal}>
64
61
  <InfoIcon size={12} color="gray" />
65
62
  </Action>
66
- ) : (
63
+ ),
64
+ })}
65
+ {...(alertInfo.action === 'change-settings' && {
66
+ action: (
67
67
  <Button
68
- size="xsmall"
69
- type={'error'}
70
- onClick={() => navigate(navigationRoutes.settings)}>
71
- {i18n.t('Change Settings')}
68
+ size="xxsmall"
69
+ type={alertInfo.alertType}
70
+ onClick={onChangeSettings}>
71
+ {i18n.t('Change')}
72
72
  </Button>
73
- )
74
- }
73
+ ),
74
+ })}
75
75
  />
76
76
  </Alerts>
77
77
  )}
@@ -9,6 +9,7 @@ export interface PropTypes {
9
9
  onOpenWarningModal: () => void;
10
10
  onCloseWarningModal: () => void;
11
11
  onConfirmWarningModal: () => void;
12
+ onChangeSettings: () => void;
12
13
  }
13
14
 
14
15
  type ModalPropTypesKeys = keyof Omit<PropTypes, 'extraSpace' | 'loading'>;
@@ -344,7 +344,7 @@ export function SwapDetails(props: SwapDetailsProps) {
344
344
  },
345
345
  }}
346
346
  percentageChange={numberToString(
347
- String(percentageChange),
347
+ percentageChange,
348
348
  PERCENTAGE_CHANGE_MIN_DECIMALS,
349
349
  PERCENTAGE_CHANGE_MAX_DECIMALS
350
350
  )}
@@ -402,7 +402,7 @@ export function SwapDetails(props: SwapDetailsProps) {
402
402
  )}
403
403
  usdValue={outputUsdValue}
404
404
  percentageChange={numberToString(
405
- String(percentageChange),
405
+ percentageChange,
406
406
  PERCENTAGE_CHANGE_MIN_DECIMALS,
407
407
  PERCENTAGE_CHANGE_MAX_DECIMALS
408
408
  )}
@@ -10,8 +10,8 @@ export const CancelContent = ({ onCancel, onClose }: CancelContentProps) => {
10
10
  <Divider size={20} />
11
11
  <MessageBox
12
12
  type="error"
13
- title={i18n.t('Transaction Cancel')}
14
- description={i18n.t('Are you sure you want to Cancel this swap?')}
13
+ title={i18n.t('Cancel Swap')}
14
+ description={i18n.t('Are you sure you want to cancel this swap?')}
15
15
  />
16
16
  <Divider size={32} />
17
17
  <Button
@@ -10,18 +10,22 @@ export const errorMessages = () => {
10
10
  liquiditySourcesError: {
11
11
  title: i18n.t('Please reset your liquidity sources.'),
12
12
  description: i18n.t(
13
- 'You have limited the liquidity sources and this might result in Rango finding no routes. Please consider resetting your liquidity sources'
13
+ 'You have limited the liquidity sources and this might result in Rango finding no routes. Please consider resetting your liquidity sources.'
14
14
  ),
15
15
  },
16
16
  noResultError: {
17
- title: i18n.t('No Routes Found'),
17
+ title: i18n.t('No Routes Found.'),
18
18
  description: i18n.t(
19
19
  "Reasons why Rango couldn't find a route: low liquidity on token, very low input amount or no routes available for the selected input/output token combination."
20
20
  ),
21
21
  },
22
22
  bridgeLimitErrors: {
23
- increaseAmount: i18n.t('Bridge Limit Error: Please increase your amount'),
24
- decreaseAmount: i18n.t('Bridge Limit Error: Please decrease your amount'),
23
+ increaseAmount: i18n.t(
24
+ 'Bridge Limit Error: Please increase your amount.'
25
+ ),
26
+ decreaseAmount: i18n.t(
27
+ 'Bridge Limit Error: Please decrease your amount.'
28
+ ),
25
29
  },
26
30
  highValueLossError: {
27
31
  impactTitle: i18n.t('High Price Impact'),
@@ -29,7 +33,7 @@ export const errorMessages = () => {
29
33
  description: i18n.t(
30
34
  'The price impact is significantly higher than the allowed amount. If you are sure, continue, otherwise, change the swap.'
31
35
  ),
32
- confirmMessage: i18n.t('Confirm High price impact'),
36
+ confirmMessage: i18n.t('Confirm high price impact'),
33
37
  },
34
38
  quoteUpdatedWithHighValueLoss: {
35
39
  title: i18n.t(
@@ -1,8 +1,24 @@
1
1
  import { styled } from '@rango-dev/ui';
2
2
 
3
+ export const PositionTopAlerts = styled('div', {
4
+ paddingBottom: '$10',
5
+ });
6
+
3
7
  export const QuoteContainer = styled('div', {
4
8
  width: '100%',
5
- paddingTop: '$2',
9
+ '& .position-top__skeleton': {
10
+ paddingTop: '$10',
11
+ },
12
+ });
13
+
14
+ export const SkeletonContainer = styled('div', {
15
+ variants: {
16
+ paddingTop: {
17
+ true: {
18
+ paddingTop: '$10',
19
+ },
20
+ },
21
+ },
6
22
  });
7
23
 
8
24
  export const FooterStepAlarm = styled('div', {
@@ -5,16 +5,14 @@ import React from 'react';
5
5
 
6
6
  import { Quote, QuoteSkeleton } from '../../components/Quote';
7
7
  import { QuoteWarningsAndErrors } from '../../components/QuoteWarningsAndErrors';
8
- import {
9
- TOKEN_AMOUNT_MAX_DECIMALS,
10
- TOKEN_AMOUNT_MIN_DECIMALS,
11
- USD_VALUE_MAX_DECIMALS,
12
- USD_VALUE_MIN_DECIMALS,
13
- } from '../../constants/routing';
14
8
  import { useQuoteStore } from '../../store/quote';
15
- import { numberToString } from '../../utils/numbers';
9
+ import { QuoteErrorType } from '../../types';
16
10
 
17
- import { QuoteContainer } from './QuoteInfo.styles';
11
+ import {
12
+ PositionTopAlerts,
13
+ QuoteContainer,
14
+ SkeletonContainer,
15
+ } from './QuoteInfo.styles';
18
16
 
19
17
  export function QuoteInfo(props: PropTypes) {
20
18
  const {
@@ -28,19 +26,46 @@ export function QuoteInfo(props: PropTypes) {
28
26
  onOpenWarningModal,
29
27
  onCloseWarningModal,
30
28
  onConfirmWarningModal,
29
+ onChangeSettings,
31
30
  expanded = false,
31
+ alertPosition = 'bottom',
32
32
  } = props;
33
33
  const { inputAmount, inputUsdValue, outputUsdValue, outputAmount } =
34
34
  useQuoteStore();
35
35
 
36
- const showQuote = quote && quote.result && !loading;
36
+ const noResult =
37
+ error &&
38
+ (error.type === QuoteErrorType.NO_RESULT ||
39
+ error.type === QuoteErrorType.REQUEST_FAILED);
40
+
41
+ const showQuote = !noResult && quote && quote.result && !loading;
42
+
43
+ const quoteWarningsAndErrors = (warning || error) && (
44
+ <QuoteWarningsAndErrors
45
+ warning={warning}
46
+ error={error}
47
+ loading={loading}
48
+ refetchQuote={refetchQuote}
49
+ showWarningModal={showWarningModal}
50
+ onOpenWarningModal={onOpenWarningModal}
51
+ onCloseWarningModal={onCloseWarningModal}
52
+ onConfirmWarningModal={onConfirmWarningModal}
53
+ onChangeSettings={onChangeSettings}
54
+ />
55
+ );
37
56
  return (
38
57
  <>
39
58
  {loading && (
40
59
  <QuoteContainer>
41
- <QuoteSkeleton type={type} expanded={expanded} />
60
+ <SkeletonContainer paddingTop={alertPosition === 'top'}>
61
+ <QuoteSkeleton type={type} expanded={expanded} />
62
+ </SkeletonContainer>
42
63
  </QuoteContainer>
43
64
  )}
65
+
66
+ {alertPosition === 'top' && (
67
+ <PositionTopAlerts>{quoteWarningsAndErrors}</PositionTopAlerts>
68
+ )}
44
69
  {showQuote ? (
45
70
  <QuoteContainer>
46
71
  <Quote
@@ -51,46 +76,22 @@ export function QuoteInfo(props: PropTypes) {
51
76
  expanded={expanded}
52
77
  recommended={true}
53
78
  input={{
54
- value: numberToString(
55
- inputAmount,
56
- TOKEN_AMOUNT_MIN_DECIMALS,
57
- TOKEN_AMOUNT_MAX_DECIMALS
58
- ),
59
- usdValue: numberToString(
60
- inputUsdValue,
61
- USD_VALUE_MIN_DECIMALS,
62
- USD_VALUE_MAX_DECIMALS
63
- ),
79
+ value: inputAmount,
80
+ usdValue: inputUsdValue?.toString() ?? '',
64
81
  }}
65
82
  output={{
66
- value: numberToString(
67
- outputAmount,
68
- TOKEN_AMOUNT_MIN_DECIMALS,
69
- TOKEN_AMOUNT_MAX_DECIMALS
70
- ),
71
- usdValue: numberToString(
72
- outputUsdValue,
73
- USD_VALUE_MIN_DECIMALS,
74
- USD_VALUE_MAX_DECIMALS
75
- ),
83
+ value: outputAmount?.toString() ?? '',
84
+ usdValue: outputUsdValue?.toString() ?? '',
76
85
  }}
77
86
  />
78
87
  </QuoteContainer>
79
88
  ) : null}
80
89
 
81
- {!warning && !error && <Divider size={16} />}
82
-
83
- {(warning || error) && (
84
- <QuoteWarningsAndErrors
85
- warning={warning}
86
- error={error}
87
- loading={loading}
88
- refetchQuote={refetchQuote}
89
- showWarningModal={showWarningModal}
90
- onOpenWarningModal={onOpenWarningModal}
91
- onCloseWarningModal={onCloseWarningModal}
92
- onConfirmWarningModal={onConfirmWarningModal}
93
- />
90
+ {alertPosition === 'bottom' && (
91
+ <>
92
+ {!warning && !error && <Divider size={16} />}
93
+ {quoteWarningsAndErrors}
94
+ </>
94
95
  )}
95
96
  </>
96
97
  );
@@ -8,10 +8,13 @@ export type PropTypes = {
8
8
  loading: boolean;
9
9
  error: QuoteError | null;
10
10
  warning: QuoteWarning | null;
11
+ autoScrollOnExpanding?: boolean;
11
12
  expanded?: boolean;
13
+ alertPosition?: 'top' | 'bottom';
12
14
  refetchQuote: () => void;
13
15
  showWarningModal: boolean;
14
16
  onOpenWarningModal: () => void;
15
17
  onCloseWarningModal: () => void;
16
18
  onConfirmWarningModal: () => void;
19
+ onChangeSettings: () => void;
17
20
  };
@@ -1,12 +1,13 @@
1
1
  import type { ConfirmSwapFetchResult } from './useConfirmSwap.types';
2
2
  import type { ConfirmSwapWarnings, Wallet } from '../../types';
3
- import type { BestRouteResponse, Token } from 'rango-sdk';
3
+ import type { BestRouteResponse, BlockchainMeta, Token } from 'rango-sdk';
4
4
 
5
5
  import { errorMessages } from '../../constants/errors';
6
6
  import { QuoteErrorType, QuoteUpdateType } from '../../types';
7
7
  import { numberToString } from '../../utils/numbers';
8
8
  import {
9
9
  generateQuoteWarnings,
10
+ getPriceImpact,
10
11
  isNumberOfSwapsChanged,
11
12
  isQuoteChanged,
12
13
  isQuoteInternalCoinsUpdated,
@@ -14,10 +15,9 @@ import {
14
15
  } from '../../utils/quote';
15
16
  import {
16
17
  checkSlippageErrors,
17
- getBalanceWarnings,
18
+ generateBalanceWarnings,
18
19
  getLimitErrorMessage,
19
20
  getMinRequiredSlippage,
20
- getPercentageChange,
21
21
  getQuoteOutputAmount,
22
22
  hasLimitError,
23
23
  isOutputAmountChangedALot,
@@ -67,17 +67,20 @@ export function throwErrorIfResponseIsNotValid(response: BestRouteResponse) {
67
67
  }
68
68
 
69
69
  export function generateWarnings(
70
- previousQuote: BestRouteResponse,
70
+ previousQuote: BestRouteResponse | undefined,
71
71
  currentQuote: BestRouteResponse,
72
72
  params: {
73
73
  fromToken: Token;
74
74
  toToken: Token;
75
- tokens: Token[];
75
+ meta: { blockchains: BlockchainMeta[]; tokens: Token[] };
76
76
  selectedWallets: Wallet[];
77
77
  userSlippage: number;
78
78
  }
79
79
  ): ConfirmSwapWarnings {
80
- const quoteChanged = isQuoteChanged(previousQuote, currentQuote);
80
+ let quoteChanged = false;
81
+ if (previousQuote) {
82
+ quoteChanged = isQuoteChanged(previousQuote, currentQuote);
83
+ }
81
84
  const output: ConfirmSwapWarnings = {
82
85
  quote: null,
83
86
  quoteUpdate: null,
@@ -87,7 +90,7 @@ export function generateWarnings(
87
90
  const quoteWarning = generateQuoteWarnings(currentQuote, {
88
91
  fromToken: params.fromToken,
89
92
  toToken: params.toToken,
90
- tokens: params.tokens,
93
+ tokens: params.meta.tokens,
91
94
  userSlippage: params.userSlippage,
92
95
  });
93
96
 
@@ -95,13 +98,13 @@ export function generateWarnings(
95
98
  output.quote = quoteWarning;
96
99
  }
97
100
 
98
- if (quoteChanged) {
101
+ if (previousQuote && quoteChanged) {
99
102
  if (isOutputAmountChangedALot(previousQuote, currentQuote)) {
100
103
  output.quoteUpdate = {
101
104
  type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
102
105
  newOutputAmount: numberToString(getQuoteOutputAmount(currentQuote)),
103
106
  percentageChange: numberToString(
104
- getPercentageChange(
107
+ getPriceImpact(
105
108
  getQuoteOutputAmount(previousQuote) ?? '',
106
109
  getQuoteOutputAmount(currentQuote) ?? ''
107
110
  ),
@@ -124,9 +127,10 @@ export function generateWarnings(
124
127
  }
125
128
  }
126
129
 
127
- const balanceWarnings = getBalanceWarnings(
130
+ const balanceWarnings = generateBalanceWarnings(
128
131
  currentQuote,
129
- params.selectedWallets
132
+ params.selectedWallets,
133
+ params.meta.blockchains
130
134
  );
131
135
  const enoughBalance = balanceWarnings.length === 0;
132
136
 
@@ -9,7 +9,6 @@ import { useAppStore } from '../../store/AppStore';
9
9
  import { useQuoteStore } from '../../store/quote';
10
10
  import { useSettingsStore } from '../../store/settings';
11
11
  import { useWalletsStore } from '../../store/wallets';
12
- import { QuoteErrorType } from '../../types';
13
12
  import { createQuoteRequestBody, getWalletsForNewSwap } from '../../utils/swap';
14
13
  import { useFetchQuote } from '../useFetchQuote';
15
14
 
@@ -25,7 +24,6 @@ export function useConfirmSwap(): ConfirmSwap {
25
24
  toToken,
26
25
  inputAmount,
27
26
  setQuote,
28
- resetQuote,
29
27
  quote: initialQuote,
30
28
  customDestination: customDestinationFromStore,
31
29
  setQuoteWarningsConfirmed,
@@ -43,6 +41,8 @@ export function useConfirmSwap(): ConfirmSwap {
43
41
  const blockchains = useAppStore().blockchains();
44
42
  const tokens = useAppStore().tokens();
45
43
  const { experimental } = useAppStore().config;
44
+ const { enableNewLiquiditySources } = useAppStore().config;
45
+
46
46
  const userSlippage = customSlippage || slippage;
47
47
 
48
48
  const { fetch: fetchQuote, cancelFetch, loading } = useFetchQuote();
@@ -54,7 +54,7 @@ export function useConfirmSwap(): ConfirmSwap {
54
54
  const customDestination =
55
55
  params?.customDestination ?? customDestinationFromStore;
56
56
 
57
- if (!fromToken || !toToken || !inputAmount || !initialQuote) {
57
+ if (!fromToken || !toToken || !inputAmount) {
58
58
  return {
59
59
  quote: null,
60
60
  swap: null,
@@ -69,12 +69,13 @@ export function useConfirmSwap(): ConfirmSwap {
69
69
  inputAmount,
70
70
  wallets: connectedWallets,
71
71
  selectedWallets,
72
+ excludeLiquiditySources: enableNewLiquiditySources,
72
73
  disabledLiquiditySources,
73
74
  slippage: userSlippage,
74
75
  affiliateRef,
75
76
  affiliatePercent,
76
77
  affiliateWallets,
77
- initialQuote: initialQuote,
78
+ initialQuote: initialQuote ?? undefined,
78
79
  destination: customDestination,
79
80
  });
80
81
  if (experimental?.routing) {
@@ -88,12 +89,6 @@ export function useConfirmSwap(): ConfirmSwap {
88
89
  setQuote(currentQuote);
89
90
  } catch (error: any) {
90
91
  const confirmSwapResult = handleQuoteErrors(error);
91
- if (
92
- confirmSwapResult.error?.type === QuoteErrorType.NO_RESULT ||
93
- confirmSwapResult.error?.type === QuoteErrorType.REQUEST_FAILED
94
- ) {
95
- resetQuote();
96
- }
97
92
  return confirmSwapResult;
98
93
  }
99
94
 
@@ -110,13 +105,17 @@ export function useConfirmSwap(): ConfirmSwap {
110
105
  { blockchains, tokens }
111
106
  );
112
107
 
113
- const confirmSwapWarnings = generateWarnings(initialQuote, currentQuote, {
114
- fromToken,
115
- toToken,
116
- tokens: tokens,
117
- selectedWallets,
118
- userSlippage,
119
- });
108
+ const confirmSwapWarnings = generateWarnings(
109
+ initialQuote ?? undefined,
110
+ currentQuote,
111
+ {
112
+ fromToken,
113
+ toToken,
114
+ meta: { blockchains, tokens },
115
+ selectedWallets,
116
+ userSlippage,
117
+ }
118
+ );
120
119
 
121
120
  if (confirmSwapWarnings.quoteUpdate) {
122
121
  setQuoteWarningsConfirmed(false);
@@ -1,6 +1,7 @@
1
1
  import type { QuoteError, QuoteWarning } from '../types';
2
+ import type { Token } from 'rango-sdk';
2
3
 
3
- import { useEffect, useRef, useState } from 'react';
4
+ import { useCallback, useEffect, useState } from 'react';
4
5
 
5
6
  import { useAppStore } from '../store/AppStore';
6
7
  import { useQuoteStore } from '../store/quote';
@@ -19,6 +20,12 @@ import {
19
20
  import { useFetchQuote } from './useFetchQuote';
20
21
 
21
22
  const DEBOUNCE_DELAY = 600;
23
+ const FIRST_INDEX = 0;
24
+
25
+ type FetchQuoteParams = Omit<
26
+ Parameters<typeof createQuoteRequestBody>[typeof FIRST_INDEX],
27
+ 'fromToken' | 'toToken'
28
+ > & { fromToken: Token | null; toToken: Token | null };
22
29
 
23
30
  type UseSwapInput = {
24
31
  fetch: () => void;
@@ -55,7 +62,6 @@ export function useSwapInput(): UseSwapInput {
55
62
  const [loading, setLoading] = useState(false);
56
63
  const [error, setError] = useState<QuoteError | null>(null);
57
64
  const [warning, setWarning] = useState<QuoteWarning | null>(null);
58
- const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
59
65
  const userSlippage = customSlippage ?? slippage;
60
66
  const hasTokensValue = !fromToken || !toToken;
61
67
  const shouldSkipRequest =
@@ -69,20 +75,32 @@ export function useSwapInput(): UseSwapInput {
69
75
  setWarning(null);
70
76
  };
71
77
 
72
- const fetch: UseSwapInput['fetch'] = () => {
78
+ const fetch = (params: FetchQuoteParams) => {
79
+ const {
80
+ fromToken,
81
+ toToken,
82
+ inputAmount,
83
+ liquiditySources,
84
+ excludeLiquiditySources,
85
+ disabledLiquiditySources,
86
+ slippage,
87
+ affiliateRef,
88
+ affiliatePercent,
89
+ affiliateWallets,
90
+ } = params;
73
91
  if (!loading) {
74
92
  resetState(true);
75
93
  }
76
- if (!shouldSkipRequest) {
94
+ if (!shouldSkipRequest && fromToken && toToken) {
77
95
  resetQuote();
78
96
  const requestBody = createQuoteRequestBody({
79
97
  fromToken,
80
98
  toToken,
81
99
  inputAmount,
82
100
  liquiditySources,
83
- excludeLiquiditySources: enableNewLiquiditySources,
101
+ excludeLiquiditySources,
84
102
  disabledLiquiditySources,
85
- slippage: userSlippage,
103
+ slippage,
86
104
  affiliateRef,
87
105
  affiliatePercent,
88
106
  affiliateWallets,
@@ -119,11 +137,14 @@ export function useSwapInput(): UseSwapInput {
119
137
  }
120
138
  };
121
139
 
122
- const debouncedFetch = debounce(() => {
123
- if (!shouldSkipRequest) {
124
- fetch();
125
- }
126
- }, DEBOUNCE_DELAY);
140
+ const debouncedFetch = useCallback(
141
+ debounce((params: FetchQuoteParams) => {
142
+ if (!shouldSkipRequest) {
143
+ fetch(params);
144
+ }
145
+ }, DEBOUNCE_DELAY),
146
+ [shouldSkipRequest]
147
+ );
127
148
 
128
149
  useEffect(() => {
129
150
  if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
@@ -136,20 +157,53 @@ export function useSwapInput(): UseSwapInput {
136
157
  }
137
158
  resetQuote();
138
159
  resetState(true);
139
- debouncedFetch();
140
- return cancelFetch;
141
- }, [inputAmount, shouldSkipRequest]);
142
-
143
- useEffect(() => {
144
- const disabledLiquiditySourceReset =
145
- !!prevDisabledLiquiditySources.current.length &&
146
- !disabledLiquiditySources.length;
147
- if (!shouldSkipRequest && disabledLiquiditySourceReset) {
148
- fetch();
149
- }
150
- prevDisabledLiquiditySources.current = disabledLiquiditySources;
160
+ debouncedFetch({
161
+ inputAmount,
162
+ fromToken,
163
+ toToken,
164
+ liquiditySources,
165
+ excludeLiquiditySources: enableNewLiquiditySources,
166
+ disabledLiquiditySources,
167
+ slippage: userSlippage,
168
+ affiliateRef,
169
+ affiliatePercent,
170
+ affiliateWallets,
171
+ });
151
172
  return cancelFetch;
152
- }, [disabledLiquiditySources.length]);
173
+ }, [
174
+ inputAmount,
175
+ fromToken?.symbol,
176
+ fromToken?.address,
177
+ fromToken?.blockchain,
178
+ toToken?.symbol,
179
+ toToken?.address,
180
+ toToken?.blockchain,
181
+ shouldSkipRequest,
182
+ liquiditySources?.length,
183
+ enableNewLiquiditySources,
184
+ disabledLiquiditySources.length,
185
+ userSlippage,
186
+ affiliateRef,
187
+ affiliatePercent,
188
+ JSON.stringify(affiliateWallets),
189
+ ]);
153
190
 
154
- return { fetch, loading, error, warning };
191
+ return {
192
+ fetch: () =>
193
+ fetch({
194
+ inputAmount,
195
+ fromToken,
196
+ toToken,
197
+ liquiditySources,
198
+ excludeLiquiditySources: enableNewLiquiditySources,
199
+ disabledLiquiditySources,
200
+ slippage: userSlippage,
201
+ affiliateRef,
202
+ affiliatePercent,
203
+ affiliateWallets,
204
+ }),
205
+ loading,
206
+ error,
207
+ warning,
208
+ };
155
209
  }