@rango-dev/widget-embedded 0.1.10-next.98 → 0.1.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/App.d.ts.map +1 -1
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +6 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -1
- package/dist/components/HeaderButtons.d.ts +4 -1
- package/dist/components/HeaderButtons.d.ts.map +1 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/RoutesOverview.d.ts +10 -0
- package/dist/components/RoutesOverview.d.ts.map +1 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts +9 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts +20 -0
- package/dist/components/TokenPreview.d.ts.map +1 -0
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -1
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts +1 -1
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -1
- package/dist/constants/navigationRoutes.d.ts +0 -1
- package/dist/constants/navigationRoutes.d.ts.map +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/HistoryPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +1 -0
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts +2 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/ui.d.ts.map +1 -1
- package/dist/store/wallets.d.ts +14 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/routing.d.ts +1 -1
- package/dist/types/swap.d.ts +6 -0
- package/dist/types/swap.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/date.d.ts +3 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/routing.d.ts +1 -0
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +18 -6
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts +4 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/wallets.d.ts +1 -1
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +1004 -418
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1004 -418
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1008 -423
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +12 -11
- package/readme.md +1 -2
- package/src/App.tsx +30 -5
- package/src/QueueManager.tsx +5 -2
- package/src/components/AppRouter.tsx +24 -13
- package/src/components/AppRoutes.tsx +15 -12
- package/src/components/ChangeSlippageButton.tsx +4 -8
- package/src/components/HeaderButtons.tsx +11 -4
- package/src/components/Layout.tsx +37 -5
- package/src/components/RoutesOverview.tsx +60 -0
- package/src/components/SwapDetailsPlaceholder.tsx +32 -0
- package/src/components/TokenInfo.tsx +125 -77
- package/src/components/TokenPreview.tsx +178 -0
- package/src/components/UpdateUrl.tsx +1 -3
- package/src/components/warnings/BalanceWarnings.tsx +1 -0
- package/src/components/warnings/HighSlippageWarning.tsx +4 -7
- package/src/components/warnings/MinRequiredSlippage.tsx +9 -4
- package/src/constants/navigationRoutes.ts +0 -1
- package/src/globalStyles.ts +3 -2
- package/src/hooks/useConfirmSwap.ts +2 -1
- package/src/hooks/useNavigateBack.ts +3 -3
- package/src/hooks/useTheme.ts +9 -9
- package/src/languages/en.json +9 -8
- package/src/lib.tsx +25 -3
- package/src/pages/ConfirmSwapPage.tsx +128 -20
- package/src/pages/HistoryPage.tsx +4 -4
- package/src/pages/Home.tsx +51 -42
- package/src/pages/LiquiditySourcesPage.tsx +2 -0
- package/src/pages/SelectTokenPage.tsx +3 -1
- package/src/pages/SettingsPage.tsx +3 -0
- package/src/pages/SwapDetailsPage.tsx +142 -6
- package/src/pages/WalletsPage.tsx +49 -16
- package/src/store/bestRoute.ts +114 -17
- package/src/store/ui.ts +4 -0
- package/src/store/wallets.ts +4 -1
- package/src/types/routing.ts +1 -1
- package/src/types/swap.ts +7 -0
- package/src/utils/common.ts +14 -0
- package/src/utils/date.ts +62 -0
- package/src/utils/routing.ts +23 -13
- package/src/utils/swap.ts +113 -11
- package/src/utils/time.ts +52 -0
- package/src/utils/wallets.ts +13 -4
- package/dist/components/Header.d.ts +0 -10
- package/dist/components/Header.d.ts.map +0 -1
- package/dist/pages/ConfirmWalletsPage.d.ts +0 -3
- package/dist/pages/ConfirmWalletsPage.d.ts.map +0 -1
- package/src/components/Header.tsx +0 -37
- package/src/pages/ConfirmWalletsPage.tsx +0 -80
package/src/lib.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
2
|
+
import React, { useEffect, useState } from 'react';
|
|
3
3
|
import { AppRouter } from './components/AppRouter';
|
|
4
4
|
import { useMetaStore } from './store/meta';
|
|
5
5
|
import { Events, Provider } from '@rango-dev/wallets-core';
|
|
6
6
|
import { allProviders } from '@rango-dev/provider-all';
|
|
7
7
|
import { EventHandler } from '@rango-dev/wallets-core/dist/wallet';
|
|
8
|
-
import { Network } from '@rango-dev/wallets-shared';
|
|
8
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
9
9
|
import {
|
|
10
10
|
prepareAccountsForWalletStore,
|
|
11
11
|
walletAndSupportedChainsNames,
|
|
@@ -41,6 +41,10 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
41
41
|
const { changeLanguage } = useSelectLanguage();
|
|
42
42
|
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
43
43
|
|
|
44
|
+
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
45
|
+
useState<string>('');
|
|
46
|
+
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
47
|
+
|
|
44
48
|
const evmBasedChainNames = blockchains
|
|
45
49
|
.filter(isEvmBlockchain)
|
|
46
50
|
.map((chain) => chain.name);
|
|
@@ -49,7 +53,7 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
49
53
|
type,
|
|
50
54
|
event,
|
|
51
55
|
value,
|
|
52
|
-
|
|
56
|
+
state,
|
|
53
57
|
supportedChains
|
|
54
58
|
) => {
|
|
55
59
|
if (event === Events.ACCOUNTS) {
|
|
@@ -67,6 +71,19 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
67
71
|
disconnectWallet(type);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
|
|
75
|
+
if (event === Events.ACCOUNTS && state.connected) {
|
|
76
|
+
const key = `${type}-${state.network}-${value}`;
|
|
77
|
+
|
|
78
|
+
if (state.connected) {
|
|
79
|
+
setLastConnectedWalletWithNetwork(key);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (event === Events.NETWORK && state.network) {
|
|
84
|
+
const key = `${type}-${state.network}`;
|
|
85
|
+
setLastConnectedWalletWithNetwork(key);
|
|
86
|
+
}
|
|
70
87
|
};
|
|
71
88
|
let providers = allProviders();
|
|
72
89
|
|
|
@@ -108,6 +125,11 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
108
125
|
title={configs.title}
|
|
109
126
|
titleSize={configs.titleSize}
|
|
110
127
|
titleWeight={configs.titleWeight}
|
|
128
|
+
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
129
|
+
disconnectedWallet={disconnectedWallet}
|
|
130
|
+
clearDisconnectedWallet={() => {
|
|
131
|
+
setDisconnectedWallet(undefined);
|
|
132
|
+
}}
|
|
111
133
|
>
|
|
112
134
|
<Layout configs={configs} />
|
|
113
135
|
</AppRouter>
|
|
@@ -1,41 +1,105 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { useNavigate } from 'react-router-dom';
|
|
3
|
-
import { ConfirmSwap } from '@rango-dev/ui';
|
|
4
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
4
|
+
import { useWalletsStore } from '../store/wallets';
|
|
5
|
+
import { useWallets } from '@rango-dev/wallets-core';
|
|
8
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
9
|
-
import {
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
getKeplrCompatibleConnectedWallets,
|
|
9
|
+
getRequiredChains,
|
|
10
|
+
getSelectableWallets,
|
|
11
|
+
isExperimentalChain,
|
|
12
|
+
} from '../utils/wallets';
|
|
13
|
+
import {
|
|
14
|
+
calcOutputUsdValue,
|
|
15
|
+
getTotalFeeInUsd,
|
|
16
|
+
requiredWallets,
|
|
17
|
+
} from '../utils/swap';
|
|
18
|
+
import { decimalNumber, numberToString } from '../utils/numbers';
|
|
19
|
+
import { useMetaStore } from '../store/meta';
|
|
20
|
+
import { Network, WalletType } from '@rango-dev/wallets-shared';
|
|
21
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
22
|
+
import { TokenPreview } from '../components/TokenPreview';
|
|
23
|
+
// @ts-ignore // TODO: fix error in tsc build
|
|
24
|
+
import { t } from 'i18next';
|
|
25
|
+
import { Spacer, ConfirmSwap } from '@rango-dev/ui';
|
|
26
|
+
import RoutesOverview from '../components/RoutesOverview';
|
|
11
27
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
12
|
-
import { useUiStore } from '../store/ui';
|
|
13
28
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
29
|
+
import { useSettingsStore } from '../store/settings';
|
|
30
|
+
import { useUiStore } from '../store/ui';
|
|
14
31
|
import { ConfirmSwapErrorTypes } from '../types';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
32
|
+
import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
|
|
33
|
+
import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
|
|
34
|
+
import { ConfirmSwapExtraMessages } from '../components/warnings/ConfirmSwapExtraMessages';
|
|
35
|
+
import { getBestRouteStatus } from '../utils/routing';
|
|
17
36
|
|
|
18
37
|
export function ConfirmSwapPage() {
|
|
19
|
-
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
20
|
-
const { navigateBackFrom } = useNavigateBack();
|
|
21
|
-
const { manager } = useManager();
|
|
22
38
|
const navigate = useNavigate();
|
|
23
|
-
|
|
39
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
24
40
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
25
41
|
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
26
|
-
const
|
|
27
|
-
|
|
42
|
+
const fetchingBestRouteError = useBestRouteStore.use.error();
|
|
43
|
+
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
44
|
+
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
45
|
+
const accounts = useWalletsStore.use.accounts();
|
|
46
|
+
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
47
|
+
const initSelectedWallets = useWalletsStore.use.initSelectedWallets();
|
|
48
|
+
const setSelectedWallet = useWalletsStore.use.setSelectedWallet();
|
|
28
49
|
const slippage = useSettingsStore.use.slippage();
|
|
29
50
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
30
|
-
|
|
51
|
+
|
|
52
|
+
const bestRouteloadingStatus = getBestRouteStatus(
|
|
53
|
+
fetchingBestRoute,
|
|
54
|
+
!!fetchingBestRouteError
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const { manager } = useManager();
|
|
31
58
|
const { loading, errors, warnings, confirmSwap } = useConfirmSwap();
|
|
32
59
|
|
|
60
|
+
const selectedSlippage = customSlippage || slippage;
|
|
61
|
+
|
|
33
62
|
const showHighSlippageWarning = !errors.find(
|
|
34
63
|
(error) => error.type === ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE
|
|
35
64
|
);
|
|
36
65
|
|
|
66
|
+
const { getWalletInfo, connect } = useWallets();
|
|
67
|
+
const confirmDisabled =
|
|
68
|
+
fetchingBestRoute ||
|
|
69
|
+
!requiredWallets(bestRoute).every((chain) =>
|
|
70
|
+
selectedWallets.map((wallet) => wallet.chain).includes(chain)
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const firstStep = bestRoute?.result?.swaps[0];
|
|
74
|
+
const lastStep =
|
|
75
|
+
bestRoute?.result?.swaps[bestRoute?.result?.swaps.length - 1];
|
|
76
|
+
|
|
77
|
+
const fromAmount = decimalNumber(firstStep?.fromAmount, 3);
|
|
78
|
+
const toAmount = decimalNumber(lastStep?.toAmount, 3);
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
initSelectedWallets();
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const selectableWallets = getSelectableWallets(
|
|
84
|
+
accounts,
|
|
85
|
+
selectedWallets,
|
|
86
|
+
getWalletInfo
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const handleConnectChain = (wallet: string) => {
|
|
90
|
+
const network = wallet as Network;
|
|
91
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).forEach(
|
|
92
|
+
(compatibleWallet: WalletType) => connect?.(compatibleWallet, network)
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
97
|
+
|
|
37
98
|
return (
|
|
38
99
|
<ConfirmSwap
|
|
100
|
+
requiredWallets={getRequiredChains(bestRoute)}
|
|
101
|
+
selectableWallets={selectableWallets}
|
|
102
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
|
|
39
103
|
onConfirm={() => {
|
|
40
104
|
confirmSwap?.().then((swap) => {
|
|
41
105
|
if (swap) {
|
|
@@ -51,8 +115,53 @@ export function ConfirmSwapPage() {
|
|
|
51
115
|
}
|
|
52
116
|
});
|
|
53
117
|
}}
|
|
54
|
-
|
|
55
|
-
|
|
118
|
+
onChange={(wallet) => setSelectedWallet(wallet)}
|
|
119
|
+
confirmDisabled={confirmDisabled}
|
|
120
|
+
handleConnectChain={(wallet) => handleConnectChain(wallet)}
|
|
121
|
+
isExperimentalChain={(wallet) =>
|
|
122
|
+
getKeplrCompatibleConnectedWallets(selectableWallets).length > 0
|
|
123
|
+
? isExperimentalChain(blockchains, wallet)
|
|
124
|
+
: false
|
|
125
|
+
}
|
|
126
|
+
previewInputs={
|
|
127
|
+
<>
|
|
128
|
+
<TokenPreview
|
|
129
|
+
chain={{
|
|
130
|
+
displayName: firstStep?.from.blockchain || '',
|
|
131
|
+
logo: firstStep?.from.blockchainLogo || '',
|
|
132
|
+
}}
|
|
133
|
+
token={{
|
|
134
|
+
symbol: firstStep?.from.symbol || '',
|
|
135
|
+
image: firstStep?.from.logo || '',
|
|
136
|
+
}}
|
|
137
|
+
usdValue={calcOutputUsdValue(fromAmount, firstStep?.from.usdPrice)}
|
|
138
|
+
amount={fromAmount}
|
|
139
|
+
label={t('From')}
|
|
140
|
+
loadingStatus={bestRouteloadingStatus}
|
|
141
|
+
/>
|
|
142
|
+
<Spacer size={12} direction="vertical" />
|
|
143
|
+
<TokenPreview
|
|
144
|
+
chain={{
|
|
145
|
+
displayName: lastStep?.to.blockchain || '',
|
|
146
|
+
logo: lastStep?.to.blockchainLogo || '',
|
|
147
|
+
}}
|
|
148
|
+
token={{
|
|
149
|
+
symbol: lastStep?.to.symbol || '',
|
|
150
|
+
image: lastStep?.to.logo || '',
|
|
151
|
+
}}
|
|
152
|
+
usdValue={calcOutputUsdValue(toAmount, lastStep?.to.usdPrice)}
|
|
153
|
+
amount={toAmount}
|
|
154
|
+
label={t('To')}
|
|
155
|
+
loadingStatus={bestRouteloadingStatus}
|
|
156
|
+
/>
|
|
157
|
+
</>
|
|
158
|
+
}
|
|
159
|
+
previewRoutes={
|
|
160
|
+
<RoutesOverview
|
|
161
|
+
routes={bestRoute}
|
|
162
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
163
|
+
/>
|
|
164
|
+
}
|
|
56
165
|
loading={loading}
|
|
57
166
|
errors={ConfirmSwapErrors(errors)}
|
|
58
167
|
warnings={ConfirmSwapWarnings(warnings)}
|
|
@@ -66,7 +175,6 @@ export function ConfirmSwapPage() {
|
|
|
66
175
|
? 'Proceed anyway!'
|
|
67
176
|
: 'Confirm swap!'
|
|
68
177
|
}
|
|
69
|
-
confirmButtonDisabled={fetchingBestRoute}
|
|
70
178
|
/>
|
|
71
179
|
);
|
|
72
180
|
}
|
|
@@ -6,6 +6,7 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
6
6
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
7
7
|
import { getPendingSwaps } from '../utils/queue';
|
|
8
8
|
import { useUiStore } from '../store/ui';
|
|
9
|
+
import { groupSwapsByDate } from '../utils/date';
|
|
9
10
|
|
|
10
11
|
export function HistoryPage() {
|
|
11
12
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
@@ -16,12 +17,11 @@ export function HistoryPage() {
|
|
|
16
17
|
|
|
17
18
|
return (
|
|
18
19
|
<History
|
|
19
|
-
//todo: move PendingSwap type to rango-types
|
|
20
|
-
//@ts-ignore
|
|
21
20
|
list={pendingSwaps}
|
|
22
|
-
|
|
21
|
+
groupBy={groupSwapsByDate}
|
|
22
|
+
onSwapClick={requestId => {
|
|
23
23
|
setSelectedSwap(requestId);
|
|
24
|
-
navigate(navigationRoutes.swaps + `/${requestId}
|
|
24
|
+
navigate(navigationRoutes.swaps + `/${requestId}`, { replace: true });
|
|
25
25
|
}}
|
|
26
26
|
onBack={navigateBackFrom.bind(null, navigationRoutes.swaps)}
|
|
27
27
|
/>
|
package/src/pages/Home.tsx
CHANGED
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
styled,
|
|
6
6
|
Typography,
|
|
7
7
|
VerticalSwapIcon,
|
|
8
|
+
Header,
|
|
8
9
|
} from '@rango-dev/ui';
|
|
9
|
-
import React, { useState } from 'react';
|
|
10
|
+
import React, { useEffect, useState } from 'react';
|
|
10
11
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
11
|
-
import { Header } from '../components/Header';
|
|
12
12
|
import { TokenInfo } from '../components/TokenInfo';
|
|
13
13
|
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
14
14
|
import { BottomLogo } from '../components/BottomLogo';
|
|
@@ -33,20 +33,25 @@ import {
|
|
|
33
33
|
secondsToString,
|
|
34
34
|
totalArrivalTime,
|
|
35
35
|
} from '../utils/numbers';
|
|
36
|
+
import BigNumber from 'bignumber.js';
|
|
37
|
+
import { HeaderButtons } from '../components/HeaderButtons';
|
|
38
|
+
import { useUiStore } from '../store/ui';
|
|
36
39
|
|
|
37
40
|
const Container = styled('div', {
|
|
38
41
|
display: 'flex',
|
|
39
42
|
flexDirection: 'column',
|
|
40
|
-
justifyContent: 'center',
|
|
41
|
-
alignItems: 'center',
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
const
|
|
45
|
-
display: 'flex',
|
|
46
|
-
justifyContent: 'center',
|
|
47
|
-
alignItems: 'center',
|
|
45
|
+
const FromContainer = styled('div', {
|
|
48
46
|
position: 'relative',
|
|
49
|
-
|
|
47
|
+
paddingBottom: '$12',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const SwitchButtonContainer = styled('div', {
|
|
51
|
+
position: 'absolute',
|
|
52
|
+
bottom: '-12px',
|
|
53
|
+
left: '50%',
|
|
54
|
+
transform: 'translate(-50%, 10%)',
|
|
50
55
|
});
|
|
51
56
|
|
|
52
57
|
const BestRouteContainer = styled('div', {
|
|
@@ -64,9 +69,8 @@ interface PropTypes {
|
|
|
64
69
|
titleWeight?: number;
|
|
65
70
|
}
|
|
66
71
|
export function Home(props: PropTypes) {
|
|
67
|
-
const { title = 'SWAP'
|
|
72
|
+
const { title = 'SWAP' } = props;
|
|
68
73
|
|
|
69
|
-
const waningMessage = '';
|
|
70
74
|
const isRouterInContext = useInRouterContext();
|
|
71
75
|
const navigate = useNavigate();
|
|
72
76
|
const [count, setCount] = useState(0);
|
|
@@ -89,6 +93,7 @@ export function Home(props: PropTypes) {
|
|
|
89
93
|
const bestRouteError = useBestRouteStore.use.error();
|
|
90
94
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
91
95
|
const accounts = useWalletsStore.use.accounts();
|
|
96
|
+
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
92
97
|
|
|
93
98
|
const swithFromAndTo = () => {
|
|
94
99
|
setFromChain(toChain);
|
|
@@ -123,6 +128,7 @@ export function Home(props: PropTypes) {
|
|
|
123
128
|
outputUsdValue
|
|
124
129
|
);
|
|
125
130
|
|
|
131
|
+
const inputIsZero = inputAmount === '0';
|
|
126
132
|
const swapButtonState = getSwapButtonState(
|
|
127
133
|
loadingMetaStatus,
|
|
128
134
|
accounts,
|
|
@@ -131,40 +137,52 @@ export function Home(props: PropTypes) {
|
|
|
131
137
|
hasLimitError(bestRoute),
|
|
132
138
|
highValueLoss,
|
|
133
139
|
priceImpactCanNotBeComputed,
|
|
134
|
-
needsToWarnEthOnPath
|
|
140
|
+
needsToWarnEthOnPath,
|
|
141
|
+
inputIsZero
|
|
135
142
|
);
|
|
136
143
|
|
|
137
144
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
138
145
|
|
|
139
146
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
140
147
|
|
|
141
|
-
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
setCurrentPage(navigationRoutes.home);
|
|
150
|
+
|
|
151
|
+
return setCurrentPage.bind(null, '');
|
|
152
|
+
}, []);
|
|
153
|
+
|
|
142
154
|
return (
|
|
143
155
|
<Container>
|
|
144
156
|
<Header
|
|
145
157
|
title={title}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
type="From"
|
|
152
|
-
chain={fromChain}
|
|
153
|
-
token={fromToken}
|
|
154
|
-
onAmountChange={setInputAmount}
|
|
155
|
-
inputAmount={inputAmount}
|
|
158
|
+
suffix={
|
|
159
|
+
<HeaderButtons
|
|
160
|
+
onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
|
|
161
|
+
/>
|
|
162
|
+
}
|
|
156
163
|
/>
|
|
157
|
-
<
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
<FromContainer>
|
|
165
|
+
<TokenInfo
|
|
166
|
+
type="From"
|
|
167
|
+
chain={fromChain}
|
|
168
|
+
token={fromToken}
|
|
169
|
+
onAmountChange={setInputAmount}
|
|
170
|
+
inputAmount={inputAmount}
|
|
171
|
+
/>
|
|
172
|
+
<SwitchButtonContainer>
|
|
173
|
+
<Button variant="ghost" onClick={swithFromAndTo}>
|
|
174
|
+
<VerticalSwapIcon size={32} />
|
|
175
|
+
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
176
|
+
</Button>
|
|
177
|
+
</SwitchButtonContainer>
|
|
178
|
+
</FromContainer>
|
|
163
179
|
<TokenInfo
|
|
164
180
|
type="To"
|
|
165
181
|
chain={toChain}
|
|
166
182
|
token={toToken}
|
|
167
|
-
outputAmount={
|
|
183
|
+
outputAmount={
|
|
184
|
+
outputAmount ? new BigNumber(outputAmount) : new BigNumber(0)
|
|
185
|
+
}
|
|
168
186
|
outputUsdValue={outputUsdValue}
|
|
169
187
|
/>
|
|
170
188
|
{showBestRoute && (
|
|
@@ -179,13 +197,9 @@ export function Home(props: PropTypes) {
|
|
|
179
197
|
/>
|
|
180
198
|
</BestRouteContainer>
|
|
181
199
|
)}
|
|
182
|
-
{(errorMessage ||
|
|
200
|
+
{(errorMessage || hasLimitError(bestRoute)) && (
|
|
183
201
|
<Alerts>
|
|
184
|
-
{errorMessage &&
|
|
185
|
-
<Alert type="error">
|
|
186
|
-
{<Typography variant="body2">{errorMessage}</Typography>}
|
|
187
|
-
</Alert>
|
|
188
|
-
)}
|
|
202
|
+
{errorMessage && <Alert type="error">{errorMessage}</Alert>}
|
|
189
203
|
{hasLimitError(bestRoute) && (
|
|
190
204
|
<Alert type="error" title={`${swap?.swapperId} Limit`}>
|
|
191
205
|
<>
|
|
@@ -200,11 +214,6 @@ export function Home(props: PropTypes) {
|
|
|
200
214
|
</>
|
|
201
215
|
</Alert>
|
|
202
216
|
)}
|
|
203
|
-
{waningMessage && (
|
|
204
|
-
<Alert type="warning">
|
|
205
|
-
<Typography variant="body2">{waningMessage}</Typography>
|
|
206
|
-
</Alert>
|
|
207
|
-
)}
|
|
208
217
|
</Alerts>
|
|
209
218
|
)}
|
|
210
219
|
<Footer>
|
|
@@ -217,7 +226,7 @@ export function Home(props: PropTypes) {
|
|
|
217
226
|
if (swapButtonState.title === 'Connect Wallet')
|
|
218
227
|
navigate(navigationRoutes.wallets);
|
|
219
228
|
else {
|
|
220
|
-
navigate(navigationRoutes.
|
|
229
|
+
navigate(navigationRoutes.confirmSwap, { replace: true });
|
|
221
230
|
}
|
|
222
231
|
}}
|
|
223
232
|
>
|
|
@@ -11,6 +11,7 @@ interface PropTypes {
|
|
|
11
11
|
}
|
|
12
12
|
export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
13
13
|
const swappers = useMetaStore.use.meta().swappers;
|
|
14
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
14
15
|
const toggleLiquiditySource = useSettingsStore.use.toggleLiquiditySource();
|
|
15
16
|
const disabledLiquiditySources =
|
|
16
17
|
useSettingsStore.use.disabledLiquiditySources();
|
|
@@ -59,6 +60,7 @@ export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
|
59
60
|
toggleLiquiditySource(liquiditySource.title)
|
|
60
61
|
}
|
|
61
62
|
onBack={navigateBackFrom.bind(null, navigationRoutes.liquiditySources)}
|
|
63
|
+
loadingStatus={loadingMetaStatus}
|
|
62
64
|
/>
|
|
63
65
|
);
|
|
64
66
|
}
|
|
@@ -5,6 +5,7 @@ import { Token } from 'rango-sdk';
|
|
|
5
5
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
7
|
import { tokensAreEqual } from '../utils/wallets';
|
|
8
|
+
import { useMetaStore } from '../store/meta';
|
|
8
9
|
|
|
9
10
|
interface PropTypes {
|
|
10
11
|
type: 'from' | 'to';
|
|
@@ -41,12 +42,12 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
41
42
|
tokensAreEqual(supportedToken, token)
|
|
42
43
|
)
|
|
43
44
|
);
|
|
44
|
-
console.log(supportedSourceTokens);
|
|
45
45
|
|
|
46
46
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
47
47
|
const toToken = useBestRouteStore.use.toToken();
|
|
48
48
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
49
49
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
50
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
50
51
|
|
|
51
52
|
return (
|
|
52
53
|
<TokenSelector
|
|
@@ -59,6 +60,7 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
59
60
|
navigateBackFrom(navigationRoutes.fromToken);
|
|
60
61
|
}}
|
|
61
62
|
onBack={navigateBackFrom.bind(null, navigationRoutes.fromToken)}
|
|
63
|
+
loadingStatus={loadingMetaStatus}
|
|
62
64
|
/>
|
|
63
65
|
);
|
|
64
66
|
}
|
|
@@ -30,6 +30,8 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
|
30
30
|
|
|
31
31
|
const infiniteApprove = useSettingsStore.use.infiniteApprove();
|
|
32
32
|
const toggleInfiniteApprove = useSettingsStore.use.toggleInfiniteApprove();
|
|
33
|
+
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
34
|
+
|
|
33
35
|
const uniqueSwappersGroups: Array<{
|
|
34
36
|
title: string;
|
|
35
37
|
logo: string;
|
|
@@ -93,6 +95,7 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
|
93
95
|
onThemeChange={setTheme}
|
|
94
96
|
infiniteApprove={infiniteApprove}
|
|
95
97
|
toggleInfiniteApprove={toggleInfiniteApprove}
|
|
98
|
+
loadingStatus={loadingMetaStatus}
|
|
96
99
|
/>
|
|
97
100
|
);
|
|
98
101
|
}
|