@rango-dev/widget-embedded 0.11.0 → 0.11.1-next.1
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/Layout.d.ts.map +1 -1
- package/dist/components/SwitchFromAndTo.d.ts +2 -3
- package/dist/components/SwitchFromAndTo.d.ts.map +1 -1
- 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 +3 -3
- package/src/components/Layout.tsx +12 -65
- package/src/components/SwitchFromAndTo.tsx +34 -4
- package/src/pages/ConfirmSwapPage.tsx +20 -9
- package/src/pages/Home.tsx +101 -144
- package/src/pages/SwapDetailsPage.tsx +5 -2
- package/src/utils/numbers.ts +2 -0
- package/dist/components/PercentageChange.d.ts +0 -9
- package/dist/components/PercentageChange.d.ts.map +0 -1
- package/dist/components/RoutesOverview.d.ts +0 -120
- package/dist/components/RoutesOverview.d.ts.map +0 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts +0 -120
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +0 -1
- package/dist/components/TokenInfo.d.ts +0 -18
- package/dist/components/TokenInfo.d.ts.map +0 -1
- package/dist/components/TokenPreview.d.ts +0 -21
- package/dist/components/TokenPreview.d.ts.map +0 -1
- package/src/components/PercentageChange.tsx +0 -33
- package/src/components/RoutesOverview.tsx +0 -57
- package/src/components/SwapDetailsPlaceholder.tsx +0 -47
- package/src/components/TokenInfo.tsx +0 -329
- package/src/components/TokenPreview.tsx +0 -187
- package/src/languages/en.json +0 -14
- package/src/languages/tr.json +0 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfirmSwapPage.d.ts","sourceRoot":"","sources":["../../src/pages/ConfirmSwapPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ConfirmSwapPage.d.ts","sourceRoot":"","sources":["../../src/pages/ConfirmSwapPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AA0CnD,wBAAgB,eAAe,CAAC,EAC9B,wBAAwB,GACzB,EAAE;IACD,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC,qBA0NA"}
|
package/dist/pages/Home.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../src/pages/Home.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Home.d.ts","sourceRoot":"","sources":["../../src/pages/Home.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AA8BzC,wBAAgB,IAAI,sBAgKnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwapDetailsPage.d.ts","sourceRoot":"","sources":["../../src/pages/SwapDetailsPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SwapDetailsPage.d.ts","sourceRoot":"","sources":["../../src/pages/SwapDetailsPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAgC1B,wBAAgB,eAAe,sBAqI9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/utils/numbers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,eAAO,MAAM,eAAe,MAAO,MAAM,yBAAkB,MAC7B,CAAC;
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../src/utils/numbers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,eAAO,MAAM,eAAe,MAAO,MAAM,yBAAkB,MAC7B,CAAC;AAE/B,eAAO,MAAM,eAAe,MAAO,MAAM,KAAG,MAM3C,CAAC;AAEF,eAAO,MAAM,cAAc,WACjB,SAAS,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,gBAChC,MAAM,GAAG,IAAI,gBACb,MAAM,GAAG,IAAI,KACzB,MA6DF,CAAC;AAEF,eAAO,MAAM,qBAAqB,UACzB,SAAS,YACN,MAAM,KACf,MAEF,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,UAAU,KAAG,MAKpD,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAQrE;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAW5E;AAED,eAAO,MAAM,gBAAgB,SAAU,iBAAiB,GAAG,IAAI,WACc,CAAC;AAE9E,eAAO,MAAM,OAAO,SAAU,iBAAiB,KAAG,MAOnC,CAAC;AAEhB,eAAO,MAAM,YAAY,SAAU,MAAM,cAAc,MAAM,YACF,CAAC;AAE5D,eAAO,MAAM,gBAAgB,UAAW,MAAM,YACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1-next.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@lingui/core": "4.2.1",
|
|
21
21
|
"@lingui/react": "4.2.1",
|
|
22
|
-
"@rango-dev/provider-all": "^0.14.0",
|
|
22
|
+
"@rango-dev/provider-all": "^0.14.1-next.0",
|
|
23
23
|
"@rango-dev/queue-manager-core": "^0.14.0",
|
|
24
24
|
"@rango-dev/queue-manager-rango-preset": "^0.14.0",
|
|
25
25
|
"@rango-dev/queue-manager-react": "^0.14.0",
|
|
26
|
-
"@rango-dev/ui": "^0.14.0",
|
|
26
|
+
"@rango-dev/ui": "^0.14.1-next.0",
|
|
27
27
|
"@rango-dev/wallets-core": "^0.14.0",
|
|
28
28
|
"@rango-dev/wallets-shared": "^0.14.0",
|
|
29
29
|
"bignumber.js": "^9.1.1",
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Button,
|
|
3
|
-
AddWalletIcon,
|
|
4
|
-
Typography,
|
|
5
|
-
styled,
|
|
6
|
-
Spinner,
|
|
7
|
-
Image,
|
|
8
|
-
} from '@rango-dev/ui';
|
|
9
1
|
import React, { useEffect } from 'react';
|
|
10
2
|
import { useNavigate } from 'react-router-dom';
|
|
3
|
+
import { HeaderLayout } from '@rango-dev/ui';
|
|
11
4
|
import { useWallets } from '@rango-dev/wallets-core';
|
|
12
5
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
13
6
|
import { useUiStore } from '../store/ui';
|
|
@@ -20,33 +13,10 @@ import {
|
|
|
20
13
|
} from '../utils/wallets';
|
|
21
14
|
import { removeDuplicateFrom } from '../utils/common';
|
|
22
15
|
import { WidgetConfig } from '../types';
|
|
23
|
-
import { i18n } from '@lingui/core';
|
|
24
16
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
25
17
|
import { useMetaStore } from '../store/meta';
|
|
26
18
|
import { useSettingsStore } from '../store/settings';
|
|
27
19
|
|
|
28
|
-
const Header = styled('div', {
|
|
29
|
-
display: 'flex',
|
|
30
|
-
width: '100%',
|
|
31
|
-
justifyContent: 'end',
|
|
32
|
-
'.balance': {
|
|
33
|
-
display: 'flex',
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const WalletImages = styled('div', {
|
|
38
|
-
display: 'flex',
|
|
39
|
-
paddingLeft: '12px',
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const WalletImageContainer = styled('div', {
|
|
43
|
-
marginLeft: -15,
|
|
44
|
-
marginRight: '$6',
|
|
45
|
-
'& img': {
|
|
46
|
-
borderRadius: '50%',
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
20
|
export type LayoutProps = {
|
|
51
21
|
config?: WidgetConfig;
|
|
52
22
|
};
|
|
@@ -119,40 +89,17 @@ export function Layout({ config }: LayoutProps) {
|
|
|
119
89
|
|
|
120
90
|
return (
|
|
121
91
|
<>
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}}
|
|
134
|
-
prefix={
|
|
135
|
-
connectedWalletsImages?.length ? (
|
|
136
|
-
<WalletImages>
|
|
137
|
-
{connectedWalletsImages.map((walletImage, index) => (
|
|
138
|
-
<WalletImageContainer key={index}>
|
|
139
|
-
<Image src={walletImage} size={24} />
|
|
140
|
-
</WalletImageContainer>
|
|
141
|
-
))}
|
|
142
|
-
</WalletImages>
|
|
143
|
-
) : null
|
|
144
|
-
}>
|
|
145
|
-
<div className="balance">
|
|
146
|
-
<Typography variant="body2">
|
|
147
|
-
{!connectedWallets?.length
|
|
148
|
-
? i18n.t('Connect Wallet')
|
|
149
|
-
: `$${totalBalance || 0}`}
|
|
150
|
-
</Typography>
|
|
151
|
-
{fetchingBalance && <Spinner />}
|
|
152
|
-
</div>
|
|
153
|
-
</Button>
|
|
154
|
-
</Header>
|
|
155
|
-
<AppRoutes config={config} />
|
|
92
|
+
<HeaderLayout
|
|
93
|
+
loadingStatus={loadingMetaStatus}
|
|
94
|
+
connectedWalletsImages={connectedWalletsImages}
|
|
95
|
+
connectedWallets={connectedWallets}
|
|
96
|
+
totalBalance={totalBalance}
|
|
97
|
+
fetchingBalance={fetchingBalance}
|
|
98
|
+
onClick={() => {
|
|
99
|
+
if (!connectWalletsButtonDisabled) navigate(navigationRoutes.wallets);
|
|
100
|
+
}}>
|
|
101
|
+
<AppRoutes config={config} />
|
|
102
|
+
</HeaderLayout>
|
|
156
103
|
</>
|
|
157
104
|
);
|
|
158
105
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { useSearchParams } from 'react-router-dom';
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useInRouterContext, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import { styled, Button, VerticalSwapIcon } from '@rango-dev/ui';
|
|
3
4
|
import { SearchParams } from '../constants/searchParams';
|
|
4
5
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
function SwithFromAndTo({ count }: { count: number }) {
|
|
7
8
|
const firstRender = useRef(true);
|
|
8
9
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
9
10
|
const outputAmount = useBestRouteStore.use.outputAmount();
|
|
@@ -19,7 +20,9 @@ export function SwithFromAndTo({ count }: { count: number }) {
|
|
|
19
20
|
...(toTokenString && { [SearchParams.FROM_TOKEN]: toTokenString }),
|
|
20
21
|
...(fromChainString && { [SearchParams.TO_CHAIN]: fromChainString }),
|
|
21
22
|
...(fromTokenString && { [SearchParams.TO_TOKEN]: fromTokenString }),
|
|
22
|
-
...(outputAmount && {
|
|
23
|
+
...(outputAmount && {
|
|
24
|
+
[SearchParams.FROM_AMOUNT]: outputAmount.toString(),
|
|
25
|
+
}),
|
|
23
26
|
});
|
|
24
27
|
} else {
|
|
25
28
|
firstRender.current = false;
|
|
@@ -28,3 +31,30 @@ export function SwithFromAndTo({ count }: { count: number }) {
|
|
|
28
31
|
|
|
29
32
|
return null;
|
|
30
33
|
}
|
|
34
|
+
|
|
35
|
+
const SwitchButtonContainer = styled('div', {
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
bottom: '-12px',
|
|
38
|
+
left: '50%',
|
|
39
|
+
transform: 'translate(-50%, 10%)',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export function SwithFromAndToButton() {
|
|
43
|
+
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
44
|
+
const isRouterInContext = useInRouterContext();
|
|
45
|
+
const [count, setCount] = useState(0);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<SwitchButtonContainer>
|
|
49
|
+
<Button
|
|
50
|
+
variant="ghost"
|
|
51
|
+
onClick={() => {
|
|
52
|
+
switchFromAndTo();
|
|
53
|
+
setCount((prev) => prev + 1);
|
|
54
|
+
}}>
|
|
55
|
+
<VerticalSwapIcon size={32} />
|
|
56
|
+
{isRouterInContext && <SwithFromAndTo count={count} />}
|
|
57
|
+
</Button>
|
|
58
|
+
</SwitchButtonContainer>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
} from '../utils/wallets';
|
|
14
14
|
import {
|
|
15
15
|
confirmSwapDisabled,
|
|
16
|
+
getPercentageChange,
|
|
16
17
|
getTotalFeeInUsd,
|
|
17
18
|
isValidCustomDestination,
|
|
18
19
|
} from '../utils/swap';
|
|
@@ -20,14 +21,15 @@ import { numberToString } from '../utils/numbers';
|
|
|
20
21
|
import { useMetaStore } from '../store/meta';
|
|
21
22
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
22
23
|
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,
|
|
29
32
|
} from '@rango-dev/ui';
|
|
30
|
-
import RoutesOverview from '../components/RoutesOverview';
|
|
31
33
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
32
34
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
33
35
|
import { useSettingsStore } from '../store/settings';
|
|
@@ -37,7 +39,6 @@ import { ConfirmSwapErrors } from '../components/ConfirmSwapErrors';
|
|
|
37
39
|
import { ConfirmSwapWarnings } from '../components/ConfirmSwapWarnings';
|
|
38
40
|
import { HIGH_SLIPPAGE } from '../constants/swapSettings';
|
|
39
41
|
import { getBestRouteStatus } from '../utils/routing';
|
|
40
|
-
import { PercentageChange } from '../components/PercentageChange';
|
|
41
42
|
|
|
42
43
|
export function ConfirmSwapPage({
|
|
43
44
|
customDestinationEnabled,
|
|
@@ -120,6 +121,14 @@ export function ConfirmSwapPage({
|
|
|
120
121
|
|
|
121
122
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
122
123
|
|
|
124
|
+
const percentageChange =
|
|
125
|
+
!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
|
|
126
|
+
? null
|
|
127
|
+
: getPercentageChange(
|
|
128
|
+
inputUsdValue.toNumber(),
|
|
129
|
+
outputUsdValue.toNumber()
|
|
130
|
+
);
|
|
131
|
+
|
|
123
132
|
return (
|
|
124
133
|
<ConfirmSwap
|
|
125
134
|
requiredWallets={getRequiredChains(bestRoute)}
|
|
@@ -182,7 +191,7 @@ export function ConfirmSwapPage({
|
|
|
182
191
|
symbol: firstStep?.from.symbol || '',
|
|
183
192
|
image: firstStep?.from.logo || '',
|
|
184
193
|
}}
|
|
185
|
-
usdValue={inputUsdValue}
|
|
194
|
+
usdValue={inputUsdValue ? numberToString(inputUsdValue) : null}
|
|
186
195
|
amount={fromAmount}
|
|
187
196
|
label={i18n.t('From')}
|
|
188
197
|
loadingStatus={
|
|
@@ -201,7 +210,7 @@ export function ConfirmSwapPage({
|
|
|
201
210
|
symbol: lastStep?.to.symbol || '',
|
|
202
211
|
image: lastStep?.to.logo || '',
|
|
203
212
|
}}
|
|
204
|
-
usdValue={outputUsdValue}
|
|
213
|
+
usdValue={outputUsdValue ? numberToString(outputUsdValue) : null}
|
|
205
214
|
amount={toAmount}
|
|
206
215
|
label={i18n.t('To')}
|
|
207
216
|
loadingStatus={
|
|
@@ -210,10 +219,12 @@ export function ConfirmSwapPage({
|
|
|
210
219
|
: bestRouteloadingStatus
|
|
211
220
|
}
|
|
212
221
|
percentageChange={
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
222
|
+
!percentageChange ? null : (
|
|
223
|
+
<PercentageChange
|
|
224
|
+
percentageChange={numberToString(percentageChange, 0, 2)}
|
|
225
|
+
showPercentageChange={!!percentageChange?.lt(0)}
|
|
226
|
+
/>
|
|
227
|
+
)
|
|
217
228
|
}
|
|
218
229
|
/>
|
|
219
230
|
</>
|
package/src/pages/Home.tsx
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
|
+
import { HomePanel } from '@rango-dev/ui';
|
|
16
4
|
import { fetchBestRoute, useBestRouteStore } from '../store/bestRoute';
|
|
17
|
-
import {
|
|
5
|
+
import { SwithFromAndToButton } from '../components/SwitchFromAndTo';
|
|
18
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
19
7
|
import { useMetaStore } from '../store/meta';
|
|
20
8
|
import { useWalletsStore } from '../store/wallets';
|
|
@@ -28,54 +16,20 @@ import {
|
|
|
28
16
|
LimitErrorMessage,
|
|
29
17
|
getTotalFeeInUsd,
|
|
30
18
|
hasHighFee,
|
|
19
|
+
getPercentageChange,
|
|
31
20
|
} from '../utils/swap';
|
|
21
|
+
import { useUiStore } from '../store/ui';
|
|
32
22
|
import {
|
|
33
23
|
numberToString,
|
|
34
24
|
secondsToString,
|
|
35
25
|
totalArrivalTime,
|
|
36
26
|
} from '../utils/numbers';
|
|
37
|
-
import
|
|
38
|
-
import { useUiStore } from '../store/ui';
|
|
27
|
+
import { getBalanceFromWallet } from '../utils/wallets';
|
|
39
28
|
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
|
-
});
|
|
29
|
+
import BigNumber from 'bignumber.js';
|
|
74
30
|
|
|
75
31
|
export function Home() {
|
|
76
|
-
const isRouterInContext = useInRouterContext();
|
|
77
32
|
const navigate = useNavigate();
|
|
78
|
-
const [count, setCount] = useState(0);
|
|
79
33
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
80
34
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
81
35
|
const toChain = useBestRouteStore.use.toChain();
|
|
@@ -92,7 +46,6 @@ export function Home() {
|
|
|
92
46
|
const loadingMetaStatus = useMetaStore.use.loadingStatus();
|
|
93
47
|
const connectedWallets = useWalletsStore.use.connectedWallets();
|
|
94
48
|
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
95
|
-
const switchFromAndTo = useBestRouteStore.use.switchFromAndTo();
|
|
96
49
|
|
|
97
50
|
const errorMessage =
|
|
98
51
|
loadingMetaStatus === 'failed'
|
|
@@ -102,7 +55,7 @@ export function Home() {
|
|
|
102
55
|
const needsToWarnEthOnPath = false;
|
|
103
56
|
|
|
104
57
|
const showBestRoute =
|
|
105
|
-
inputAmount && (!!bestRoute || fetchingBestRoute || bestRouteError);
|
|
58
|
+
!!inputAmount && (!!bestRoute || fetchingBestRoute || !!bestRouteError);
|
|
106
59
|
|
|
107
60
|
const outToInRatio = getOutputRatio(inputUsdValue, outputUsdValue);
|
|
108
61
|
|
|
@@ -134,101 +87,105 @@ export function Home() {
|
|
|
134
87
|
|
|
135
88
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
136
89
|
|
|
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
|
+
|
|
137
121
|
useEffect(() => {
|
|
138
122
|
setCurrentPage(navigationRoutes.home);
|
|
139
123
|
|
|
140
124
|
return setCurrentPage.bind(null, '');
|
|
141
125
|
}, []);
|
|
142
126
|
|
|
127
|
+
const percentageChange =
|
|
128
|
+
!inputUsdValue || !outputUsdValue || !outputUsdValue.gt(0)
|
|
129
|
+
? null
|
|
130
|
+
: getPercentageChange(
|
|
131
|
+
inputUsdValue.toNumber(),
|
|
132
|
+
outputUsdValue.toNumber()
|
|
133
|
+
);
|
|
134
|
+
|
|
143
135
|
return (
|
|
144
|
-
<
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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)
|
|
136
|
+
<HomePanel
|
|
137
|
+
bestRoute={bestRoute}
|
|
138
|
+
bestRouteError={bestRouteError}
|
|
139
|
+
fetchBestRoute={fetchBestRoute}
|
|
140
|
+
onClickHistory={() => navigate(navigationRoutes.swaps)}
|
|
141
|
+
onClickSettings={() => navigate(navigationRoutes.settings)}
|
|
142
|
+
setInputAmount={setInputAmount}
|
|
143
|
+
fromChain={fromChain}
|
|
144
|
+
toChain={toChain}
|
|
145
|
+
fromToken={fromToken}
|
|
146
|
+
toToken={toToken}
|
|
147
|
+
outputAmount={
|
|
148
|
+
outputAmount
|
|
149
|
+
? numberToString(new BigNumber(outputAmount))
|
|
150
|
+
: numberToString(new BigNumber(0))
|
|
151
|
+
}
|
|
152
|
+
inputAmount={inputAmount}
|
|
153
|
+
loadingStatus={loadingMetaStatus}
|
|
154
|
+
showBestRoute={showBestRoute}
|
|
155
|
+
fetchingBestRoute={fetchingBestRoute}
|
|
156
|
+
outputUsdValue={numberToString(outputUsdValue)}
|
|
157
|
+
inputUsdValue={numberToString(inputUsdValue)}
|
|
158
|
+
swapButtonTitle={swapButtonState.title}
|
|
159
|
+
swapButtonDisabled={swapButtonState.disabled}
|
|
160
|
+
swapButtonClick={() => {
|
|
161
|
+
if (swapButtonState.title === 'Connect Wallet')
|
|
162
|
+
navigate(navigationRoutes.wallets);
|
|
163
|
+
else {
|
|
164
|
+
navigate(navigationRoutes.confirmSwap, { replace: true });
|
|
183
165
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
)}
|
|
198
|
-
{
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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>
|
|
166
|
+
}}
|
|
167
|
+
onChainClick={(route) => {
|
|
168
|
+
navigate(route);
|
|
169
|
+
}}
|
|
170
|
+
onTokenClick={(route) => {
|
|
171
|
+
navigate(route);
|
|
172
|
+
}}
|
|
173
|
+
highFee={highFee}
|
|
174
|
+
errorMessage={errorMessage}
|
|
175
|
+
hasLimitError={hasLimitError}
|
|
176
|
+
swap={swap}
|
|
177
|
+
fromAmountRangeError={fromAmountRangeError}
|
|
178
|
+
recommendation={recommendation}
|
|
179
|
+
totalFeeInUsd={numberToString(totalFeeInUsd, 0, 2)}
|
|
180
|
+
swithFromAndToComponent={<SwithFromAndToButton />}
|
|
181
|
+
connectedWallets={connectedWallets}
|
|
182
|
+
percentageChange={numberToString(percentageChange, 0, 2)}
|
|
183
|
+
showPercentageChange={!!percentageChange?.lt(0)}
|
|
184
|
+
tokenBalanceReal={tokenBalanceReal}
|
|
185
|
+
tokenBalance={tokenBalance}
|
|
186
|
+
totalTime={secondsToString(totalArrivalTime(bestRoute))}
|
|
187
|
+
bestRouteData={getFormatedBestRoute(bestRoute)}
|
|
188
|
+
swapFromAmount={numberToString(swap?.fromAmount || null)}
|
|
189
|
+
/>
|
|
233
190
|
);
|
|
234
191
|
}
|
|
@@ -3,7 +3,11 @@ 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 {
|
|
6
|
+
import {
|
|
7
|
+
SwapHistory,
|
|
8
|
+
useCopyToClipboard,
|
|
9
|
+
SwapDetailsPlaceholder,
|
|
10
|
+
} from '@rango-dev/ui';
|
|
7
11
|
import { useUiStore } from '../store/ui';
|
|
8
12
|
import {
|
|
9
13
|
cancelSwap,
|
|
@@ -24,7 +28,6 @@ import {
|
|
|
24
28
|
isNetworkStatusInWarningState,
|
|
25
29
|
shouldRetrySwap,
|
|
26
30
|
} from '../utils/swap';
|
|
27
|
-
import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
|
|
28
31
|
import { getFormatedPendingSwap } from '../utils/routing';
|
|
29
32
|
|
|
30
33
|
export function SwapDetailsPage() {
|
package/src/utils/numbers.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { BestRouteResponse } from 'rango-sdk';
|
|
|
3
3
|
|
|
4
4
|
export const percentToString = (p: number, fractions = 0): string =>
|
|
5
5
|
(p * 100).toFixed(fractions);
|
|
6
|
+
|
|
6
7
|
export const secondsToString = (s: number): string => {
|
|
7
8
|
const seconds = (s % 60).toString().padStart(2, '0');
|
|
8
9
|
const minutes = parseInt((s / 60).toString())
|
|
@@ -87,6 +88,7 @@ export const convertBigNumberToHex = (
|
|
|
87
88
|
|
|
88
89
|
export const uint8ArrayToHex = (buffer: Uint8Array): string => {
|
|
89
90
|
// buffer is an ArrayBuffer
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
90
92
|
// @ts-ignore
|
|
91
93
|
return [...buffer].map((x) => x.toString(16).padStart(2, '0')).join('');
|
|
92
94
|
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
interface PropTypes {
|
|
4
|
-
inputUsdValue: BigNumber | null;
|
|
5
|
-
outputUsdValue: BigNumber | null;
|
|
6
|
-
}
|
|
7
|
-
export declare function PercentageChange(props: PropTypes): React.JSX.Element | null;
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=PercentageChange.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PercentageChange.d.ts","sourceRoot":"","sources":["../../src/components/PercentageChange.tsx"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,UAAU,SAAS;IACjB,aAAa,EAAE,SAAS,GAAG,IAAI,CAAC;IAChC,cAAc,EAAE,SAAS,GAAG,IAAI,CAAC;CAClC;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,4BAqBhD"}
|