@rango-dev/widget-embedded 0.1.10-next.80 → 0.1.10-next.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/ChangeSlippageButton.d.ts +2 -0
- package/dist/components/ChangeSlippageButton.d.ts.map +1 -0
- package/dist/components/ConfirmSwapErrors.d.ts +3 -0
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -0
- package/dist/components/ConfirmSwapWarnings.d.ts +3 -0
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -0
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/UpdateUrl.d.ts.map +1 -1
- package/dist/components/warnings/BalanceWarnings.d.ts +6 -0
- package/dist/components/warnings/BalanceWarnings.d.ts.map +1 -0
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts +6 -0
- package/dist/components/warnings/ConfirmSwapExtraMessages.d.ts.map +1 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts +6 -0
- package/dist/components/warnings/HighSlippageWarning.d.ts.map +1 -0
- package/dist/components/warnings/MinRequiredSlippage.d.ts +6 -0
- package/dist/components/warnings/MinRequiredSlippage.d.ts.map +1 -0
- package/dist/constants/swapSettings.d.ts +6 -0
- package/dist/constants/swapSettings.d.ts.map +1 -0
- package/dist/hooks/useNavigateBack.d.ts +4 -0
- package/dist/hooks/useNavigateBack.d.ts.map +1 -0
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/ConfirmWalletsPage.d.ts +0 -5
- package/dist/pages/ConfirmWalletsPage.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/SelectChainPage.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.map +1 -1
- package/dist/store/bestRoute.d.ts +1 -0
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/confirmSwap.d.ts +35 -0
- package/dist/store/confirmSwap.d.ts.map +1 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/store/ui.d.ts +2 -0
- package/dist/store/ui.d.ts.map +1 -0
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.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 +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts +5 -0
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +5 -7
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +31 -3
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +2 -3
- package/dist/utils/wallets.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +1814 -1327
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +1814 -1327
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +1818 -1331
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AppRouter.tsx +38 -3
- package/src/components/AppRoutes.tsx +8 -2
- package/src/components/ChangeSlippageButton.tsx +23 -0
- package/src/components/ConfirmSwapErrors.tsx +38 -0
- package/src/components/ConfirmSwapWarnings.tsx +38 -0
- package/src/components/Layout.tsx +22 -6
- package/src/components/UpdateUrl.tsx +100 -18
- package/src/components/warnings/BalanceWarnings.tsx +16 -0
- package/src/components/warnings/ConfirmSwapExtraMessages.tsx +14 -0
- package/src/components/warnings/HighSlippageWarning.tsx +21 -0
- package/src/components/warnings/MinRequiredSlippage.tsx +18 -0
- package/src/constants/navigationRoutes.ts +2 -2
- package/src/constants/swapSettings.ts +9 -0
- package/src/hooks/useNavigateBack.ts +37 -0
- package/src/pages/ConfirmSwapPage.tsx +30 -8
- package/src/pages/ConfirmWalletsPage.tsx +30 -17
- package/src/pages/HistoryPage.tsx +4 -4
- package/src/pages/Home.tsx +79 -36
- package/src/pages/LiquiditySourcesPage.tsx +11 -8
- package/src/pages/SelectChainPage.tsx +9 -28
- package/src/pages/SelectTokenPage.tsx +38 -27
- package/src/pages/SettingsPage.tsx +26 -11
- package/src/pages/SwapDetailsPage.tsx +9 -3
- package/src/pages/WalletsPage.tsx +37 -22
- package/src/store/bestRoute.ts +147 -28
- package/src/store/confirmSwap.ts +327 -0
- package/src/store/settings.ts +44 -32
- package/src/store/ui.ts +15 -0
- package/src/store/wallets.ts +93 -80
- package/src/swapBox.tsx +5 -5
- package/src/types/index.ts +1 -0
- package/src/types/swap.ts +13 -0
- package/src/utils/common.ts +4 -0
- package/src/utils/numbers.ts +17 -0
- package/src/utils/routing.ts +28 -77
- package/src/utils/swap.ts +445 -67
- package/src/utils/wallets.ts +4 -19
- package/dist/hooks/useBestRoute.d.ts +0 -8
- package/dist/hooks/useBestRoute.d.ts.map +0 -1
- package/dist/hooks/useConfirmSwap.d.ts +0 -2
- package/dist/hooks/useConfirmSwap.d.ts.map +0 -1
- package/src/hooks/useBestRoute.ts +0 -70
- package/src/hooks/useConfirmSwap.ts +0 -268
|
@@ -4,6 +4,7 @@ import { TransactionType } from 'rango-sdk';
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { useNavigate } from 'react-router-dom';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
7
8
|
|
|
8
9
|
export const pendingSwap: PendingSwap[] = [
|
|
9
10
|
{
|
|
@@ -824,13 +825,12 @@ export const pendingSwap: PendingSwap[] = [
|
|
|
824
825
|
|
|
825
826
|
export function HistoryPage() {
|
|
826
827
|
const navigate = useNavigate();
|
|
828
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
827
829
|
return (
|
|
828
830
|
<History
|
|
829
831
|
list={pendingSwap}
|
|
830
|
-
onSwapClick={(
|
|
831
|
-
onBack={()
|
|
832
|
-
navigate(-1);
|
|
833
|
-
}}
|
|
832
|
+
onSwapClick={navigate.bind(null, navigationRoutes.swapDetails)}
|
|
833
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.history)}
|
|
834
834
|
/>
|
|
835
835
|
);
|
|
836
836
|
}
|
package/src/pages/Home.tsx
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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';
|
|
3
10
|
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
4
11
|
import { Header } from '../components/Header';
|
|
5
12
|
import { TokenInfo } from '../components/TokenInfo';
|
|
6
|
-
import { useBestRouteStore } from '../store/bestRoute';
|
|
13
|
+
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
7
14
|
import { BottomLogo } from '../components/BottomLogo';
|
|
8
15
|
import { SwithFromAndTo } from '../components/SwitchFromAndTo';
|
|
9
16
|
import { Footer } from '../components/Footer';
|
|
10
17
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
11
|
-
import { useBestRoute } from '../hooks/useBestRoute';
|
|
12
18
|
import { useMetaStore } from '../store/meta';
|
|
13
19
|
import { useWalletsStore } from '../store/wallets';
|
|
14
20
|
import { errorMessages } from '../constants/errors';
|
|
15
21
|
import {
|
|
16
|
-
|
|
22
|
+
getSwapButtonState,
|
|
17
23
|
getOutputRatio,
|
|
18
24
|
hasLimitError,
|
|
19
25
|
outputRatioHasWarning,
|
|
20
26
|
canComputePriceImpact,
|
|
27
|
+
LimitErrorMessage,
|
|
28
|
+
getTotalFeeInUsd,
|
|
29
|
+
hasHighFee,
|
|
21
30
|
} from '../utils/swap';
|
|
31
|
+
import {
|
|
32
|
+
numberToString,
|
|
33
|
+
secondsToString,
|
|
34
|
+
totalArrivalTime,
|
|
35
|
+
} from '../utils/numbers';
|
|
22
36
|
|
|
23
37
|
const Container = styled('div', {
|
|
24
38
|
display: 'flex',
|
|
@@ -41,6 +55,7 @@ const BestRouteContainer = styled('div', {
|
|
|
41
55
|
});
|
|
42
56
|
|
|
43
57
|
const Alerts = styled('div', {
|
|
58
|
+
width: '100%',
|
|
44
59
|
paddingTop: '$16',
|
|
45
60
|
});
|
|
46
61
|
|
|
@@ -57,13 +72,15 @@ export function Home() {
|
|
|
57
72
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
58
73
|
const setToChain = useBestRouteStore.use.setToChain();
|
|
59
74
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
60
|
-
const setBestRoute = useBestRouteStore.use.setBestRoute();
|
|
61
75
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
62
76
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
63
77
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
64
78
|
const outputAmount = useBestRouteStore.use.outputAmount();
|
|
65
79
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
66
80
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
81
|
+
const tokens = useMetaStore.use.meta().tokens;
|
|
82
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
83
|
+
const bestRouteError = useBestRouteStore.use.error();
|
|
67
84
|
|
|
68
85
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
69
86
|
const accounts = useWalletsStore.use.accounts();
|
|
@@ -77,53 +94,48 @@ export function Home() {
|
|
|
77
94
|
setCount((prev) => prev + 1);
|
|
78
95
|
};
|
|
79
96
|
|
|
80
|
-
const { data, loading: fetchingBestRoute, error: bestRouteError, retry } = useBestRoute();
|
|
81
|
-
|
|
82
|
-
const noConnectedWallet = accounts.length > 0;
|
|
83
|
-
|
|
84
|
-
const noRoutesFound = !bestRoute?.result;
|
|
85
|
-
|
|
86
97
|
const errorMessage =
|
|
87
|
-
loadingMetaStatus === 'failed'
|
|
98
|
+
loadingMetaStatus === 'failed'
|
|
99
|
+
? errorMessages.genericServerError
|
|
100
|
+
: bestRouteError;
|
|
88
101
|
|
|
89
102
|
const needsToWarnEthOnPath = false;
|
|
90
103
|
|
|
91
|
-
const showBestRoute =
|
|
104
|
+
const showBestRoute =
|
|
105
|
+
inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
|
|
92
106
|
|
|
93
107
|
const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
|
|
94
108
|
|
|
95
109
|
const highValueLoss = outputRatioHasWarning(inputUsdValue, outToInRatio);
|
|
96
110
|
|
|
111
|
+
const { fromAmountRangeError, recommendation, swap } =
|
|
112
|
+
LimitErrorMessage(bestRoute);
|
|
113
|
+
|
|
97
114
|
const priceImpactCanNotBeComputed = !canComputePriceImpact(
|
|
98
115
|
bestRoute,
|
|
99
116
|
inputAmount,
|
|
100
117
|
inputUsdValue,
|
|
101
|
-
outputUsdValue
|
|
118
|
+
outputUsdValue
|
|
102
119
|
);
|
|
103
120
|
|
|
104
|
-
const
|
|
121
|
+
const swapButtonState = getSwapButtonState(
|
|
122
|
+
loadingMetaStatus,
|
|
105
123
|
accounts,
|
|
106
124
|
fetchingBestRoute,
|
|
125
|
+
bestRoute,
|
|
107
126
|
hasLimitError(bestRoute),
|
|
108
127
|
highValueLoss,
|
|
109
128
|
priceImpactCanNotBeComputed,
|
|
110
|
-
needsToWarnEthOnPath
|
|
129
|
+
needsToWarnEthOnPath
|
|
111
130
|
);
|
|
112
131
|
|
|
113
|
-
const
|
|
114
|
-
loadingMetaStatus != 'success' ||
|
|
115
|
-
fetchingBestRoute ||
|
|
116
|
-
highValueLoss ||
|
|
117
|
-
(noConnectedWallet && noRoutesFound) ||
|
|
118
|
-
hasLimitError(bestRoute);
|
|
132
|
+
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
119
133
|
|
|
120
|
-
|
|
121
|
-
setBestRoute(data);
|
|
122
|
-
}, [data]);
|
|
134
|
+
const highFee = hasHighFee(totalFeeInUsd);
|
|
123
135
|
|
|
124
136
|
return (
|
|
125
137
|
<Container>
|
|
126
|
-
<Header onClickRefresh={
|
|
138
|
+
<Header onClickRefresh={fetchBestRoute} />
|
|
127
139
|
<TokenInfo
|
|
128
140
|
type="From"
|
|
129
141
|
chain={fromChain}
|
|
@@ -146,13 +158,42 @@ export function Home() {
|
|
|
146
158
|
/>
|
|
147
159
|
{showBestRoute && (
|
|
148
160
|
<BestRouteContainer>
|
|
149
|
-
<BestRoute
|
|
161
|
+
<BestRoute
|
|
162
|
+
error={bestRouteError}
|
|
163
|
+
loading={fetchingBestRoute}
|
|
164
|
+
data={bestRoute}
|
|
165
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
166
|
+
feeWarning={highFee}
|
|
167
|
+
totalTime={secondsToString(totalArrivalTime(bestRoute))}
|
|
168
|
+
/>
|
|
150
169
|
</BestRouteContainer>
|
|
151
170
|
)}
|
|
152
|
-
{(errorMessage || waningMessage) && (
|
|
171
|
+
{(errorMessage || waningMessage || hasLimitError(bestRoute)) && (
|
|
153
172
|
<Alerts>
|
|
154
|
-
{errorMessage &&
|
|
155
|
-
|
|
173
|
+
{errorMessage && (
|
|
174
|
+
<Alert type="error">
|
|
175
|
+
{<Typography variant="body2">{errorMessage}</Typography>}
|
|
176
|
+
</Alert>
|
|
177
|
+
)}
|
|
178
|
+
{hasLimitError(bestRoute) && (
|
|
179
|
+
<Alert type="error" title={`${swap?.swapperId} Limit`}>
|
|
180
|
+
<>
|
|
181
|
+
<Typography variant="body2">{fromAmountRangeError}</Typography>
|
|
182
|
+
<br />
|
|
183
|
+
<Typography variant="body2">
|
|
184
|
+
Yours: {numberToString(swap?.fromAmount || null)}
|
|
185
|
+
{swap?.from.symbol}
|
|
186
|
+
</Typography>
|
|
187
|
+
<br />
|
|
188
|
+
<Typography variant="body2">{recommendation}</Typography>
|
|
189
|
+
</>
|
|
190
|
+
</Alert>
|
|
191
|
+
)}
|
|
192
|
+
{waningMessage && (
|
|
193
|
+
<Alert type="warning">
|
|
194
|
+
<Typography variant="body2">{waningMessage}</Typography>
|
|
195
|
+
</Alert>
|
|
196
|
+
)}
|
|
156
197
|
</Alerts>
|
|
157
198
|
)}
|
|
158
199
|
<Footer>
|
|
@@ -160,17 +201,19 @@ export function Home() {
|
|
|
160
201
|
type="primary"
|
|
161
202
|
align="grow"
|
|
162
203
|
size="large"
|
|
163
|
-
disabled={
|
|
204
|
+
disabled={swapButtonState.disabled}
|
|
164
205
|
onClick={() => {
|
|
165
|
-
if (
|
|
206
|
+
if (swapButtonState.title === 'Connect Wallet')
|
|
207
|
+
navigate(navigationRoutes.wallets);
|
|
166
208
|
else {
|
|
167
209
|
navigate(navigationRoutes.confirmWallets);
|
|
168
210
|
}
|
|
169
|
-
}}
|
|
170
|
-
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
{swapButtonState.title}
|
|
171
214
|
</Button>
|
|
172
215
|
<BottomLogo />
|
|
173
216
|
</Footer>
|
|
174
217
|
</Container>
|
|
175
218
|
);
|
|
176
|
-
}
|
|
219
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LiquiditySourcesSelector } from '@rango-dev/ui';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
4
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
4
5
|
import { useMetaStore } from '../store/meta';
|
|
5
6
|
import { useSettingsStore } from '../store/settings';
|
|
6
7
|
import { removeDuplicateFrom } from '../utils/common';
|
|
@@ -8,10 +9,12 @@ import { removeDuplicateFrom } from '../utils/common';
|
|
|
8
9
|
export function LiquiditySourcePage() {
|
|
9
10
|
const { swappers } = useMetaStore.use.meta();
|
|
10
11
|
const toggleLiquiditySource = useSettingsStore.use.toggleLiquiditySource();
|
|
11
|
-
const disabledLiquiditySources =
|
|
12
|
-
|
|
12
|
+
const disabledLiquiditySources =
|
|
13
|
+
useSettingsStore.use.disabledLiquiditySources();
|
|
14
|
+
const toggleAllLiquiditySources =
|
|
15
|
+
useSettingsStore.use.toggleAllLiquiditySources();
|
|
13
16
|
|
|
14
|
-
const
|
|
17
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
15
18
|
|
|
16
19
|
const uniqueSwappersGroups: Array<{
|
|
17
20
|
title: string;
|
|
@@ -40,10 +43,10 @@ export function LiquiditySourcePage() {
|
|
|
40
43
|
<LiquiditySourcesSelector
|
|
41
44
|
toggleAll={toggleAllLiquiditySources}
|
|
42
45
|
list={uniqueSwappersGroups}
|
|
43
|
-
onChange={(liquiditySource) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
46
|
+
onChange={(liquiditySource) =>
|
|
47
|
+
toggleLiquiditySource(liquiditySource.title)
|
|
48
|
+
}
|
|
49
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.liquiditySources)}
|
|
47
50
|
/>
|
|
48
51
|
);
|
|
49
52
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { BlockchainSelector } from '@rango-dev/ui';
|
|
3
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
4
|
import { useMetaStore } from '../store/meta';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { BlockchainMeta } from 'rango-sdk';
|
|
8
|
-
import { removeDuplicateFrom } from '../utils/common';
|
|
5
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
9
7
|
|
|
10
8
|
interface PropTypes {
|
|
11
9
|
type: 'from' | 'to';
|
|
@@ -13,7 +11,6 @@ interface PropTypes {
|
|
|
13
11
|
|
|
14
12
|
export function SelectChainPage(props: PropTypes) {
|
|
15
13
|
const { type } = props;
|
|
16
|
-
const accounts = useWalletsStore.use.accounts();
|
|
17
14
|
|
|
18
15
|
const { blockchains } = useMetaStore.use.meta();
|
|
19
16
|
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
@@ -24,39 +21,23 @@ export function SelectChainPage(props: PropTypes) {
|
|
|
24
21
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
25
22
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
26
23
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const [list, setList] = useState(blockchains);
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
let chainSortedByConnectedWallets: BlockchainMeta[] = [];
|
|
33
|
-
if (accounts.length !== 0) {
|
|
34
|
-
const connectedChains = removeDuplicateFrom(accounts.map((account) => account.chain));
|
|
35
|
-
chainSortedByConnectedWallets = blockchains.sort(
|
|
36
|
-
(blockchainA, blockchainB) =>
|
|
37
|
-
connectedChains.lastIndexOf(blockchainA.name) -
|
|
38
|
-
connectedChains.lastIndexOf(blockchainB.name),
|
|
39
|
-
);
|
|
40
|
-
} else {
|
|
41
|
-
chainSortedByConnectedWallets = blockchains;
|
|
42
|
-
}
|
|
43
|
-
setList(chainSortedByConnectedWallets);
|
|
44
|
-
}, [blockchains.length, accounts.length]);
|
|
24
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
45
25
|
|
|
46
26
|
return (
|
|
47
27
|
<BlockchainSelector
|
|
48
28
|
type={type === 'from' ? 'Source' : 'Destination'}
|
|
49
|
-
list={
|
|
29
|
+
list={blockchains}
|
|
50
30
|
selected={type === 'from' ? fromChain : toChain}
|
|
51
31
|
loadingStatus={loadingStatus}
|
|
52
32
|
onChange={(chain) => {
|
|
53
33
|
if (type === 'from') setFromChain(chain);
|
|
54
34
|
else setToChain(chain);
|
|
55
|
-
if (type === 'from' && fromChain?.name != chain.name)
|
|
35
|
+
if (type === 'from' && fromChain?.name != chain.name)
|
|
36
|
+
setFromToken(null);
|
|
56
37
|
if (type === 'to' && toChain?.name != chain.name) setToToken(null);
|
|
57
|
-
|
|
38
|
+
navigateBackFrom(navigationRoutes.fromChain);
|
|
58
39
|
}}
|
|
59
|
-
onBack={
|
|
40
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.fromChain)}
|
|
60
41
|
/>
|
|
61
42
|
);
|
|
62
43
|
}
|
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import { TokenSelector } from '@rango-dev/ui';
|
|
3
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
4
|
import { useMetaStore } from '../store/meta';
|
|
5
|
-
import { useNavigate } from 'react-router-dom';
|
|
6
5
|
import { Token } from 'rango-sdk';
|
|
7
6
|
import { numberToString } from '../utils/numbers';
|
|
8
7
|
import BigNumber from 'bignumber.js';
|
|
@@ -10,6 +9,8 @@ import { getBalanceFromWallet } from '../utils/wallets';
|
|
|
10
9
|
import { useWalletsStore } from '../store/wallets';
|
|
11
10
|
import { sortedTokens } from '../utils/wallets';
|
|
12
11
|
import { ZERO } from '../constants/numbers';
|
|
12
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
13
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
13
14
|
|
|
14
15
|
interface PropTypes {
|
|
15
16
|
type: 'from' | 'to';
|
|
@@ -24,7 +25,7 @@ export interface TokenWithBalance extends Token {
|
|
|
24
25
|
|
|
25
26
|
export function SelectTokenPage(props: PropTypes) {
|
|
26
27
|
const { type } = props;
|
|
27
|
-
const
|
|
28
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
28
29
|
|
|
29
30
|
const { tokens } = useMetaStore.use.meta();
|
|
30
31
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
@@ -41,30 +42,40 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
41
42
|
return token.blockchain === toChain?.name;
|
|
42
43
|
});
|
|
43
44
|
|
|
44
|
-
const TokensWithBalance: TokenWithBalance[] = tokenWithSelectedChain.map(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
getBalanceFromWallet(balance, token.blockchain, token.symbol, token.address)?.amount ||
|
|
48
|
-
ZERO,
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
let tokenUsdValue = '';
|
|
53
|
-
if (token.usdPrice)
|
|
54
|
-
tokenUsdValue = numberToString(
|
|
45
|
+
const TokensWithBalance: TokenWithBalance[] = tokenWithSelectedChain.map(
|
|
46
|
+
(token) => {
|
|
47
|
+
const tokenAmount = numberToString(
|
|
55
48
|
new BigNumber(
|
|
56
|
-
getBalanceFromWallet(
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
getBalanceFromWallet(
|
|
50
|
+
balance,
|
|
51
|
+
token.blockchain,
|
|
52
|
+
token.symbol,
|
|
53
|
+
token.address
|
|
54
|
+
)?.amount || ZERO
|
|
55
|
+
)
|
|
59
56
|
);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
57
|
+
|
|
58
|
+
let tokenUsdValue = '';
|
|
59
|
+
if (token.usdPrice)
|
|
60
|
+
tokenUsdValue = numberToString(
|
|
61
|
+
new BigNumber(
|
|
62
|
+
getBalanceFromWallet(
|
|
63
|
+
balance,
|
|
64
|
+
token.blockchain,
|
|
65
|
+
token.symbol,
|
|
66
|
+
token.address
|
|
67
|
+
)?.amount || ZERO
|
|
68
|
+
).multipliedBy(token.usdPrice)
|
|
69
|
+
);
|
|
70
|
+
return {
|
|
71
|
+
...token,
|
|
72
|
+
balance: {
|
|
73
|
+
amount: tokenAmount !== '0' ? tokenAmount : '',
|
|
74
|
+
usdValue: tokenUsdValue !== '0' ? tokenUsdValue : '',
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
);
|
|
68
79
|
|
|
69
80
|
const sortedTokenList = sortedTokens(TokensWithBalance, type, balance);
|
|
70
81
|
|
|
@@ -76,9 +87,9 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
76
87
|
onChange={(token) => {
|
|
77
88
|
if (type === 'from') setFromToken(token);
|
|
78
89
|
else setToToken(token);
|
|
79
|
-
|
|
90
|
+
navigateBackFrom(navigationRoutes.fromToken);
|
|
80
91
|
}}
|
|
81
|
-
onBack={
|
|
92
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.fromToken)}
|
|
82
93
|
/>
|
|
83
94
|
);
|
|
84
|
-
}
|
|
95
|
+
}
|
|
@@ -5,29 +5,39 @@ import { useMetaStore } from '../store/meta';
|
|
|
5
5
|
import { useNavigate } from 'react-router-dom';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
7
|
import { removeDuplicateFrom } from '../utils/common';
|
|
8
|
+
import {
|
|
9
|
+
MAX_SLIPPAGE,
|
|
10
|
+
MIN_SLIPPGAE,
|
|
11
|
+
SLIPPAGES,
|
|
12
|
+
} from '../constants/swapSettings';
|
|
13
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
8
14
|
|
|
9
15
|
export function SettingsPage() {
|
|
10
16
|
const slippage = useSettingsStore.use.slippage();
|
|
11
17
|
const setSlippage = useSettingsStore.use.setSlippage();
|
|
12
|
-
const disabledLiquiditySources =
|
|
18
|
+
const disabledLiquiditySources =
|
|
19
|
+
useSettingsStore.use.disabledLiquiditySources();
|
|
13
20
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
14
21
|
const setCustomSlippage = useSettingsStore.use.setCustomSlippage();
|
|
15
22
|
const theme = useSettingsStore.use.theme();
|
|
16
23
|
const setTheme = useSettingsStore.use.setTheme();
|
|
17
24
|
const { swappers } = useMetaStore.use.meta();
|
|
18
25
|
const navigate = useNavigate();
|
|
26
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
19
27
|
|
|
28
|
+
const infiniteApprove = useSettingsStore.use.infiniteApprove();
|
|
29
|
+
const toggleInfiniteApprove = useSettingsStore.use.toggleInfiniteApprove();
|
|
20
30
|
const uniqueSwappersGroups: Array<{
|
|
21
31
|
title: string;
|
|
22
32
|
logo: string;
|
|
23
33
|
type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
24
34
|
selected: boolean;
|
|
25
35
|
}> = [];
|
|
26
|
-
removeDuplicateFrom(swappers.map(
|
|
27
|
-
.map(
|
|
28
|
-
return swappers.find(
|
|
36
|
+
removeDuplicateFrom(swappers.map(s => s.swapperGroup))
|
|
37
|
+
.map(swapperGroup => {
|
|
38
|
+
return swappers.find(s => s.swapperGroup === swapperGroup);
|
|
29
39
|
})
|
|
30
|
-
.find(
|
|
40
|
+
.find(s => {
|
|
31
41
|
if (s) {
|
|
32
42
|
for (const type of s.types) {
|
|
33
43
|
uniqueSwappersGroups.push({
|
|
@@ -42,19 +52,24 @@ export function SettingsPage() {
|
|
|
42
52
|
|
|
43
53
|
return (
|
|
44
54
|
<Settings
|
|
45
|
-
slippages={
|
|
55
|
+
slippages={SLIPPAGES}
|
|
46
56
|
selectedSlippage={slippage}
|
|
47
|
-
onSlippageChange={
|
|
57
|
+
onSlippageChange={slippage => setSlippage(slippage)}
|
|
48
58
|
liquiditySources={uniqueSwappersGroups}
|
|
49
59
|
selectedLiquiditySources={uniqueSwappersGroups.filter((s) => s.selected)}
|
|
50
|
-
onLiquiditySourcesClick={
|
|
51
|
-
|
|
60
|
+
onLiquiditySourcesClick={navigate.bind(
|
|
61
|
+
null,
|
|
62
|
+
navigationRoutes.liquiditySources
|
|
63
|
+
)}
|
|
64
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.settings)}
|
|
52
65
|
customSlippage={customSlippage || NaN}
|
|
53
66
|
onCustomSlippageChange={setCustomSlippage}
|
|
54
|
-
minSlippage={
|
|
55
|
-
maxSlippage={
|
|
67
|
+
minSlippage={MIN_SLIPPGAE}
|
|
68
|
+
maxSlippage={MAX_SLIPPAGE}
|
|
56
69
|
selectedTheme={theme}
|
|
57
70
|
onThemeChange={setTheme}
|
|
71
|
+
infiniteApprove={infiniteApprove}
|
|
72
|
+
toggleInfiniteApprove={toggleInfiniteApprove}
|
|
58
73
|
/>
|
|
59
74
|
);
|
|
60
75
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { SwapHistory } from '@rango-dev/ui';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
4
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
4
5
|
import { pendingSwap } from '../mockData/pendingSwap';
|
|
5
6
|
|
|
6
7
|
export function SwapDetailsPage() {
|
|
7
|
-
const
|
|
8
|
-
return
|
|
8
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
9
|
+
return (
|
|
10
|
+
<SwapHistory
|
|
11
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
|
|
12
|
+
pendingSwap={pendingSwap}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
9
15
|
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
Alert,
|
|
3
|
+
SecondaryPage,
|
|
4
|
+
styled,
|
|
5
|
+
Wallet,
|
|
6
|
+
Typography,
|
|
7
|
+
} from '@rango-dev/ui';
|
|
8
|
+
import React, { useEffect, useState } from 'react';
|
|
4
9
|
import { getlistWallet } from '../utils/wallets';
|
|
5
10
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
6
11
|
import { useWallets } from '@rango-dev/wallets-core';
|
|
12
|
+
import { useUiStore } from '../store/ui';
|
|
13
|
+
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
14
|
+
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
15
|
|
|
8
16
|
const ListContainer = styled('div', {
|
|
9
17
|
display: 'grid',
|
|
@@ -18,7 +26,7 @@ const AlertContainer = styled('div', {
|
|
|
18
26
|
paddingBottom: '$16',
|
|
19
27
|
});
|
|
20
28
|
export function WalletsPage() {
|
|
21
|
-
const
|
|
29
|
+
const { navigateBackFrom } = useNavigateBack();
|
|
22
30
|
const { state, disconnect, getWalletInfo, connect } = useWallets();
|
|
23
31
|
const wallets = getlistWallet(
|
|
24
32
|
state,
|
|
@@ -26,6 +34,8 @@ export function WalletsPage() {
|
|
|
26
34
|
Object.values(WalletType)
|
|
27
35
|
);
|
|
28
36
|
const [walletErrorMessage, setWalletErrorMessage] = useState('');
|
|
37
|
+
const toggleConnectWalletsButton =
|
|
38
|
+
useUiStore.use.toggleConnectWalletsButton();
|
|
29
39
|
|
|
30
40
|
const onSelectWallet = async (type: WalletType) => {
|
|
31
41
|
const wallet = state(type);
|
|
@@ -40,27 +50,32 @@ export function WalletsPage() {
|
|
|
40
50
|
setWalletErrorMessage('Error: ' + e.message);
|
|
41
51
|
}
|
|
42
52
|
};
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
toggleConnectWalletsButton();
|
|
56
|
+
return () => toggleConnectWalletsButton();
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
43
59
|
return (
|
|
44
60
|
<SecondaryPage
|
|
45
61
|
title="Select Wallet"
|
|
46
62
|
textField={false}
|
|
47
|
-
onBack={()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
/>
|
|
63
|
+
onBack={navigateBackFrom.bind(null, navigationRoutes.wallets)}
|
|
64
|
+
>
|
|
65
|
+
<>
|
|
66
|
+
{walletErrorMessage && (
|
|
67
|
+
<AlertContainer>
|
|
68
|
+
<Alert type="error">
|
|
69
|
+
<Typography variant="body2">{walletErrorMessage}</Typography>
|
|
70
|
+
</Alert>
|
|
71
|
+
</AlertContainer>
|
|
72
|
+
)}
|
|
73
|
+
<ListContainer>
|
|
74
|
+
{wallets.map((info, index) => (
|
|
75
|
+
<Wallet {...info} key={index} onClick={onSelectWallet} />
|
|
76
|
+
))}
|
|
77
|
+
</ListContainer>
|
|
78
|
+
</>
|
|
79
|
+
</SecondaryPage>
|
|
65
80
|
);
|
|
66
81
|
}
|