@rango-dev/widget-embedded 0.10.1-next.0 → 0.11.0
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/CHANGELOG.md +4 -0
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/PercentageChange.d.ts +9 -0
- package/dist/components/PercentageChange.d.ts.map +1 -0
- package/dist/components/RoutesOverview.d.ts +120 -0
- package/dist/components/RoutesOverview.d.ts.map +1 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts +120 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -0
- package/dist/components/SwitchFromAndTo.d.ts +3 -2
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts +18 -0
- package/dist/components/TokenInfo.d.ts.map +1 -0
- package/dist/components/TokenPreview.d.ts +21 -0
- package/dist/components/TokenPreview.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/components/Layout.tsx +65 -12
- package/src/components/PercentageChange.tsx +33 -0
- package/src/components/RoutesOverview.tsx +57 -0
- package/src/components/SwapDetailsPlaceholder.tsx +47 -0
- package/src/components/SwitchFromAndTo.tsx +4 -34
- package/src/components/TokenInfo.tsx +329 -0
- package/src/components/TokenPreview.tsx +187 -0
- package/src/languages/en.json +14 -0
- package/src/languages/tr.json +11 -0
- package/src/pages/ConfirmSwapPage.tsx +9 -20
- package/src/pages/Home.tsx +144 -101
- package/src/pages/SwapDetailsPage.tsx +2 -5
- package/src/utils/numbers.ts +0 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Button,
|
|
4
|
+
InfoCircleIcon,
|
|
5
|
+
styled,
|
|
6
|
+
Typography,
|
|
7
|
+
Divider,
|
|
8
|
+
Image,
|
|
9
|
+
} from '@rango-dev/ui';
|
|
10
|
+
import { LoadingStatus } from '../store/meta';
|
|
11
|
+
import { i18n } from '@lingui/core';
|
|
12
|
+
import BigNumber from 'bignumber.js';
|
|
13
|
+
import { numberToString } from '../utils/numbers';
|
|
14
|
+
|
|
15
|
+
const Box = styled('div', {
|
|
16
|
+
display: 'flex',
|
|
17
|
+
flexDirection: 'column',
|
|
18
|
+
width: '100%',
|
|
19
|
+
overflow: 'hidden',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const Container = styled('div', {
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
borderRadius: '$5',
|
|
25
|
+
padding: '$8 $16 $16 $16',
|
|
26
|
+
|
|
27
|
+
variants: {
|
|
28
|
+
type: {
|
|
29
|
+
filled: {
|
|
30
|
+
backgroundColor: '$neutral100',
|
|
31
|
+
},
|
|
32
|
+
outlined: {
|
|
33
|
+
border: '1px solid $neutral100',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
defaultVariants: {
|
|
39
|
+
type: 'filled',
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
'.head': {
|
|
43
|
+
display: 'flex',
|
|
44
|
+
justifyContent: 'space-between',
|
|
45
|
+
alignItems: 'center',
|
|
46
|
+
minHeight: '32px',
|
|
47
|
+
'.usd-value': {
|
|
48
|
+
paddingLeft: '$8',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
'.form': {
|
|
52
|
+
display: 'flex',
|
|
53
|
+
width: '100%',
|
|
54
|
+
padding: '$2 0',
|
|
55
|
+
'.selectors': {
|
|
56
|
+
width: '35%',
|
|
57
|
+
|
|
58
|
+
'._text': {
|
|
59
|
+
whiteSpace: 'nowrap',
|
|
60
|
+
overflow: 'hidden',
|
|
61
|
+
textOverflow: 'ellipsis',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
'.amount': {
|
|
65
|
+
width: '30%',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const ImagePlaceholder = styled('span', {
|
|
71
|
+
width: '24px',
|
|
72
|
+
height: '24px',
|
|
73
|
+
backgroundColor: '$neutral100',
|
|
74
|
+
borderRadius: '99999px',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const OutputContainer = styled('div', {
|
|
78
|
+
windth: '100%',
|
|
79
|
+
height: '$48',
|
|
80
|
+
borderRadius: '$5',
|
|
81
|
+
backgroundColor: '$surface',
|
|
82
|
+
border: '1px solid transparent',
|
|
83
|
+
position: 'relative',
|
|
84
|
+
display: 'flex',
|
|
85
|
+
alignItems: 'center',
|
|
86
|
+
paddingLeft: '$8',
|
|
87
|
+
paddingRight: '$8',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
interface PropTypes {
|
|
91
|
+
label: string;
|
|
92
|
+
amount: string;
|
|
93
|
+
usdValue: BigNumber | null;
|
|
94
|
+
loadingStatus: LoadingStatus;
|
|
95
|
+
chain: {
|
|
96
|
+
displayName: string;
|
|
97
|
+
logo: string;
|
|
98
|
+
};
|
|
99
|
+
token: {
|
|
100
|
+
symbol: string;
|
|
101
|
+
image: string;
|
|
102
|
+
};
|
|
103
|
+
percentageChange?: ReactNode;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function TokenPreview(props: PropTypes) {
|
|
107
|
+
const { chain, token, loadingStatus, percentageChange } = props;
|
|
108
|
+
|
|
109
|
+
const ItemSuffix = (
|
|
110
|
+
<div
|
|
111
|
+
style={{
|
|
112
|
+
display: 'flex',
|
|
113
|
+
justifyContent: 'center',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
}}>
|
|
116
|
+
{loadingStatus === 'failed' && <InfoCircleIcon color="error" size={24} />}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Box>
|
|
122
|
+
<Container type={'outlined'}>
|
|
123
|
+
<div className="head">
|
|
124
|
+
<Typography variant="body2" color="neutral800">
|
|
125
|
+
{props.label}
|
|
126
|
+
</Typography>
|
|
127
|
+
<div>
|
|
128
|
+
{percentageChange}
|
|
129
|
+
{props.usdValue && (
|
|
130
|
+
<Typography
|
|
131
|
+
variant="caption"
|
|
132
|
+
color="neutral600"
|
|
133
|
+
className="usd-value">{`$${numberToString(
|
|
134
|
+
props.usdValue
|
|
135
|
+
)}`}</Typography>
|
|
136
|
+
)}
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
<div className="form">
|
|
140
|
+
<Button
|
|
141
|
+
className="selectors"
|
|
142
|
+
variant="outlined"
|
|
143
|
+
loading={loadingStatus === 'loading'}
|
|
144
|
+
prefix={
|
|
145
|
+
loadingStatus === 'success' && chain ? (
|
|
146
|
+
<Image src={chain.logo} size={24} />
|
|
147
|
+
) : (
|
|
148
|
+
<ImagePlaceholder />
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
suffix={ItemSuffix}
|
|
152
|
+
align="start"
|
|
153
|
+
size="large">
|
|
154
|
+
{loadingStatus === 'success' && chain
|
|
155
|
+
? chain.displayName
|
|
156
|
+
: i18n.t('Chain')}
|
|
157
|
+
</Button>
|
|
158
|
+
<Divider size={12} direction="horizontal" />
|
|
159
|
+
<Button
|
|
160
|
+
className="selectors"
|
|
161
|
+
variant="outlined"
|
|
162
|
+
loading={loadingStatus === 'loading'}
|
|
163
|
+
prefix={
|
|
164
|
+
loadingStatus === 'success' && token ? (
|
|
165
|
+
<Image src={token.image} size={24} />
|
|
166
|
+
) : (
|
|
167
|
+
<ImagePlaceholder />
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
suffix={ItemSuffix}
|
|
171
|
+
size="large"
|
|
172
|
+
align="start">
|
|
173
|
+
{loadingStatus === 'success' && token
|
|
174
|
+
? token.symbol
|
|
175
|
+
: i18n.t('Token')}
|
|
176
|
+
</Button>
|
|
177
|
+
<Divider size={12} direction="horizontal" />
|
|
178
|
+
<div className="amount">
|
|
179
|
+
<OutputContainer>
|
|
180
|
+
<Typography variant="h4">{props.amount}</Typography>
|
|
181
|
+
</OutputContainer>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
</Container>
|
|
185
|
+
</Box>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"swap": "SWAP",
|
|
3
|
+
"Connect Wallet": "Connect Wallet",
|
|
4
|
+
"Powered By": "Powered By",
|
|
5
|
+
"From": "You sell",
|
|
6
|
+
"To": "You receive",
|
|
7
|
+
"Balance": "Balance",
|
|
8
|
+
"Max": "Max",
|
|
9
|
+
"Chain": "Chain",
|
|
10
|
+
"Token": "Token",
|
|
11
|
+
"Source": "Source",
|
|
12
|
+
"Destination": "Destination",
|
|
13
|
+
"Select Wallet": "Connect Your Wallet"
|
|
14
|
+
}
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
} from '../utils/wallets';
|
|
14
14
|
import {
|
|
15
15
|
confirmSwapDisabled,
|
|
16
|
-
getPercentageChange,
|
|
17
16
|
getTotalFeeInUsd,
|
|
18
17
|
isValidCustomDestination,
|
|
19
18
|
} from '../utils/swap';
|
|
@@ -21,15 +20,14 @@ import { numberToString } from '../utils/numbers';
|
|
|
21
20
|
import { useMetaStore } from '../store/meta';
|
|
22
21
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
23
22
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
23
|
+
import { TokenPreview } from '../components/TokenPreview';
|
|
24
24
|
import {
|
|
25
25
|
Divider,
|
|
26
26
|
ConfirmSwap,
|
|
27
27
|
LoadingFailedAlert,
|
|
28
28
|
HighSlippageWarning,
|
|
29
|
-
PercentageChange,
|
|
30
|
-
RoutesOverview,
|
|
31
|
-
TokenPreview,
|
|
32
29
|
} from '@rango-dev/ui';
|
|
30
|
+
import RoutesOverview from '../components/RoutesOverview';
|
|
33
31
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
34
32
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
35
33
|
import { useSettingsStore } from '../store/settings';
|
|
@@ -39,6 +37,7 @@ import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
|
|
|
39
37
|
import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
|
|
40
38
|
import { HIGH_SLIPPAGE } from '../constants/swapSettings';
|
|
41
39
|
import { getBestRouteStatus } from '../utils/routing';
|
|
40
|
+
import { PercentageChange } from '../components/PercentageChange';
|
|
42
41
|
|
|
43
42
|
export function ConfirmSwapPage({
|
|
44
43
|
customDestinationEnabled,
|
|
@@ -121,14 +120,6 @@ export function ConfirmSwapPage({
|
|
|
121
120
|
|
|
122
121
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
123
122
|
|
|
124
|
-
const percentageChange =
|
|
125
|
-
!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
|
|
126
|
-
? null
|
|
127
|
-
: getPercentageChange(
|
|
128
|
-
inputUsdValue.toNumber(),
|
|
129
|
-
outputUsdValue.toNumber()
|
|
130
|
-
);
|
|
131
|
-
|
|
132
123
|
return (
|
|
133
124
|
<ConfirmSwap
|
|
134
125
|
requiredWallets={getRequiredChains(bestRoute)}
|
|
@@ -191,7 +182,7 @@ export function ConfirmSwapPage({
|
|
|
191
182
|
symbol: firstStep?.from.symbol || '',
|
|
192
183
|
image: firstStep?.from.logo || '',
|
|
193
184
|
}}
|
|
194
|
-
usdValue={inputUsdValue
|
|
185
|
+
usdValue={inputUsdValue}
|
|
195
186
|
amount={fromAmount}
|
|
196
187
|
label={i18n.t('From')}
|
|
197
188
|
loadingStatus={
|
|
@@ -210,7 +201,7 @@ export function ConfirmSwapPage({
|
|
|
210
201
|
symbol: lastStep?.to.symbol || '',
|
|
211
202
|
image: lastStep?.to.logo || '',
|
|
212
203
|
}}
|
|
213
|
-
usdValue={outputUsdValue
|
|
204
|
+
usdValue={outputUsdValue}
|
|
214
205
|
amount={toAmount}
|
|
215
206
|
label={i18n.t('To')}
|
|
216
207
|
loadingStatus={
|
|
@@ -219,12 +210,10 @@ export function ConfirmSwapPage({
|
|
|
219
210
|
: bestRouteloadingStatus
|
|
220
211
|
}
|
|
221
212
|
percentageChange={
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
/>
|
|
227
|
-
)
|
|
213
|
+
<PercentageChange
|
|
214
|
+
inputUsdValue={inputUsdValue}
|
|
215
|
+
outputUsdValue={outputUsdValue}
|
|
216
|
+
/>
|
|
228
217
|
}
|
|
229
218
|
/>
|
|
230
219
|
</>
|
package/src/pages/Home.tsx
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
Alert,
|
|
3
|
+
BestRoute,
|
|
4
|
+
BottomLogo,
|
|
5
|
+
Button,
|
|
6
|
+
styled,
|
|
7
|
+
Typography,
|
|
8
|
+
VerticalSwapIcon,
|
|
9
|
+
Header,
|
|
10
|
+
HeaderButtons,
|
|
11
|
+
} from '@rango-dev/ui';
|
|
12
|
+
import React, { useEffect, useState } from 'react';
|
|
13
|
+
import { i18n } from '@lingui/core';
|
|
14
|
+
import { useInRouterContext, useNavigate } from 'react-router-dom';
|
|
15
|
+
import { TokenInfo } from '../components/TokenInfo';
|
|
4
16
|
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
5
|
-
import {
|
|
17
|
+
import { SwithFromAndTo } from '../components/SwitchFromAndTo';
|
|
6
18
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
19
|
import { useMetaStore } from '../store/meta';
|
|
8
20
|
import { useWalletsStore } from '../store/wallets';
|
|
@@ -16,20 +28,54 @@ import {
|
|
|
16
28
|
LimitErrorMessage,
|
|
17
29
|
getTotalFeeInUsd,
|
|
18
30
|
hasHighFee,
|
|
19
|
-
getPercentageChange,
|
|
20
31
|
} from '../utils/swap';
|
|
21
|
-
import { useUiStore } from '../store/ui';
|
|
22
32
|
import {
|
|
23
33
|
numberToString,
|
|
24
34
|
secondsToString,
|
|
25
35
|
totalArrivalTime,
|
|
26
36
|
} from '../utils/numbers';
|
|
27
|
-
import { getBalanceFromWallet } from '../utils/wallets';
|
|
28
|
-
import { getFormatedBestRoute } from '../utils/routing';
|
|
29
37
|
import BigNumber from 'bignumber.js';
|
|
38
|
+
import { useUiStore } from '../store/ui';
|
|
39
|
+
import { getFormatedBestRoute } from '../utils/routing';
|
|
40
|
+
|
|
41
|
+
const Container = styled('div', {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexDirection: 'column',
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const FromContainer = styled('div', {
|
|
47
|
+
position: 'relative',
|
|
48
|
+
paddingBottom: '$12',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const SwitchButtonContainer = styled('div', {
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
bottom: '-12px',
|
|
54
|
+
left: '50%',
|
|
55
|
+
transform: 'translate(-50%, 10%)',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const BestRouteContainer = styled('div', {
|
|
59
|
+
width: '100%',
|
|
60
|
+
paddingTop: '$16',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const Alerts = styled('div', {
|
|
64
|
+
width: '100%',
|
|
65
|
+
paddingTop: '$16',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const Footer = styled('div', {
|
|
69
|
+
display: 'flex',
|
|
70
|
+
flexDirection: 'column',
|
|
71
|
+
width: '100%',
|
|
72
|
+
paddingTop: '$16',
|
|
73
|
+
});
|
|
30
74
|
|
|
31
75
|
export function Home() {
|
|
76
|
+
const isRouterInContext = useInRouterContext();
|
|
32
77
|
const navigate = useNavigate();
|
|
78
|
+
const [count, setCount] = useState(0);
|
|
33
79
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
34
80
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
35
81
|
const toChain = useBestRouteStore.use.toChain();
|
|
@@ -46,6 +92,7 @@ export function Home() {
|
|
|
46
92
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
47
93
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
48
94
|
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
95
|
+
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
49
96
|
|
|
50
97
|
const errorMessage =
|
|
51
98
|
loadingMetaStatus === 'failed'
|
|
@@ -55,7 +102,7 @@ export function Home() {
|
|
|
55
102
|
const needsToWarnEthOnPath = false;
|
|
56
103
|
|
|
57
104
|
const showBestRoute =
|
|
58
|
-
|
|
105
|
+
inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
|
|
59
106
|
|
|
60
107
|
const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
|
|
61
108
|
|
|
@@ -87,105 +134,101 @@ export function Home() {
|
|
|
87
134
|
|
|
88
135
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
89
136
|
|
|
90
|
-
const tokenBalance =
|
|
91
|
-
!!fromChain && !!fromToken
|
|
92
|
-
? numberToString(
|
|
93
|
-
getBalanceFromWallet(
|
|
94
|
-
connectedWallets,
|
|
95
|
-
fromChain?.name,
|
|
96
|
-
fromToken?.symbol,
|
|
97
|
-
fromToken?.address
|
|
98
|
-
)?.amount || '0',
|
|
99
|
-
8
|
|
100
|
-
)
|
|
101
|
-
: '0';
|
|
102
|
-
|
|
103
|
-
const tokenBalanceReal =
|
|
104
|
-
!!fromChain && !!fromToken
|
|
105
|
-
? numberToString(
|
|
106
|
-
getBalanceFromWallet(
|
|
107
|
-
connectedWallets,
|
|
108
|
-
fromChain?.name,
|
|
109
|
-
fromToken?.symbol,
|
|
110
|
-
fromToken?.address
|
|
111
|
-
)?.amount || '0',
|
|
112
|
-
getBalanceFromWallet(
|
|
113
|
-
connectedWallets,
|
|
114
|
-
fromChain?.name,
|
|
115
|
-
fromToken?.symbol,
|
|
116
|
-
fromToken?.address
|
|
117
|
-
)?.decimal
|
|
118
|
-
)
|
|
119
|
-
: '0';
|
|
120
|
-
|
|
121
137
|
useEffect(() => {
|
|
122
138
|
setCurrentPage(navigationRoutes.home);
|
|
123
139
|
|
|
124
140
|
return setCurrentPage.bind(null, '');
|
|
125
141
|
}, []);
|
|
126
142
|
|
|
127
|
-
const percentageChange =
|
|
128
|
-
!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
|
|
129
|
-
? null
|
|
130
|
-
: getPercentageChange(
|
|
131
|
-
inputUsdValue.toNumber(),
|
|
132
|
-
outputUsdValue.toNumber()
|
|
133
|
-
);
|
|
134
|
-
|
|
135
143
|
return (
|
|
136
|
-
<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
144
|
+
<Container>
|
|
145
|
+
<Header
|
|
146
|
+
title={i18n.t('SWAP')}
|
|
147
|
+
suffix={
|
|
148
|
+
<HeaderButtons
|
|
149
|
+
onClickRefresh={
|
|
150
|
+
!!bestRoute || bestRouteError ? fetchBestRoute : undefined
|
|
151
|
+
}
|
|
152
|
+
onClickHistory={() => navigate(navigationRoutes.swaps)}
|
|
153
|
+
onClickSettings={() => navigate(navigationRoutes.settings)}
|
|
154
|
+
/>
|
|
155
|
+
}
|
|
156
|
+
/>
|
|
157
|
+
<FromContainer>
|
|
158
|
+
<TokenInfo
|
|
159
|
+
type="From"
|
|
160
|
+
chain={fromChain}
|
|
161
|
+
token={fromToken}
|
|
162
|
+
onAmountChange={setInputAmount}
|
|
163
|
+
inputAmount={inputAmount}
|
|
164
|
+
/>
|
|
165
|
+
<SwitchButtonContainer>
|
|
166
|
+
<Button
|
|
167
|
+
variant="ghost"
|
|
168
|
+
onClick={() => {
|
|
169
|
+
switchFromAndTo();
|
|
170
|
+
setCount((prev) => prev + 1);
|
|
171
|
+
}}>
|
|
172
|
+
<VerticalSwapIcon size={32} />
|
|
173
|
+
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
174
|
+
</Button>
|
|
175
|
+
</SwitchButtonContainer>
|
|
176
|
+
</FromContainer>
|
|
177
|
+
<TokenInfo
|
|
178
|
+
type="To"
|
|
179
|
+
chain={toChain}
|
|
180
|
+
token={toToken}
|
|
181
|
+
outputAmount={
|
|
182
|
+
outputAmount ? new BigNumber(outputAmount) : new BigNumber(0)
|
|
165
183
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
184
|
+
outputUsdValue={outputUsdValue}
|
|
185
|
+
/>
|
|
186
|
+
{showBestRoute && (
|
|
187
|
+
<BestRouteContainer>
|
|
188
|
+
<BestRoute
|
|
189
|
+
error={bestRouteError}
|
|
190
|
+
loading={fetchingBestRoute}
|
|
191
|
+
data={getFormatedBestRoute(bestRoute)}
|
|
192
|
+
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
193
|
+
feeWarning={highFee}
|
|
194
|
+
totalTime={secondsToString(totalArrivalTime(bestRoute))}
|
|
195
|
+
/>
|
|
196
|
+
</BestRouteContainer>
|
|
197
|
+
)}
|
|
198
|
+
{(errorMessage || hasLimitError(bestRoute)) && (
|
|
199
|
+
<Alerts>
|
|
200
|
+
{errorMessage && <Alert type="error">{errorMessage}</Alert>}
|
|
201
|
+
{hasLimitError(bestRoute) && (
|
|
202
|
+
<Alert type="error" title={`${swap?.swapperId} Limit`}>
|
|
203
|
+
<>
|
|
204
|
+
<Typography variant="body2">
|
|
205
|
+
{`${fromAmountRangeError}, Yours: ${numberToString(
|
|
206
|
+
swap?.fromAmount || null
|
|
207
|
+
)} ${swap?.from.symbol}`}
|
|
208
|
+
</Typography>
|
|
209
|
+
<Typography variant="body2">{recommendation}</Typography>
|
|
210
|
+
</>
|
|
211
|
+
</Alert>
|
|
212
|
+
)}
|
|
213
|
+
</Alerts>
|
|
214
|
+
)}
|
|
215
|
+
<Footer>
|
|
216
|
+
<Button
|
|
217
|
+
type="primary"
|
|
218
|
+
align="grow"
|
|
219
|
+
size="large"
|
|
220
|
+
disabled={swapButtonState.disabled}
|
|
221
|
+
onClick={() => {
|
|
222
|
+
if (swapButtonState.title === 'Connect Wallet')
|
|
223
|
+
navigate(navigationRoutes.wallets);
|
|
224
|
+
else {
|
|
225
|
+
navigate(navigationRoutes.confirmSwap, { replace: true });
|
|
226
|
+
}
|
|
227
|
+
}}>
|
|
228
|
+
{swapButtonState.title}
|
|
229
|
+
</Button>
|
|
230
|
+
<BottomLogo />
|
|
231
|
+
</Footer>
|
|
232
|
+
</Container>
|
|
190
233
|
);
|
|
191
234
|
}
|
|
@@ -3,11 +3,7 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
3
3
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
4
4
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
5
5
|
import { getPendingSwaps } from '../utils/queue';
|
|
6
|
-
import {
|
|
7
|
-
SwapHistory,
|
|
8
|
-
useCopyToClipboard,
|
|
9
|
-
SwapDetailsPlaceholder,
|
|
10
|
-
} from '@rango-dev/ui';
|
|
6
|
+
import { SwapHistory, useCopyToClipboard } from '@rango-dev/ui';
|
|
11
7
|
import { useUiStore } from '../store/ui';
|
|
12
8
|
import {
|
|
13
9
|
cancelSwap,
|
|
@@ -28,6 +24,7 @@ import {
|
|
|
28
24
|
isNetworkStatusInWarningState,
|
|
29
25
|
shouldRetrySwap,
|
|
30
26
|
} from '../utils/swap';
|
|
27
|
+
import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
|
|
31
28
|
import { getFormatedPendingSwap } from '../utils/routing';
|
|
32
29
|
|
|
33
30
|
export function SwapDetailsPage() {
|
package/src/utils/numbers.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { BestRouteResponse } from 'rango-sdk';
|
|
|
3
3
|
|
|
4
4
|
export const percentToString = (p: number, fractions = 0): string =>
|
|
5
5
|
(p * 100).toFixed(fractions);
|
|
6
|
-
|
|
7
6
|
export const secondsToString = (s: number): string => {
|
|
8
7
|
const seconds = (s % 60).toString().padStart(2, '0');
|
|
9
8
|
const minutes = parseInt((s / 60).toString())
|
|
@@ -88,7 +87,6 @@ export const convertBigNumberToHex = (
|
|
|
88
87
|
|
|
89
88
|
export const uint8ArrayToHex = (buffer: Uint8Array): string => {
|
|
90
89
|
// buffer is an ArrayBuffer
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
92
90
|
// @ts-ignore
|
|
93
91
|
return [...buffer].map((x) => x.toString(16).padStart(2, '0')).join('');
|
|
94
92
|
};
|