@rango-dev/widget-embedded 0.17.1-next.2 → 0.17.1-next.3
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.
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts +1 -3
- package/dist/components/ConfirmWalletsModal/ConfirmWallets.helpers.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts +4 -0
- package/dist/components/NoResult/NoResult.d.ts.map +1 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts +4 -0
- package/dist/components/NoResult/NoResult.helpers.d.ts.map +1 -0
- package/dist/components/{NoRoutes/NoRoutes.styles.d.ts → NoResult/NoResult.styles.d.ts} +1 -1
- package/dist/components/{NoRoutes/NoRoutes.styles.d.ts.map → NoResult/NoResult.styles.d.ts.map} +1 -1
- package/dist/components/{NoRoutes/NoRoutes.types.d.ts → NoResult/NoResult.types.d.ts} +3 -3
- package/dist/components/NoResult/NoResult.types.d.ts.map +1 -0
- package/dist/components/NoResult/index.d.ts +2 -0
- package/dist/components/NoResult/index.d.ts.map +1 -0
- package/dist/components/Quote/Quote.d.ts +4 -0
- package/dist/components/Quote/Quote.d.ts.map +1 -0
- package/dist/components/Quote/Quote.styles.d.ts +1429 -0
- package/dist/components/Quote/Quote.styles.d.ts.map +1 -0
- package/dist/components/Quote/Quote.types.d.ts +22 -0
- package/dist/components/Quote/Quote.types.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.d.ts +4 -0
- package/dist/components/Quote/QuoteSkeleton.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts +319 -0
- package/dist/components/Quote/QuoteSkeleton.styles.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSkeleton.types.d.ts +6 -0
- package/dist/components/Quote/QuoteSkeleton.types.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.d.ts +11 -0
- package/dist/components/Quote/QuoteSummary.d.ts.map +1 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts +158 -0
- package/dist/components/Quote/QuoteSummary.styles.d.ts.map +1 -0
- package/dist/components/Quote/index.d.ts +4 -0
- package/dist/components/Quote/index.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/HighValueLossWarningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteErrorsModalItem.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts +4 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts +9 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.d.ts.map +1 -0
- package/dist/components/{RouteErrors/RouteErrors.styles.d.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts} +1 -1
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts +22 -0
- package/dist/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/SlippageWariningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts +11 -0
- package/dist/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.d.ts.map +1 -0
- package/dist/components/QuoteWarningsAndErrors/index.d.ts +2 -0
- package/dist/components/QuoteWarningsAndErrors/index.d.ts.map +1 -0
- package/dist/components/SwapDetails/SwapDetails.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +4 -4
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/constants/messages.d.ts +1 -1
- package/dist/constants/warnings.d.ts +2 -2
- package/dist/constants/warnings.d.ts.map +1 -1
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts +4 -0
- package/dist/containers/QuoteInfo/QuoteInfo.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts +472 -0
- package/dist/containers/QuoteInfo/QuoteInfo.styles.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts +17 -0
- package/dist/containers/QuoteInfo/QuoteInfo.types.d.ts.map +1 -0
- package/dist/containers/QuoteInfo/index.d.ts +2 -0
- package/dist/containers/QuoteInfo/index.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/index.d.ts +2 -0
- package/dist/hooks/useConfirmSwap/index.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts +3 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts +16 -0
- package/dist/hooks/useConfirmSwap/useConfirmSwap.helpers.d.ts.map +1 -0
- package/dist/hooks/{useConfirmSwap.d.ts → useConfirmSwap/useConfirmSwap.types.d.ts} +5 -7
- package/dist/hooks/useConfirmSwap/useConfirmSwap.types.d.ts.map +1 -0
- package/dist/hooks/{useFetchBestRoute.d.ts → useFetchQuote.d.ts} +3 -3
- package/dist/hooks/useFetchQuote.d.ts.map +1 -0
- package/dist/hooks/usePrepareBlockchainList/usePrepareBlockchainList.helpers.d.ts +2 -2
- package/dist/hooks/useSwapInput.d.ts +4 -2
- package/dist/hooks/useSwapInput.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/store/app.d.ts +2 -2
- package/dist/store/{bestRoute.d.ts → quote.d.ts} +25 -20
- package/dist/store/quote.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/quote.d.ts +82 -0
- package/dist/types/quote.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/{routing.d.ts → quote.d.ts} +16 -12
- package/dist/utils/quote.d.ts.map +1 -0
- package/dist/utils/settings.d.ts +1 -1
- package/dist/utils/swap.d.ts +22 -20
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +3 -3
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +2 -64
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +23 -26
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +1 -1
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.styles.ts +3 -3
- package/src/components/LoadingSwapDetails/LoadingSwapDetails.tsx +6 -6
- package/src/components/{NoRoutes/NoRoutes.helper.ts → NoResult/NoResult.helpers.ts} +16 -9
- package/src/components/{NoRoutes/NoRoutes.styles.ts → NoResult/NoResult.styles.ts} +2 -0
- package/src/components/{NoRoutes/NoRoutes.tsx → NoResult/NoResult.tsx} +7 -12
- package/src/components/{NoRoutes/NoRoutes.types.ts → NoResult/NoResult.types.ts} +3 -2
- package/src/components/NoResult/index.ts +1 -0
- package/src/components/Quote/Quote.styles.ts +212 -0
- package/src/components/Quote/Quote.tsx +347 -0
- package/src/components/Quote/Quote.types.ts +16 -0
- package/src/components/Quote/QuoteSkeleton.styles.ts +110 -0
- package/src/components/Quote/QuoteSkeleton.tsx +108 -0
- package/src/components/Quote/QuoteSkeleton.types.ts +5 -0
- package/src/components/Quote/QuoteSummary.styles.ts +15 -0
- package/src/components/Quote/QuoteSummary.tsx +46 -0
- package/src/components/Quote/index.ts +3 -0
- package/src/components/QuoteWarningsAndErrors/HighValueLossWarningModal.tsx +107 -0
- package/src/components/{RouteErrors/RouteErrorsModalItem.tsx → QuoteWarningsAndErrors/QuoteErrorsModalItem.tsx} +3 -3
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.helpers.ts +67 -0
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.tsx +103 -0
- package/src/components/QuoteWarningsAndErrors/QuoteWarningsAndErrors.types.ts +24 -0
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +77 -0
- package/src/components/QuoteWarningsAndErrors/UnknownPriceWarningModal.tsx +38 -0
- package/src/components/QuoteWarningsAndErrors/index.ts +1 -0
- package/src/components/SwapDetails/SwapDetails.Placeholder.tsx +1 -1
- package/src/components/SwapDetails/SwapDetails.tsx +13 -16
- package/src/components/SwitchFromAndTo.tsx +2 -2
- package/src/components/UpdateUrl.tsx +12 -12
- package/src/constants/errors.ts +8 -10
- package/src/constants/messages.ts +1 -1
- package/src/constants/warnings.ts +7 -7
- package/src/containers/QuoteInfo/QuoteInfo.styles.ts +15 -0
- package/src/containers/QuoteInfo/QuoteInfo.tsx +97 -0
- package/src/containers/QuoteInfo/QuoteInfo.types.ts +17 -0
- package/src/containers/QuoteInfo/index.ts +1 -0
- package/src/hooks/useConfirmSwap/index.ts +1 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.helpers.ts +168 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +136 -0
- package/src/hooks/useConfirmSwap/useConfirmSwap.types.ts +19 -0
- package/src/hooks/{useFetchBestRoute.ts → useFetchQuote.ts} +3 -3
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useSwapInput.ts +57 -23
- package/src/hooks/useSyncStoresWithConfig.ts +2 -2
- package/src/pages/ConfirmSwapPage.tsx +58 -227
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +52 -241
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +1 -1
- package/src/pages/SelectBlockchainPage.tsx +3 -3
- package/src/pages/SelectSwapItemsPage.tsx +2 -2
- package/src/pages/SettingsPage.tsx +1 -1
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +1 -1
- package/src/store/{bestRoute.ts → quote.ts} +42 -38
- package/src/types/index.ts +1 -1
- package/src/types/quote.ts +107 -0
- package/src/utils/numbers.ts +1 -1
- package/src/utils/quote.ts +338 -0
- package/src/utils/swap.ts +99 -69
- package/src/utils/wallets.ts +2 -2
- package/dist/components/NoRoutes/NoRoutes.d.ts +0 -4
- package/dist/components/NoRoutes/NoRoutes.d.ts.map +0 -1
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts +0 -3
- package/dist/components/NoRoutes/NoRoutes.helper.d.ts.map +0 -1
- package/dist/components/NoRoutes/NoRoutes.types.d.ts.map +0 -1
- package/dist/components/NoRoutes/index.d.ts +0 -2
- package/dist/components/NoRoutes/index.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrors.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.styles.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrors.types.d.ts +0 -24
- package/dist/components/RouteErrors/RouteErrors.types.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrorsModal.d.ts.map +0 -1
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts +0 -4
- package/dist/components/RouteErrors/RouteErrorsModalItem.d.ts.map +0 -1
- package/dist/components/RouteErrors/index.d.ts +0 -2
- package/dist/components/RouteErrors/index.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +0 -1
- package/dist/hooks/useFetchBestRoute.d.ts.map +0 -1
- package/dist/store/bestRoute.d.ts.map +0 -1
- package/dist/types/routing.d.ts +0 -65
- package/dist/types/routing.d.ts.map +0 -1
- package/dist/utils/routing.d.ts.map +0 -1
- package/src/components/NoRoutes/index.ts +0 -1
- package/src/components/RouteErrors/RouteErrors.tsx +0 -79
- package/src/components/RouteErrors/RouteErrors.types.ts +0 -29
- package/src/components/RouteErrors/RouteErrorsModal.tsx +0 -129
- package/src/components/RouteErrors/index.ts +0 -1
- package/src/hooks/useConfirmSwap.ts +0 -303
- package/src/types/routing.ts +0 -77
- package/src/utils/routing.ts +0 -321
- /package/src/components/{RouteErrors/RouteErrors.styles.ts → QuoteWarningsAndErrors/QuoteWarningsAndErrors.styles.ts} +0 -0
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type BigNumber from 'bignumber.js';
|
|
2
|
-
|
|
3
|
-
export interface PropTypes {
|
|
4
|
-
openModal: boolean;
|
|
5
|
-
onToggle: (open: boolean) => void;
|
|
6
|
-
totalFeeInUsd: BigNumber | null;
|
|
7
|
-
outputUsdValue: BigNumber | null;
|
|
8
|
-
inputUsdValue: BigNumber | null;
|
|
9
|
-
percentageChange: BigNumber | null;
|
|
10
|
-
highValueLoss: boolean;
|
|
11
|
-
priceImpactCanNotBeComputed: boolean;
|
|
12
|
-
loading: boolean;
|
|
13
|
-
extraSpace: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
type ModalPropTypesKeys = keyof Omit<
|
|
17
|
-
PropTypes,
|
|
18
|
-
'priceImpactCanNotBeComputed' | 'openModal' | 'extraSpace' | 'loading'
|
|
19
|
-
>;
|
|
20
|
-
|
|
21
|
-
export type ModalPropTypes = Pick<PropTypes, ModalPropTypesKeys> & {
|
|
22
|
-
open: boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export interface ModalContentData {
|
|
26
|
-
title: string;
|
|
27
|
-
value: string;
|
|
28
|
-
valueColor?: string;
|
|
29
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import type { ModalPropTypes } from './RouteErrors.types';
|
|
2
|
-
|
|
3
|
-
import { i18n } from '@lingui/core';
|
|
4
|
-
import {
|
|
5
|
-
Button,
|
|
6
|
-
Divider,
|
|
7
|
-
MessageBox,
|
|
8
|
-
Modal,
|
|
9
|
-
Typography,
|
|
10
|
-
WarningIcon,
|
|
11
|
-
} from '@rango-dev/ui';
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import { useNavigate } from 'react-router-dom';
|
|
14
|
-
|
|
15
|
-
import { errorMessages } from '../../constants/errors';
|
|
16
|
-
import { navigationRoutes } from '../../constants/navigationRoutes';
|
|
17
|
-
import {
|
|
18
|
-
GAS_FEE_MAX_DECIMALS,
|
|
19
|
-
GAS_FEE_MIN_DECIMALS,
|
|
20
|
-
HIGHT_PRICE_IMPACT,
|
|
21
|
-
PERCENTAGE_CHANGE_MAX_DECIMALS,
|
|
22
|
-
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
23
|
-
USD_VALUE_MAX_DECIMALS,
|
|
24
|
-
USD_VALUE_MIN_DECIMALS,
|
|
25
|
-
} from '../../constants/routing';
|
|
26
|
-
import { numberToString } from '../../utils/numbers';
|
|
27
|
-
|
|
28
|
-
import { Flex } from './RouteErrors.styles';
|
|
29
|
-
import { RouteErrorsModalItem } from './RouteErrorsModalItem';
|
|
30
|
-
|
|
31
|
-
export function RouteErrorsModal(props: ModalPropTypes) {
|
|
32
|
-
const {
|
|
33
|
-
highValueLoss,
|
|
34
|
-
open,
|
|
35
|
-
onToggle,
|
|
36
|
-
percentageChange,
|
|
37
|
-
inputUsdValue,
|
|
38
|
-
outputUsdValue,
|
|
39
|
-
totalFeeInUsd,
|
|
40
|
-
} = props;
|
|
41
|
-
const navigate = useNavigate();
|
|
42
|
-
const type =
|
|
43
|
-
highValueLoss && !!percentageChange?.lt(HIGHT_PRICE_IMPACT)
|
|
44
|
-
? 'error'
|
|
45
|
-
: 'warning';
|
|
46
|
-
const highValueLossData = [
|
|
47
|
-
{
|
|
48
|
-
title: i18n.t('Swapping'),
|
|
49
|
-
value: numberToString(
|
|
50
|
-
inputUsdValue,
|
|
51
|
-
USD_VALUE_MIN_DECIMALS,
|
|
52
|
-
USD_VALUE_MAX_DECIMALS
|
|
53
|
-
),
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
title: i18n.t('Gas cost'),
|
|
57
|
-
value: numberToString(
|
|
58
|
-
totalFeeInUsd,
|
|
59
|
-
GAS_FEE_MIN_DECIMALS,
|
|
60
|
-
GAS_FEE_MAX_DECIMALS
|
|
61
|
-
),
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
title: i18n.t('Receiving'),
|
|
65
|
-
value: numberToString(
|
|
66
|
-
outputUsdValue,
|
|
67
|
-
USD_VALUE_MIN_DECIMALS,
|
|
68
|
-
USD_VALUE_MAX_DECIMALS
|
|
69
|
-
),
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
title: i18n.t('Price impact'),
|
|
73
|
-
value: numberToString(
|
|
74
|
-
percentageChange,
|
|
75
|
-
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
76
|
-
PERCENTAGE_CHANGE_MAX_DECIMALS
|
|
77
|
-
),
|
|
78
|
-
valueColor: `${type}500`,
|
|
79
|
-
},
|
|
80
|
-
];
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<Modal
|
|
84
|
-
open={open}
|
|
85
|
-
onClose={() => onToggle(false)}
|
|
86
|
-
container={document.getElementById('swap-box') || document.body}>
|
|
87
|
-
{highValueLoss ? (
|
|
88
|
-
<MessageBox
|
|
89
|
-
type={type}
|
|
90
|
-
title={errorMessages().highValueLossError.impactTitle}
|
|
91
|
-
description={errorMessages().highValueLossError.description}
|
|
92
|
-
/>
|
|
93
|
-
) : (
|
|
94
|
-
<MessageBox
|
|
95
|
-
type={type}
|
|
96
|
-
title={errorMessages().unknownPriceError.impactTitle}
|
|
97
|
-
description={errorMessages().unknownPriceError.description}
|
|
98
|
-
/>
|
|
99
|
-
)}
|
|
100
|
-
{highValueLoss && (
|
|
101
|
-
<Flex>
|
|
102
|
-
<Divider size={20} />
|
|
103
|
-
<Typography size="small" variant="title">
|
|
104
|
-
{i18n.t('Details')}
|
|
105
|
-
</Typography>
|
|
106
|
-
<Flex>
|
|
107
|
-
{highValueLossData.map((item, index) => {
|
|
108
|
-
const key = index;
|
|
109
|
-
return <RouteErrorsModalItem key={key} {...item} />;
|
|
110
|
-
})}
|
|
111
|
-
</Flex>
|
|
112
|
-
</Flex>
|
|
113
|
-
)}
|
|
114
|
-
<Divider size={32} />
|
|
115
|
-
<Button
|
|
116
|
-
type="primary"
|
|
117
|
-
size="large"
|
|
118
|
-
prefix={<WarningIcon />}
|
|
119
|
-
fullWidth
|
|
120
|
-
onClick={() => {
|
|
121
|
-
navigate(navigationRoutes.confirmSwap);
|
|
122
|
-
}}>
|
|
123
|
-
{highValueLoss
|
|
124
|
-
? errorMessages().highValueLossError.confirmMessage
|
|
125
|
-
: errorMessages().unknownPriceError.confirmMessage}
|
|
126
|
-
</Button>
|
|
127
|
-
</Modal>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RouteErrors } from './RouteErrors';
|
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import type {
|
|
3
|
-
ConfirmSwapError,
|
|
4
|
-
ConfirmSwapWarnings,
|
|
5
|
-
PendingSwapSettings,
|
|
6
|
-
Wallet,
|
|
7
|
-
} from '../types';
|
|
8
|
-
import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
9
|
-
import type { BestRouteResponse } from 'rango-sdk';
|
|
10
|
-
|
|
11
|
-
import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
12
|
-
import BigNumber from 'bignumber.js';
|
|
13
|
-
import { useEffect } from 'react';
|
|
14
|
-
|
|
15
|
-
import { errorMessages } from '../constants/errors';
|
|
16
|
-
import { HIGH_SLIPPAGE } from '../constants/swapSettings';
|
|
17
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
18
|
-
import { useMetaStore } from '../store/meta';
|
|
19
|
-
import { useSettingsStore } from '../store/settings';
|
|
20
|
-
import { useWalletsStore } from '../store/wallets';
|
|
21
|
-
import {
|
|
22
|
-
ConfirmSwapErrorTypes,
|
|
23
|
-
RouteWarningType,
|
|
24
|
-
SlippageWarningType,
|
|
25
|
-
} from '../types';
|
|
26
|
-
import { numberToString } from '../utils/numbers';
|
|
27
|
-
import {
|
|
28
|
-
isNumberOfSwapsChanged,
|
|
29
|
-
isRouteChanged,
|
|
30
|
-
isRouteInternalCoinsUpdated,
|
|
31
|
-
isRouteSwappersUpdated,
|
|
32
|
-
} from '../utils/routing';
|
|
33
|
-
import {
|
|
34
|
-
createBestRouteRequestBody,
|
|
35
|
-
getBalanceWarnings,
|
|
36
|
-
getMinRequiredSlippage,
|
|
37
|
-
getOutputRatio,
|
|
38
|
-
getPercentageChange,
|
|
39
|
-
getRouteOutputAmount,
|
|
40
|
-
getWalletsForNewSwap,
|
|
41
|
-
hasProperSlippage,
|
|
42
|
-
isOutputAmountChangedALot,
|
|
43
|
-
outputRatioHasWarning,
|
|
44
|
-
} from '../utils/swap';
|
|
45
|
-
|
|
46
|
-
import { useFetchBestRoute } from './useFetchBestRoute';
|
|
47
|
-
|
|
48
|
-
export type ConfirmSwapFetchResult = {
|
|
49
|
-
swap: PendingSwap | null;
|
|
50
|
-
error: ConfirmSwapError | null;
|
|
51
|
-
warnings: ConfirmSwapWarnings | null;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type ConfirmSwap = {
|
|
55
|
-
loading: boolean;
|
|
56
|
-
fetch: (params: Params) => Promise<ConfirmSwapFetchResult>;
|
|
57
|
-
cancelFetch: () => void;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
type Params = {
|
|
61
|
-
selectedWallets: Wallet[];
|
|
62
|
-
customDestination?: string;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* A request can be successful but in body of the response, it can be some case which is considered as failed.
|
|
67
|
-
*/
|
|
68
|
-
function throwErrorIfResponseIsNotValid(
|
|
69
|
-
response: BestRouteResponse,
|
|
70
|
-
params: { inputUsdValue: BigNumber | null; outputUsdValue: number | null }
|
|
71
|
-
) {
|
|
72
|
-
if (!response.result) {
|
|
73
|
-
throw new Error(errorMessages().noRoutesError.title, {
|
|
74
|
-
cause: {
|
|
75
|
-
type: ConfirmSwapErrorTypes.NO_ROUTE,
|
|
76
|
-
diagnosisMessage: response.diagnosisMessages?.[0],
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const newRouteOutputUsdValue = new BigNumber(
|
|
82
|
-
response.result?.outputAmount || '0'
|
|
83
|
-
).multipliedBy(params.outputUsdValue || 0);
|
|
84
|
-
|
|
85
|
-
const outputRatio = getOutputRatio(
|
|
86
|
-
params.inputUsdValue,
|
|
87
|
-
newRouteOutputUsdValue
|
|
88
|
-
);
|
|
89
|
-
const highValueLoss = outputRatioHasWarning(
|
|
90
|
-
params.inputUsdValue,
|
|
91
|
-
outputRatio
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
if (highValueLoss) {
|
|
95
|
-
throw new Error('High value loss for route', {
|
|
96
|
-
cause: {
|
|
97
|
-
type: ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return response;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function generateWarnings(
|
|
106
|
-
previousRoute: BestRouteResponse,
|
|
107
|
-
currentRoute: BestRouteResponse,
|
|
108
|
-
params: {
|
|
109
|
-
selectedWallets: Wallet[];
|
|
110
|
-
userSlippage: number;
|
|
111
|
-
}
|
|
112
|
-
): ConfirmSwapWarnings {
|
|
113
|
-
const routeChanged = isRouteChanged(previousRoute, currentRoute);
|
|
114
|
-
const output: ConfirmSwapWarnings = {
|
|
115
|
-
balance: null,
|
|
116
|
-
route: null,
|
|
117
|
-
slippage: null,
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (routeChanged) {
|
|
121
|
-
if (isOutputAmountChangedALot(previousRoute, currentRoute)) {
|
|
122
|
-
output.route = {
|
|
123
|
-
type: RouteWarningType.ROUTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
124
|
-
newOutputAmount: numberToString(getRouteOutputAmount(currentRoute)),
|
|
125
|
-
percentageChange: numberToString(
|
|
126
|
-
getPercentageChange(
|
|
127
|
-
getRouteOutputAmount(previousRoute),
|
|
128
|
-
getRouteOutputAmount(currentRoute)
|
|
129
|
-
),
|
|
130
|
-
null,
|
|
131
|
-
2
|
|
132
|
-
),
|
|
133
|
-
};
|
|
134
|
-
} else if (isNumberOfSwapsChanged(previousRoute, currentRoute)) {
|
|
135
|
-
output.route = {
|
|
136
|
-
type: RouteWarningType.ROUTE_UPDATED,
|
|
137
|
-
};
|
|
138
|
-
} else if (isRouteSwappersUpdated(previousRoute, currentRoute)) {
|
|
139
|
-
output.route = {
|
|
140
|
-
type: RouteWarningType.ROUTE_SWAPPERS_UPDATED,
|
|
141
|
-
};
|
|
142
|
-
} else if (isRouteInternalCoinsUpdated(previousRoute, currentRoute)) {
|
|
143
|
-
output.route = {
|
|
144
|
-
type: RouteWarningType.ROUTE_COINS_UPDATED,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const balanceWarnings = getBalanceWarnings(
|
|
150
|
-
currentRoute,
|
|
151
|
-
params.selectedWallets
|
|
152
|
-
);
|
|
153
|
-
const enoughBalance = balanceWarnings.length === 0;
|
|
154
|
-
|
|
155
|
-
if (!enoughBalance) {
|
|
156
|
-
output.balance = {
|
|
157
|
-
messages: balanceWarnings,
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const minRequiredSlippage = getMinRequiredSlippage(previousRoute);
|
|
162
|
-
const highSlippage = params.userSlippage > HIGH_SLIPPAGE;
|
|
163
|
-
|
|
164
|
-
if (!hasProperSlippage(params.userSlippage.toString(), minRequiredSlippage)) {
|
|
165
|
-
output.slippage = {
|
|
166
|
-
type: SlippageWarningType.INSUFFICIENT_SLIPPAGE,
|
|
167
|
-
slippage: minRequiredSlippage,
|
|
168
|
-
};
|
|
169
|
-
} else if (highSlippage) {
|
|
170
|
-
output.slippage = {
|
|
171
|
-
type: SlippageWarningType.HIGH_SLIPPAGE,
|
|
172
|
-
slippage: params.userSlippage.toString(),
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return output;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function useConfirmSwap(): ConfirmSwap {
|
|
180
|
-
const {
|
|
181
|
-
fromToken,
|
|
182
|
-
toToken,
|
|
183
|
-
inputAmount,
|
|
184
|
-
inputUsdValue,
|
|
185
|
-
setRoute,
|
|
186
|
-
bestRoute: initialRoute,
|
|
187
|
-
customDestination: customDestinationFromStore,
|
|
188
|
-
} = useBestRouteStore();
|
|
189
|
-
|
|
190
|
-
const {
|
|
191
|
-
slippage,
|
|
192
|
-
customSlippage,
|
|
193
|
-
affiliatePercent,
|
|
194
|
-
affiliateRef,
|
|
195
|
-
affiliateWallets,
|
|
196
|
-
disabledLiquiditySources,
|
|
197
|
-
} = useSettingsStore();
|
|
198
|
-
const { connectedWallets } = useWalletsStore();
|
|
199
|
-
|
|
200
|
-
const { meta } = useMetaStore();
|
|
201
|
-
|
|
202
|
-
const userSlippage = customSlippage || slippage;
|
|
203
|
-
|
|
204
|
-
const { fetch: fetchBestRoute, cancelFetch, loading } = useFetchBestRoute();
|
|
205
|
-
|
|
206
|
-
useEffect(() => cancelFetch, []);
|
|
207
|
-
|
|
208
|
-
const fetch: ConfirmSwap['fetch'] = async (params: Params) => {
|
|
209
|
-
const selectedWallets = params.selectedWallets;
|
|
210
|
-
const customDestination =
|
|
211
|
-
params?.customDestination ?? customDestinationFromStore;
|
|
212
|
-
|
|
213
|
-
if (!fromToken || !toToken || !inputAmount || !initialRoute) {
|
|
214
|
-
return {
|
|
215
|
-
route: null,
|
|
216
|
-
swap: null,
|
|
217
|
-
error: null,
|
|
218
|
-
warnings: null,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const requestBody = createBestRouteRequestBody({
|
|
223
|
-
fromToken,
|
|
224
|
-
toToken,
|
|
225
|
-
inputAmount,
|
|
226
|
-
wallets: connectedWallets,
|
|
227
|
-
selectedWallets,
|
|
228
|
-
disabledLiquiditySources,
|
|
229
|
-
slippage: userSlippage,
|
|
230
|
-
affiliateRef,
|
|
231
|
-
affiliatePercent,
|
|
232
|
-
affiliateWallets,
|
|
233
|
-
initialRoute,
|
|
234
|
-
destination: customDestination,
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
let currentRoute: BestRouteResponse;
|
|
238
|
-
try {
|
|
239
|
-
currentRoute = await fetchBestRoute(requestBody).then((response) =>
|
|
240
|
-
throwErrorIfResponseIsNotValid(response, {
|
|
241
|
-
outputUsdValue: toToken.usdPrice,
|
|
242
|
-
inputUsdValue,
|
|
243
|
-
})
|
|
244
|
-
);
|
|
245
|
-
setRoute(currentRoute);
|
|
246
|
-
} catch (error: any) {
|
|
247
|
-
if (error?.code === 'ERR_CANCELED') {
|
|
248
|
-
return {
|
|
249
|
-
swap: null,
|
|
250
|
-
error: {
|
|
251
|
-
type: ConfirmSwapErrorTypes.REQUEST_CANCELED,
|
|
252
|
-
},
|
|
253
|
-
warnings: null,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (error.cause) {
|
|
258
|
-
return {
|
|
259
|
-
swap: null,
|
|
260
|
-
error: error.cause,
|
|
261
|
-
warnings: null,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return {
|
|
266
|
-
swap: null,
|
|
267
|
-
error: {
|
|
268
|
-
type: ConfirmSwapErrorTypes.REQUEST_FAILED,
|
|
269
|
-
},
|
|
270
|
-
warnings: null,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const swapSettings: PendingSwapSettings = {
|
|
275
|
-
slippage: userSlippage.toString(),
|
|
276
|
-
disabledSwappersGroups: disabledLiquiditySources,
|
|
277
|
-
};
|
|
278
|
-
const swap = calculatePendingSwap(
|
|
279
|
-
inputAmount.toString(),
|
|
280
|
-
currentRoute,
|
|
281
|
-
getWalletsForNewSwap(selectedWallets),
|
|
282
|
-
swapSettings,
|
|
283
|
-
false,
|
|
284
|
-
meta
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
return {
|
|
288
|
-
route: currentRoute,
|
|
289
|
-
swap,
|
|
290
|
-
error: null,
|
|
291
|
-
warnings: generateWarnings(initialRoute, currentRoute, {
|
|
292
|
-
selectedWallets,
|
|
293
|
-
userSlippage,
|
|
294
|
-
}),
|
|
295
|
-
};
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
loading,
|
|
300
|
-
fetch,
|
|
301
|
-
cancelFetch,
|
|
302
|
-
};
|
|
303
|
-
}
|
package/src/types/routing.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/prefer-enum-initializers */
|
|
2
|
-
import type { RouteState } from '../store/bestRoute';
|
|
3
|
-
import type { SettingsState } from '../store/settings';
|
|
4
|
-
|
|
5
|
-
interface BestRouteStoreParams {
|
|
6
|
-
fromBlockchain?: RouteState['fromBlockchain'];
|
|
7
|
-
toBlockchain?: RouteState['toBlockchain'];
|
|
8
|
-
fromToken?: RouteState['fromToken'];
|
|
9
|
-
toToken?: RouteState['toToken'];
|
|
10
|
-
inputAmount?: RouteState['inputAmount'];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface SettingsStoreParams {
|
|
14
|
-
slippage?: SettingsState['slippage'];
|
|
15
|
-
customSlippage?: SettingsState['customSlippage'];
|
|
16
|
-
disabledLiquiditySources?: SettingsState['disabledLiquiditySources'];
|
|
17
|
-
infiniteApprove?: SettingsState['infiniteApprove'];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type BestRouteEqualityParams =
|
|
21
|
-
| {
|
|
22
|
-
store: 'bestRoute';
|
|
23
|
-
prevState: BestRouteStoreParams;
|
|
24
|
-
currentState: BestRouteStoreParams;
|
|
25
|
-
}
|
|
26
|
-
| {
|
|
27
|
-
store: 'settings';
|
|
28
|
-
prevState: SettingsStoreParams;
|
|
29
|
-
currentState: SettingsStoreParams;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export enum ConfirmSwapErrorTypes {
|
|
33
|
-
NO_ROUTE,
|
|
34
|
-
ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS,
|
|
35
|
-
REQUEST_FAILED,
|
|
36
|
-
REQUEST_CANCELED,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type ConfirmSwapError =
|
|
40
|
-
| {
|
|
41
|
-
type: ConfirmSwapErrorTypes.NO_ROUTE;
|
|
42
|
-
diagnosisMessage?: string;
|
|
43
|
-
}
|
|
44
|
-
| {
|
|
45
|
-
type: Exclude<ConfirmSwapErrorTypes, ConfirmSwapErrorTypes.NO_ROUTE>;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export enum RouteWarningType {
|
|
49
|
-
ROUTE_UPDATED,
|
|
50
|
-
ROUTE_SWAPPERS_UPDATED,
|
|
51
|
-
ROUTE_COINS_UPDATED,
|
|
52
|
-
ROUTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export type RouteWarning =
|
|
56
|
-
| {
|
|
57
|
-
type: RouteWarningType.ROUTE_AND_OUTPUT_AMOUNT_UPDATED;
|
|
58
|
-
newOutputAmount: string;
|
|
59
|
-
percentageChange: string;
|
|
60
|
-
}
|
|
61
|
-
| {
|
|
62
|
-
type: Exclude<
|
|
63
|
-
RouteWarningType,
|
|
64
|
-
RouteWarningType.ROUTE_AND_OUTPUT_AMOUNT_UPDATED
|
|
65
|
-
>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export enum SlippageWarningType {
|
|
69
|
-
INSUFFICIENT_SLIPPAGE,
|
|
70
|
-
HIGH_SLIPPAGE,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export type ConfirmSwapWarnings = {
|
|
74
|
-
route: RouteWarning | null;
|
|
75
|
-
balance: { messages: string[] } | null;
|
|
76
|
-
slippage: { type: SlippageWarningType; slippage: string | null } | null;
|
|
77
|
-
};
|