@rango-dev/widget-embedded 0.17.1-next.0 → 0.17.1-next.10
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/QueueManager.d.ts +5 -2
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +0 -2
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +1 -6
- package/dist/components/AppRoutes.d.ts.map +1 -1
- 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/ConfirmWallets.styles.d.ts +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts +1 -3
- package/dist/components/ConfirmWalletsModal/ConfirmWalletsModal.types.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.d.ts.map +1 -1
- package/dist/components/ConfirmWalletsModal/WalletList.type.d.ts +1 -4
- package/dist/components/ConfirmWalletsModal/WalletList.type.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/NotificationContent/NotificationContent.d.ts.map +1 -1
- 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/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts +1 -6
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/WidgetEvents.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/searchParams.d.ts +2 -1
- package/dist/constants/searchParams.d.ts.map +1 -1
- package/dist/constants/warnings.d.ts +2 -2
- package/dist/constants/warnings.d.ts.map +1 -1
- package/dist/containers/App/App.d.ts +3 -0
- package/dist/containers/App/App.d.ts.map +1 -0
- package/dist/containers/App/App.styles.d.ts +158 -0
- package/dist/containers/App/App.styles.d.ts.map +1 -0
- package/dist/containers/App/index.d.ts +2 -0
- package/dist/containers/App/index.d.ts.map +1 -0
- 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/containers/Wallets/Wallets.d.ts +6 -0
- package/dist/containers/Wallets/Wallets.d.ts.map +1 -0
- package/dist/containers/Wallets/Wallets.types.d.ts +11 -0
- package/dist/containers/Wallets/Wallets.types.d.ts.map +1 -0
- package/dist/containers/Wallets/index.d.ts +2 -0
- package/dist/containers/Wallets/index.d.ts.map +1 -0
- package/dist/containers/Widget/Widget.d.ts +5 -0
- package/dist/containers/Widget/Widget.d.ts.map +1 -0
- package/dist/containers/Widget/Widget.types.d.ts +5 -0
- package/dist/containers/Widget/Widget.types.d.ts.map +1 -0
- package/dist/containers/Widget/index.d.ts +3 -0
- package/dist/containers/Widget/index.d.ts.map +1 -0
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts +6 -0
- package/dist/containers/WidgetInfo/WidgetInfo.d.ts.map +1 -0
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts +5 -0
- package/dist/containers/WidgetInfo/WidgetInfo.types.d.ts.map +1 -0
- package/dist/containers/WidgetInfo/index.d.ts +2 -0
- package/dist/containers/WidgetInfo/index.d.ts.map +1 -0
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts +5 -0
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -0
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts +7 -0
- package/dist/containers/WidgetProvider/WidgetProvider.types.d.ts.map +1 -0
- package/dist/containers/WidgetProvider/index.d.ts +2 -0
- package/dist/containers/WidgetProvider/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/useForceAutoConnect.d.ts +2 -0
- package/dist/hooks/useForceAutoConnect.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/hooks/useSyncStoresWithConfig.d.ts +1 -2
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useWalletList.d.ts.map +1 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts +1 -6
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts +1 -2
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectBlockchainPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +1 -6
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +1 -8
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/AppStore.d.ts +11 -0
- package/dist/store/AppStore.d.ts.map +1 -0
- package/dist/store/app.d.ts +5 -23
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/{bestRoute.d.ts → quote.d.ts} +39 -27
- package/dist/store/quote.d.ts.map +1 -0
- package/dist/store/settings.d.ts +3 -2
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/slices/config.d.ts +3 -2
- package/dist/store/slices/config.d.ts.map +1 -1
- package/dist/store/slices/data.d.ts +3 -0
- package/dist/store/slices/data.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +5 -4
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +5 -5
- package/dist/types/config.d.ts.map +1 -1
- 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 +3 -2
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +25 -22
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -2
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/QueueManager.tsx +17 -17
- package/src/components/AppRouter.tsx +6 -5
- package/src/components/AppRoutes.tsx +6 -39
- package/src/components/BlockchainList/BlockchainList.tsx +4 -4
- package/src/components/BlockchainsSection/BlockchainsSection.tsx +7 -7
- package/src/components/ConfirmWalletsModal/ConfirmWallets.helpers.ts +2 -64
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.tsx +28 -40
- package/src/components/ConfirmWalletsModal/ConfirmWalletsModal.types.ts +1 -3
- package/src/components/ConfirmWalletsModal/WalletList.tsx +6 -5
- package/src/components/ConfirmWalletsModal/WalletList.type.ts +1 -4
- 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} +10 -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/NotificationContent/NotificationContent.tsx +3 -2
- package/src/components/Quote/Quote.styles.ts +212 -0
- package/src/components/Quote/Quote.tsx +345 -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 +18 -22
- package/src/components/SwitchFromAndTo.tsx +2 -2
- package/src/components/TokenList/TokenList.tsx +5 -6
- package/src/components/UpdateUrl.tsx +36 -26
- package/src/components/WidgetEvents.tsx +4 -2
- package/src/constants/errors.ts +8 -10
- package/src/constants/messages.ts +1 -1
- package/src/constants/searchParams.ts +1 -0
- package/src/constants/warnings.ts +7 -7
- package/src/containers/App/App.styles.ts +18 -0
- package/src/containers/App/App.tsx +65 -0
- package/src/containers/App/index.ts +1 -0
- 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/{Wallets.tsx → containers/Wallets/Wallets.tsx} +40 -32
- package/src/containers/Wallets/Wallets.types.ts +12 -0
- package/src/containers/Wallets/index.ts +1 -0
- package/src/containers/Widget/Widget.tsx +19 -0
- package/src/containers/Widget/Widget.types.ts +5 -0
- package/src/containers/Widget/index.ts +2 -0
- package/src/containers/WidgetInfo/WidgetInfo.tsx +36 -0
- package/src/containers/WidgetInfo/WidgetInfo.types.ts +5 -0
- package/src/containers/WidgetInfo/index.ts +1 -0
- package/src/containers/WidgetProvider/WidgetProvider.tsx +19 -0
- package/src/containers/WidgetProvider/WidgetProvider.types.ts +7 -0
- package/src/containers/WidgetProvider/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/useForceAutoConnect.ts +27 -0
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useSwapInput.ts +58 -23
- package/src/hooks/useSyncStoresWithConfig.ts +22 -19
- package/src/hooks/useWalletList.ts +3 -5
- package/src/index.ts +10 -3
- package/src/pages/ConfirmSwapPage.tsx +58 -235
- package/src/pages/HistoryPage.tsx +1 -1
- package/src/pages/Home.tsx +58 -247
- package/src/pages/LanguagePage.tsx +1 -1
- package/src/pages/LiquiditySourcePage.tsx +23 -32
- package/src/pages/SelectBlockchainPage.tsx +6 -7
- package/src/pages/SelectSwapItemsPage.tsx +5 -5
- package/src/pages/SettingsPage.tsx +9 -13
- package/src/pages/SwapDetailsPage.tsx +3 -3
- package/src/pages/ThemePage.tsx +1 -1
- package/src/pages/WalletsPage.tsx +5 -12
- package/src/store/AppStore.tsx +35 -0
- package/src/store/app.ts +18 -6
- package/src/store/{bestRoute.ts → quote.ts} +68 -60
- package/src/store/settings.ts +7 -4
- package/src/store/slices/config.ts +25 -15
- package/src/store/slices/data.ts +64 -29
- package/src/store/wallets.ts +11 -8
- package/src/types/config.ts +5 -5
- 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/settings.ts +8 -7
- package/src/utils/swap.ts +113 -85
- package/src/utils/wallets.ts +29 -17
- package/dist/Wallets.d.ts +0 -17
- package/dist/Wallets.d.ts.map +0 -1
- package/dist/Widget.d.ts +0 -9
- package/dist/Widget.d.ts.map +0 -1
- 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/store/meta.d.ts +0 -23
- package/dist/store/meta.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/Widget.tsx +0 -119
- 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/store/meta.ts +0 -39
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WidgetInfo, useWidget } from './WidgetInfo';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PropTypes } from './WidgetProvider.types';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
import React from 'react';
|
|
5
|
+
|
|
6
|
+
import QueueManager from '../../QueueManager';
|
|
7
|
+
import { WidgetWallets } from '../Wallets';
|
|
8
|
+
import { WidgetInfo } from '../WidgetInfo';
|
|
9
|
+
|
|
10
|
+
export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
11
|
+
const { onUpdateState, config } = props;
|
|
12
|
+
return (
|
|
13
|
+
<WidgetWallets config={config} onUpdateState={onUpdateState}>
|
|
14
|
+
<QueueManager apiKey={config.apiKey}>
|
|
15
|
+
<WidgetInfo>{props.children}</WidgetInfo>
|
|
16
|
+
</QueueManager>
|
|
17
|
+
</WidgetWallets>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WidgetProvider } from './WidgetProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useConfirmSwap } from './useConfirmSwap';
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { ConfirmSwapFetchResult } from './useConfirmSwap.types';
|
|
2
|
+
import type { ConfirmSwapWarnings, Wallet } from '../../types';
|
|
3
|
+
import type { BestRouteResponse, Token } from 'rango-sdk';
|
|
4
|
+
|
|
5
|
+
import { errorMessages } from '../../constants/errors';
|
|
6
|
+
import { QuoteErrorType, QuoteUpdateType } from '../../types';
|
|
7
|
+
import { numberToString } from '../../utils/numbers';
|
|
8
|
+
import {
|
|
9
|
+
generateQuoteWarnings,
|
|
10
|
+
isNumberOfSwapsChanged,
|
|
11
|
+
isQuoteChanged,
|
|
12
|
+
isQuoteInternalCoinsUpdated,
|
|
13
|
+
isQuoteSwappersUpdated,
|
|
14
|
+
} from '../../utils/quote';
|
|
15
|
+
import {
|
|
16
|
+
checkSlippageErrors,
|
|
17
|
+
getBalanceWarnings,
|
|
18
|
+
getLimitErrorMessage,
|
|
19
|
+
getMinRequiredSlippage,
|
|
20
|
+
getPercentageChange,
|
|
21
|
+
getQuoteOutputAmount,
|
|
22
|
+
hasLimitError,
|
|
23
|
+
isOutputAmountChangedALot,
|
|
24
|
+
} from '../../utils/swap';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A request can be successful but in body of the response, it can be some case which is considered as failed.
|
|
28
|
+
*/
|
|
29
|
+
export function throwErrorIfResponseIsNotValid(response: BestRouteResponse) {
|
|
30
|
+
if (!response.result) {
|
|
31
|
+
throw new Error(errorMessages().noResultError.title, {
|
|
32
|
+
cause: {
|
|
33
|
+
type: QuoteErrorType.NO_RESULT,
|
|
34
|
+
diagnosisMessage: response.diagnosisMessages?.[0],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const limitError = hasLimitError(response);
|
|
39
|
+
if (limitError) {
|
|
40
|
+
const { swap, recommendation, fromAmountRangeError } =
|
|
41
|
+
getLimitErrorMessage(response);
|
|
42
|
+
|
|
43
|
+
throw new Error('bridge limit error', {
|
|
44
|
+
cause: {
|
|
45
|
+
type: QuoteErrorType.BRIDGE_LIMIT,
|
|
46
|
+
swap: swap,
|
|
47
|
+
recommendation,
|
|
48
|
+
fromAmountRangeError,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const recommendedSlippages = checkSlippageErrors(response);
|
|
54
|
+
|
|
55
|
+
if (recommendedSlippages) {
|
|
56
|
+
const minRequiredSlippage = getMinRequiredSlippage(response);
|
|
57
|
+
throw new Error('', {
|
|
58
|
+
cause: {
|
|
59
|
+
type: QuoteErrorType.INSUFFICIENT_SLIPPAGE,
|
|
60
|
+
recommendedSlippages,
|
|
61
|
+
minRequiredSlippage,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function generateWarnings(
|
|
70
|
+
previousQuote: BestRouteResponse,
|
|
71
|
+
currentQuote: BestRouteResponse,
|
|
72
|
+
params: {
|
|
73
|
+
fromToken: Token;
|
|
74
|
+
toToken: Token;
|
|
75
|
+
tokens: Token[];
|
|
76
|
+
selectedWallets: Wallet[];
|
|
77
|
+
userSlippage: number;
|
|
78
|
+
}
|
|
79
|
+
): ConfirmSwapWarnings {
|
|
80
|
+
const quoteChanged = isQuoteChanged(previousQuote, currentQuote);
|
|
81
|
+
const output: ConfirmSwapWarnings = {
|
|
82
|
+
quote: null,
|
|
83
|
+
quoteUpdate: null,
|
|
84
|
+
balance: null,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const quoteWarning = generateQuoteWarnings(currentQuote, {
|
|
88
|
+
fromToken: params.fromToken,
|
|
89
|
+
toToken: params.toToken,
|
|
90
|
+
tokens: params.tokens,
|
|
91
|
+
userSlippage: params.userSlippage,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (quoteWarning) {
|
|
95
|
+
output.quote = quoteWarning;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (quoteChanged) {
|
|
99
|
+
if (isOutputAmountChangedALot(previousQuote, currentQuote)) {
|
|
100
|
+
output.quoteUpdate = {
|
|
101
|
+
type: QuoteUpdateType.QUOTE_AND_OUTPUT_AMOUNT_UPDATED,
|
|
102
|
+
newOutputAmount: numberToString(getQuoteOutputAmount(currentQuote)),
|
|
103
|
+
percentageChange: numberToString(
|
|
104
|
+
getPercentageChange(
|
|
105
|
+
getQuoteOutputAmount(previousQuote) ?? '',
|
|
106
|
+
getQuoteOutputAmount(currentQuote) ?? ''
|
|
107
|
+
),
|
|
108
|
+
null,
|
|
109
|
+
2
|
|
110
|
+
),
|
|
111
|
+
};
|
|
112
|
+
} else if (isNumberOfSwapsChanged(previousQuote, currentQuote)) {
|
|
113
|
+
output.quoteUpdate = {
|
|
114
|
+
type: QuoteUpdateType.QUOTE_UPDATED,
|
|
115
|
+
};
|
|
116
|
+
} else if (isQuoteSwappersUpdated(previousQuote, currentQuote)) {
|
|
117
|
+
output.quoteUpdate = {
|
|
118
|
+
type: QuoteUpdateType.QUOTE_SWAPPERS_UPDATED,
|
|
119
|
+
};
|
|
120
|
+
} else if (isQuoteInternalCoinsUpdated(previousQuote, currentQuote)) {
|
|
121
|
+
output.quoteUpdate = {
|
|
122
|
+
type: QuoteUpdateType.QUOTE_COINS_UPDATED,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const balanceWarnings = getBalanceWarnings(
|
|
128
|
+
currentQuote,
|
|
129
|
+
params.selectedWallets
|
|
130
|
+
);
|
|
131
|
+
const enoughBalance = balanceWarnings.length === 0;
|
|
132
|
+
|
|
133
|
+
if (!enoughBalance) {
|
|
134
|
+
output.balance = {
|
|
135
|
+
messages: balanceWarnings,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return output;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function handleQuoteErrors(error: any): ConfirmSwapFetchResult {
|
|
143
|
+
if (error?.code === 'ERR_CANCELED') {
|
|
144
|
+
return {
|
|
145
|
+
swap: null,
|
|
146
|
+
error: {
|
|
147
|
+
type: QuoteErrorType.REQUEST_CANCELED,
|
|
148
|
+
},
|
|
149
|
+
warnings: null,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (error.cause) {
|
|
154
|
+
return {
|
|
155
|
+
swap: null,
|
|
156
|
+
error: error.cause,
|
|
157
|
+
warnings: null,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
swap: null,
|
|
163
|
+
error: {
|
|
164
|
+
type: QuoteErrorType.REQUEST_FAILED,
|
|
165
|
+
},
|
|
166
|
+
warnings: null,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { ConfirmSwap, Params } from './useConfirmSwap.types';
|
|
2
|
+
import type { PendingSwapSettings } from '../../types';
|
|
3
|
+
import type { BestRouteResponse } from 'rango-sdk';
|
|
4
|
+
|
|
5
|
+
import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
6
|
+
import { useEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useAppStore } from '../../store/AppStore';
|
|
9
|
+
import { useQuoteStore } from '../../store/quote';
|
|
10
|
+
import { useSettingsStore } from '../../store/settings';
|
|
11
|
+
import { useWalletsStore } from '../../store/wallets';
|
|
12
|
+
import { QuoteErrorType } from '../../types';
|
|
13
|
+
import { createQuoteRequestBody, getWalletsForNewSwap } from '../../utils/swap';
|
|
14
|
+
import { useFetchQuote } from '../useFetchQuote';
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
generateWarnings,
|
|
18
|
+
handleQuoteErrors,
|
|
19
|
+
throwErrorIfResponseIsNotValid,
|
|
20
|
+
} from './useConfirmSwap.helpers';
|
|
21
|
+
|
|
22
|
+
export function useConfirmSwap(): ConfirmSwap {
|
|
23
|
+
const {
|
|
24
|
+
fromToken,
|
|
25
|
+
toToken,
|
|
26
|
+
inputAmount,
|
|
27
|
+
setQuote,
|
|
28
|
+
resetQuote,
|
|
29
|
+
quote: initialQuote,
|
|
30
|
+
customDestination: customDestinationFromStore,
|
|
31
|
+
setQuoteWarningsConfirmed,
|
|
32
|
+
} = useQuoteStore();
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
slippage,
|
|
36
|
+
customSlippage,
|
|
37
|
+
affiliatePercent,
|
|
38
|
+
affiliateRef,
|
|
39
|
+
affiliateWallets,
|
|
40
|
+
disabledLiquiditySources,
|
|
41
|
+
} = useSettingsStore();
|
|
42
|
+
const { connectedWallets } = useWalletsStore();
|
|
43
|
+
const blockchains = useAppStore().blockchains();
|
|
44
|
+
const tokens = useAppStore().tokens();
|
|
45
|
+
|
|
46
|
+
const userSlippage = customSlippage || slippage;
|
|
47
|
+
|
|
48
|
+
const { fetch: fetchQuote, cancelFetch, loading } = useFetchQuote();
|
|
49
|
+
|
|
50
|
+
useEffect(() => cancelFetch, []);
|
|
51
|
+
|
|
52
|
+
const fetch: ConfirmSwap['fetch'] = async (params: Params) => {
|
|
53
|
+
const selectedWallets = params.selectedWallets;
|
|
54
|
+
const customDestination =
|
|
55
|
+
params?.customDestination ?? customDestinationFromStore;
|
|
56
|
+
|
|
57
|
+
if (!fromToken || !toToken || !inputAmount || !initialQuote) {
|
|
58
|
+
return {
|
|
59
|
+
quote: null,
|
|
60
|
+
swap: null,
|
|
61
|
+
error: null,
|
|
62
|
+
warnings: null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const requestBody = createQuoteRequestBody({
|
|
67
|
+
fromToken,
|
|
68
|
+
toToken,
|
|
69
|
+
inputAmount,
|
|
70
|
+
wallets: connectedWallets,
|
|
71
|
+
selectedWallets,
|
|
72
|
+
disabledLiquiditySources,
|
|
73
|
+
slippage: userSlippage,
|
|
74
|
+
affiliateRef,
|
|
75
|
+
affiliatePercent,
|
|
76
|
+
affiliateWallets,
|
|
77
|
+
initialQuote: initialQuote,
|
|
78
|
+
destination: customDestination,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
let currentQuote: BestRouteResponse;
|
|
82
|
+
try {
|
|
83
|
+
currentQuote = await fetchQuote(requestBody).then((response) =>
|
|
84
|
+
throwErrorIfResponseIsNotValid(response)
|
|
85
|
+
);
|
|
86
|
+
setQuote(currentQuote);
|
|
87
|
+
} catch (error: any) {
|
|
88
|
+
const confirmSwapResult = handleQuoteErrors(error);
|
|
89
|
+
if (
|
|
90
|
+
confirmSwapResult.error?.type === QuoteErrorType.NO_RESULT ||
|
|
91
|
+
confirmSwapResult.error?.type === QuoteErrorType.REQUEST_FAILED
|
|
92
|
+
) {
|
|
93
|
+
resetQuote();
|
|
94
|
+
}
|
|
95
|
+
return confirmSwapResult;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const swapSettings: PendingSwapSettings = {
|
|
99
|
+
slippage: userSlippage.toString(),
|
|
100
|
+
disabledSwappersGroups: disabledLiquiditySources,
|
|
101
|
+
};
|
|
102
|
+
const swap = calculatePendingSwap(
|
|
103
|
+
inputAmount.toString(),
|
|
104
|
+
currentQuote,
|
|
105
|
+
getWalletsForNewSwap(selectedWallets),
|
|
106
|
+
swapSettings,
|
|
107
|
+
false,
|
|
108
|
+
{ blockchains, tokens }
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const confirmSwapWarnings = generateWarnings(initialQuote, currentQuote, {
|
|
112
|
+
fromToken,
|
|
113
|
+
toToken,
|
|
114
|
+
tokens: tokens,
|
|
115
|
+
selectedWallets,
|
|
116
|
+
userSlippage,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
if (confirmSwapWarnings.quoteUpdate) {
|
|
120
|
+
setQuoteWarningsConfirmed(false);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
quote: currentQuote,
|
|
125
|
+
swap,
|
|
126
|
+
error: null,
|
|
127
|
+
warnings: confirmSwapWarnings,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
loading,
|
|
133
|
+
fetch,
|
|
134
|
+
cancelFetch,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConfirmSwapWarnings, QuoteError, Wallet } from '../../types';
|
|
2
|
+
import type { PendingSwap } from 'rango-types/lib';
|
|
3
|
+
|
|
4
|
+
export type ConfirmSwapFetchResult = {
|
|
5
|
+
swap: PendingSwap | null;
|
|
6
|
+
error: QuoteError | null;
|
|
7
|
+
warnings: ConfirmSwapWarnings | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type ConfirmSwap = {
|
|
11
|
+
loading: boolean;
|
|
12
|
+
fetch: (params: Params) => Promise<ConfirmSwapFetchResult>;
|
|
13
|
+
cancelFetch: () => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type Params = {
|
|
17
|
+
selectedWallets: Wallet[];
|
|
18
|
+
customDestination?: string;
|
|
19
|
+
};
|
|
@@ -4,18 +4,18 @@ import { useRef, useState } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { httpService } from '../services/httpService';
|
|
6
6
|
|
|
7
|
-
interface
|
|
7
|
+
interface UseFetchQuote {
|
|
8
8
|
fetch: (requestBody: BestRouteRequest) => Promise<BestRouteResponse>;
|
|
9
9
|
cancelFetch: () => void;
|
|
10
10
|
loading: boolean;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function
|
|
13
|
+
export function useFetchQuote(): UseFetchQuote {
|
|
14
14
|
const [loading, setLoading] = useState(false);
|
|
15
15
|
const abortController = useRef<AbortController | null>(null);
|
|
16
16
|
const cancel = () => abortController.current?.abort();
|
|
17
17
|
|
|
18
|
-
const fetch:
|
|
18
|
+
const fetch: UseFetchQuote['fetch'] = async (requestBody) => {
|
|
19
19
|
cancel();
|
|
20
20
|
abortController.current = new AbortController();
|
|
21
21
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useWallets } from '@rango-dev/wallets-react';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
|
|
4
|
+
import { SearchParams } from '../constants/searchParams';
|
|
5
|
+
import { useAppStore } from '../store/AppStore';
|
|
6
|
+
|
|
7
|
+
export function useForceAutoConnect(): void {
|
|
8
|
+
const { connect, state } = useWallets();
|
|
9
|
+
const initiated = useRef<{ [key: string]: boolean }>({});
|
|
10
|
+
const { fetchStatus } = useAppStore();
|
|
11
|
+
const walletType =
|
|
12
|
+
new URLSearchParams(location.search).get(SearchParams.AUTO_CONNECT) || '';
|
|
13
|
+
const walletState = state(walletType);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const shouldTryConnect =
|
|
17
|
+
fetchStatus === 'success' &&
|
|
18
|
+
walletType &&
|
|
19
|
+
walletState.installed &&
|
|
20
|
+
!walletState.connecting &&
|
|
21
|
+
!walletState.connected;
|
|
22
|
+
if (shouldTryConnect && !initiated.current[walletType]) {
|
|
23
|
+
initiated.current[walletType] = true;
|
|
24
|
+
void connect(walletType);
|
|
25
|
+
}
|
|
26
|
+
}, [walletState, fetchStatus]);
|
|
27
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
2
2
|
|
|
3
3
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
4
|
-
import {
|
|
4
|
+
import { useQuoteStore } from '../store/quote';
|
|
5
5
|
|
|
6
6
|
export function useNavigateBack() {
|
|
7
7
|
const isRouterInContext = useInRouterContext();
|
|
8
8
|
const navigate = useNavigate();
|
|
9
|
-
const
|
|
9
|
+
const quoteWalletsConfirmed = useQuoteStore.use.quoteWalletsConfirmed();
|
|
10
10
|
|
|
11
11
|
navigationRoutes;
|
|
12
12
|
|
|
@@ -26,7 +26,7 @@ export function useNavigateBack() {
|
|
|
26
26
|
[navigationRoutes.settings, navigationRoutes.wallets].includes(
|
|
27
27
|
currentRoute
|
|
28
28
|
) &&
|
|
29
|
-
|
|
29
|
+
quoteWalletsConfirmed
|
|
30
30
|
) {
|
|
31
31
|
return navigate('/' + navigationRoutes.confirmSwap, { replace: true });
|
|
32
32
|
}
|
|
@@ -1,37 +1,48 @@
|
|
|
1
|
+
import type { QuoteError, QuoteWarning } from '../types';
|
|
2
|
+
|
|
1
3
|
import { useEffect, useRef, useState } from 'react';
|
|
2
4
|
|
|
3
|
-
import {
|
|
5
|
+
import { useAppStore } from '../store/AppStore';
|
|
6
|
+
import { useQuoteStore } from '../store/quote';
|
|
4
7
|
import { useSettingsStore } from '../store/settings';
|
|
8
|
+
import { QuoteErrorType } from '../types';
|
|
5
9
|
import { debounce } from '../utils/common';
|
|
6
10
|
import { isPositiveNumber } from '../utils/numbers';
|
|
7
|
-
import {
|
|
11
|
+
import { generateQuoteWarnings } from '../utils/quote';
|
|
12
|
+
import { createQuoteRequestBody } from '../utils/swap';
|
|
8
13
|
import { tokensAreEqual } from '../utils/wallets';
|
|
9
14
|
|
|
10
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
handleQuoteErrors,
|
|
17
|
+
throwErrorIfResponseIsNotValid,
|
|
18
|
+
} from './useConfirmSwap/useConfirmSwap.helpers';
|
|
19
|
+
import { useFetchQuote } from './useFetchQuote';
|
|
11
20
|
|
|
12
21
|
const DEBOUNCE_DELAY = 600;
|
|
13
22
|
|
|
14
23
|
type UseSwapInput = {
|
|
15
24
|
fetch: () => void;
|
|
16
25
|
loading: boolean;
|
|
17
|
-
error:
|
|
26
|
+
error: QuoteError | null;
|
|
27
|
+
warning: QuoteWarning | null;
|
|
18
28
|
};
|
|
19
29
|
|
|
20
30
|
/**
|
|
21
|
-
* a hook for fetching
|
|
31
|
+
* a hook for fetching quote based on from and to input values
|
|
22
32
|
* we use this hook in home page
|
|
23
33
|
*/
|
|
24
34
|
export function useSwapInput(): UseSwapInput {
|
|
25
|
-
const { fetch:
|
|
26
|
-
const
|
|
35
|
+
const { fetch: fetchQuote, cancelFetch } = useFetchQuote();
|
|
36
|
+
const { liquiditySources, enableNewLiquiditySources } = useAppStore().config;
|
|
37
|
+
const tokens = useAppStore().tokens();
|
|
27
38
|
const {
|
|
28
39
|
fromToken,
|
|
29
40
|
toToken,
|
|
30
41
|
inputAmount,
|
|
31
42
|
inputUsdValue,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} =
|
|
43
|
+
resetQuote,
|
|
44
|
+
setQuote,
|
|
45
|
+
} = useQuoteStore();
|
|
35
46
|
const {
|
|
36
47
|
slippage,
|
|
37
48
|
customSlippage,
|
|
@@ -40,7 +51,9 @@ export function useSwapInput(): UseSwapInput {
|
|
|
40
51
|
affiliateWallets,
|
|
41
52
|
disabledLiquiditySources,
|
|
42
53
|
} = useSettingsStore();
|
|
43
|
-
const [
|
|
54
|
+
const [loading, setLoading] = useState(false);
|
|
55
|
+
const [error, setError] = useState<QuoteError | null>(null);
|
|
56
|
+
const [warning, setWarning] = useState<QuoteWarning | null>(null);
|
|
44
57
|
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
45
58
|
const userSlippage = customSlippage ?? slippage;
|
|
46
59
|
const hasTokensValue = !fromToken || !toToken;
|
|
@@ -49,31 +62,53 @@ export function useSwapInput(): UseSwapInput {
|
|
|
49
62
|
tokensAreEqual(fromToken, toToken) ||
|
|
50
63
|
!isPositiveNumber(inputAmount);
|
|
51
64
|
|
|
65
|
+
const resetState = (loading: boolean) => {
|
|
66
|
+
setLoading(loading);
|
|
67
|
+
setError(null);
|
|
68
|
+
setWarning(null);
|
|
69
|
+
};
|
|
70
|
+
|
|
52
71
|
const fetch: UseSwapInput['fetch'] = () => {
|
|
53
72
|
if (!loading) {
|
|
54
|
-
|
|
73
|
+
resetState(true);
|
|
55
74
|
}
|
|
56
75
|
if (!shouldSkipRequest) {
|
|
57
|
-
|
|
58
|
-
const requestBody =
|
|
76
|
+
resetQuote();
|
|
77
|
+
const requestBody = createQuoteRequestBody({
|
|
59
78
|
fromToken,
|
|
60
79
|
toToken,
|
|
61
80
|
inputAmount,
|
|
81
|
+
liquiditySources,
|
|
82
|
+
excludeLiquiditySources: enableNewLiquiditySources,
|
|
62
83
|
disabledLiquiditySources,
|
|
63
84
|
slippage: userSlippage,
|
|
64
85
|
affiliateRef,
|
|
65
86
|
affiliatePercent,
|
|
66
87
|
affiliateWallets,
|
|
67
88
|
});
|
|
68
|
-
|
|
89
|
+
fetchQuote(requestBody)
|
|
69
90
|
.then((res) => {
|
|
70
91
|
setLoading(false);
|
|
71
|
-
|
|
92
|
+
setQuote(res);
|
|
93
|
+
throwErrorIfResponseIsNotValid(res);
|
|
94
|
+
const quoteWarning = generateQuoteWarnings(res, {
|
|
95
|
+
fromToken,
|
|
96
|
+
toToken,
|
|
97
|
+
userSlippage,
|
|
98
|
+
tokens,
|
|
99
|
+
});
|
|
100
|
+
setWarning(quoteWarning);
|
|
72
101
|
})
|
|
73
102
|
.catch((error) => {
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
103
|
+
const { error: quoteError } = handleQuoteErrors(error);
|
|
104
|
+
if (
|
|
105
|
+
quoteError?.type === QuoteErrorType.NO_RESULT ||
|
|
106
|
+
quoteError?.type === QuoteErrorType.REQUEST_FAILED
|
|
107
|
+
) {
|
|
108
|
+
resetQuote();
|
|
109
|
+
}
|
|
110
|
+
if (quoteError?.type !== QuoteErrorType.REQUEST_CANCELED) {
|
|
111
|
+
setError(quoteError);
|
|
77
112
|
setLoading(false);
|
|
78
113
|
}
|
|
79
114
|
});
|
|
@@ -88,15 +123,15 @@ export function useSwapInput(): UseSwapInput {
|
|
|
88
123
|
|
|
89
124
|
useEffect(() => {
|
|
90
125
|
if (!isPositiveNumber(inputAmount) || inputUsdValue?.eq(0)) {
|
|
91
|
-
|
|
126
|
+
resetState(false);
|
|
92
127
|
cancelFetch();
|
|
93
128
|
return;
|
|
94
129
|
}
|
|
95
130
|
if (shouldSkipRequest) {
|
|
96
131
|
return;
|
|
97
132
|
}
|
|
98
|
-
|
|
99
|
-
|
|
133
|
+
resetQuote();
|
|
134
|
+
resetState(true);
|
|
100
135
|
debouncedFetch();
|
|
101
136
|
return cancelFetch;
|
|
102
137
|
}, [inputAmount, shouldSkipRequest]);
|
|
@@ -112,5 +147,5 @@ export function useSwapInput(): UseSwapInput {
|
|
|
112
147
|
return cancelFetch;
|
|
113
148
|
}, [disabledLiquiditySources.length]);
|
|
114
149
|
|
|
115
|
-
return { fetch, loading, error };
|
|
150
|
+
return { fetch, loading, error, warning };
|
|
116
151
|
}
|