@rango-dev/widget-embedded 0.1.10-next.100
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/App.d.ts +9 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/QueueManager.d.ts +4 -0
- package/dist/QueueManager.d.ts.map +1 -0
- package/dist/components/AppRouter.d.ts +9 -0
- package/dist/components/AppRouter.d.ts.map +1 -0
- package/dist/components/AppRoutes.d.ts +8 -0
- package/dist/components/AppRoutes.d.ts.map +1 -0
- package/dist/components/BottomLogo.d.ts +3 -0
- package/dist/components/BottomLogo.d.ts.map +1 -0
- package/dist/components/ChangeSlippageButton.d.ts +3 -0
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -0
- package/dist/components/ConfirmSwapErrors.d.ts +4 -0
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -0
- package/dist/components/ConfirmSwapWarnings.d.ts +4 -0
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -0
- package/dist/components/Footer.d.ts +2 -0
- package/dist/components/Footer.d.ts.map +1 -0
- package/dist/components/Header.d.ts +10 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/HeaderButtons.d.ts +4 -0
- package/dist/components/HeaderButtons.d.ts.map +1 -0
- package/dist/components/Layout.d.ts +7 -0
- package/dist/components/Layout.d.ts.map +1 -0
- package/dist/components/RoutesOverview.d.ts +10 -0
- package/dist/components/RoutesOverview.d.ts.map +1 -0
- package/dist/components/SwitchFromAndTo.d.ts +4 -0
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -0
- package/dist/components/TokenInfo.d.ts +18 -0
- package/dist/components/TokenInfo.d.ts.map +1 -0
- package/dist/components/TokenPreview.d.ts +20 -0
- package/dist/components/TokenPreview.d.ts.map +1 -0
- package/dist/components/UpdateUrl.d.ts +2 -0
- package/dist/components/UpdateUrl.d.ts.map +1 -0
- package/dist/components/warnings/BalanceWarnings.d.ts +7 -0
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -0
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts +7 -0
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts.map +1 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts +7 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -0
- package/dist/components/warnings/MinRequiredSlippage.d.ts +7 -0
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -0
- package/dist/constants/errors.d.ts +4 -0
- package/dist/constants/errors.d.ts.map +1 -0
- package/dist/constants/navigationRoutes.d.ts +15 -0
- package/dist/constants/navigationRoutes.d.ts.map +1 -0
- package/dist/constants/numbers.d.ts +3 -0
- package/dist/constants/numbers.d.ts.map +1 -0
- package/dist/constants/searchParams.d.ts +8 -0
- package/dist/constants/searchParams.d.ts.map +1 -0
- package/dist/constants/swapSettings.d.ts +6 -0
- package/dist/constants/swapSettings.d.ts.map +1 -0
- package/dist/globalStyles.d.ts +3 -0
- package/dist/globalStyles.d.ts.map +1 -0
- package/dist/hooks/useConfirmSwap.d.ts +11 -0
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -0
- package/dist/hooks/useCopyToClipboard.d.ts +2 -0
- package/dist/hooks/useCopyToClipboard.d.ts.map +1 -0
- package/dist/hooks/useNavigateBack.d.ts +4 -0
- package/dist/hooks/useNavigateBack.d.ts.map +1 -0
- package/dist/hooks/usePrevious.d.ts +2 -0
- package/dist/hooks/usePrevious.d.ts.map +1 -0
- package/dist/hooks/useSelectLanguage.d.ts +5 -0
- package/dist/hooks/useSelectLanguage.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts +8 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/i18n.d.ts +3 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/lib.d.ts +8 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/mockData/pendingSwap.d.ts +2 -0
- package/dist/mockData/pendingSwap.d.ts.map +1 -0
- package/dist/pages/ConfirmSwapPage.d.ts +3 -0
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -0
- package/dist/pages/ConfirmWalletsPage.d.ts +3 -0
- package/dist/pages/ConfirmWalletsPage.d.ts.map +1 -0
- package/dist/pages/HistoryPage.d.ts +3 -0
- package/dist/pages/HistoryPage.d.ts.map +1 -0
- package/dist/pages/Home.d.ts +9 -0
- package/dist/pages/Home.d.ts.map +1 -0
- package/dist/pages/LiquiditySourcesPage.d.ts +8 -0
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -0
- package/dist/pages/SelectChainPage.d.ts +9 -0
- package/dist/pages/SelectChainPage.d.ts.map +1 -0
- package/dist/pages/SelectTokenPage.d.ts +15 -0
- package/dist/pages/SelectTokenPage.d.ts.map +1 -0
- package/dist/pages/SettingsPage.d.ts +8 -0
- package/dist/pages/SettingsPage.d.ts.map +1 -0
- package/dist/pages/SwapDetailsPage.d.ts +3 -0
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -0
- package/dist/pages/WalletsPage.d.ts +9 -0
- package/dist/pages/WalletsPage.d.ts.map +1 -0
- package/dist/services/httpService.d.ts +3 -0
- package/dist/services/httpService.d.ts.map +1 -0
- package/dist/store/bestRoute.d.ts +28 -0
- package/dist/store/bestRoute.d.ts.map +1 -0
- package/dist/store/meta.d.ts +9 -0
- package/dist/store/meta.d.ts.map +1 -0
- package/dist/store/selectors.d.ts +11 -0
- package/dist/store/selectors.d.ts.map +1 -0
- package/dist/store/settings.d.ts +17 -0
- package/dist/store/settings.d.ts.map +1 -0
- package/dist/store/ui.d.ts +2 -0
- package/dist/store/ui.d.ts.map +1 -0
- package/dist/store/wallets.d.ts +28 -0
- package/dist/store/wallets.d.ts.map +1 -0
- package/dist/types/config.d.ts +40 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/routing.d.ts +45 -0
- package/dist/types/routing.d.ts.map +1 -0
- package/dist/types/swap.d.ts +11 -0
- package/dist/types/swap.d.ts.map +1 -0
- package/dist/utils/common.d.ts +4 -0
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +14 -0
- package/dist/utils/numbers.d.ts.map +1 -0
- package/dist/utils/queue.d.ts +4 -0
- package/dist/utils/queue.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +18 -0
- package/dist/utils/routing.d.ts.map +1 -0
- package/dist/utils/swap.d.ts +45 -0
- package/dist/utils/swap.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts +29 -0
- package/dist/utils/wallets.d.ts.map +1 -0
- package/dist/widget-embedded.cjs.development.js +3101 -0
- package/dist/widget-embedded.cjs.development.js.map +1 -0
- package/dist/widget-embedded.cjs.production.min.js +3101 -0
- package/dist/widget-embedded.cjs.production.min.js.map +1 -0
- package/dist/widget-embedded.esm.js +3092 -0
- package/dist/widget-embedded.esm.js.map +1 -0
- package/package.json +55 -0
- package/readme.md +2 -0
- package/src/App.tsx +91 -0
- package/src/QueueManager.tsx +94 -0
- package/src/app.css +27 -0
- package/src/components/AppRouter.tsx +60 -0
- package/src/components/AppRoutes.tsx +105 -0
- package/src/components/BottomLogo.tsx +47 -0
- package/src/components/ChangeSlippageButton.tsx +19 -0
- package/src/components/ConfirmSwapErrors.tsx +38 -0
- package/src/components/ConfirmSwapWarnings.tsx +35 -0
- package/src/components/Footer.tsx +8 -0
- package/src/components/Header.tsx +37 -0
- package/src/components/HeaderButtons.tsx +47 -0
- package/src/components/Layout.tsx +96 -0
- package/src/components/RoutesOverview.tsx +60 -0
- package/src/components/SwitchFromAndTo.tsx +30 -0
- package/src/components/TokenInfo.tsx +311 -0
- package/src/components/TokenPreview.tsx +175 -0
- package/src/components/UpdateUrl.tsx +162 -0
- package/src/components/warnings/BalanceWarnings.tsx +39 -0
- package/src/components/warnings/ConfirmSwapExtraMessages.tsx +20 -0
- package/src/components/warnings/HighSlippageWarning.tsx +18 -0
- package/src/components/warnings/MinRequiredSlippage.tsx +18 -0
- package/src/constants/errors.ts +3 -0
- package/src/constants/navigationRoutes.ts +14 -0
- package/src/constants/numbers.ts +3 -0
- package/src/constants/searchParams.ts +7 -0
- package/src/constants/swapSettings.ts +9 -0
- package/src/globalStyles.ts +26 -0
- package/src/hooks/useConfirmSwap.ts +260 -0
- package/src/hooks/useCopyToClipboard.ts +23 -0
- package/src/hooks/useNavigateBack.ts +40 -0
- package/src/hooks/usePrevious.ts +13 -0
- package/src/hooks/useSelectLanguage.ts +15 -0
- package/src/hooks/useTheme.ts +127 -0
- package/src/i18n.js +30 -0
- package/src/index.tsx +14 -0
- package/src/languages/en.json +14 -0
- package/src/languages/tr.json +11 -0
- package/src/lib.tsx +119 -0
- package/src/mockData/pendingSwap.ts +607 -0
- package/src/pages/ConfirmSwapPage.tsx +72 -0
- package/src/pages/ConfirmWalletsPage.tsx +127 -0
- package/src/pages/HistoryPage.tsx +29 -0
- package/src/pages/Home.tsx +228 -0
- package/src/pages/LiquiditySourcesPage.tsx +64 -0
- package/src/pages/SelectChainPage.tsx +42 -0
- package/src/pages/SelectTokenPage.tsx +64 -0
- package/src/pages/SettingsPage.tsx +98 -0
- package/src/pages/SwapDetailsPage.tsx +38 -0
- package/src/pages/WalletsPage.tsx +119 -0
- package/src/services/httpService.ts +5 -0
- package/src/store/bestRoute.ts +245 -0
- package/src/store/meta.ts +35 -0
- package/src/store/selectors.ts +19 -0
- package/src/store/settings.ts +84 -0
- package/src/store/ui.ts +21 -0
- package/src/store/wallets.ts +190 -0
- package/src/types/config.ts +44 -0
- package/src/types/index.ts +3 -0
- package/src/types/routing.ts +60 -0
- package/src/types/swap.ts +13 -0
- package/src/utils/common.ts +35 -0
- package/src/utils/numbers.ts +133 -0
- package/src/utils/queue.ts +24 -0
- package/src/utils/routing.ts +150 -0
- package/src/utils/swap.ts +552 -0
- package/src/utils/wallets.ts +481 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { ConfirmWallets } from '@rango-dev/ui';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
|
+
import { useWalletsStore } from '../store/wallets';
|
|
6
|
+
import { useWallets } from '@rango-dev/wallets-core';
|
|
7
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
8
|
+
import {
|
|
9
|
+
getKeplrCompatibleConnectedWallets,
|
|
10
|
+
getRequiredChains,
|
|
11
|
+
getSelectableWallets,
|
|
12
|
+
isExperimentalChain,
|
|
13
|
+
} from '../utils/wallets';
|
|
14
|
+
import {
|
|
15
|
+
calcOutputUsdValue,
|
|
16
|
+
getTotalFeeInUsd,
|
|
17
|
+
requiredWallets,
|
|
18
|
+
} from '../utils/swap';
|
|
19
|
+
import { decimalNumber, numberToString } from '../utils/numbers';
|
|
20
|
+
import { useMetaStore } from '../store/meta';
|
|
21
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
22
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
23
|
+
import { TokenPreview } from '../components/TokenPreview';
|
|
24
|
+
// @ts-ignore // TODO: fix error in tsc build
|
|
25
|
+
import { t } from 'i18next';
|
|
26
|
+
import { Spacer } from '@rango-dev/ui';
|
|
27
|
+
import RoutesOverview from '../components/RoutesOverview';
|
|
28
|
+
|
|
29
|
+
export function ConfirmWalletsPage() {
|
|
30
|
+
const navigate = useNavigate();
|
|
31
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
32
|
+
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
33
|
+
|
|
34
|
+
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
35
|
+
const accounts = useWalletsStore.use.accounts();
|
|
36
|
+
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
37
|
+
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
38
|
+
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
39
|
+
|
|
40
|
+
const { getWalletInfo, connect } = useWallets();
|
|
41
|
+
const confirmDisabled = !requiredWallets(bestRoute).every((chain) =>
|
|
42
|
+
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const firstStep = bestRoute?.result?.swaps[0];
|
|
46
|
+
const lastStep =
|
|
47
|
+
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
48
|
+
|
|
49
|
+
const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
|
|
50
|
+
const toAmount = decimalNumber(lastStep?.toAmount, 3);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
initSelectedWallets();
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
const selectableWallets = getSelectableWallets(
|
|
56
|
+
accounts,
|
|
57
|
+
selectedWallets,
|
|
58
|
+
getWalletInfo
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const handleConnectChain = (wallet: string) => {
|
|
62
|
+
const network = wallet as Network;
|
|
63
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
|
|
64
|
+
(compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<ConfirmWallets
|
|
72
|
+
requiredWallets={getRequiredChains(bestRoute)}
|
|
73
|
+
selectableWallets={selectableWallets}
|
|
74
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmWallets)}
|
|
75
|
+
onConfirm={() =>
|
|
76
|
+
navigate(navigationRoutes.confirmSwap, { replace: true })
|
|
77
|
+
}
|
|
78
|
+
onChange={(wallet) => setSelectedWallet(wallet)}
|
|
79
|
+
confirmDisabled={confirmDisabled}
|
|
80
|
+
handleConnectChain={(wallet) => handleConnectChain(wallet)}
|
|
81
|
+
isExperimentalChain={(wallet) =>
|
|
82
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
|
|
83
|
+
? isExperimentalChain(blockchains, wallet)
|
|
84
|
+
: false
|
|
85
|
+
}
|
|
86
|
+
previewInputs={
|
|
87
|
+
<>
|
|
88
|
+
<TokenPreview
|
|
89
|
+
chain={{
|
|
90
|
+
displayName: firstStep?.from.blockchain || '',
|
|
91
|
+
logo: firstStep?.from.blockchainLogo || '',
|
|
92
|
+
}}
|
|
93
|
+
token={{
|
|
94
|
+
symbol: firstStep?.from.symbol || '',
|
|
95
|
+
image: firstStep?.from.logo || '',
|
|
96
|
+
}}
|
|
97
|
+
usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
|
|
98
|
+
amount={fromAmount}
|
|
99
|
+
label={t('From')}
|
|
100
|
+
loadingStatus={'success'}
|
|
101
|
+
/>
|
|
102
|
+
<Spacer size={12} direction="vertical" />
|
|
103
|
+
<TokenPreview
|
|
104
|
+
chain={{
|
|
105
|
+
displayName: lastStep?.to.blockchain || '',
|
|
106
|
+
logo: lastStep?.to.blockchainLogo || '',
|
|
107
|
+
}}
|
|
108
|
+
token={{
|
|
109
|
+
symbol: lastStep?.to.symbol || '',
|
|
110
|
+
image: lastStep?.to.logo || '',
|
|
111
|
+
}}
|
|
112
|
+
usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
|
|
113
|
+
amount={toAmount}
|
|
114
|
+
label={t('To')}
|
|
115
|
+
loadingStatus={'success'}
|
|
116
|
+
/>
|
|
117
|
+
</>
|
|
118
|
+
}
|
|
119
|
+
previewRoutes={
|
|
120
|
+
<RoutesOverview
|
|
121
|
+
routes={bestRoute}
|
|
122
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
123
|
+
/>
|
|
124
|
+
}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { History } from '@rango-dev/ui';
|
|
2
|
+
import { useManager } from '@rango-dev/queue-manager-react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useNavigate } from 'react-router-dom';
|
|
5
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
6
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
7
|
+
import { getPendingSwaps } from '../utils/queue';
|
|
8
|
+
import { useUiStore } from '../store/ui';
|
|
9
|
+
|
|
10
|
+
export function HistoryPage() {
|
|
11
|
+
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
12
|
+
const navigate = useNavigate();
|
|
13
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
14
|
+
const { manager } = useManager();
|
|
15
|
+
const pendingSwaps = getPendingSwaps(manager).map(({ swap }) => swap);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<History
|
|
19
|
+
//todo: move PendingSwap type to rango-types
|
|
20
|
+
//@ts-ignore
|
|
21
|
+
list={pendingSwaps}
|
|
22
|
+
onSwapClick={(requestId) => {
|
|
23
|
+
setSelectedSwap(requestId);
|
|
24
|
+
navigate(navigationRoutes.swaps + `/${requestId}`);
|
|
25
|
+
}}
|
|
26
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.swaps)}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Alert,
|
|
3
|
+
BestRoute,
|
|
4
|
+
Button,
|
|
5
|
+
styled,
|
|
6
|
+
Typography,
|
|
7
|
+
VerticalSwapIcon,
|
|
8
|
+
} from '@rango-dev/ui';
|
|
9
|
+
import React, { useState } from 'react';
|
|
10
|
+
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
11
|
+
import { Header } from '../components/Header';
|
|
12
|
+
import { TokenInfo } from '../components/TokenInfo';
|
|
13
|
+
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
14
|
+
import { BottomLogo } from '../components/BottomLogo';
|
|
15
|
+
import { SwithFromAndTo } from '../components/SwitchFromAndTo';
|
|
16
|
+
import { Footer } from '../components/Footer';
|
|
17
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
18
|
+
import { useMetaStore } from '../store/meta';
|
|
19
|
+
import { useWalletsStore } from '../store/wallets';
|
|
20
|
+
import { errorMessages } from '../constants/errors';
|
|
21
|
+
import {
|
|
22
|
+
getSwapButtonState,
|
|
23
|
+
getOutputRatio,
|
|
24
|
+
hasLimitError,
|
|
25
|
+
outputRatioHasWarning,
|
|
26
|
+
canComputePriceImpact,
|
|
27
|
+
LimitErrorMessage,
|
|
28
|
+
getTotalFeeInUsd,
|
|
29
|
+
hasHighFee,
|
|
30
|
+
} from '../utils/swap';
|
|
31
|
+
import {
|
|
32
|
+
numberToString,
|
|
33
|
+
secondsToString,
|
|
34
|
+
totalArrivalTime,
|
|
35
|
+
} from '../utils/numbers';
|
|
36
|
+
import BigNumber from 'bignumber.js';
|
|
37
|
+
|
|
38
|
+
const Container = styled('div', {
|
|
39
|
+
display: 'flex',
|
|
40
|
+
flexDirection: 'column',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const FromContainer = styled('div', {
|
|
44
|
+
position: 'relative',
|
|
45
|
+
paddingBottom: '$12',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const SwitchButtonContainer = styled('div', {
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
bottom: '-12px',
|
|
51
|
+
left: '50%',
|
|
52
|
+
transform: 'translate(-50%, 10%)',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const BestRouteContainer = styled('div', {
|
|
56
|
+
width: '100%',
|
|
57
|
+
paddingTop: '$16',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const Alerts = styled('div', {
|
|
61
|
+
width: '100%',
|
|
62
|
+
paddingTop: '$16',
|
|
63
|
+
});
|
|
64
|
+
interface PropTypes {
|
|
65
|
+
title?: string;
|
|
66
|
+
titleSize?: number;
|
|
67
|
+
titleWeight?: number;
|
|
68
|
+
}
|
|
69
|
+
export function Home(props: PropTypes) {
|
|
70
|
+
const { title = 'SWAP', titleSize = 18, titleWeight = 600 } = props;
|
|
71
|
+
|
|
72
|
+
const isRouterInContext = useInRouterContext();
|
|
73
|
+
const navigate = useNavigate();
|
|
74
|
+
const [count, setCount] = useState(0);
|
|
75
|
+
const fromChain = useBestRouteStore.use.fromChain();
|
|
76
|
+
const fromToken = useBestRouteStore.use.fromToken();
|
|
77
|
+
const toChain = useBestRouteStore.use.toChain();
|
|
78
|
+
const toToken = useBestRouteStore.use.toToken();
|
|
79
|
+
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
80
|
+
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
81
|
+
const setToChain = useBestRouteStore.use.setToChain();
|
|
82
|
+
const setToToken = useBestRouteStore.use.setToToken();
|
|
83
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
84
|
+
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
85
|
+
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
86
|
+
const outputAmount = useBestRouteStore.use.outputAmount();
|
|
87
|
+
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
88
|
+
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
89
|
+
const tokens = useMetaStore.use.meta().tokens;
|
|
90
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
91
|
+
const bestRouteError = useBestRouteStore.use.error();
|
|
92
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
93
|
+
const accounts = useWalletsStore.use.accounts();
|
|
94
|
+
|
|
95
|
+
const swithFromAndTo = () => {
|
|
96
|
+
setFromChain(toChain);
|
|
97
|
+
setFromToken(toToken);
|
|
98
|
+
setToChain(fromChain);
|
|
99
|
+
setToToken(fromToken);
|
|
100
|
+
setInputAmount(outputAmount?.toString() || '');
|
|
101
|
+
setCount((prev) => prev + 1);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const errorMessage =
|
|
105
|
+
loadingMetaStatus === 'failed'
|
|
106
|
+
? errorMessages.genericServerError
|
|
107
|
+
: bestRouteError;
|
|
108
|
+
|
|
109
|
+
const needsToWarnEthOnPath = false;
|
|
110
|
+
|
|
111
|
+
const showBestRoute =
|
|
112
|
+
inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
|
|
113
|
+
|
|
114
|
+
const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
|
|
115
|
+
|
|
116
|
+
const highValueLoss = outputRatioHasWarning(inputUsdValue, outToInRatio);
|
|
117
|
+
|
|
118
|
+
const { fromAmountRangeError, recommendation, swap } =
|
|
119
|
+
LimitErrorMessage(bestRoute);
|
|
120
|
+
|
|
121
|
+
const priceImpactCanNotBeComputed = !canComputePriceImpact(
|
|
122
|
+
bestRoute,
|
|
123
|
+
inputAmount,
|
|
124
|
+
inputUsdValue,
|
|
125
|
+
outputUsdValue
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const inputIsZero = inputAmount === '0';
|
|
129
|
+
const swapButtonState = getSwapButtonState(
|
|
130
|
+
loadingMetaStatus,
|
|
131
|
+
accounts,
|
|
132
|
+
fetchingBestRoute,
|
|
133
|
+
bestRoute,
|
|
134
|
+
hasLimitError(bestRoute),
|
|
135
|
+
highValueLoss,
|
|
136
|
+
priceImpactCanNotBeComputed,
|
|
137
|
+
needsToWarnEthOnPath,
|
|
138
|
+
inputIsZero
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
142
|
+
|
|
143
|
+
const highFee = hasHighFee(totalFeeInUsd);
|
|
144
|
+
|
|
145
|
+
return (
|
|
146
|
+
<Container>
|
|
147
|
+
<Header
|
|
148
|
+
title={title}
|
|
149
|
+
titleSize={titleSize}
|
|
150
|
+
titleWeight={titleWeight}
|
|
151
|
+
onClickRefresh={fetchBestRoute}
|
|
152
|
+
/>
|
|
153
|
+
<FromContainer>
|
|
154
|
+
<TokenInfo
|
|
155
|
+
type="From"
|
|
156
|
+
chain={fromChain}
|
|
157
|
+
token={fromToken}
|
|
158
|
+
onAmountChange={setInputAmount}
|
|
159
|
+
inputAmount={inputAmount}
|
|
160
|
+
/>
|
|
161
|
+
<SwitchButtonContainer>
|
|
162
|
+
<Button variant="ghost" onClick={swithFromAndTo}>
|
|
163
|
+
<VerticalSwapIcon size={24} />
|
|
164
|
+
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
165
|
+
</Button>
|
|
166
|
+
</SwitchButtonContainer>
|
|
167
|
+
</FromContainer>
|
|
168
|
+
<TokenInfo
|
|
169
|
+
type="To"
|
|
170
|
+
chain={toChain}
|
|
171
|
+
token={toToken}
|
|
172
|
+
outputAmount={
|
|
173
|
+
outputAmount ? new BigNumber(outputAmount) : new BigNumber(0)
|
|
174
|
+
}
|
|
175
|
+
outputUsdValue={outputUsdValue}
|
|
176
|
+
/>
|
|
177
|
+
{showBestRoute && (
|
|
178
|
+
<BestRouteContainer>
|
|
179
|
+
<BestRoute
|
|
180
|
+
error={bestRouteError}
|
|
181
|
+
loading={fetchingBestRoute}
|
|
182
|
+
data={bestRoute}
|
|
183
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
184
|
+
feeWarning={highFee}
|
|
185
|
+
totalTime={secondsToString(totalArrivalTime(bestRoute))}
|
|
186
|
+
/>
|
|
187
|
+
</BestRouteContainer>
|
|
188
|
+
)}
|
|
189
|
+
{(errorMessage || hasLimitError(bestRoute)) && (
|
|
190
|
+
<Alerts>
|
|
191
|
+
{errorMessage && <Alert type="error">{errorMessage}</Alert>}
|
|
192
|
+
{hasLimitError(bestRoute) && (
|
|
193
|
+
<Alert type="error" title={`${swap?.swapperId} Limit`}>
|
|
194
|
+
<>
|
|
195
|
+
<Typography variant="body2">{fromAmountRangeError}</Typography>
|
|
196
|
+
<br />
|
|
197
|
+
<Typography variant="body2">
|
|
198
|
+
Yours: {numberToString(swap?.fromAmount || null)}
|
|
199
|
+
{swap?.from.symbol}
|
|
200
|
+
</Typography>
|
|
201
|
+
<br />
|
|
202
|
+
<Typography variant="body2">{recommendation}</Typography>
|
|
203
|
+
</>
|
|
204
|
+
</Alert>
|
|
205
|
+
)}
|
|
206
|
+
</Alerts>
|
|
207
|
+
)}
|
|
208
|
+
<Footer>
|
|
209
|
+
<Button
|
|
210
|
+
type="primary"
|
|
211
|
+
align="grow"
|
|
212
|
+
size="large"
|
|
213
|
+
disabled={swapButtonState.disabled}
|
|
214
|
+
onClick={() => {
|
|
215
|
+
if (swapButtonState.title === 'Connect Wallet')
|
|
216
|
+
navigate(navigationRoutes.wallets);
|
|
217
|
+
else {
|
|
218
|
+
navigate(navigationRoutes.confirmWallets, { replace: true });
|
|
219
|
+
}
|
|
220
|
+
}}
|
|
221
|
+
>
|
|
222
|
+
{swapButtonState.title}
|
|
223
|
+
</Button>
|
|
224
|
+
<BottomLogo />
|
|
225
|
+
</Footer>
|
|
226
|
+
</Container>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { LiquiditySourcesSelector } from '@rango-dev/ui';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
4
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
5
|
+
import { useMetaStore } from '../store/meta';
|
|
6
|
+
import { useSettingsStore } from '../store/settings';
|
|
7
|
+
import { Source } from '../types';
|
|
8
|
+
import { removeDuplicateFrom } from '../utils/common';
|
|
9
|
+
interface PropTypes {
|
|
10
|
+
supportedSwappers: 'all' | Source[];
|
|
11
|
+
}
|
|
12
|
+
export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
13
|
+
const swappers = useMetaStore.use.meta().swappers;
|
|
14
|
+
const toggleLiquiditySource = useSettingsStore.use.toggleLiquiditySource();
|
|
15
|
+
const disabledLiquiditySources =
|
|
16
|
+
useSettingsStore.use.disabledLiquiditySources();
|
|
17
|
+
const toggleAllLiquiditySources =
|
|
18
|
+
useSettingsStore.use.toggleAllLiquiditySources();
|
|
19
|
+
|
|
20
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
21
|
+
|
|
22
|
+
const uniqueSwappersGroups: Array<{
|
|
23
|
+
title: string;
|
|
24
|
+
logo: string;
|
|
25
|
+
type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
26
|
+
selected: boolean;
|
|
27
|
+
}> = [];
|
|
28
|
+
removeDuplicateFrom(swappers.map((s) => s.swapperGroup))
|
|
29
|
+
.map((swapperGroup) => {
|
|
30
|
+
return swappers.find((s) => s.swapperGroup === swapperGroup);
|
|
31
|
+
})
|
|
32
|
+
.find((s) => {
|
|
33
|
+
if (s) {
|
|
34
|
+
for (const type of s.types) {
|
|
35
|
+
uniqueSwappersGroups.push({
|
|
36
|
+
title: s.swapperGroup,
|
|
37
|
+
logo: s.logo,
|
|
38
|
+
type,
|
|
39
|
+
selected: !disabledLiquiditySources.includes(s.swapperGroup),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<LiquiditySourcesSelector
|
|
47
|
+
toggleAll={toggleAllLiquiditySources}
|
|
48
|
+
list={
|
|
49
|
+
supportedSwappers !== 'all'
|
|
50
|
+
? uniqueSwappersGroups.filter(
|
|
51
|
+
(item) =>
|
|
52
|
+
supportedSwappers.filter(
|
|
53
|
+
(s) => s.title === item.title && s.type === item.type
|
|
54
|
+
).length > 0
|
|
55
|
+
)
|
|
56
|
+
: uniqueSwappersGroups
|
|
57
|
+
}
|
|
58
|
+
onChange={(liquiditySource) =>
|
|
59
|
+
toggleLiquiditySource(liquiditySource.title)
|
|
60
|
+
}
|
|
61
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.liquiditySources)}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BlockchainSelector } from '@rango-dev/ui';
|
|
3
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
|
+
import { useMetaStore } from '../store/meta';
|
|
5
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
|
+
import { BlockchainMeta } from 'rango-sdk';
|
|
8
|
+
|
|
9
|
+
interface PropTypes {
|
|
10
|
+
type: 'from' | 'to';
|
|
11
|
+
supportedChains: 'all' | BlockchainMeta[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function SelectChainPage(props: PropTypes) {
|
|
15
|
+
const { type, supportedChains } = props;
|
|
16
|
+
const blockchains =
|
|
17
|
+
supportedChains === 'all'
|
|
18
|
+
? useMetaStore.use.meta().blockchains
|
|
19
|
+
: supportedChains;
|
|
20
|
+
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
21
|
+
const fromChain = useBestRouteStore.use.fromChain();
|
|
22
|
+
const toChain = useBestRouteStore.use.toChain();
|
|
23
|
+
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
24
|
+
const setToChain = useBestRouteStore.use.setToChain();
|
|
25
|
+
|
|
26
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<BlockchainSelector
|
|
30
|
+
type={type === 'from' ? 'Source' : 'Destination'}
|
|
31
|
+
list={blockchains}
|
|
32
|
+
selected={type === 'from' ? fromChain : toChain}
|
|
33
|
+
loadingStatus={loadingStatus}
|
|
34
|
+
onChange={(chain) => {
|
|
35
|
+
if (type === 'from') setFromChain(chain, true);
|
|
36
|
+
else setToChain(chain, true);
|
|
37
|
+
navigateBackFrom(navigationRoutes.fromChain);
|
|
38
|
+
}}
|
|
39
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.fromChain)}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TokenSelector } from '@rango-dev/ui';
|
|
3
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
|
+
import { Token } from 'rango-sdk';
|
|
5
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
|
+
import { tokensAreEqual } from '../utils/wallets';
|
|
8
|
+
|
|
9
|
+
interface PropTypes {
|
|
10
|
+
type: 'from' | 'to';
|
|
11
|
+
supportedTokens: 'all' | Token[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TokenWithBalance extends Token {
|
|
15
|
+
balance?: {
|
|
16
|
+
amount: string;
|
|
17
|
+
usdValue: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function SelectTokenPage(props: PropTypes) {
|
|
22
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
23
|
+
|
|
24
|
+
const { type, supportedTokens } = props;
|
|
25
|
+
const sourceTokens = useBestRouteStore.use.sourceTokens();
|
|
26
|
+
const destinationTokens = useBestRouteStore.use.destinationTokens();
|
|
27
|
+
const supportedSourceTokens =
|
|
28
|
+
supportedTokens === 'all'
|
|
29
|
+
? sourceTokens
|
|
30
|
+
: sourceTokens.filter((token) =>
|
|
31
|
+
supportedTokens.some((supportedToken) =>
|
|
32
|
+
tokensAreEqual(supportedToken, token)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const supportedDestinationTokens =
|
|
37
|
+
supportedTokens === 'all'
|
|
38
|
+
? destinationTokens
|
|
39
|
+
: destinationTokens.filter((token) =>
|
|
40
|
+
supportedTokens.some((supportedToken) =>
|
|
41
|
+
tokensAreEqual(supportedToken, token)
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
console.log(supportedSourceTokens);
|
|
45
|
+
|
|
46
|
+
const fromToken = useBestRouteStore.use.fromToken();
|
|
47
|
+
const toToken = useBestRouteStore.use.toToken();
|
|
48
|
+
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
49
|
+
const setToToken = useBestRouteStore.use.setToToken();
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<TokenSelector
|
|
53
|
+
type={type === 'from' ? 'Source' : 'Destination'}
|
|
54
|
+
list={type == 'from' ? supportedSourceTokens : supportedDestinationTokens}
|
|
55
|
+
selected={type === 'from' ? fromToken : toToken}
|
|
56
|
+
onChange={(token) => {
|
|
57
|
+
if (type === 'from') setFromToken(token);
|
|
58
|
+
else setToToken(token);
|
|
59
|
+
navigateBackFrom(navigationRoutes.fromToken);
|
|
60
|
+
}}
|
|
61
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.fromToken)}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Settings } from '@rango-dev/ui';
|
|
3
|
+
import { useSettingsStore } from '../store/settings';
|
|
4
|
+
import { useMetaStore } from '../store/meta';
|
|
5
|
+
import { useNavigate } from 'react-router-dom';
|
|
6
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
|
+
import { removeDuplicateFrom } from '../utils/common';
|
|
8
|
+
import { Source } from '../types';
|
|
9
|
+
import {
|
|
10
|
+
MAX_SLIPPAGE,
|
|
11
|
+
MIN_SLIPPGAE,
|
|
12
|
+
SLIPPAGES,
|
|
13
|
+
} from '../constants/swapSettings';
|
|
14
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
15
|
+
interface PropTypes {
|
|
16
|
+
supportedSwappers: 'all' | Source[];
|
|
17
|
+
}
|
|
18
|
+
export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
19
|
+
const slippage = useSettingsStore.use.slippage();
|
|
20
|
+
const setSlippage = useSettingsStore.use.setSlippage();
|
|
21
|
+
const disabledLiquiditySources =
|
|
22
|
+
useSettingsStore.use.disabledLiquiditySources();
|
|
23
|
+
const customSlippage = useSettingsStore.use.customSlippage();
|
|
24
|
+
const setCustomSlippage = useSettingsStore.use.setCustomSlippage();
|
|
25
|
+
const theme = useSettingsStore.use.theme();
|
|
26
|
+
const setTheme = useSettingsStore.use.setTheme();
|
|
27
|
+
const swappers = useMetaStore.use.meta().swappers;
|
|
28
|
+
const navigate = useNavigate();
|
|
29
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
30
|
+
|
|
31
|
+
const infiniteApprove = useSettingsStore.use.infiniteApprove();
|
|
32
|
+
const toggleInfiniteApprove = useSettingsStore.use.toggleInfiniteApprove();
|
|
33
|
+
const uniqueSwappersGroups: Array<{
|
|
34
|
+
title: string;
|
|
35
|
+
logo: string;
|
|
36
|
+
type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
37
|
+
selected: boolean;
|
|
38
|
+
}> = [];
|
|
39
|
+
removeDuplicateFrom(swappers.map((s) => s.swapperGroup))
|
|
40
|
+
.map((swapperGroup) => {
|
|
41
|
+
return swappers.find((s) => s.swapperGroup === swapperGroup);
|
|
42
|
+
})
|
|
43
|
+
.find((s) => {
|
|
44
|
+
if (s) {
|
|
45
|
+
for (const type of s.types) {
|
|
46
|
+
if (supportedSwappers !== 'all') {
|
|
47
|
+
}
|
|
48
|
+
uniqueSwappersGroups.push({
|
|
49
|
+
title: s.swapperGroup,
|
|
50
|
+
logo: s.logo,
|
|
51
|
+
type,
|
|
52
|
+
selected: !disabledLiquiditySources.includes(s.swapperGroup),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
supportedSwappers !== 'all' &&
|
|
58
|
+
uniqueSwappersGroups.filter(
|
|
59
|
+
(item) =>
|
|
60
|
+
supportedSwappers.filter(
|
|
61
|
+
(s) => s.title === item.title && s.type === item.type
|
|
62
|
+
).length > 0
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const supportedUniqueSwappersGroups =
|
|
66
|
+
supportedSwappers !== 'all'
|
|
67
|
+
? uniqueSwappersGroups.filter(
|
|
68
|
+
(item) =>
|
|
69
|
+
supportedSwappers.filter(
|
|
70
|
+
(s) => s.title === item.title && s.type === item.type
|
|
71
|
+
).length > 0
|
|
72
|
+
)
|
|
73
|
+
: uniqueSwappersGroups;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Settings
|
|
77
|
+
slippages={SLIPPAGES}
|
|
78
|
+
selectedSlippage={slippage}
|
|
79
|
+
onSlippageChange={(slippage) => setSlippage(slippage)}
|
|
80
|
+
onLiquiditySourcesClick={() =>
|
|
81
|
+
navigate(navigationRoutes.liquiditySources)
|
|
82
|
+
}
|
|
83
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.settings)}
|
|
84
|
+
liquiditySources={supportedUniqueSwappersGroups}
|
|
85
|
+
selectedLiquiditySources={supportedUniqueSwappersGroups.filter(
|
|
86
|
+
(s) => s.selected
|
|
87
|
+
)}
|
|
88
|
+
customSlippage={customSlippage || NaN}
|
|
89
|
+
onCustomSlippageChange={setCustomSlippage}
|
|
90
|
+
minSlippage={MIN_SLIPPGAE}
|
|
91
|
+
maxSlippage={MAX_SLIPPAGE}
|
|
92
|
+
selectedTheme={theme}
|
|
93
|
+
onThemeChange={setTheme}
|
|
94
|
+
infiniteApprove={infiniteApprove}
|
|
95
|
+
toggleInfiniteApprove={toggleInfiniteApprove}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
3
|
+
import useCopyToClipboard from '../hooks/useCopyToClipboard';
|
|
4
|
+
import { useManager } from '@rango-dev/queue-manager-react';
|
|
5
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
|
+
import { getPendingSwaps } from '../utils/queue';
|
|
7
|
+
import { SwapHistory } from '@rango-dev/ui';
|
|
8
|
+
import { useUiStore } from '../store/ui';
|
|
9
|
+
import { cancelSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
10
|
+
|
|
11
|
+
export function SwapDetailsPage() {
|
|
12
|
+
const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
|
|
13
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
14
|
+
const { manager } = useManager();
|
|
15
|
+
const [isCopied, handleCopy] = useCopyToClipboard(2000);
|
|
16
|
+
|
|
17
|
+
const pendingSwaps = getPendingSwaps(manager);
|
|
18
|
+
const selectedSwap = pendingSwaps.find(
|
|
19
|
+
({ swap }) => swap.requestId === selectedSwapRequestId
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
//TODO: implement swap cancellation (move queueManager logic to queueManager/rango-preset)
|
|
23
|
+
const onCancel = () => {
|
|
24
|
+
const swap = selectedSwap ? manager?.get(selectedSwap.id) : undefined;
|
|
25
|
+
if (swap) cancelSwap(swap);
|
|
26
|
+
};
|
|
27
|
+
return (
|
|
28
|
+
<SwapHistory
|
|
29
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
|
|
30
|
+
//todo: move PendingSwap type to rango-types
|
|
31
|
+
//@ts-ignore
|
|
32
|
+
pendingSwap={selectedSwap?.swap}
|
|
33
|
+
onCopy={handleCopy}
|
|
34
|
+
isCopied={isCopied}
|
|
35
|
+
onCancel={onCancel}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|