@rango-dev/widget-embedded 0.1.10-next.89 → 0.1.10-next.91
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/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 +25 -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/swap.ts +1 -1
- package/src/utils/wallets.ts +1 -1
package/src/hooks/useTheme.ts
CHANGED
|
@@ -1,36 +1,126 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useState, useEffect } from 'react';
|
|
1
|
+
import { createTheme } from '@rango-dev/ui';
|
|
2
|
+
import { useState, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import { useMetaStore } from '../store/meta';
|
|
4
4
|
import { useSettingsStore } from '../store/settings';
|
|
5
|
+
import { Colors } from '../types';
|
|
6
|
+
import { shadeColor } from '../utils/common';
|
|
7
|
+
import usePrevious from './usePrevious';
|
|
5
8
|
|
|
6
|
-
export function useTheme(
|
|
9
|
+
export function useTheme({
|
|
10
|
+
primary = '#5FA425',
|
|
11
|
+
background = '#fff',
|
|
12
|
+
foreground = '#000',
|
|
13
|
+
error = '#FF0000',
|
|
14
|
+
warning = '#F5A623',
|
|
15
|
+
success = '#0070F3',
|
|
16
|
+
fontFamily = 'Robot',
|
|
17
|
+
borderRadius = 5,
|
|
18
|
+
}: Colors & { borderRadius?: number; fontFamily?: string }) {
|
|
7
19
|
const theme = useSettingsStore.use.theme();
|
|
8
20
|
const fetchMeta = useMetaStore.use.fetchMeta();
|
|
21
|
+
const colors = {
|
|
22
|
+
neutrals200: '#FAFAFA',
|
|
23
|
+
neutrals300: '#EAEAEA',
|
|
24
|
+
neutrals400: '#999999',
|
|
25
|
+
neutrals500: '#888888',
|
|
26
|
+
neutrals600: '#666666',
|
|
27
|
+
neutrals700: '#444444',
|
|
28
|
+
neutrals800: '#333333',
|
|
29
|
+
neutrals900: '#111111',
|
|
30
|
+
primary,
|
|
31
|
+
primary100: shadeColor(primary, 15),
|
|
32
|
+
primary200: shadeColor(primary, -10),
|
|
33
|
+
primary300: shadeColor(primary, -15),
|
|
34
|
+
primary400: shadeColor(primary, -20),
|
|
35
|
+
primary500: shadeColor(primary, -25),
|
|
36
|
+
primary600: shadeColor(primary, -30),
|
|
37
|
+
primary700: shadeColor(primary, -35),
|
|
38
|
+
primary800: shadeColor(primary, -40),
|
|
39
|
+
primary900: shadeColor(primary, -45),
|
|
40
|
+
background,
|
|
41
|
+
foreground,
|
|
42
|
+
error,
|
|
43
|
+
error100: shadeColor(error, 50),
|
|
44
|
+
error300: shadeColor(error, -10),
|
|
45
|
+
error500: shadeColor(error, -20),
|
|
46
|
+
error700: shadeColor(error, -30),
|
|
47
|
+
warning,
|
|
48
|
+
warning100: shadeColor(warning, 50),
|
|
49
|
+
warning300: shadeColor(warning, -10),
|
|
50
|
+
warning500: shadeColor(warning, -20),
|
|
51
|
+
warning700: shadeColor(warning, -30),
|
|
52
|
+
success,
|
|
53
|
+
success100: shadeColor(success, 50),
|
|
54
|
+
success300: shadeColor(success, -10),
|
|
55
|
+
success500: shadeColor(success, -20),
|
|
56
|
+
success700: shadeColor(success, -30),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const customeLightTheme = createTheme({
|
|
60
|
+
colors,
|
|
61
|
+
radii: {
|
|
62
|
+
5: `${borderRadius}px`,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
9
65
|
|
|
10
|
-
const
|
|
66
|
+
const customeDarkTheme = createTheme({
|
|
67
|
+
colors: {
|
|
68
|
+
...colors,
|
|
69
|
+
neutrals200: '#111111',
|
|
70
|
+
neutrals300: '#333333',
|
|
71
|
+
neutrals400: '#444444',
|
|
72
|
+
neutrals500: '#666666',
|
|
73
|
+
neutrals600: '#888888',
|
|
74
|
+
neutrals700: '#999999',
|
|
75
|
+
neutrals800: '#EAEAEA',
|
|
76
|
+
neutrals900: '#FAFAFA',
|
|
77
|
+
foreground: background,
|
|
78
|
+
background: foreground,
|
|
79
|
+
},
|
|
80
|
+
radii: {
|
|
81
|
+
5: `${borderRadius}px`,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const [OSTheme, setOSTheme] = useState(customeLightTheme);
|
|
11
85
|
useEffect(() => {
|
|
12
86
|
(async () => {
|
|
13
87
|
await fetchMeta();
|
|
14
88
|
})();
|
|
15
89
|
|
|
16
90
|
const switchTheme = (event: MediaQueryListEvent) => {
|
|
17
|
-
if (event.matches) setOSTheme(
|
|
18
|
-
else setOSTheme(
|
|
91
|
+
if (event.matches) setOSTheme(customeDarkTheme);
|
|
92
|
+
else setOSTheme(customeLightTheme);
|
|
19
93
|
};
|
|
20
94
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
95
|
+
if (
|
|
96
|
+
window.matchMedia &&
|
|
97
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
98
|
+
) {
|
|
99
|
+
setOSTheme(customeDarkTheme);
|
|
23
100
|
}
|
|
24
101
|
|
|
25
|
-
window
|
|
102
|
+
window
|
|
103
|
+
.matchMedia('(prefers-color-scheme: dark)')
|
|
104
|
+
.addEventListener('change', switchTheme);
|
|
26
105
|
return () => {
|
|
27
|
-
window
|
|
106
|
+
window
|
|
107
|
+
.matchMedia('(prefers-color-scheme: dark)')
|
|
108
|
+
.removeEventListener('change', switchTheme);
|
|
28
109
|
};
|
|
29
110
|
}, []);
|
|
30
111
|
|
|
112
|
+
const prevFont = usePrevious(fontFamily);
|
|
113
|
+
|
|
114
|
+
useLayoutEffect(() => {
|
|
115
|
+
const { classList } = document.body;
|
|
116
|
+
|
|
117
|
+
if (prevFont) classList.remove(`font_${prevFont.replace(/ /g, '')}`);
|
|
118
|
+
classList.add(`font_${fontFamily.replace(/ /g, '')}`);
|
|
119
|
+
}, [fontFamily]);
|
|
120
|
+
|
|
31
121
|
const getActiveTheme = () => {
|
|
32
122
|
if (theme === 'auto') return OSTheme;
|
|
33
|
-
else return theme === 'dark' ?
|
|
123
|
+
else return theme === 'dark' ? customeDarkTheme : customeLightTheme;
|
|
34
124
|
};
|
|
35
125
|
|
|
36
126
|
return { activeTheme: getActiveTheme() };
|
package/src/i18n.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import i18n from 'i18next';
|
|
2
|
+
import { initReactI18next } from 'react-i18next';
|
|
3
|
+
import en from './languages/en.json';
|
|
4
|
+
import tr from './languages/tr.json';
|
|
5
|
+
import Backend from 'i18next-http-backend';
|
|
6
|
+
import LanguageDetector from 'i18next-browser-languagedetector';
|
|
7
|
+
|
|
8
|
+
const languages = ['en', 'tr'];
|
|
9
|
+
|
|
10
|
+
i18n
|
|
11
|
+
.use(Backend)
|
|
12
|
+
// detect user language
|
|
13
|
+
.use(LanguageDetector)
|
|
14
|
+
// pass the i18n instance to react-i18next.
|
|
15
|
+
.use(initReactI18next)
|
|
16
|
+
.init({
|
|
17
|
+
resources: {
|
|
18
|
+
en: {
|
|
19
|
+
translation: en,
|
|
20
|
+
},
|
|
21
|
+
tr: {
|
|
22
|
+
translation: tr,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
fallbackLng: 'en',
|
|
26
|
+
debug: true,
|
|
27
|
+
whitelist: languages,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export default i18n;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"swap": "SWAP",
|
|
3
|
+
"Connect Wallet":"Connect Wallet",
|
|
4
|
+
"Powered By":"Powered By",
|
|
5
|
+
"From":"From",
|
|
6
|
+
"To":"To",
|
|
7
|
+
"Max":"Max",
|
|
8
|
+
"Chain": "Chain",
|
|
9
|
+
"Token": "Token",
|
|
10
|
+
"Source" :"Source",
|
|
11
|
+
"Destination" :"Destination",
|
|
12
|
+
"Select Wallet":"Select Wallet"
|
|
13
|
+
}
|
package/src/lib.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SwapContainer } from '@rango-dev/ui';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } 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';
|
|
@@ -12,27 +12,49 @@ import {
|
|
|
12
12
|
} from './utils/wallets';
|
|
13
13
|
import { useWalletsStore } from './store/wallets';
|
|
14
14
|
import { Layout } from './components/Layout';
|
|
15
|
-
import { globalStyles } from './globalStyles';
|
|
15
|
+
import { globalFont, globalStyles } from './globalStyles';
|
|
16
16
|
import { useTheme } from './hooks/useTheme';
|
|
17
17
|
import { isEvmBlockchain } from 'rango-sdk';
|
|
18
|
+
import { Configs } from './types';
|
|
19
|
+
import { useSettingsStore } from './store/settings';
|
|
20
|
+
import useSelectLanguage from './hooks/useSelectLanguage';
|
|
21
|
+
import './i18n';
|
|
22
|
+
import QueueManager from './QueueManager';
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
export type WidgetProps = {
|
|
25
|
+
configs: Configs;
|
|
26
|
+
};
|
|
20
27
|
|
|
21
|
-
export const SwapBox: React.FC = () => {
|
|
28
|
+
export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
22
29
|
globalStyles();
|
|
23
|
-
|
|
30
|
+
globalFont(configs?.fontFamily || 'Roboto');
|
|
31
|
+
|
|
32
|
+
const { activeTheme } = useTheme({
|
|
33
|
+
...configs.colors,
|
|
34
|
+
borderRadius: configs?.borderRadius,
|
|
35
|
+
fontFamily: configs?.fontFamily,
|
|
36
|
+
});
|
|
24
37
|
const { blockchains } = useMetaStore.use.meta();
|
|
25
38
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
26
39
|
const connectWallet = useWalletsStore.use.connectWallet();
|
|
40
|
+
const setTheme = useSettingsStore.use.setTheme();
|
|
41
|
+
const { changeLanguage } = useSelectLanguage();
|
|
42
|
+
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
43
|
+
|
|
27
44
|
const evmBasedChainNames = blockchains
|
|
28
45
|
.filter(isEvmBlockchain)
|
|
29
46
|
.map((chain) => chain.name);
|
|
30
47
|
|
|
31
|
-
const onUpdateState: EventHandler = (
|
|
48
|
+
const onUpdateState: EventHandler = (
|
|
49
|
+
type,
|
|
50
|
+
event,
|
|
51
|
+
value,
|
|
52
|
+
_,
|
|
53
|
+
supportedChains
|
|
54
|
+
) => {
|
|
32
55
|
if (event === Events.ACCOUNTS) {
|
|
33
56
|
if (value) {
|
|
34
57
|
const supportedChainNames: Network[] | null =
|
|
35
|
-
//@ts-ignore
|
|
36
58
|
walletAndSupportedChainsNames(supportedChains);
|
|
37
59
|
const data = prepareAccountsForWalletStore(
|
|
38
60
|
type,
|
|
@@ -46,6 +68,27 @@ export const SwapBox: React.FC = () => {
|
|
|
46
68
|
}
|
|
47
69
|
}
|
|
48
70
|
};
|
|
71
|
+
let providers = allProviders();
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (configs.theme !== 'auto') setTheme(configs.theme);
|
|
75
|
+
}, [configs.theme]);
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const wallets = configs.wallets;
|
|
79
|
+
clearConnectedWallet();
|
|
80
|
+
providers =
|
|
81
|
+
wallets === 'all'
|
|
82
|
+
? allProviders()
|
|
83
|
+
: allProviders().filter((provider) => {
|
|
84
|
+
const type = provider.config.type;
|
|
85
|
+
return wallets.find((w) => w === type);
|
|
86
|
+
});
|
|
87
|
+
}, [configs?.wallets]);
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
changeLanguage(configs?.languege);
|
|
91
|
+
}, [configs?.languege]);
|
|
49
92
|
|
|
50
93
|
return (
|
|
51
94
|
<Provider
|
|
@@ -54,11 +97,22 @@ export const SwapBox: React.FC = () => {
|
|
|
54
97
|
onUpdateState={onUpdateState}
|
|
55
98
|
>
|
|
56
99
|
<div id="pageContainer" className={activeTheme}>
|
|
57
|
-
<
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
100
|
+
<QueueManager>
|
|
101
|
+
<SwapContainer
|
|
102
|
+
style={{
|
|
103
|
+
width: configs?.width || 'auto',
|
|
104
|
+
height: configs?.height || 'auto',
|
|
105
|
+
}}
|
|
106
|
+
>
|
|
107
|
+
<AppRouter
|
|
108
|
+
title={configs.title}
|
|
109
|
+
titleSize={configs.titleSize}
|
|
110
|
+
titleWeight={configs.titleWeight}
|
|
111
|
+
>
|
|
112
|
+
<Layout configs={configs} />
|
|
113
|
+
</AppRouter>
|
|
114
|
+
</SwapContainer>
|
|
115
|
+
</QueueManager>
|
|
62
116
|
</div>
|
|
63
117
|
</Provider>
|
|
64
118
|
);
|
package/src/pages/Home.tsx
CHANGED
|
@@ -58,8 +58,14 @@ const Alerts = styled('div', {
|
|
|
58
58
|
width: '100%',
|
|
59
59
|
paddingTop: '$16',
|
|
60
60
|
});
|
|
61
|
+
interface PropTypes {
|
|
62
|
+
title?: string;
|
|
63
|
+
titleSize?: number;
|
|
64
|
+
titleWeight?: number;
|
|
65
|
+
}
|
|
66
|
+
export function Home(props: PropTypes) {
|
|
67
|
+
const { title = 'SWAP', titleSize = 18, titleWeight = 600 } = props;
|
|
61
68
|
|
|
62
|
-
export function Home() {
|
|
63
69
|
const waningMessage = '';
|
|
64
70
|
const isRouterInContext = useInRouterContext();
|
|
65
71
|
const navigate = useNavigate();
|
|
@@ -72,9 +78,9 @@ export function Home() {
|
|
|
72
78
|
const setFromToken = useBestRouteStore.use.setFromToken();
|
|
73
79
|
const setToChain = useBestRouteStore.use.setToChain();
|
|
74
80
|
const setToToken = useBestRouteStore.use.setToToken();
|
|
81
|
+
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
75
82
|
const inputUsdValue = useBestRouteStore.use.inputUsdValue();
|
|
76
83
|
const inputAmount = useBestRouteStore.use.inputAmount();
|
|
77
|
-
const setInputAmount = useBestRouteStore.use.setInputAmount();
|
|
78
84
|
const outputAmount = useBestRouteStore.use.outputAmount();
|
|
79
85
|
const outputUsdValue = useBestRouteStore.use.outputUsdValue();
|
|
80
86
|
const bestRoute = useBestRouteStore.use.bestRoute();
|
|
@@ -133,9 +139,15 @@ export function Home() {
|
|
|
133
139
|
|
|
134
140
|
const highFee = hasHighFee(totalFeeInUsd);
|
|
135
141
|
|
|
142
|
+
|
|
136
143
|
return (
|
|
137
144
|
<Container>
|
|
138
|
-
<Header
|
|
145
|
+
<Header
|
|
146
|
+
title={title}
|
|
147
|
+
titleSize={titleSize}
|
|
148
|
+
titleWeight={titleWeight}
|
|
149
|
+
onClickRefresh={fetchBestRoute}
|
|
150
|
+
/>
|
|
139
151
|
<TokenInfo
|
|
140
152
|
type="From"
|
|
141
153
|
chain={fromChain}
|
|
@@ -4,10 +4,13 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
4
4
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
5
5
|
import { useMetaStore } from '../store/meta';
|
|
6
6
|
import { useSettingsStore } from '../store/settings';
|
|
7
|
+
import { Source } from '../types';
|
|
7
8
|
import { removeDuplicateFrom } from '../utils/common';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
interface PropTypes {
|
|
10
|
+
supportedSwappers: 'all' | Source[];
|
|
11
|
+
}
|
|
12
|
+
export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
13
|
+
const swappers = useMetaStore.use.meta().swappers;
|
|
11
14
|
const toggleLiquiditySource = useSettingsStore.use.toggleLiquiditySource();
|
|
12
15
|
const disabledLiquiditySources =
|
|
13
16
|
useSettingsStore.use.disabledLiquiditySources();
|
|
@@ -42,7 +45,16 @@ export function LiquiditySourcePage() {
|
|
|
42
45
|
return (
|
|
43
46
|
<LiquiditySourcesSelector
|
|
44
47
|
toggleAll={toggleAllLiquiditySources}
|
|
45
|
-
list={
|
|
48
|
+
list={
|
|
49
|
+
supportedSwappers !== 'all'
|
|
50
|
+
? uniqueSwappersGroups.filter(
|
|
51
|
+
(item) =>
|
|
52
|
+
supportedSwappers.filter(
|
|
53
|
+
(s) => s.title === item.title && s.type === item.type
|
|
54
|
+
).length > 0
|
|
55
|
+
)
|
|
56
|
+
: uniqueSwappersGroups
|
|
57
|
+
}
|
|
46
58
|
onChange={(liquiditySource) =>
|
|
47
59
|
toggleLiquiditySource(liquiditySource.title)
|
|
48
60
|
}
|
|
@@ -4,15 +4,19 @@ import { useBestRouteStore } from '../store/bestRoute';
|
|
|
4
4
|
import { useMetaStore } from '../store/meta';
|
|
5
5
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
|
+
import { BlockchainMeta } from 'rango-sdk';
|
|
7
8
|
|
|
8
9
|
interface PropTypes {
|
|
9
10
|
type: 'from' | 'to';
|
|
11
|
+
supportedChains: 'all' | BlockchainMeta[];
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
export function SelectChainPage(props: PropTypes) {
|
|
13
|
-
const { type } = props;
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const { type, supportedChains } = props;
|
|
16
|
+
const blockchains =
|
|
17
|
+
supportedChains === 'all'
|
|
18
|
+
? useMetaStore.use.meta().blockchains
|
|
19
|
+
: supportedChains;
|
|
16
20
|
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
17
21
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
18
22
|
const toChain = useBestRouteStore.use.toChain();
|
|
@@ -14,6 +14,7 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
14
14
|
|
|
15
15
|
interface PropTypes {
|
|
16
16
|
type: 'from' | 'to';
|
|
17
|
+
supportedTokens: 'all' | Token[];
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export interface TokenWithBalance extends Token {
|
|
@@ -24,10 +25,13 @@ export interface TokenWithBalance extends Token {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export function SelectTokenPage(props: PropTypes) {
|
|
27
|
-
const { type } = props;
|
|
28
28
|
const { navigateBackFrom } = useNavigateBack();
|
|
29
29
|
|
|
30
|
-
const {
|
|
30
|
+
const { type, supportedTokens } = props;
|
|
31
|
+
const tokens =
|
|
32
|
+
supportedTokens === 'all'
|
|
33
|
+
? useMetaStore.use.meta().tokens
|
|
34
|
+
: supportedTokens;
|
|
31
35
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
32
36
|
const toChain = useBestRouteStore.use.toChain();
|
|
33
37
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
@@ -5,14 +5,17 @@ import { useMetaStore } from '../store/meta';
|
|
|
5
5
|
import { useNavigate } from 'react-router-dom';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
7
|
import { removeDuplicateFrom } from '../utils/common';
|
|
8
|
+
import { Source } from '../types';
|
|
8
9
|
import {
|
|
9
10
|
MAX_SLIPPAGE,
|
|
10
11
|
MIN_SLIPPGAE,
|
|
11
12
|
SLIPPAGES,
|
|
12
13
|
} from '../constants/swapSettings';
|
|
13
14
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
interface PropTypes {
|
|
16
|
+
supportedSwappers: 'all' | Source[];
|
|
17
|
+
}
|
|
18
|
+
export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
16
19
|
const slippage = useSettingsStore.use.slippage();
|
|
17
20
|
const setSlippage = useSettingsStore.use.setSlippage();
|
|
18
21
|
const disabledLiquiditySources =
|
|
@@ -21,7 +24,7 @@ export function SettingsPage() {
|
|
|
21
24
|
const setCustomSlippage = useSettingsStore.use.setCustomSlippage();
|
|
22
25
|
const theme = useSettingsStore.use.theme();
|
|
23
26
|
const setTheme = useSettingsStore.use.setTheme();
|
|
24
|
-
const
|
|
27
|
+
const swappers = useMetaStore.use.meta().swappers;
|
|
25
28
|
const navigate = useNavigate();
|
|
26
29
|
const { navigateBackFrom } = useNavigateBack();
|
|
27
30
|
|
|
@@ -40,6 +43,8 @@ export function SettingsPage() {
|
|
|
40
43
|
.find(s => {
|
|
41
44
|
if (s) {
|
|
42
45
|
for (const type of s.types) {
|
|
46
|
+
if (supportedSwappers !== 'all') {
|
|
47
|
+
}
|
|
43
48
|
uniqueSwappersGroups.push({
|
|
44
49
|
title: s.swapperGroup,
|
|
45
50
|
logo: s.logo,
|
|
@@ -49,19 +54,38 @@ export function SettingsPage() {
|
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
});
|
|
57
|
+
supportedSwappers !== 'all' &&
|
|
58
|
+
uniqueSwappersGroups.filter(
|
|
59
|
+
(item) =>
|
|
60
|
+
supportedSwappers.filter(
|
|
61
|
+
(s) => s.title === item.title && s.type === item.type
|
|
62
|
+
).length > 0
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const supportedUniqueSwappersGroups =
|
|
66
|
+
supportedSwappers !== 'all'
|
|
67
|
+
? uniqueSwappersGroups.filter(
|
|
68
|
+
(item) =>
|
|
69
|
+
supportedSwappers.filter(
|
|
70
|
+
(s) => s.title === item.title && s.type === item.type
|
|
71
|
+
).length > 0
|
|
72
|
+
)
|
|
73
|
+
: uniqueSwappersGroups;
|
|
52
74
|
|
|
53
75
|
return (
|
|
54
76
|
<Settings
|
|
55
77
|
slippages={SLIPPAGES}
|
|
56
78
|
selectedSlippage={slippage}
|
|
57
79
|
onSlippageChange={slippage => setSlippage(slippage)}
|
|
58
|
-
liquiditySources={uniqueSwappersGroups}
|
|
59
|
-
selectedLiquiditySources={uniqueSwappersGroups.filter((s) => s.selected)}
|
|
60
80
|
onLiquiditySourcesClick={navigate.bind(
|
|
61
81
|
null,
|
|
62
82
|
navigationRoutes.liquiditySources
|
|
63
83
|
)}
|
|
64
84
|
onBack={navigateBackFrom.bind(null, navigationRoutes.settings)}
|
|
85
|
+
liquiditySources={supportedUniqueSwappersGroups}
|
|
86
|
+
selectedLiquiditySources={supportedUniqueSwappersGroups.filter(
|
|
87
|
+
(s) => s.selected
|
|
88
|
+
)}
|
|
65
89
|
customSlippage={customSlippage || NaN}
|
|
66
90
|
onCustomSlippageChange={setCustomSlippage}
|
|
67
91
|
minSlippage={MIN_SLIPPGAE}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
styled,
|
|
5
5
|
Wallet,
|
|
6
6
|
Typography,
|
|
7
|
+
WalletState,
|
|
7
8
|
} from '@rango-dev/ui';
|
|
8
9
|
import React, { useEffect, useState } from 'react';
|
|
9
10
|
import { getlistWallet } from '../utils/wallets';
|
|
@@ -12,6 +13,12 @@ import { useWallets } from '@rango-dev/wallets-core';
|
|
|
12
13
|
import { useUiStore } from '../store/ui';
|
|
13
14
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
14
15
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
16
|
+
import { useTranslation } from 'react-i18next';
|
|
17
|
+
|
|
18
|
+
interface PropTypes {
|
|
19
|
+
supportedWallets: 'all' | WalletType[];
|
|
20
|
+
multiWallets: boolean;
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
const ListContainer = styled('div', {
|
|
17
24
|
display: 'grid',
|
|
@@ -25,17 +32,18 @@ const ListContainer = styled('div', {
|
|
|
25
32
|
const AlertContainer = styled('div', {
|
|
26
33
|
paddingBottom: '$16',
|
|
27
34
|
});
|
|
28
|
-
export function WalletsPage() {
|
|
35
|
+
export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
29
36
|
const { navigateBackFrom } = useNavigateBack();
|
|
30
37
|
const { state, disconnect, getWalletInfo, connect } = useWallets();
|
|
31
38
|
const wallets = getlistWallet(
|
|
32
39
|
state,
|
|
33
40
|
getWalletInfo,
|
|
34
|
-
Object.values(WalletType)
|
|
41
|
+
supportedWallets === 'all' ? Object.values(WalletType) : supportedWallets
|
|
35
42
|
);
|
|
36
43
|
const [walletErrorMessage, setWalletErrorMessage] = useState('');
|
|
37
44
|
const toggleConnectWalletsButton =
|
|
38
45
|
useUiStore.use.toggleConnectWalletsButton();
|
|
46
|
+
const { t } = useTranslation();
|
|
39
47
|
|
|
40
48
|
const onSelectWallet = async (type: WalletType) => {
|
|
41
49
|
const wallet = state(type);
|
|
@@ -44,6 +52,12 @@ export function WalletsPage() {
|
|
|
44
52
|
if (wallet.connected) {
|
|
45
53
|
await disconnect(type);
|
|
46
54
|
} else {
|
|
55
|
+
if (
|
|
56
|
+
!multiWallets &&
|
|
57
|
+
!!wallets.find((w) => w.state === WalletState.CONNECTED)
|
|
58
|
+
) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
47
61
|
await connect(type);
|
|
48
62
|
}
|
|
49
63
|
} catch (e) {
|
|
@@ -58,7 +72,7 @@ export function WalletsPage() {
|
|
|
58
72
|
|
|
59
73
|
return (
|
|
60
74
|
<SecondaryPage
|
|
61
|
-
title=
|
|
75
|
+
title={t('Select Wallet')}
|
|
62
76
|
textField={false}
|
|
63
77
|
onBack={navigateBackFrom.bind(null, navigationRoutes.wallets)}
|
|
64
78
|
>
|
package/src/store/wallets.ts
CHANGED
|
@@ -50,6 +50,7 @@ interface WalletsStore {
|
|
|
50
50
|
disconnectWallet: (walletType: WalletType) => void;
|
|
51
51
|
initSelectedWallets: () => void;
|
|
52
52
|
setSelectedWallet: (wallet: SelectableWallet) => void;
|
|
53
|
+
clearConnectedWallet: () => void;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
export const useWalletsStore = createSelectors(
|
|
@@ -151,6 +152,13 @@ export const useWalletsStore = createSelectors(
|
|
|
151
152
|
walletType: wallet.walletType,
|
|
152
153
|
}),
|
|
153
154
|
})),
|
|
155
|
+
|
|
156
|
+
clearConnectedWallet: () =>
|
|
157
|
+
set(() => ({
|
|
158
|
+
accounts: [],
|
|
159
|
+
balances: [],
|
|
160
|
+
selectedWallets: [],
|
|
161
|
+
})),
|
|
154
162
|
}))
|
|
155
163
|
)
|
|
156
164
|
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BlockchainMeta, Token } from 'rango-sdk';
|
|
2
|
+
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
|
+
export interface Source {
|
|
4
|
+
title: string;
|
|
5
|
+
type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type Colors = {
|
|
9
|
+
background?: string;
|
|
10
|
+
// inputBackground?: string;
|
|
11
|
+
// icons?: string;
|
|
12
|
+
primary?: string;
|
|
13
|
+
foreground?: string;
|
|
14
|
+
// text?: string;
|
|
15
|
+
success?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
warning?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type Configs = {
|
|
21
|
+
fromChain: BlockchainMeta | null;
|
|
22
|
+
fromToken: Token | null;
|
|
23
|
+
toChain: BlockchainMeta | null;
|
|
24
|
+
toToken: Token | null;
|
|
25
|
+
fromAmount: number;
|
|
26
|
+
fromChains: 'all' | BlockchainMeta[];
|
|
27
|
+
fromTokens: 'all' | Token[];
|
|
28
|
+
toChains: 'all' | BlockchainMeta[];
|
|
29
|
+
toTokens: 'all' | Token[];
|
|
30
|
+
liquiditySources: 'all' | Source[];
|
|
31
|
+
wallets: 'all' | WalletType[];
|
|
32
|
+
multiWallets: boolean;
|
|
33
|
+
customeAddress: boolean;
|
|
34
|
+
theme: 'dark' | 'light' | 'auto';
|
|
35
|
+
title: string;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
languege: string;
|
|
39
|
+
borderRadius: number;
|
|
40
|
+
fontFamily: string;
|
|
41
|
+
titleSize: number;
|
|
42
|
+
titleWeight: number;
|
|
43
|
+
colors: Colors;
|
|
44
|
+
};
|
package/src/types/index.ts
CHANGED