@rango-dev/widget-embedded 0.1.11-next.9 → 0.1.11
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/ConfirmSwapErrors.d.ts +1 -1
- package/dist/components/ConfirmSwapErrors.d.ts.map +1 -1
- package/dist/components/ConfirmSwapWarnings.d.ts +1 -2
- package/dist/components/ConfirmSwapWarnings.d.ts.map +1 -1
- package/dist/components/SwapDetailsPlaceholder.d.ts +1 -0
- package/dist/components/SwapDetailsPlaceholder.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/warnings/BalanceErrors.d.ts +7 -0
- package/dist/components/warnings/BalanceErrors.d.ts.map +1 -0
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -2
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib.d.ts +4 -2
- 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/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +0 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/services/httpService.d.ts +2 -1
- package/dist/services/httpService.d.ts.map +1 -1
- package/dist/store/bestRoute.d.ts.map +1 -1
- package/dist/store/meta.d.ts.map +1 -1
- package/dist/types/config.d.ts +78 -9
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/routing.d.ts +8 -8
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +7 -0
- package/dist/utils/configs.d.ts.map +1 -0
- package/dist/utils/numbers.d.ts +1 -0
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/routing.d.ts +4 -4
- package/dist/utils/routing.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +2 -2
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/utils/time.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +346 -277
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +346 -277
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +342 -278
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/App.tsx +10 -16
- package/src/QueueManager.tsx +9 -3
- package/src/app.css +0 -15
- package/src/components/ConfirmSwapErrors.tsx +8 -16
- package/src/components/ConfirmSwapWarnings.tsx +5 -15
- package/src/components/SwapDetailsPlaceholder.tsx +8 -1
- package/src/components/TokenInfo.tsx +6 -5
- package/src/components/warnings/BalanceErrors.tsx +45 -0
- package/src/globalStyles.ts +4 -0
- package/src/hooks/useConfirmSwap.ts +5 -5
- package/src/hooks/useTheme.ts +2 -2
- package/src/index.tsx +1 -1
- package/src/lib.tsx +16 -15
- package/src/pages/ConfirmSwapPage.tsx +4 -2
- package/src/pages/HistoryPage.tsx +4 -1
- package/src/pages/Home.tsx +6 -8
- package/src/pages/SwapDetailsPage.tsx +8 -21
- package/src/pages/WalletsPage.tsx +2 -2
- package/src/services/httpService.ts +9 -4
- package/src/store/bestRoute.ts +7 -5
- package/src/store/meta.ts +6 -4
- package/src/store/wallets.ts +2 -2
- package/src/types/config.ts +79 -12
- package/src/types/routing.ts +4 -4
- package/src/utils/configs.ts +30 -0
- package/src/utils/numbers.ts +4 -0
- package/src/utils/routing.ts +31 -11
- package/src/utils/swap.ts +16 -5
- package/src/utils/time.ts +2 -8
- package/dist/components/warnings/BalanceWarnings.d.ts +0 -7
- package/dist/components/warnings/BalanceWarnings.d.ts.map +0 -1
- package/src/components/warnings/BalanceWarnings.tsx +0 -40
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.1.11
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"watch-tsc": "tsc --watch --noEmit",
|
|
14
|
-
"dev": "parcel public/index.html -p 3001 --
|
|
14
|
+
"dev": "parcel public/index.html -p 3001 --no-cache",
|
|
15
15
|
"dev-tsc": "npm-run-all --parallel watch-tsc dev",
|
|
16
16
|
"build:app": "parcel build --cache-dir=.parcel-cache",
|
|
17
17
|
"build": "tsdx build --entry ./src/lib.tsx"
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@rango-dev/provider-all": "^0.1.11-next.84",
|
|
32
32
|
"@rango-dev/queue-manager-core": "^0.1.11-next.0",
|
|
33
|
-
"@rango-dev/queue-manager-rango-preset": "^0.1.11-next.
|
|
33
|
+
"@rango-dev/queue-manager-rango-preset": "^0.1.11-next.7",
|
|
34
34
|
"@rango-dev/queue-manager-react": "^0.1.10-next.76",
|
|
35
|
-
"@rango-dev/ui": "^0.1.11-next.
|
|
35
|
+
"@rango-dev/ui": "^0.1.11-next.12",
|
|
36
36
|
"@rango-dev/wallets-core": "^0.1.11-next.88",
|
|
37
37
|
"@rango-dev/wallets-shared": "^0.1.11-next.84",
|
|
38
38
|
"bignumber.js": "^9.1.1",
|
package/src/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { AppRouter } from './components/AppRouter';
|
|
4
4
|
import { useMetaStore } from './store/meta';
|
|
5
5
|
import './app.css';
|
|
@@ -21,6 +21,7 @@ import { WidgetConfig } from './types';
|
|
|
21
21
|
import './i18n';
|
|
22
22
|
import { useUiStore } from './store/ui';
|
|
23
23
|
import { navigationRoutes } from './constants/navigationRoutes';
|
|
24
|
+
import { initConfig } from './utils/configs';
|
|
24
25
|
|
|
25
26
|
const providers = allProviders();
|
|
26
27
|
|
|
@@ -32,6 +33,13 @@ export function App({ config }: WidgetProps) {
|
|
|
32
33
|
globalStyles();
|
|
33
34
|
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
34
35
|
const { activeTheme } = useTheme({ ...config?.theme });
|
|
36
|
+
useMemo(() => {
|
|
37
|
+
if (config?.apiKey) {
|
|
38
|
+
initConfig({
|
|
39
|
+
API_KEY: config?.apiKey,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}, [config]);
|
|
35
43
|
|
|
36
44
|
const { blockchains } = useMetaStore.use.meta();
|
|
37
45
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
@@ -98,21 +106,7 @@ export function App({ config }: WidgetProps) {
|
|
|
98
106
|
>
|
|
99
107
|
<div id="pageContainer" className={activeTheme}>
|
|
100
108
|
<QueueManager>
|
|
101
|
-
<SwapContainer
|
|
102
|
-
// style={
|
|
103
|
-
// currentPage !== navigationRoutes.home && config?.theme?.height
|
|
104
|
-
// ? {
|
|
105
|
-
// height: config?.theme?.height,
|
|
106
|
-
// width: config?.theme?.width || 'auto',
|
|
107
|
-
// }
|
|
108
|
-
// : config?.theme?.width
|
|
109
|
-
// ? {
|
|
110
|
-
// width: config?.theme?.width || 'auto',
|
|
111
|
-
// }
|
|
112
|
-
// : undefined
|
|
113
|
-
// }
|
|
114
|
-
fixedHeight={currentPage !== navigationRoutes.home}
|
|
115
|
-
>
|
|
109
|
+
<SwapContainer fixedHeight={currentPage !== navigationRoutes.home}>
|
|
116
110
|
<AppRouter
|
|
117
111
|
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
118
112
|
disconnectedWallet={disconnectedWallet}
|
package/src/QueueManager.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React, { PropsWithChildren } from 'react';
|
|
1
|
+
import React, { PropsWithChildren, useMemo } from 'react';
|
|
2
2
|
import { Provider as ManagerProvider } from '@rango-dev/queue-manager-react';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
makeQueueDefinition,
|
|
5
5
|
SwapQueueContext,
|
|
6
6
|
checkWaitingForNetworkChange,
|
|
7
7
|
} from '@rango-dev/queue-manager-rango-preset';
|
|
@@ -15,6 +15,7 @@ import { useMetaStore } from './store/meta';
|
|
|
15
15
|
import { useWalletsStore } from './store/wallets';
|
|
16
16
|
import { walletAndSupportedChainsNames } from './utils/wallets';
|
|
17
17
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
|
+
import { getConfig } from './utils/configs';
|
|
18
19
|
|
|
19
20
|
function QueueManager(props: PropsWithChildren<{}>) {
|
|
20
21
|
const {
|
|
@@ -26,6 +27,11 @@ function QueueManager(props: PropsWithChildren<{}>) {
|
|
|
26
27
|
getWalletInfo,
|
|
27
28
|
} = useWallets();
|
|
28
29
|
|
|
30
|
+
const swapQueueDef = useMemo(() => {
|
|
31
|
+
return makeQueueDefinition({
|
|
32
|
+
API_KEY: getConfig('API_KEY'),
|
|
33
|
+
});
|
|
34
|
+
}, []);
|
|
29
35
|
const { blockchains } = useMetaStore.use.meta();
|
|
30
36
|
const balances = useWalletsStore.use.balances();
|
|
31
37
|
|
|
@@ -63,7 +69,7 @@ function QueueManager(props: PropsWithChildren<{}>) {
|
|
|
63
69
|
blockchains: allBlockchains,
|
|
64
70
|
evmBasedChains: evmBasedChains,
|
|
65
71
|
evmNetworkChainInfo:
|
|
66
|
-
|
|
72
|
+
convertEvmBlockchainMetaToEvmChainInfo(evmBasedChains),
|
|
67
73
|
getSupportedChainNames,
|
|
68
74
|
},
|
|
69
75
|
getSigners,
|
package/src/app.css
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap');
|
|
2
|
-
* {
|
|
3
|
-
box-sizing: border-box;
|
|
4
|
-
margin: 0;
|
|
5
|
-
padding: 0;
|
|
6
|
-
list-style-type: none;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
input::-webkit-outer-spin-button,
|
|
10
|
-
input::-webkit-inner-spin-button {
|
|
11
|
-
-webkit-appearance: none;
|
|
12
|
-
margin: 0;
|
|
13
|
-
}
|
|
14
|
-
input[type='number'] {
|
|
15
|
-
-moz-appearance: textfield;
|
|
16
|
-
}
|
|
17
2
|
|
|
18
3
|
#app {
|
|
19
4
|
height: 100vh;
|
|
@@ -1,36 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Typography } from '@rango-dev/ui';
|
|
3
2
|
import { ConfirmSwapError, ConfirmSwapErrorTypes } from '../types';
|
|
4
3
|
import { MinRequiredSlippage } from './warnings/MinRequiredSlippage';
|
|
4
|
+
import { BalanceErrors } from './warnings/BalanceErrors';
|
|
5
5
|
|
|
6
6
|
export function ConfirmSwapErrors(errors: ConfirmSwapError[]) {
|
|
7
7
|
return errors.flatMap((error) => {
|
|
8
8
|
switch (error.type) {
|
|
9
9
|
case ConfirmSwapErrorTypes.NO_ROUTE:
|
|
10
|
-
return
|
|
11
|
-
<Typography variant="body2">
|
|
12
|
-
No routes found. Please try again later.
|
|
13
|
-
</Typography>
|
|
14
|
-
);
|
|
10
|
+
return 'No routes found. Please try again later.';
|
|
15
11
|
case ConfirmSwapErrorTypes.REQUEST_FAILED:
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}, please try again.`}</Typography>
|
|
20
|
-
);
|
|
12
|
+
return `Failed to confirm swap ${
|
|
13
|
+
error.status ? `'status': ${error.status})` : ''
|
|
14
|
+
}, please try again.`;
|
|
21
15
|
|
|
22
16
|
case ConfirmSwapErrorTypes.ROUTE_UPDATED_WITH_HIGH_VALUE_LOSS:
|
|
23
|
-
return
|
|
24
|
-
<Typography variant="body2">
|
|
25
|
-
Route updated and price impact is too high, try again later!
|
|
26
|
-
</Typography>
|
|
27
|
-
);
|
|
17
|
+
return 'Route updated and price impact is too high, try again later!';
|
|
28
18
|
case ConfirmSwapErrorTypes.INSUFFICIENT_SLIPPAGE:
|
|
29
19
|
return (
|
|
30
20
|
<MinRequiredSlippage
|
|
31
21
|
minRequiredSlippage={error.minRequiredSlippage}
|
|
32
22
|
/>
|
|
33
23
|
);
|
|
24
|
+
case ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE:
|
|
25
|
+
return <BalanceErrors messages={error.messages} />;
|
|
34
26
|
default:
|
|
35
27
|
return [];
|
|
36
28
|
}
|
|
@@ -1,35 +1,25 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Typography } from '@rango-dev/ui';
|
|
3
1
|
import { ConfirmSwapWarningTypes, ConfirmSwapWarnings } from '../types';
|
|
4
|
-
import { BalanceWarnings } from './warnings/BalanceWarnings';
|
|
5
2
|
|
|
6
3
|
export function ConfirmSwapWarnings(warnings: ConfirmSwapWarnings[]) {
|
|
7
4
|
return warnings.flatMap((warning) => {
|
|
8
5
|
switch (warning.type) {
|
|
9
6
|
case ConfirmSwapWarningTypes.ROUTE_UPDATED:
|
|
10
|
-
return
|
|
7
|
+
return "Route has been updated.";
|
|
11
8
|
case ConfirmSwapWarningTypes.ROUTE_AND_OUTPUT_AMOUNT_UPDATED:
|
|
12
9
|
return (
|
|
13
|
-
|
|
14
|
-
(${warning.percentageChange}% change).`}</Typography>
|
|
10
|
+
`Output amount changed to ${warning.newOutputAmount} (${warning.percentageChange}% change).`
|
|
15
11
|
);
|
|
16
12
|
|
|
17
13
|
case ConfirmSwapWarningTypes.ROUTE_SWAPPERS_UPDATED:
|
|
18
14
|
return (
|
|
19
|
-
|
|
20
|
-
Route swappers has been updated.
|
|
21
|
-
</Typography>
|
|
15
|
+
"Route swappers has been updated."
|
|
22
16
|
);
|
|
23
17
|
case ConfirmSwapWarningTypes.ROUTE_COINS_UPDATED:
|
|
24
18
|
return (
|
|
25
|
-
|
|
26
|
-
Route internal coins has been updated.
|
|
27
|
-
</Typography>
|
|
19
|
+
"Route internal coins has been updated."
|
|
28
20
|
);
|
|
29
|
-
case ConfirmSwapWarningTypes.INSUFFICIENT_BALANCE:
|
|
30
|
-
return <BalanceWarnings messages={warning.messages} />;
|
|
31
21
|
default:
|
|
32
22
|
return [];
|
|
33
23
|
}
|
|
34
24
|
});
|
|
35
|
-
}
|
|
25
|
+
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SecondaryPage, Spinner, Alert, styled } from '@rango-dev/ui';
|
|
3
|
-
import { LoaderContainer } from '../pages/WalletsPage';
|
|
4
3
|
|
|
5
4
|
const PlaceholderContainer = styled('div', { height: '450px' });
|
|
6
5
|
|
|
6
|
+
export const LoaderContainer = styled('div', {
|
|
7
|
+
display: 'flex',
|
|
8
|
+
justifyContent: 'center',
|
|
9
|
+
width: '100%',
|
|
10
|
+
paddingTop: '33%',
|
|
11
|
+
flex: 1,
|
|
12
|
+
});
|
|
13
|
+
|
|
7
14
|
interface PropTypes {
|
|
8
15
|
requestId: string;
|
|
9
16
|
loading: boolean;
|
|
@@ -132,6 +132,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
132
132
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
133
133
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
134
134
|
const balances = useWalletsStore.use.balances();
|
|
135
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
135
136
|
const navigate = useNavigate();
|
|
136
137
|
const { t } = useTranslation();
|
|
137
138
|
|
|
@@ -296,6 +297,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
296
297
|
</span>
|
|
297
298
|
}
|
|
298
299
|
value={props.inputAmount || ''}
|
|
300
|
+
min={0}
|
|
299
301
|
onChange={
|
|
300
302
|
props.type === 'From'
|
|
301
303
|
? (event) => {
|
|
@@ -307,11 +309,10 @@ export function TokenInfo(props: PropTypes) {
|
|
|
307
309
|
) : (
|
|
308
310
|
<OutputContainer>
|
|
309
311
|
<Typography variant="h4">
|
|
310
|
-
{
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
: '0'}
|
|
312
|
+
{fetchingBestRoute && '?'}
|
|
313
|
+
{!!bestRoute?.result &&
|
|
314
|
+
`≈ ${numberToString(props.outputAmount)}`}
|
|
315
|
+
{(!inputAmount || inputAmount === '0') && '0'}
|
|
315
316
|
</Typography>
|
|
316
317
|
</OutputContainer>
|
|
317
318
|
)}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Spacer, styled, Typography } from '@rango-dev/ui';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
interface PropTypes {
|
|
5
|
+
messages: string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const List = styled('ul', {
|
|
9
|
+
variants: {
|
|
10
|
+
showListStyle: {
|
|
11
|
+
true: { paddingLeft: '$24' },
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const ListItem = styled('li', {
|
|
17
|
+
variants: {
|
|
18
|
+
showListStyle: {
|
|
19
|
+
true: { listStyleType: 'disc', listStylePosition: 'outside' },
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const Message = styled(Typography, {
|
|
25
|
+
display: 'block',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export function BalanceErrors({ messages }: PropTypes) {
|
|
29
|
+
const showListStyle = messages.length > 1;
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<Typography className="title" variant="title" color={'error'}>
|
|
33
|
+
Insufficent Balance:
|
|
34
|
+
</Typography>
|
|
35
|
+
<Spacer size={8} direction="vertical" />
|
|
36
|
+
<List showListStyle={showListStyle}>
|
|
37
|
+
{messages.map((warning) => (
|
|
38
|
+
<ListItem showListStyle={showListStyle}>
|
|
39
|
+
<Message variant="body2">{warning}</Message>
|
|
40
|
+
</ListItem>
|
|
41
|
+
))}
|
|
42
|
+
</List>
|
|
43
|
+
</>
|
|
44
|
+
);
|
|
45
|
+
}
|
package/src/globalStyles.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { globalCss } from '@rango-dev/ui';
|
|
|
2
2
|
|
|
3
3
|
export const globalStyles = globalCss({
|
|
4
4
|
'*': {
|
|
5
|
+
boxSizing: 'border-box',
|
|
6
|
+
margin: 0,
|
|
7
|
+
padding: 0,
|
|
8
|
+
listStyleType: 'none',
|
|
5
9
|
'&::-webkit-scrollbar': { width: '$8', height: '$8' },
|
|
6
10
|
'&::-webkit-scrollbar-thumb': {
|
|
7
11
|
backgroundColor: '$neutrals400',
|
|
@@ -112,12 +112,12 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
112
112
|
selectedWallets,
|
|
113
113
|
disabledLiquiditySources,
|
|
114
114
|
userSlippage,
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
affiliateRef,
|
|
116
|
+
initialRoute
|
|
117
117
|
);
|
|
118
118
|
|
|
119
119
|
try {
|
|
120
|
-
const confiremedRoute = await httpService.getBestRoute(requestBody, {
|
|
120
|
+
const confiremedRoute = await httpService().getBestRoute(requestBody, {
|
|
121
121
|
signal: abortControllerRef.current?.signal,
|
|
122
122
|
});
|
|
123
123
|
|
|
@@ -198,8 +198,8 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
198
198
|
const enoughBalance = balanceWarnings.length === 0;
|
|
199
199
|
|
|
200
200
|
if (!enoughBalance)
|
|
201
|
-
confirmSwapState.
|
|
202
|
-
type:
|
|
201
|
+
confirmSwapState.errors.push({
|
|
202
|
+
type: ConfirmSwapErrorTypes.INSUFFICIENT_BALANCE,
|
|
203
203
|
messages: balanceWarnings,
|
|
204
204
|
});
|
|
205
205
|
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createTheme } from '@rango-dev/ui';
|
|
|
2
2
|
import { useState, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import { useMetaStore } from '../store/meta';
|
|
4
4
|
import { useSettingsStore } from '../store/settings';
|
|
5
|
-
import {
|
|
5
|
+
import { WidgetTheme } from '../types';
|
|
6
6
|
import { shadeColor } from '../utils/common';
|
|
7
7
|
import usePrevious from './usePrevious';
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ export function useTheme({
|
|
|
11
11
|
fontFamily = 'Robot',
|
|
12
12
|
borderRadius = 8,
|
|
13
13
|
mode = 'auto',
|
|
14
|
-
}:
|
|
14
|
+
}: WidgetTheme) {
|
|
15
15
|
const theme = useSettingsStore.use.theme();
|
|
16
16
|
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
17
17
|
const setTheme = useSettingsStore.use.setTheme();
|
package/src/index.tsx
CHANGED
package/src/lib.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import React, { useEffect, useMemo, 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';
|
|
@@ -15,18 +15,22 @@ import { Layout } from './components/Layout';
|
|
|
15
15
|
import { globalFont, globalStyles } from './globalStyles';
|
|
16
16
|
import { useTheme } from './hooks/useTheme';
|
|
17
17
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
|
-
import { WidgetConfig } from './types';
|
|
18
|
+
import { WidgetTheme, WidgetConfig, WidgetColors, BlockchainAndTokenConfig } from './types';
|
|
19
19
|
import useSelectLanguage from './hooks/useSelectLanguage';
|
|
20
20
|
import './i18n';
|
|
21
21
|
import QueueManager from './QueueManager';
|
|
22
22
|
import { useUiStore } from './store/ui';
|
|
23
23
|
import { navigationRoutes } from './constants/navigationRoutes';
|
|
24
|
+
import { initConfig } from './utils/configs';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
export {WidgetConfig, WalletType, WidgetTheme, WidgetColors, BlockchainAndTokenConfig}
|
|
24
28
|
|
|
25
29
|
export type WidgetProps = {
|
|
26
30
|
config?: WidgetConfig;
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
export const
|
|
33
|
+
export const Widget: React.FC<WidgetProps> = ({ config }) => {
|
|
30
34
|
globalStyles();
|
|
31
35
|
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
32
36
|
|
|
@@ -45,6 +49,14 @@ export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
|
|
|
45
49
|
.filter(isEvmBlockchain)
|
|
46
50
|
.map((chain) => chain.name);
|
|
47
51
|
|
|
52
|
+
useMemo(() => {
|
|
53
|
+
if (config?.apiKey) {
|
|
54
|
+
initConfig({
|
|
55
|
+
API_KEY: config?.apiKey,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}, [config]);
|
|
59
|
+
|
|
48
60
|
const onUpdateState: EventHandler = (
|
|
49
61
|
type,
|
|
50
62
|
event,
|
|
@@ -106,18 +118,7 @@ export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
|
|
|
106
118
|
<div id="pageContainer" className={activeTheme}>
|
|
107
119
|
<QueueManager>
|
|
108
120
|
<SwapContainer
|
|
109
|
-
fixedHeight={currentPage !== navigationRoutes.home}
|
|
110
|
-
// style={
|
|
111
|
-
// currentPage !== navigationRoutes.home && config?.theme?.height
|
|
112
|
-
// ? {
|
|
113
|
-
// height: config?.theme?.height,
|
|
114
|
-
// width: config?.theme?.width || 'auto',
|
|
115
|
-
// }
|
|
116
|
-
// : {
|
|
117
|
-
// width: config?.theme?.width || 'auto',
|
|
118
|
-
// }
|
|
119
|
-
// }
|
|
120
|
-
>
|
|
121
|
+
fixedHeight={currentPage !== navigationRoutes.home}>
|
|
121
122
|
<AppRouter
|
|
122
123
|
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
123
124
|
disconnectedWallet={disconnectedWallet}
|
|
@@ -47,6 +47,7 @@ export function ConfirmSwapPage() {
|
|
|
47
47
|
const customSlippage = useSettingsStore.use.customSlippage();
|
|
48
48
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
49
49
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
50
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
50
51
|
|
|
51
52
|
const bestRouteloadingStatus = getBestRouteStatus(
|
|
52
53
|
fetchingBestRoute,
|
|
@@ -96,7 +97,6 @@ export function ConfirmSwapPage() {
|
|
|
96
97
|
|
|
97
98
|
return (
|
|
98
99
|
<ConfirmSwap
|
|
99
|
-
// @ts-ignore
|
|
100
100
|
requiredWallets={getRequiredChains(bestRoute)}
|
|
101
101
|
selectableWallets={selectableWallets}
|
|
102
102
|
onBack={navigateBackFrom.bind(null, navigationRoutes.confirmSwap)}
|
|
@@ -106,13 +106,15 @@ export function ConfirmSwapPage() {
|
|
|
106
106
|
manager?.create(
|
|
107
107
|
'swap',
|
|
108
108
|
{ swapDetails: swap },
|
|
109
|
-
// @ts-ignore
|
|
110
109
|
{ id: swap.requestId }
|
|
111
110
|
);
|
|
112
111
|
setSelectedSwap(swap.requestId);
|
|
113
112
|
navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
114
113
|
replace: true,
|
|
115
114
|
});
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
setInputAmount('');
|
|
117
|
+
}, 0);
|
|
116
118
|
}
|
|
117
119
|
});
|
|
118
120
|
}}
|
|
@@ -15,11 +15,14 @@ export function HistoryPage() {
|
|
|
15
15
|
const { manager } = useManager();
|
|
16
16
|
const pendingSwaps = getPendingSwaps(manager).map(({ swap }) => swap);
|
|
17
17
|
|
|
18
|
+
const loading = !manager?.isLoaded();
|
|
19
|
+
|
|
18
20
|
return (
|
|
19
21
|
<History
|
|
20
22
|
list={pendingSwaps}
|
|
21
23
|
groupBy={groupSwapsByDate}
|
|
22
|
-
|
|
24
|
+
loading={loading}
|
|
25
|
+
onSwapClick={(requestId) => {
|
|
23
26
|
setSelectedSwap(requestId);
|
|
24
27
|
navigate(navigationRoutes.swaps + `/${requestId}`, { replace: true });
|
|
25
28
|
}}
|
package/src/pages/Home.tsx
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
import BigNumber from 'bignumber.js';
|
|
37
37
|
import { HeaderButtons } from '../components/HeaderButtons';
|
|
38
38
|
import { useUiStore } from '../store/ui';
|
|
39
|
+
import { getFormatedBestRoute } from '../utils/routing';
|
|
39
40
|
|
|
40
41
|
const Container = styled('div', {
|
|
41
42
|
display: 'flex',
|
|
@@ -110,7 +111,6 @@ export function Home() {
|
|
|
110
111
|
outputUsdValue
|
|
111
112
|
);
|
|
112
113
|
|
|
113
|
-
const inputIsZero = inputAmount === '0';
|
|
114
114
|
const swapButtonState = getSwapButtonState(
|
|
115
115
|
loadingMetaStatus,
|
|
116
116
|
accounts,
|
|
@@ -120,7 +120,7 @@ export function Home() {
|
|
|
120
120
|
highValueLoss,
|
|
121
121
|
priceImpactCanNotBeComputed,
|
|
122
122
|
needsToWarnEthOnPath,
|
|
123
|
-
|
|
123
|
+
inputAmount
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
@@ -178,7 +178,7 @@ export function Home() {
|
|
|
178
178
|
<BestRoute
|
|
179
179
|
error={bestRouteError}
|
|
180
180
|
loading={fetchingBestRoute}
|
|
181
|
-
data={bestRoute}
|
|
181
|
+
data={getFormatedBestRoute(bestRoute)}
|
|
182
182
|
totalFee={numberToString(totalFeeInUsd, 0, 2)}
|
|
183
183
|
feeWarning={highFee}
|
|
184
184
|
totalTime={secondsToString(totalArrivalTime(bestRoute))}
|
|
@@ -191,13 +191,11 @@ export function Home() {
|
|
|
191
191
|
{hasLimitError(bestRoute) && (
|
|
192
192
|
<Alert type="error" title={`${swap?.swapperId} Limit`}>
|
|
193
193
|
<>
|
|
194
|
-
<Typography variant="body2">{fromAmountRangeError}</Typography>
|
|
195
|
-
<br />
|
|
196
194
|
<Typography variant="body2">
|
|
197
|
-
Yours: {numberToString(
|
|
198
|
-
|
|
195
|
+
{`${fromAmountRangeError}, Yours: ${numberToString(
|
|
196
|
+
swap?.fromAmount || null
|
|
197
|
+
)} ${swap?.from.symbol}`}
|
|
199
198
|
</Typography>
|
|
200
|
-
<br />
|
|
201
199
|
<Typography variant="body2">{recommendation}</Typography>
|
|
202
200
|
</>
|
|
203
201
|
</Alert>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
3
3
|
import useCopyToClipboard from '../hooks/useCopyToClipboard';
|
|
4
4
|
import { useManager } from '@rango-dev/queue-manager-react';
|
|
5
5
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
6
|
import { getPendingSwaps } from '../utils/queue';
|
|
7
|
-
import { SwapHistory
|
|
7
|
+
import { SwapHistory } from '@rango-dev/ui';
|
|
8
8
|
import { useUiStore } from '../store/ui';
|
|
9
9
|
import {
|
|
10
10
|
cancelSwap,
|
|
@@ -25,11 +25,10 @@ import {
|
|
|
25
25
|
isNetworkStatusInWarningState,
|
|
26
26
|
shouldRetrySwap,
|
|
27
27
|
} from '../utils/swap';
|
|
28
|
-
import { TokenPreview } from '../components/TokenPreview';
|
|
29
|
-
import { numberToString } from '../utils/numbers';
|
|
30
28
|
//@ts-ignore
|
|
31
29
|
import { t } from 'i18next';
|
|
32
30
|
import { SwapDetailsPlaceholder } from '../components/SwapDetailsPlaceholder';
|
|
31
|
+
import { getFormatedPendingSwap } from '../utils/routing';
|
|
33
32
|
|
|
34
33
|
export function SwapDetailsPage() {
|
|
35
34
|
const selectedSwapRequestId = useUiStore.use.selectedSwapRequestId();
|
|
@@ -40,14 +39,6 @@ export function SwapDetailsPage() {
|
|
|
40
39
|
const [isCopied, handleCopy] = useCopyToClipboard(2000);
|
|
41
40
|
const { manager } = useManager();
|
|
42
41
|
|
|
43
|
-
const [loading, setLoading] = useState(true);
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
setLoading(false);
|
|
48
|
-
}, 5000);
|
|
49
|
-
}, []);
|
|
50
|
-
|
|
51
42
|
const pendingSwaps = getPendingSwaps(manager);
|
|
52
43
|
const selectedSwap = pendingSwaps.find(
|
|
53
44
|
({ swap }) => swap.requestId === selectedSwapRequestId
|
|
@@ -58,6 +49,7 @@ export function SwapDetailsPage() {
|
|
|
58
49
|
if (swap) cancelSwap(swap);
|
|
59
50
|
};
|
|
60
51
|
const swap = selectedSwap?.swap;
|
|
52
|
+
const loading = !manager?.isLoaded();
|
|
61
53
|
|
|
62
54
|
if (!swap)
|
|
63
55
|
return (
|
|
@@ -68,11 +60,6 @@ export function SwapDetailsPage() {
|
|
|
68
60
|
/>
|
|
69
61
|
);
|
|
70
62
|
|
|
71
|
-
const firstStep = swap.steps[0];
|
|
72
|
-
const lastStep = swap.steps[swap.steps.length - 1];
|
|
73
|
-
const fromAmount = numberToString(swap.inputAmount);
|
|
74
|
-
const toAmount = numberToString(swap.simulationResult.outputAmount);
|
|
75
|
-
|
|
76
63
|
const currentStep = getCurrentStep(swap);
|
|
77
64
|
|
|
78
65
|
const currentStepBlockchain = currentStep
|
|
@@ -106,12 +93,13 @@ export function SwapDetailsPage() {
|
|
|
106
93
|
return (
|
|
107
94
|
<SwapHistory
|
|
108
95
|
onBack={navigateBackFrom.bind(null, navigationRoutes.swapDetails)}
|
|
96
|
+
/* TODO: It was temporarily removed to find a better solution*/
|
|
97
|
+
/*
|
|
109
98
|
previewInputs={
|
|
110
99
|
<>
|
|
111
100
|
<TokenPreview
|
|
112
101
|
chain={{
|
|
113
102
|
displayName: firstStep?.fromBlockchain || '',
|
|
114
|
-
// @ts-ignore
|
|
115
103
|
logo: firstStep?.fromBlockchainLogo || '',
|
|
116
104
|
}}
|
|
117
105
|
token={{
|
|
@@ -126,7 +114,6 @@ export function SwapDetailsPage() {
|
|
|
126
114
|
<TokenPreview
|
|
127
115
|
chain={{
|
|
128
116
|
displayName: lastStep?.toBlockchain || '',
|
|
129
|
-
//@ts-ignore
|
|
130
117
|
logo: lastStep?.toBlockchainLogo || '',
|
|
131
118
|
}}
|
|
132
119
|
token={{
|
|
@@ -139,8 +126,8 @@ export function SwapDetailsPage() {
|
|
|
139
126
|
/>
|
|
140
127
|
</>
|
|
141
128
|
}
|
|
142
|
-
|
|
143
|
-
pendingSwap={swap}
|
|
129
|
+
*/
|
|
130
|
+
pendingSwap={getFormatedPendingSwap(swap)}
|
|
144
131
|
onCopy={handleCopy}
|
|
145
132
|
isCopied={isCopied}
|
|
146
133
|
onCancel={onCancel}
|
|
@@ -33,7 +33,7 @@ const ListContainer = styled('div', {
|
|
|
33
33
|
overflowY: 'auto',
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const LoaderContainer = styled('div', {
|
|
37
37
|
display: 'flex',
|
|
38
38
|
justifyContent: 'center',
|
|
39
39
|
width: '100%',
|
|
@@ -113,7 +113,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
|
113
113
|
<>
|
|
114
114
|
{walletErrorMessage && (
|
|
115
115
|
<AlertContainer>
|
|
116
|
-
<Alert type="error"
|
|
116
|
+
<Alert type="error" title={walletErrorMessage} />
|
|
117
117
|
</AlertContainer>
|
|
118
118
|
)}
|
|
119
119
|
{loadingMetaStatus === 'loading' && (
|