@rango-dev/widget-embedded 0.1.11-next.0 → 0.1.11-next.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 +3 -3
- package/dist/App.d.ts.map +1 -1
- package/dist/QueueManager.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +1 -7
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +2 -2
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +3 -3
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/components/TokenPreview.d.ts.map +1 -1
- package/dist/hooks/useConfirmSwap.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +2 -5
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts +1 -7
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts +1 -2
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts +1 -2
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts +2 -2
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +1 -2
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/SwapDetailsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +1 -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/store/settings.d.ts +2 -0
- package/dist/store/settings.d.ts.map +1 -1
- package/dist/types/config.d.ts +27 -29
- package/dist/types/config.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/swap.d.ts +3 -7
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +144 -195
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +144 -195
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +144 -195
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +6 -4
- package/readme.md +1 -1
- package/src/App.tsx +36 -14
- package/src/QueueManager.tsx +9 -3
- package/src/components/AppRouter.tsx +7 -16
- package/src/components/AppRoutes.tsx +13 -32
- package/src/components/HeaderButtons.tsx +1 -1
- package/src/components/Layout.tsx +37 -27
- package/src/components/TokenInfo.tsx +9 -13
- package/src/components/TokenPreview.tsx +3 -7
- package/src/hooks/useConfirmSwap.ts +6 -5
- package/src/hooks/useTheme.ts +21 -9
- package/src/lib.tsx +30 -36
- package/src/pages/ConfirmSwapPage.tsx +2 -0
- package/src/pages/Home.tsx +3 -10
- package/src/pages/LiquiditySourcesPage.tsx +3 -6
- package/src/pages/SelectChainPage.tsx +6 -6
- package/src/pages/SelectTokenPage.tsx +16 -18
- package/src/pages/SettingsPage.tsx +8 -18
- package/src/pages/SwapDetailsPage.tsx +2 -4
- package/src/pages/WalletsPage.tsx +2 -2
- package/src/services/httpService.ts +12 -3
- package/src/store/bestRoute.ts +5 -4
- package/src/store/meta.ts +6 -4
- package/src/store/settings.ts +7 -0
- package/src/store/wallets.ts +2 -2
- package/src/types/config.ts +28 -29
- package/src/utils/configs.ts +24 -0
- package/src/utils/swap.ts +17 -99
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.1.11-next.
|
|
3
|
+
"version": "0.1.11-next.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
],
|
|
11
11
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
12
12
|
"scripts": {
|
|
13
|
+
"watch-tsc": "tsc --watch --noEmit",
|
|
13
14
|
"dev": "parcel public/index.html -p 3001 --cache-dir=.parcel-cache",
|
|
15
|
+
"dev-tsc": "npm-run-all --parallel watch-tsc dev",
|
|
14
16
|
"build:app": "parcel build --cache-dir=.parcel-cache",
|
|
15
17
|
"build": "tsdx build --entry ./src/lib.tsx"
|
|
16
18
|
},
|
|
@@ -27,10 +29,10 @@
|
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"@rango-dev/provider-all": "^0.1.11-next.84",
|
|
30
|
-
"@rango-dev/queue-manager-core": "^0.1.
|
|
31
|
-
"@rango-dev/queue-manager-rango-preset": "^0.1.
|
|
32
|
+
"@rango-dev/queue-manager-core": "^0.1.11-next.0",
|
|
33
|
+
"@rango-dev/queue-manager-rango-preset": "^0.1.11-next.3",
|
|
32
34
|
"@rango-dev/queue-manager-react": "^0.1.10-next.76",
|
|
33
|
-
"@rango-dev/ui": "^0.1.
|
|
35
|
+
"@rango-dev/ui": "^0.1.11-next.4",
|
|
34
36
|
"@rango-dev/wallets-core": "^0.1.11-next.88",
|
|
35
37
|
"@rango-dev/wallets-shared": "^0.1.11-next.84",
|
|
36
38
|
"bignumber.js": "^9.1.1",
|
package/readme.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# @rango-dev/widget-embedded
|
|
1
|
+
# @rango-dev/widget-embedded
|
package/src/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React, { 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';
|
|
@@ -17,24 +17,29 @@ import { globalFont, globalStyles } from './globalStyles';
|
|
|
17
17
|
import { useTheme } from './hooks/useTheme';
|
|
18
18
|
import QueueManager from './QueueManager';
|
|
19
19
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
20
|
-
import {
|
|
20
|
+
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
|
|
|
27
28
|
export type WidgetProps = {
|
|
28
|
-
|
|
29
|
+
config?: WidgetConfig;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
export function App({
|
|
32
|
+
export function App({ config }: WidgetProps) {
|
|
32
33
|
globalStyles();
|
|
33
|
-
globalFont(
|
|
34
|
-
const { activeTheme } = useTheme({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
35
|
+
const { activeTheme } = useTheme({ ...config?.theme });
|
|
36
|
+
useMemo(() => {
|
|
37
|
+
if (config?.apiKey) {
|
|
38
|
+
initConfig({
|
|
39
|
+
API_KEY: config?.apiKey,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}, [config]);
|
|
38
43
|
|
|
39
44
|
const { blockchains } = useMetaStore.use.meta();
|
|
40
45
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
@@ -49,6 +54,12 @@ export function App({ configs }: WidgetProps) {
|
|
|
49
54
|
.filter(isEvmBlockchain)
|
|
50
55
|
.map((chain) => chain.name);
|
|
51
56
|
|
|
57
|
+
const themeBackground = activeTheme?.colors?.background?.value;
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
document.body.style.background = themeBackground;
|
|
61
|
+
}, [themeBackground]);
|
|
62
|
+
|
|
52
63
|
const onUpdateState: EventHandler = (
|
|
53
64
|
type,
|
|
54
65
|
event,
|
|
@@ -95,18 +106,29 @@ export function App({ configs }: WidgetProps) {
|
|
|
95
106
|
>
|
|
96
107
|
<div id="pageContainer" className={activeTheme}>
|
|
97
108
|
<QueueManager>
|
|
98
|
-
<SwapContainer
|
|
109
|
+
<SwapContainer
|
|
110
|
+
// style={
|
|
111
|
+
// currentPage !== navigationRoutes.home && config?.theme?.height
|
|
112
|
+
// ? {
|
|
113
|
+
// height: config?.theme?.height,
|
|
114
|
+
// width: config?.theme?.width || 'auto',
|
|
115
|
+
// }
|
|
116
|
+
// : config?.theme?.width
|
|
117
|
+
// ? {
|
|
118
|
+
// width: config?.theme?.width || 'auto',
|
|
119
|
+
// }
|
|
120
|
+
// : undefined
|
|
121
|
+
// }
|
|
122
|
+
fixedHeight={currentPage !== navigationRoutes.home}
|
|
123
|
+
>
|
|
99
124
|
<AppRouter
|
|
100
|
-
title={configs?.title}
|
|
101
|
-
titleSize={configs?.titleSize}
|
|
102
|
-
titleWeight={configs?.titleWeight}
|
|
103
125
|
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
104
126
|
disconnectedWallet={disconnectedWallet}
|
|
105
127
|
clearDisconnectedWallet={() => {
|
|
106
128
|
setDisconnectedWallet(undefined);
|
|
107
129
|
}}
|
|
108
130
|
>
|
|
109
|
-
<Layout
|
|
131
|
+
<Layout config={config} />
|
|
110
132
|
</AppRouter>
|
|
111
133
|
</SwapContainer>
|
|
112
134
|
</QueueManager>
|
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,
|
|
@@ -13,15 +13,7 @@ import { UpdateUrl } from './UpdateUrl';
|
|
|
13
13
|
import { Home } from '../pages/Home';
|
|
14
14
|
import { useMetaStore } from '../store/meta';
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
title?: string;
|
|
18
|
-
titleSize?: number;
|
|
19
|
-
titleWeight?: number;
|
|
20
|
-
}
|
|
21
|
-
const Route: React.FC = ({
|
|
22
|
-
children,
|
|
23
|
-
...props
|
|
24
|
-
}: PropTypes & PropsWithChildren) => {
|
|
16
|
+
const Route: React.FC = ({ children }: PropsWithChildren) => {
|
|
25
17
|
const location = useLocation();
|
|
26
18
|
const navigate = useNavigate();
|
|
27
19
|
const ref = useRef(true);
|
|
@@ -34,7 +26,7 @@ const Route: React.FC = ({
|
|
|
34
26
|
}, []);
|
|
35
27
|
|
|
36
28
|
if (location.pathname === navigationRoutes.confirmSwap && ref.current)
|
|
37
|
-
return <Home
|
|
29
|
+
return <Home />;
|
|
38
30
|
|
|
39
31
|
return <> {children}</>;
|
|
40
32
|
};
|
|
@@ -42,12 +34,11 @@ const Route: React.FC = ({
|
|
|
42
34
|
export function AppRouter({
|
|
43
35
|
children,
|
|
44
36
|
...props
|
|
45
|
-
}:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}) {
|
|
37
|
+
}: PropsWithChildren & {
|
|
38
|
+
lastConnectedWallet: string;
|
|
39
|
+
disconnectedWallet: WalletType | undefined;
|
|
40
|
+
clearDisconnectedWallet: () => void;
|
|
41
|
+
}) {
|
|
51
42
|
const isRouterInContext = useInRouterContext();
|
|
52
43
|
const Router = isRouterInContext ? Route : MemoryRouter;
|
|
53
44
|
const { blockchains } = useMetaStore.use.meta();
|
|
@@ -10,76 +10,57 @@ import { SelectTokenPage } from '../pages/SelectTokenPage';
|
|
|
10
10
|
import { SettingsPage } from '../pages/SettingsPage';
|
|
11
11
|
import { WalletsPage } from '../pages/WalletsPage';
|
|
12
12
|
import { SwapDetailsPage } from '../pages/SwapDetailsPage';
|
|
13
|
-
import {
|
|
13
|
+
import { WidgetConfig } from '../types';
|
|
14
14
|
|
|
15
15
|
const getAbsolutePath = (path: string) => path.replace('/', '');
|
|
16
16
|
|
|
17
17
|
interface PropTypes {
|
|
18
|
-
|
|
18
|
+
config?: WidgetConfig;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function AppRoutes(props: PropTypes) {
|
|
22
|
-
const {
|
|
22
|
+
const { config } = props;
|
|
23
23
|
|
|
24
24
|
return useRoutes([
|
|
25
25
|
{
|
|
26
26
|
path: getAbsolutePath(navigationRoutes.home),
|
|
27
|
-
element:
|
|
28
|
-
<Home
|
|
29
|
-
title={configs?.title}
|
|
30
|
-
titleSize={configs?.titleSize}
|
|
31
|
-
titleWeight={configs?.titleWeight}
|
|
32
|
-
/>
|
|
33
|
-
),
|
|
27
|
+
element: <Home />,
|
|
34
28
|
},
|
|
35
29
|
{
|
|
36
30
|
path: getAbsolutePath(navigationRoutes.fromChain),
|
|
37
31
|
element: (
|
|
38
32
|
<SelectChainPage
|
|
39
33
|
type="from"
|
|
40
|
-
supportedChains={
|
|
34
|
+
supportedChains={config?.from?.blockchains}
|
|
41
35
|
/>
|
|
42
36
|
),
|
|
43
37
|
},
|
|
44
38
|
{
|
|
45
39
|
path: getAbsolutePath(navigationRoutes.toChain),
|
|
46
40
|
element: (
|
|
47
|
-
<SelectChainPage
|
|
48
|
-
type="to"
|
|
49
|
-
supportedChains={configs?.toChains || 'all'}
|
|
50
|
-
/>
|
|
41
|
+
<SelectChainPage type="to" supportedChains={config?.to?.blockchains} />
|
|
51
42
|
),
|
|
52
43
|
},
|
|
53
44
|
{
|
|
54
45
|
path: getAbsolutePath(navigationRoutes.fromToken),
|
|
55
46
|
element: (
|
|
56
|
-
<SelectTokenPage
|
|
57
|
-
type="from"
|
|
58
|
-
supportedTokens={configs?.fromTokens || 'all'}
|
|
59
|
-
/>
|
|
47
|
+
<SelectTokenPage type="from" supportedTokens={config?.from?.tokens} />
|
|
60
48
|
),
|
|
61
49
|
},
|
|
62
50
|
{
|
|
63
51
|
path: getAbsolutePath(navigationRoutes.toToken),
|
|
64
52
|
element: (
|
|
65
|
-
<SelectTokenPage
|
|
66
|
-
type="to"
|
|
67
|
-
supportedTokens={configs?.toTokens || 'all'}
|
|
68
|
-
/>
|
|
53
|
+
<SelectTokenPage type="to" supportedTokens={config?.to?.tokens} />
|
|
69
54
|
),
|
|
70
55
|
},
|
|
71
56
|
{
|
|
72
57
|
path: getAbsolutePath(navigationRoutes.settings),
|
|
73
|
-
element:
|
|
74
|
-
<SettingsPage supportedSwappers={configs?.liquiditySources || 'all'} />
|
|
75
|
-
),
|
|
58
|
+
element: <SettingsPage supportedSwappers={config?.liquiditySources} />,
|
|
76
59
|
},
|
|
77
60
|
{
|
|
78
61
|
path: getAbsolutePath(navigationRoutes.liquiditySources),
|
|
79
62
|
element: (
|
|
80
|
-
<LiquiditySourcePage
|
|
81
|
-
supportedSwappers={configs?.liquiditySources || 'all'}
|
|
82
|
-
/>
|
|
63
|
+
<LiquiditySourcePage supportedSwappers={config?.liquiditySources} />
|
|
83
64
|
),
|
|
84
65
|
},
|
|
85
66
|
{ path: getAbsolutePath(navigationRoutes.swaps), element: <HistoryPage /> },
|
|
@@ -91,11 +72,11 @@ export function AppRoutes(props: PropTypes) {
|
|
|
91
72
|
path: getAbsolutePath(navigationRoutes.wallets),
|
|
92
73
|
element: (
|
|
93
74
|
<WalletsPage
|
|
94
|
-
supportedWallets={
|
|
75
|
+
supportedWallets={config?.wallets}
|
|
95
76
|
multiWallets={
|
|
96
|
-
typeof
|
|
77
|
+
typeof config?.multiWallets === 'undefined'
|
|
97
78
|
? true
|
|
98
|
-
:
|
|
79
|
+
: config.multiWallets
|
|
99
80
|
}
|
|
100
81
|
/>
|
|
101
82
|
),
|
|
@@ -30,7 +30,7 @@ export function HeaderButtons(props: PropTypes) {
|
|
|
30
30
|
onClick={onClickRefresh}
|
|
31
31
|
disabled={!onClickRefresh}
|
|
32
32
|
>
|
|
33
|
-
<RetryIcon size={24} />
|
|
33
|
+
<RetryIcon size={24} disabled={!onClickRefresh} />
|
|
34
34
|
</Button>
|
|
35
35
|
</Tooltip>
|
|
36
36
|
<Tooltip content="Transactions History">
|
|
@@ -15,12 +15,15 @@ import { fetchingBalanceSelector, useWalletsStore } from '../store/wallets';
|
|
|
15
15
|
import {
|
|
16
16
|
calculateWalletUsdValue,
|
|
17
17
|
getSelectableWallets,
|
|
18
|
+
tokensAreEqual,
|
|
18
19
|
} from '../utils/wallets';
|
|
19
20
|
import { removeDuplicateFrom } from '../utils/common';
|
|
20
|
-
import {
|
|
21
|
+
import { WidgetConfig } from '../types';
|
|
21
22
|
import { useTranslation } from 'react-i18next';
|
|
22
23
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
23
24
|
import { useMetaStore } from '../store/meta';
|
|
25
|
+
import { useSettingsStore } from '../store/settings';
|
|
26
|
+
import { Image } from '@rango-dev/ui';
|
|
24
27
|
|
|
25
28
|
const Header = styled('div', {
|
|
26
29
|
display: 'flex',
|
|
@@ -31,19 +34,17 @@ const Header = styled('div', {
|
|
|
31
34
|
},
|
|
32
35
|
});
|
|
33
36
|
|
|
34
|
-
const
|
|
35
|
-
width: '$24',
|
|
36
|
-
height: '$24',
|
|
37
|
+
const WalletImageContainer = styled('div', {
|
|
37
38
|
marginLeft: -15,
|
|
38
39
|
marginRight: '$6',
|
|
39
40
|
borderRadius: '99999px',
|
|
40
41
|
});
|
|
41
42
|
|
|
42
43
|
export type LayoutProps = {
|
|
43
|
-
|
|
44
|
+
config?: WidgetConfig;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
|
-
export function Layout({
|
|
47
|
+
export function Layout({ config }: LayoutProps) {
|
|
47
48
|
const navigate = useNavigate();
|
|
48
49
|
const { balances, accounts, selectedWallets } = useWalletsStore();
|
|
49
50
|
const { getWalletInfo } = useWallets();
|
|
@@ -52,12 +53,13 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
52
53
|
(w) => w.image
|
|
53
54
|
)
|
|
54
55
|
);
|
|
55
|
-
|
|
56
|
+
const { blockchains, tokens } = useMetaStore.use.meta();
|
|
56
57
|
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
57
58
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
58
59
|
const setToChain = useBestRouteStore.use.setToChain();
|
|
59
60
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
60
61
|
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
62
|
+
const setAffiliateRef = useSettingsStore.use.setAffiliateRef();
|
|
61
63
|
|
|
62
64
|
const totalBalance = calculateWalletUsdValue(balances);
|
|
63
65
|
const connectWalletsButtonDisabled =
|
|
@@ -67,29 +69,35 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
67
69
|
|
|
68
70
|
const { t } = useTranslation();
|
|
69
71
|
useEffect(() => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const chain = blockchains.find(
|
|
73
|
+
(chain) => chain.name === config?.to?.blockchain
|
|
74
|
+
);
|
|
75
|
+
const token = tokens.find((t) =>
|
|
76
|
+
tokensAreEqual(t, config?.to?.token || null)
|
|
77
|
+
);
|
|
78
|
+
setToChain(chain || null);
|
|
79
|
+
setToToken(token || null);
|
|
80
|
+
}, [config?.to?.token, config?.to?.blockchain]);
|
|
81
|
+
|
|
73
82
|
useEffect(() => {
|
|
74
|
-
setInputAmount(
|
|
75
|
-
}, [
|
|
83
|
+
setInputAmount(config?.amount?.toString() || '');
|
|
84
|
+
}, [config?.amount]);
|
|
76
85
|
|
|
77
86
|
useEffect(() => {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
const chain = blockchains.find(
|
|
88
|
+
(chain) => chain.name === config?.from?.blockchain
|
|
89
|
+
);
|
|
90
|
+
const token = tokens.find((t) =>
|
|
91
|
+
tokensAreEqual(t, config?.from?.token || null)
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
setFromChain(chain || null);
|
|
95
|
+
setFromToken(token || null);
|
|
96
|
+
}, [config?.from?.token, config?.from?.blockchain]);
|
|
81
97
|
|
|
82
98
|
useEffect(() => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
setFromToken(null);
|
|
86
|
-
setToToken(null);
|
|
87
|
-
}, [
|
|
88
|
-
configs?.fromChains,
|
|
89
|
-
configs?.toChains,
|
|
90
|
-
configs?.fromTokens,
|
|
91
|
-
configs?.toTokens,
|
|
92
|
-
]);
|
|
99
|
+
setAffiliateRef(config?.affiliateRef || null);
|
|
100
|
+
}, [config?.affiliateRef]);
|
|
93
101
|
return (
|
|
94
102
|
<>
|
|
95
103
|
<Header>
|
|
@@ -107,7 +115,9 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
107
115
|
>
|
|
108
116
|
{connectedWalletsImages?.length ? (
|
|
109
117
|
connectedWalletsImages.map((walletImage, index) => (
|
|
110
|
-
<
|
|
118
|
+
<WalletImageContainer key={index}>
|
|
119
|
+
<Image src={walletImage} size={24} />
|
|
120
|
+
</WalletImageContainer>
|
|
111
121
|
))
|
|
112
122
|
) : (
|
|
113
123
|
<></>
|
|
@@ -122,7 +132,7 @@ export function Layout({ configs }: LayoutProps) {
|
|
|
122
132
|
</div>
|
|
123
133
|
</Button>
|
|
124
134
|
</Header>
|
|
125
|
-
<AppRoutes
|
|
135
|
+
<AppRoutes config={config} />
|
|
126
136
|
</>
|
|
127
137
|
);
|
|
128
138
|
}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
styled,
|
|
7
7
|
TextField,
|
|
8
8
|
Typography,
|
|
9
|
+
Image,
|
|
10
|
+
Spacer,
|
|
9
11
|
} from '@rango-dev/ui';
|
|
10
12
|
import { useMetaStore } from '../store/meta';
|
|
11
13
|
import { BlockchainMeta, Token } from 'rango-sdk';
|
|
@@ -16,7 +18,6 @@ import BigNumber from 'bignumber.js';
|
|
|
16
18
|
import { getBalanceFromWallet } from '../utils/wallets';
|
|
17
19
|
import { useWalletsStore } from '../store/wallets';
|
|
18
20
|
import { useTranslation } from 'react-i18next';
|
|
19
|
-
import { Spacer } from '@rango-dev/ui';
|
|
20
21
|
import { PercentageChange } from './PercentageChange';
|
|
21
22
|
|
|
22
23
|
type PropTypes = (
|
|
@@ -90,11 +91,6 @@ const Container = styled('div', {
|
|
|
90
91
|
},
|
|
91
92
|
});
|
|
92
93
|
|
|
93
|
-
const StyledImage = styled('img', {
|
|
94
|
-
width: '$24',
|
|
95
|
-
maxHeight: '$24',
|
|
96
|
-
});
|
|
97
|
-
|
|
98
94
|
const Options = styled('div', {
|
|
99
95
|
display: 'flex',
|
|
100
96
|
justifyContent: 'flex-end',
|
|
@@ -136,6 +132,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
136
132
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
137
133
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
138
134
|
const balances = useWalletsStore.use.balances();
|
|
135
|
+
const fetchingBestRoute = useBestRouteStore.use.loading();
|
|
139
136
|
const navigate = useNavigate();
|
|
140
137
|
const { t } = useTranslation();
|
|
141
138
|
|
|
@@ -234,7 +231,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
234
231
|
loading={loadingStatus === 'loading'}
|
|
235
232
|
prefix={
|
|
236
233
|
loadingStatus === 'success' && chain ? (
|
|
237
|
-
<
|
|
234
|
+
<Image src={chain.logo} size={24} />
|
|
238
235
|
) : (
|
|
239
236
|
<ImagePlaceholder />
|
|
240
237
|
)
|
|
@@ -262,7 +259,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
262
259
|
loading={loadingStatus === 'loading'}
|
|
263
260
|
prefix={
|
|
264
261
|
loadingStatus === 'success' && token ? (
|
|
265
|
-
<
|
|
262
|
+
<Image src={token.image} size={24} />
|
|
266
263
|
) : (
|
|
267
264
|
<ImagePlaceholder />
|
|
268
265
|
)
|
|
@@ -311,11 +308,10 @@ export function TokenInfo(props: PropTypes) {
|
|
|
311
308
|
) : (
|
|
312
309
|
<OutputContainer>
|
|
313
310
|
<Typography variant="h4">
|
|
314
|
-
{
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
: '0'}
|
|
311
|
+
{fetchingBestRoute && '?'}
|
|
312
|
+
{!!bestRoute?.result &&
|
|
313
|
+
`≈ ${numberToString(props.outputAmount)}`}
|
|
314
|
+
{(!inputAmount || inputAmount === '0') && '0'}
|
|
319
315
|
</Typography>
|
|
320
316
|
</OutputContainer>
|
|
321
317
|
)}
|
|
@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
5
5
|
import { Spacer } from '@rango-dev/ui';
|
|
6
6
|
import BigNumber from 'bignumber.js';
|
|
7
7
|
import { numberToString } from '../utils/numbers';
|
|
8
|
+
import { Image } from '@rango-dev/ui';
|
|
8
9
|
|
|
9
10
|
const Box = styled('div', {
|
|
10
11
|
display: 'flex',
|
|
@@ -60,11 +61,6 @@ const Container = styled('div', {
|
|
|
60
61
|
},
|
|
61
62
|
});
|
|
62
63
|
|
|
63
|
-
const StyledImage = styled('img', {
|
|
64
|
-
width: '$24',
|
|
65
|
-
maxHeight: '$24',
|
|
66
|
-
});
|
|
67
|
-
|
|
68
64
|
const ImagePlaceholder = styled('span', {
|
|
69
65
|
width: '24px',
|
|
70
66
|
height: '24px',
|
|
@@ -142,7 +138,7 @@ export function TokenPreview(props: PropTypes) {
|
|
|
142
138
|
loading={loadingStatus === 'loading'}
|
|
143
139
|
prefix={
|
|
144
140
|
loadingStatus === 'success' && chain ? (
|
|
145
|
-
<
|
|
141
|
+
<Image src={chain.logo} size={24} />
|
|
146
142
|
) : (
|
|
147
143
|
<ImagePlaceholder />
|
|
148
144
|
)
|
|
@@ -162,7 +158,7 @@ export function TokenPreview(props: PropTypes) {
|
|
|
162
158
|
loading={loadingStatus === 'loading'}
|
|
163
159
|
prefix={
|
|
164
160
|
loadingStatus === 'success' && token ? (
|
|
165
|
-
<
|
|
161
|
+
<Image src={token.image} size={24} />
|
|
166
162
|
) : (
|
|
167
163
|
<ImagePlaceholder />
|
|
168
164
|
)
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
} from '../types';
|
|
13
13
|
import { PendingSwap } from '@rango-dev/ui/dist/containers/History/types';
|
|
14
14
|
import {
|
|
15
|
-
calculatePendingSwap,
|
|
16
15
|
createBestRouteRequestBody,
|
|
17
16
|
getBalanceWarnings,
|
|
18
17
|
getMinRequiredSlippage,
|
|
@@ -34,6 +33,7 @@ import {
|
|
|
34
33
|
} from '../utils/routing';
|
|
35
34
|
import { numberToString } from '../utils/numbers';
|
|
36
35
|
import { BestRouteResponse } from 'rango-sdk';
|
|
36
|
+
import { calculatePendingSwap } from '@rango-dev/queue-manager-rango-preset';
|
|
37
37
|
|
|
38
38
|
type ConfirmSwap = {
|
|
39
39
|
loading: boolean;
|
|
@@ -49,6 +49,8 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
49
49
|
const initialRoute = useBestRouteStore.use.bestRoute();
|
|
50
50
|
const setBestRoute = useBestRouteStore.use.setBestRoute();
|
|
51
51
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
52
|
+
const affiliateRef = useSettingsStore.use.affiliateRef();
|
|
53
|
+
|
|
52
54
|
const accounts = useWalletsStore.use.accounts();
|
|
53
55
|
const selectedWallets = useWalletsStore.use.selectedWallets();
|
|
54
56
|
const meta = useMetaStore.use.meta();
|
|
@@ -93,7 +95,6 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
93
95
|
meta
|
|
94
96
|
);
|
|
95
97
|
|
|
96
|
-
//@ts-ignore
|
|
97
98
|
return newSwap;
|
|
98
99
|
}
|
|
99
100
|
return;
|
|
@@ -111,11 +112,12 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
111
112
|
selectedWallets,
|
|
112
113
|
disabledLiquiditySources,
|
|
113
114
|
userSlippage,
|
|
114
|
-
|
|
115
|
+
affiliateRef,
|
|
116
|
+
initialRoute
|
|
115
117
|
);
|
|
116
118
|
|
|
117
119
|
try {
|
|
118
|
-
const confiremedRoute = await httpService.getBestRoute(requestBody, {
|
|
120
|
+
const confiremedRoute = await httpService().getBestRoute(requestBody, {
|
|
119
121
|
signal: abortControllerRef.current?.signal,
|
|
120
122
|
});
|
|
121
123
|
|
|
@@ -229,7 +231,6 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
229
231
|
false,
|
|
230
232
|
meta
|
|
231
233
|
);
|
|
232
|
-
//@ts-ignore
|
|
233
234
|
return newSwap;
|
|
234
235
|
} else if (!proceedAnywayRef.current) {
|
|
235
236
|
proceedAnywayRef.current = true;
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -2,22 +2,26 @@ 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 { Theme } from '../types';
|
|
6
6
|
import { shadeColor } from '../utils/common';
|
|
7
7
|
import usePrevious from './usePrevious';
|
|
8
8
|
|
|
9
9
|
export function useTheme({
|
|
10
|
-
|
|
11
|
-
background = '#fff',
|
|
12
|
-
foreground = '#000',
|
|
13
|
-
error = '#FF0000',
|
|
14
|
-
warning = '#F5A623',
|
|
15
|
-
success = '#0070F3',
|
|
10
|
+
colors: themeColors,
|
|
16
11
|
fontFamily = 'Robot',
|
|
17
12
|
borderRadius = 8,
|
|
18
|
-
|
|
13
|
+
mode = 'auto',
|
|
14
|
+
}: Theme) {
|
|
19
15
|
const theme = useSettingsStore.use.theme();
|
|
20
16
|
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
17
|
+
const setTheme = useSettingsStore.use.setTheme();
|
|
18
|
+
|
|
19
|
+
const primary = themeColors?.primary || '#5FA425',
|
|
20
|
+
background = themeColors?.background || '#fff',
|
|
21
|
+
foreground = themeColors?.foreground || '#000',
|
|
22
|
+
error = themeColors?.error || '#FF0000',
|
|
23
|
+
warning = themeColors?.warning || '#F5A623',
|
|
24
|
+
success = themeColors?.success || '#0070F3';
|
|
21
25
|
const colors = {
|
|
22
26
|
neutrals200: '#FAFAFA',
|
|
23
27
|
neutrals300: '#f2f2f2',
|
|
@@ -61,6 +65,9 @@ export function useTheme({
|
|
|
61
65
|
radii: {
|
|
62
66
|
5: `${borderRadius}px`,
|
|
63
67
|
},
|
|
68
|
+
shadows: {
|
|
69
|
+
s: '0px 3px 5px 3px #f0f2f5, 0px 6px 10px 3px #f0f2f5, 0px 1px 18px 3px #f0f2f5',
|
|
70
|
+
},
|
|
64
71
|
});
|
|
65
72
|
|
|
66
73
|
const customeDarkTheme = createTheme({
|
|
@@ -80,6 +87,9 @@ export function useTheme({
|
|
|
80
87
|
radii: {
|
|
81
88
|
5: `${borderRadius}px`,
|
|
82
89
|
},
|
|
90
|
+
shadows: {
|
|
91
|
+
s: '0px 3px 5px 3px #222, 0px 6px 10px 3px #222, 0px 1px 18px 3px #222',
|
|
92
|
+
},
|
|
83
93
|
});
|
|
84
94
|
const [OSTheme, setOSTheme] = useState(customeLightTheme);
|
|
85
95
|
useEffect(() => {
|
|
@@ -108,7 +118,9 @@ export function useTheme({
|
|
|
108
118
|
.removeEventListener('change', switchTheme);
|
|
109
119
|
};
|
|
110
120
|
}, []);
|
|
111
|
-
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (mode !== 'auto') setTheme(mode);
|
|
123
|
+
}, [mode]);
|
|
112
124
|
const prevFont = usePrevious(fontFamily);
|
|
113
125
|
|
|
114
126
|
useLayoutEffect(() => {
|