@rango-dev/widget-embedded 0.1.10-next.89 → 0.1.10-next.92
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 +4 -16
- package/dist/App.d.ts.map +1 -1
- package/dist/components/AppRouter.d.ts +7 -1
- package/dist/components/AppRouter.d.ts.map +1 -1
- package/dist/components/AppRoutes.d.ts +2 -1
- package/dist/components/AppRoutes.d.ts.map +1 -1
- package/dist/components/BottomLogo.d.ts.map +1 -1
- package/dist/components/Header.d.ts +3 -0
- package/dist/components/Header.d.ts.map +1 -1
- package/dist/components/Layout.d.ts +5 -1
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/TokenInfo.d.ts.map +1 -1
- package/dist/globalStyles.d.ts +1 -0
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/usePrevious.d.ts +2 -0
- package/dist/hooks/usePrevious.d.ts.map +1 -0
- package/dist/hooks/useSelectLanguage.d.ts +5 -0
- package/dist/hooks/useSelectLanguage.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts +5 -1
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/i18n.d.ts +3 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/lib.d.ts +6 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/pages/Home.d.ts +7 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcesPage.d.ts +6 -1
- package/dist/pages/LiquiditySourcesPage.d.ts.map +1 -1
- package/dist/pages/SelectChainPage.d.ts +2 -0
- package/dist/pages/SelectChainPage.d.ts.map +1 -1
- package/dist/pages/SelectTokenPage.d.ts +1 -0
- package/dist/pages/SelectTokenPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts +6 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/WalletsPage.d.ts +7 -1
- package/dist/pages/WalletsPage.d.ts.map +1 -1
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +40 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/numbers.d.ts.map +1 -1
- package/dist/utils/swap.d.ts +1 -1
- package/dist/utils/swap.d.ts.map +1 -1
- package/dist/widget-embedded.cjs.development.js +500 -100
- package/dist/widget-embedded.cjs.development.js.map +1 -1
- package/dist/widget-embedded.cjs.production.min.js +500 -100
- package/dist/widget-embedded.cjs.production.min.js.map +1 -1
- package/dist/widget-embedded.esm.js +506 -106
- package/dist/widget-embedded.esm.js.map +1 -1
- package/package.json +5 -1
- package/src/App.tsx +20 -30
- package/src/app.css +0 -1
- package/src/components/AppRouter.tsx +16 -6
- package/src/components/AppRoutes.tsx +40 -9
- package/src/components/BottomLogo.tsx +4 -1
- package/src/components/Header.tsx +15 -3
- package/src/components/Layout.tsx +30 -4
- package/src/components/TokenInfo.tsx +68 -23
- package/src/globalStyles.ts +10 -0
- package/src/hooks/usePrevious.ts +13 -0
- package/src/hooks/useSelectLanguage.ts +15 -0
- package/src/hooks/useTheme.ts +101 -11
- package/src/i18n.js +30 -0
- package/src/languages/en.json +13 -0
- package/src/languages/tr.json +11 -0
- package/src/lib.tsx +66 -12
- package/src/pages/Home.tsx +15 -3
- package/src/pages/LiquiditySourcesPage.tsx +16 -4
- package/src/pages/SelectChainPage.tsx +7 -3
- package/src/pages/SelectTokenPage.tsx +6 -2
- package/src/pages/SettingsPage.tsx +29 -5
- package/src/pages/WalletsPage.tsx +17 -3
- package/src/store/wallets.ts +8 -0
- package/src/types/config.ts +44 -0
- package/src/types/index.ts +1 -0
- package/src/utils/common.ts +30 -2
- package/src/utils/numbers.ts +1 -0
- package/src/utils/swap.ts +1 -1
- package/src/utils/wallets.ts +1 -1
- package/dist/swapBox.d.ts +0 -3
- package/dist/swapBox.d.ts.map +0 -1
- package/src/swapBox.tsx +0 -65
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.1.10-next.
|
|
3
|
+
"version": "0.1.10-next.92",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"@rango-dev/wallets-shared": "^0.1.11-next.78",
|
|
36
36
|
"bignumber.js": "^9.1.1",
|
|
37
37
|
"copy-to-clipboard": "^3.3.3",
|
|
38
|
+
"i18next": "^22.4.11",
|
|
39
|
+
"i18next-browser-languagedetector": "^7.0.1",
|
|
40
|
+
"i18next-http-backend": "^2.1.1",
|
|
38
41
|
"immer": "^9.0.19",
|
|
39
42
|
"mitt": "^3.0.0",
|
|
40
43
|
"parcel": "^2.8.0",
|
|
@@ -42,6 +45,7 @@
|
|
|
42
45
|
"rango-types": "^0.1.22",
|
|
43
46
|
"react": "^18.2.0",
|
|
44
47
|
"react-dom": "^18.2.0",
|
|
48
|
+
"react-i18next": "^12.2.0",
|
|
45
49
|
"react-router-dom": "^6.8.0",
|
|
46
50
|
"zustand": "^4.3.2"
|
|
47
51
|
},
|
package/src/App.tsx
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Alert,
|
|
4
|
-
Button,
|
|
5
|
-
Typography,
|
|
6
|
-
Drawer,
|
|
7
|
-
} from '@rango-dev/ui';
|
|
8
|
-
import React, { useState } from 'react';
|
|
1
|
+
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
+
import React from 'react';
|
|
9
3
|
import { AppRouter } from './components/AppRouter';
|
|
10
4
|
import { useMetaStore } from './store/meta';
|
|
11
5
|
import './app.css';
|
|
@@ -19,34 +13,28 @@ import {
|
|
|
19
13
|
} from './utils/wallets';
|
|
20
14
|
import { useWalletsStore } from './store/wallets';
|
|
21
15
|
import { Layout } from './components/Layout';
|
|
22
|
-
import { globalStyles } from './globalStyles';
|
|
16
|
+
import { globalFont, globalStyles } from './globalStyles';
|
|
23
17
|
import { useTheme } from './hooks/useTheme';
|
|
24
18
|
import QueueManager from './QueueManager';
|
|
25
19
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
20
|
+
import { Configs } from './types';
|
|
21
|
+
import './i18n';
|
|
26
22
|
|
|
27
23
|
const providers = allProviders();
|
|
28
|
-
interface Token {
|
|
29
|
-
name: string;
|
|
30
|
-
contractAddress?: string;
|
|
31
|
-
}
|
|
32
24
|
|
|
33
25
|
//todo: update interface and update widget state based on WidgetProps change
|
|
34
26
|
export type WidgetProps = {
|
|
35
|
-
|
|
36
|
-
fromToken?: string;
|
|
37
|
-
toChain?: string;
|
|
38
|
-
toToken?: string;
|
|
39
|
-
fromAmount?: string;
|
|
40
|
-
slippage?: number;
|
|
41
|
-
chains?: string[];
|
|
42
|
-
tokens?: Token[];
|
|
43
|
-
liquiditySources?: string[];
|
|
44
|
-
theme: 'dark' | 'light' | 'auto';
|
|
27
|
+
configs?: Configs;
|
|
45
28
|
};
|
|
46
29
|
|
|
47
|
-
export function App() {
|
|
30
|
+
export function App({ configs }: WidgetProps) {
|
|
48
31
|
globalStyles();
|
|
49
|
-
|
|
32
|
+
globalFont(configs?.fontFamily || 'Roboto');
|
|
33
|
+
const { activeTheme } = useTheme({
|
|
34
|
+
...configs?.colors,
|
|
35
|
+
borderRadius: configs?.borderRadius,
|
|
36
|
+
});
|
|
37
|
+
|
|
50
38
|
const { blockchains } = useMetaStore.use.meta();
|
|
51
39
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
52
40
|
const connectWallet = useWalletsStore.use.connectWallet();
|
|
@@ -59,13 +47,12 @@ export function App() {
|
|
|
59
47
|
type,
|
|
60
48
|
event,
|
|
61
49
|
value,
|
|
62
|
-
|
|
50
|
+
_,
|
|
63
51
|
supportedChains
|
|
64
52
|
) => {
|
|
65
53
|
if (event === Events.ACCOUNTS) {
|
|
66
54
|
if (value) {
|
|
67
55
|
const supportedChainNames: Network[] | null =
|
|
68
|
-
//@ts-ignore
|
|
69
56
|
walletAndSupportedChainsNames(supportedChains);
|
|
70
57
|
const data = prepareAccountsForWalletStore(
|
|
71
58
|
type,
|
|
@@ -81,7 +68,6 @@ export function App() {
|
|
|
81
68
|
};
|
|
82
69
|
|
|
83
70
|
return (
|
|
84
|
-
//@ts-ignore
|
|
85
71
|
<Provider
|
|
86
72
|
allBlockChains={blockchains}
|
|
87
73
|
providers={providers}
|
|
@@ -90,8 +76,12 @@ export function App() {
|
|
|
90
76
|
<div id="pageContainer" className={activeTheme}>
|
|
91
77
|
<QueueManager>
|
|
92
78
|
<SwapContainer>
|
|
93
|
-
<AppRouter
|
|
94
|
-
|
|
79
|
+
<AppRouter
|
|
80
|
+
title={configs?.title}
|
|
81
|
+
titleSize={configs?.titleSize}
|
|
82
|
+
titleWeight={configs?.titleWeight}
|
|
83
|
+
>
|
|
84
|
+
<Layout configs={configs} />
|
|
95
85
|
</AppRouter>
|
|
96
86
|
</SwapContainer>
|
|
97
87
|
</QueueManager>
|
package/src/app.css
CHANGED
|
@@ -8,8 +8,15 @@ import {
|
|
|
8
8
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
9
9
|
import { UpdateUrl } from './UpdateUrl';
|
|
10
10
|
import { Home } from '../pages/Home';
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
interface PropTypes {
|
|
12
|
+
title?: string;
|
|
13
|
+
titleSize?: number;
|
|
14
|
+
titleWeight?: number;
|
|
15
|
+
}
|
|
16
|
+
const Route: React.FC = ({
|
|
17
|
+
children,
|
|
18
|
+
...props
|
|
19
|
+
}: PropTypes & PropsWithChildren) => {
|
|
13
20
|
const location = useLocation();
|
|
14
21
|
const navigate = useNavigate();
|
|
15
22
|
const ref = useRef(true);
|
|
@@ -32,18 +39,21 @@ const Route: React.FC = (props: PropsWithChildren) => {
|
|
|
32
39
|
) &&
|
|
33
40
|
ref.current
|
|
34
41
|
)
|
|
35
|
-
return <Home />;
|
|
42
|
+
return <Home {...props} />;
|
|
36
43
|
|
|
37
|
-
return <> {
|
|
44
|
+
return <> {children}</>;
|
|
38
45
|
};
|
|
39
46
|
|
|
40
|
-
export function AppRouter({
|
|
47
|
+
export function AppRouter({
|
|
48
|
+
children,
|
|
49
|
+
...props
|
|
50
|
+
}: PropTypes & PropsWithChildren) {
|
|
41
51
|
const isRouterInContext = useInRouterContext();
|
|
42
52
|
const Router = isRouterInContext ? Route : MemoryRouter;
|
|
43
53
|
|
|
44
54
|
return (
|
|
45
55
|
<>
|
|
46
|
-
<Router>{children}</Router>
|
|
56
|
+
<Router {...props}>{children}</Router>
|
|
47
57
|
{isRouterInContext && <UpdateUrl />}
|
|
48
58
|
</>
|
|
49
59
|
);
|
|
@@ -11,31 +11,62 @@ import { SettingsPage } from '../pages/SettingsPage';
|
|
|
11
11
|
import { WalletsPage } from '../pages/WalletsPage';
|
|
12
12
|
import { ConfirmWalletsPage } from '../pages/ConfirmWalletsPage';
|
|
13
13
|
import { SwapDetailsPage } from '../pages/SwapDetailsPage';
|
|
14
|
+
import { Configs } from '../types';
|
|
14
15
|
|
|
15
|
-
export const AppRoutes = (
|
|
16
|
+
export const AppRoutes = ({
|
|
17
|
+
fromChains = 'all',
|
|
18
|
+
toChains = 'all',
|
|
19
|
+
fromTokens = 'all',
|
|
20
|
+
toTokens = 'all',
|
|
21
|
+
liquiditySources = 'all',
|
|
22
|
+
wallets = 'all',
|
|
23
|
+
title,
|
|
24
|
+
multiWallets = true,
|
|
25
|
+
titleSize,
|
|
26
|
+
titleWeight,
|
|
27
|
+
}: Configs) =>
|
|
16
28
|
useRoutes([
|
|
17
|
-
{
|
|
29
|
+
{
|
|
30
|
+
path: navigationRoutes.home,
|
|
31
|
+
element: (
|
|
32
|
+
<Home title={title} titleSize={titleSize} titleWeight={titleWeight} />
|
|
33
|
+
),
|
|
34
|
+
},
|
|
18
35
|
{
|
|
19
36
|
path: navigationRoutes.fromChain,
|
|
20
|
-
element: <SelectChainPage type="from" />,
|
|
37
|
+
element: <SelectChainPage type="from" supportedChains={fromChains} />,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
path: navigationRoutes.toChain,
|
|
41
|
+
element: <SelectChainPage type="to" supportedChains={toChains} />,
|
|
21
42
|
},
|
|
22
|
-
{ path: navigationRoutes.toChain, element: <SelectChainPage type="to" /> },
|
|
23
43
|
{
|
|
24
44
|
path: navigationRoutes.fromToken + '/*',
|
|
25
|
-
element: <SelectTokenPage type="from" />,
|
|
45
|
+
element: <SelectTokenPage type="from" supportedTokens={fromTokens} />,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
path: navigationRoutes.toToken,
|
|
49
|
+
element: <SelectTokenPage type="to" supportedTokens={toTokens} />,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
path: navigationRoutes.settings,
|
|
53
|
+
element: <SettingsPage supportedSwappers={liquiditySources} />,
|
|
26
54
|
},
|
|
27
|
-
{ path: navigationRoutes.toToken, element: <SelectTokenPage type="to" /> },
|
|
28
|
-
{ path: navigationRoutes.settings, element: <SettingsPage /> },
|
|
29
55
|
{
|
|
30
56
|
path: navigationRoutes.liquiditySources,
|
|
31
|
-
element: <LiquiditySourcePage />,
|
|
57
|
+
element: <LiquiditySourcePage supportedSwappers={liquiditySources} />,
|
|
32
58
|
},
|
|
33
59
|
{ path: navigationRoutes.swaps, element: <HistoryPage /> },
|
|
34
60
|
{
|
|
35
61
|
path: navigationRoutes.swapDetails,
|
|
36
62
|
element: <SwapDetailsPage />,
|
|
37
63
|
},
|
|
38
|
-
{
|
|
64
|
+
{
|
|
65
|
+
path: navigationRoutes.wallets,
|
|
66
|
+
element: (
|
|
67
|
+
<WalletsPage supportedWallets={wallets} multiWallets={multiWallets} />
|
|
68
|
+
),
|
|
69
|
+
},
|
|
39
70
|
{ path: navigationRoutes.confirmSwap, element: <ConfirmSwapPage /> },
|
|
40
71
|
{ path: navigationRoutes.confirmWallets, element: <ConfirmWalletsPage /> },
|
|
41
72
|
]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { styled } from '@rango-dev/ui/src/theme';
|
|
3
3
|
import { Typography } from '@rango-dev/ui';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
4
5
|
|
|
5
6
|
const Container = styled('div', {
|
|
6
7
|
display: 'flex',
|
|
@@ -24,9 +25,11 @@ const StyledAnchor = styled('a', {
|
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
export function BottomLogo() {
|
|
28
|
+
const { t } = useTranslation();
|
|
29
|
+
|
|
27
30
|
return (
|
|
28
31
|
<Container>
|
|
29
|
-
<Typography variant="caption">Powered By</Typography>
|
|
32
|
+
<Typography variant="caption">{t('Powered By')}</Typography>
|
|
30
33
|
<StyledAnchor href="https://rango.exchange" target="_blank">
|
|
31
34
|
<Logo xmlns="http://www.w3.org/2000/svg" viewBox="0 0 33.68 29">
|
|
32
35
|
<defs></defs>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { styled, Typography } from '@rango-dev/ui';
|
|
2
|
+
import { css, styled, Typography } from '@rango-dev/ui';
|
|
3
3
|
import { HeaderButtons } from './HeaderButtons';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
4
5
|
|
|
5
6
|
export const HeaderContainer = styled('div', {
|
|
6
7
|
display: 'flex',
|
|
@@ -12,13 +13,24 @@ export const HeaderContainer = styled('div', {
|
|
|
12
13
|
|
|
13
14
|
export interface PropTypes {
|
|
14
15
|
onClickRefresh: () => void;
|
|
16
|
+
title?: string;
|
|
17
|
+
titleSize?: number;
|
|
18
|
+
titleWeight?: number;
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export function Header(props: PropTypes) {
|
|
18
|
-
const { onClickRefresh } = props;
|
|
22
|
+
const { onClickRefresh, title, titleSize, titleWeight } = props;
|
|
23
|
+
const { t } = useTranslation();
|
|
24
|
+
const titleStyle = css({
|
|
25
|
+
fontSize: `${titleSize}px !important`,
|
|
26
|
+
fontWeight: `${titleWeight} !important`,
|
|
27
|
+
});
|
|
28
|
+
|
|
19
29
|
return (
|
|
20
30
|
<HeaderContainer>
|
|
21
|
-
<Typography variant="h4">
|
|
31
|
+
<Typography variant="h4" className={titleStyle()}>
|
|
32
|
+
{t(title.toLocaleLowerCase()) || title}
|
|
33
|
+
</Typography>
|
|
22
34
|
<HeaderButtons onClickRefresh={onClickRefresh} />
|
|
23
35
|
</HeaderContainer>
|
|
24
36
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Button, AddWalletIcon, Typography, styled } from '@rango-dev/ui';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
3
|
import { useNavigate } from 'react-router-dom';
|
|
4
4
|
import { useWallets } from '@rango-dev/wallets-core';
|
|
5
5
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
getSelectableWallets,
|
|
12
12
|
} from '../utils/wallets';
|
|
13
13
|
import { removeDuplicateFrom } from '../utils/common';
|
|
14
|
+
import { Configs } from '../types';
|
|
15
|
+
import { useTranslation } from 'react-i18next';
|
|
16
|
+
import { useBestRouteStore } from '../store/bestRoute';
|
|
14
17
|
|
|
15
18
|
const Header = styled('div', {
|
|
16
19
|
display: 'flex',
|
|
@@ -26,7 +29,11 @@ const WalletImage = styled('img', {
|
|
|
26
29
|
borderRadius: '99999px',
|
|
27
30
|
});
|
|
28
31
|
|
|
29
|
-
export
|
|
32
|
+
export type LayoutProps = {
|
|
33
|
+
configs: Configs;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function Layout({ configs }: LayoutProps) {
|
|
30
37
|
const navigate = useNavigate();
|
|
31
38
|
const { balances, accounts, selectedWallets } = useWalletsStore();
|
|
32
39
|
const { getWalletInfo } = useWallets();
|
|
@@ -36,10 +43,29 @@ export function Layout() {
|
|
|
36
43
|
)
|
|
37
44
|
);
|
|
38
45
|
|
|
46
|
+
const { fromChain, toChain, toToken, fromToken, fromAmount } = configs;
|
|
47
|
+
const setFromChain = useBestRouteStore.use.setFromChain();
|
|
48
|
+
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
49
|
+
const setToChain = useBestRouteStore.use.setToChain();
|
|
50
|
+
const setToToken = useBestRouteStore.use.setToToken();
|
|
51
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
52
|
+
|
|
39
53
|
const totalBalance = calculateWalletUsdValue(balances);
|
|
40
54
|
const connectWalletsButtonDisabled =
|
|
41
55
|
useUiStore.use.connectWalletsButtonDisabled();
|
|
56
|
+
const { t } = useTranslation();
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
setToChain(toChain);
|
|
59
|
+
setToToken(toToken);
|
|
60
|
+
}, [toChain, toToken]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setInputAmount(fromAmount.toString());
|
|
63
|
+
}, [fromAmount]);
|
|
42
64
|
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
setFromToken(fromToken);
|
|
67
|
+
setFromChain(fromChain);
|
|
68
|
+
}, [fromToken, fromChain]);
|
|
43
69
|
return (
|
|
44
70
|
<>
|
|
45
71
|
<Header>
|
|
@@ -61,11 +87,11 @@ export function Layout() {
|
|
|
61
87
|
<></>
|
|
62
88
|
)}
|
|
63
89
|
<Typography variant="body2">
|
|
64
|
-
{!accounts?.length ? 'Connect Wallet' : `$${totalBalance || 0}`}
|
|
90
|
+
{!accounts?.length ? t('Connect Wallet') : `$${totalBalance || 0}`}
|
|
65
91
|
</Typography>
|
|
66
92
|
</Button>
|
|
67
93
|
</Header>
|
|
68
|
-
<AppRoutes />
|
|
94
|
+
<AppRoutes {...configs} />
|
|
69
95
|
</>
|
|
70
96
|
);
|
|
71
97
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AngleDownIcon,
|
|
4
|
+
Button,
|
|
5
|
+
InfoCircleIcon,
|
|
6
|
+
styled,
|
|
7
|
+
TextField,
|
|
8
|
+
Typography,
|
|
9
|
+
} from '@rango-dev/ui';
|
|
3
10
|
import { useMetaStore } from '../store/meta';
|
|
4
11
|
import { BlockchainMeta, Token } from 'rango-sdk';
|
|
5
12
|
import { useNavigate } from 'react-router-dom';
|
|
@@ -8,9 +15,14 @@ import { numberToString } from '../utils/numbers';
|
|
|
8
15
|
import BigNumber from 'bignumber.js';
|
|
9
16
|
import { getBalanceFromWallet } from '../utils/wallets';
|
|
10
17
|
import { useWalletsStore } from '../store/wallets';
|
|
18
|
+
import { useTranslation } from 'react-i18next';
|
|
11
19
|
|
|
12
20
|
type PropTypes = (
|
|
13
|
-
| {
|
|
21
|
+
| {
|
|
22
|
+
type: 'From';
|
|
23
|
+
inputAmount: string;
|
|
24
|
+
onAmountChange: (amount: string) => void;
|
|
25
|
+
}
|
|
14
26
|
| {
|
|
15
27
|
type: 'To';
|
|
16
28
|
outputAmount: BigNumber | null;
|
|
@@ -81,28 +93,47 @@ export function TokenInfo(props: PropTypes) {
|
|
|
81
93
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
82
94
|
const balances = useWalletsStore.use.balances();
|
|
83
95
|
const navigate = useNavigate();
|
|
96
|
+
const { t } = useTranslation();
|
|
84
97
|
|
|
85
98
|
const tokenBalance =
|
|
86
99
|
!!fromChain && !!fromToken
|
|
87
100
|
? numberToString(
|
|
88
|
-
getBalanceFromWallet(
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
getBalanceFromWallet(
|
|
102
|
+
balances,
|
|
103
|
+
fromChain?.name,
|
|
104
|
+
fromToken?.symbol,
|
|
105
|
+
fromToken?.address
|
|
106
|
+
)?.amount || '0',
|
|
107
|
+
8
|
|
91
108
|
)
|
|
92
109
|
: '0';
|
|
93
110
|
|
|
94
111
|
const tokenBalanceReal =
|
|
95
112
|
!!fromChain && !!fromToken
|
|
96
113
|
? numberToString(
|
|
97
|
-
getBalanceFromWallet(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
?.
|
|
114
|
+
getBalanceFromWallet(
|
|
115
|
+
balances,
|
|
116
|
+
fromChain?.name,
|
|
117
|
+
fromToken?.symbol,
|
|
118
|
+
fromToken?.address
|
|
119
|
+
)?.amount || '0',
|
|
120
|
+
getBalanceFromWallet(
|
|
121
|
+
balances,
|
|
122
|
+
fromChain?.name,
|
|
123
|
+
fromToken?.symbol,
|
|
124
|
+
fromToken?.address
|
|
125
|
+
)?.decimal
|
|
101
126
|
)
|
|
102
127
|
: '0';
|
|
103
128
|
|
|
104
129
|
const ItemSuffix = (
|
|
105
|
-
<div
|
|
130
|
+
<div
|
|
131
|
+
style={{
|
|
132
|
+
display: 'flex',
|
|
133
|
+
justifyContent: 'center',
|
|
134
|
+
alignItems: 'center',
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
106
137
|
{loadingStatus === 'failed' && <InfoCircleIcon color="error" size={24} />}
|
|
107
138
|
<AngleDownIcon />
|
|
108
139
|
</div>
|
|
@@ -111,7 +142,7 @@ export function TokenInfo(props: PropTypes) {
|
|
|
111
142
|
return (
|
|
112
143
|
<Box>
|
|
113
144
|
<div>
|
|
114
|
-
<Typography variant="body2">{type}</Typography>
|
|
145
|
+
<Typography variant="body2">{t(type)}</Typography>
|
|
115
146
|
</div>
|
|
116
147
|
<Container>
|
|
117
148
|
{props.type === 'From' && (
|
|
@@ -119,10 +150,12 @@ export function TokenInfo(props: PropTypes) {
|
|
|
119
150
|
<div
|
|
120
151
|
className="balance"
|
|
121
152
|
onClick={() => {
|
|
122
|
-
if (tokenBalance !== '0')
|
|
123
|
-
|
|
153
|
+
if (tokenBalance !== '0')
|
|
154
|
+
setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
124
157
|
<Button variant="ghost" size="small">
|
|
125
|
-
<Typography variant="body2">{
|
|
158
|
+
<Typography variant="body2">{`${t('Max')}: ${tokenBalance} ${
|
|
126
159
|
fromToken?.symbol || ''
|
|
127
160
|
}`}</Typography>
|
|
128
161
|
</Button>
|
|
@@ -147,8 +180,9 @@ export function TokenInfo(props: PropTypes) {
|
|
|
147
180
|
suffix={ItemSuffix}
|
|
148
181
|
align="start"
|
|
149
182
|
size="large"
|
|
150
|
-
style={{ marginRight: '.5rem' }}
|
|
151
|
-
|
|
183
|
+
style={{ marginRight: '.5rem' }}
|
|
184
|
+
>
|
|
185
|
+
{loadingStatus === 'success' && chain ? chain.displayName : t('Chain')}
|
|
152
186
|
</Button>
|
|
153
187
|
<Button
|
|
154
188
|
onClick={() => {
|
|
@@ -171,8 +205,9 @@ export function TokenInfo(props: PropTypes) {
|
|
|
171
205
|
suffix={ItemSuffix}
|
|
172
206
|
size="large"
|
|
173
207
|
align="start"
|
|
174
|
-
style={{ marginRight: '.5rem' }}
|
|
175
|
-
|
|
208
|
+
style={{ marginRight: '.5rem' }}
|
|
209
|
+
>
|
|
210
|
+
{loadingStatus === 'success' && token ? token.symbol : t('Token')}
|
|
176
211
|
</Button>
|
|
177
212
|
{props.type === 'From' ? (
|
|
178
213
|
<TextField
|
|
@@ -186,8 +221,12 @@ export function TokenInfo(props: PropTypes) {
|
|
|
186
221
|
backgroundColor: '$background !important',
|
|
187
222
|
}}
|
|
188
223
|
suffix={
|
|
189
|
-
<span
|
|
190
|
-
|
|
224
|
+
<span
|
|
225
|
+
style={{ position: 'absolute', right: '4px', bottom: '2px' }}
|
|
226
|
+
>
|
|
227
|
+
<Typography variant="caption">{`$${numberToString(
|
|
228
|
+
inputUsdValue
|
|
229
|
+
)}`}</Typography>
|
|
191
230
|
</span>
|
|
192
231
|
}
|
|
193
232
|
value={props.inputAmount || ''}
|
|
@@ -202,11 +241,17 @@ export function TokenInfo(props: PropTypes) {
|
|
|
202
241
|
) : (
|
|
203
242
|
<OutputContainer>
|
|
204
243
|
<Typography variant="body1">
|
|
205
|
-
{bestRoute
|
|
244
|
+
{bestRoute
|
|
245
|
+
? `≈ ${numberToString(props.outputAmount)}`
|
|
246
|
+
: inputAmount
|
|
247
|
+
? '?'
|
|
248
|
+
: '0'}
|
|
206
249
|
</Typography>
|
|
207
|
-
<span
|
|
250
|
+
<span
|
|
251
|
+
style={{ position: 'absolute', right: '4px', bottom: '2px' }}
|
|
252
|
+
>
|
|
208
253
|
<Typography variant="caption">{`$${numberToString(
|
|
209
|
-
props.outputUsdValue
|
|
254
|
+
props.outputUsdValue
|
|
210
255
|
)}`}</Typography>
|
|
211
256
|
</span>
|
|
212
257
|
</OutputContainer>
|
package/src/globalStyles.ts
CHANGED
|
@@ -14,3 +14,13 @@ export const globalStyles = globalCss({
|
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
|
+
export const globalFont = (fontFamily: string) =>
|
|
18
|
+
globalCss({
|
|
19
|
+
'@import': [
|
|
20
|
+
"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')",
|
|
21
|
+
"url('https://fonts.cdnfonts.com/css/times-new-roman')",
|
|
22
|
+
],
|
|
23
|
+
[`.font_${fontFamily.replace(/ /g, '')} ._text`]: {
|
|
24
|
+
fontFamily,
|
|
25
|
+
},
|
|
26
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export default function usePrevious(value: string) {
|
|
4
|
+
// The ref object is a generic container whose current property is mutable ...
|
|
5
|
+
// ... and can hold any value, similar to an instance property on a class
|
|
6
|
+
const ref = useRef<string>();
|
|
7
|
+
// Store current value in ref
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
ref.current = value;
|
|
10
|
+
}, [value]); // Only re-run if value changes
|
|
11
|
+
// Return previous value (happens before update in useEffect above)
|
|
12
|
+
return ref.current;
|
|
13
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
|
|
3
|
+
export default function useSelectLanguage() {
|
|
4
|
+
const { i18n } = useTranslation();
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const currentLanguage = i18n?.language || 'en';
|
|
7
|
+
const changeLanguage = (value: string) => {
|
|
8
|
+
if (currentLanguage !== value) {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
i18n.changeLanguage(value);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return { changeLanguage, currentLanguage };
|
|
15
|
+
}
|