@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/src/lib.tsx
CHANGED
|
@@ -15,35 +15,31 @@ 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 {
|
|
19
|
-
import { useSettingsStore } from './store/settings';
|
|
18
|
+
import { WidgetConfig } from './types';
|
|
20
19
|
import useSelectLanguage from './hooks/useSelectLanguage';
|
|
21
20
|
import './i18n';
|
|
22
21
|
import QueueManager from './QueueManager';
|
|
22
|
+
import { useUiStore } from './store/ui';
|
|
23
|
+
import { navigationRoutes } from './constants/navigationRoutes';
|
|
23
24
|
|
|
24
25
|
export type WidgetProps = {
|
|
25
|
-
|
|
26
|
+
config?: WidgetConfig;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
export const SwapBox: React.FC<WidgetProps> = ({
|
|
29
|
+
export const SwapBox: React.FC<WidgetProps> = ({ config }) => {
|
|
29
30
|
globalStyles();
|
|
30
|
-
globalFont(
|
|
31
|
+
globalFont(config?.theme?.fontFamily || 'Roboto');
|
|
31
32
|
|
|
32
|
-
const { activeTheme } = useTheme({
|
|
33
|
-
...configs.colors,
|
|
34
|
-
borderRadius: configs?.borderRadius,
|
|
35
|
-
fontFamily: configs?.fontFamily,
|
|
36
|
-
});
|
|
33
|
+
const { activeTheme } = useTheme({ ...config?.theme });
|
|
37
34
|
const { blockchains } = useMetaStore.use.meta();
|
|
38
35
|
const disconnectWallet = useWalletsStore.use.disconnectWallet();
|
|
39
36
|
const connectWallet = useWalletsStore.use.connectWallet();
|
|
40
|
-
const setTheme = useSettingsStore.use.setTheme();
|
|
41
37
|
const { changeLanguage } = useSelectLanguage();
|
|
42
38
|
const clearConnectedWallet = useWalletsStore.use.clearConnectedWallet();
|
|
43
|
-
|
|
44
39
|
const [lastConnectedWalletWithNetwork, setLastConnectedWalletWithNetwork] =
|
|
45
40
|
useState<string>('');
|
|
46
41
|
const [disconnectedWallet, setDisconnectedWallet] = useState<WalletType>();
|
|
42
|
+
const currentPage = useUiStore.use.currentPage();
|
|
47
43
|
|
|
48
44
|
const evmBasedChainNames = blockchains
|
|
49
45
|
.filter(isEvmBlockchain)
|
|
@@ -71,7 +67,6 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
71
67
|
disconnectWallet(type);
|
|
72
68
|
}
|
|
73
69
|
}
|
|
74
|
-
|
|
75
70
|
if (event === Events.ACCOUNTS && state.connected) {
|
|
76
71
|
const key = `${type}-${state.network}-${value}`;
|
|
77
72
|
|
|
@@ -88,24 +83,19 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
88
83
|
let providers = allProviders();
|
|
89
84
|
|
|
90
85
|
useEffect(() => {
|
|
91
|
-
|
|
92
|
-
}, [configs.theme]);
|
|
93
|
-
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
const wallets = configs.wallets;
|
|
86
|
+
const wallets = config?.wallets;
|
|
96
87
|
clearConnectedWallet();
|
|
97
|
-
providers =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}, [configs?.wallets]);
|
|
88
|
+
providers = !wallets
|
|
89
|
+
? allProviders()
|
|
90
|
+
: allProviders().filter((provider) => {
|
|
91
|
+
const type = provider.config.type;
|
|
92
|
+
return wallets.find((w) => w === type);
|
|
93
|
+
});
|
|
94
|
+
}, [config?.wallets]);
|
|
105
95
|
|
|
106
96
|
useEffect(() => {
|
|
107
|
-
changeLanguage(
|
|
108
|
-
}, [
|
|
97
|
+
changeLanguage(config?.language || 'en');
|
|
98
|
+
}, [config?.language]);
|
|
109
99
|
|
|
110
100
|
return (
|
|
111
101
|
<Provider
|
|
@@ -116,22 +106,26 @@ export const SwapBox: React.FC<WidgetProps> = ({ configs }) => {
|
|
|
116
106
|
<div id="pageContainer" className={activeTheme}>
|
|
117
107
|
<QueueManager>
|
|
118
108
|
<SwapContainer
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
// }
|
|
123
120
|
>
|
|
124
121
|
<AppRouter
|
|
125
|
-
title={configs.title}
|
|
126
|
-
titleSize={configs.titleSize}
|
|
127
|
-
titleWeight={configs.titleWeight}
|
|
128
122
|
lastConnectedWallet={lastConnectedWalletWithNetwork}
|
|
129
123
|
disconnectedWallet={disconnectedWallet}
|
|
130
124
|
clearDisconnectedWallet={() => {
|
|
131
125
|
setDisconnectedWallet(undefined);
|
|
132
126
|
}}
|
|
133
127
|
>
|
|
134
|
-
<Layout
|
|
128
|
+
<Layout config={config} />
|
|
135
129
|
</AppRouter>
|
|
136
130
|
</SwapContainer>
|
|
137
131
|
</QueueManager>
|
|
@@ -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,
|
|
@@ -111,6 +112,7 @@ export function ConfirmSwapPage() {
|
|
|
111
112
|
navigate(navigationRoutes.swaps + `/${swap.requestId}`, {
|
|
112
113
|
replace: true,
|
|
113
114
|
});
|
|
115
|
+
setInputAmount('');
|
|
114
116
|
}
|
|
115
117
|
});
|
|
116
118
|
}}
|
package/src/pages/Home.tsx
CHANGED
|
@@ -63,14 +63,8 @@ const Alerts = styled('div', {
|
|
|
63
63
|
width: '100%',
|
|
64
64
|
paddingTop: '$16',
|
|
65
65
|
});
|
|
66
|
-
interface PropTypes {
|
|
67
|
-
title?: string;
|
|
68
|
-
titleSize?: number;
|
|
69
|
-
titleWeight?: number;
|
|
70
|
-
}
|
|
71
|
-
export function Home(props: PropTypes) {
|
|
72
|
-
const { title = 'SWAP' } = props;
|
|
73
66
|
|
|
67
|
+
export function Home() {
|
|
74
68
|
const isRouterInContext = useInRouterContext();
|
|
75
69
|
const navigate = useNavigate();
|
|
76
70
|
const [count, setCount] = useState(0);
|
|
@@ -116,7 +110,6 @@ export function Home(props: PropTypes) {
|
|
|
116
110
|
outputUsdValue
|
|
117
111
|
);
|
|
118
112
|
|
|
119
|
-
const inputIsZero = inputAmount === '0';
|
|
120
113
|
const swapButtonState = getSwapButtonState(
|
|
121
114
|
loadingMetaStatus,
|
|
122
115
|
accounts,
|
|
@@ -126,7 +119,7 @@ export function Home(props: PropTypes) {
|
|
|
126
119
|
highValueLoss,
|
|
127
120
|
priceImpactCanNotBeComputed,
|
|
128
121
|
needsToWarnEthOnPath,
|
|
129
|
-
|
|
122
|
+
inputAmount
|
|
130
123
|
);
|
|
131
124
|
|
|
132
125
|
const totalFeeInUsd = getTotalFeeInUsd(bestRoute, tokens);
|
|
@@ -142,7 +135,7 @@ export function Home(props: PropTypes) {
|
|
|
142
135
|
return (
|
|
143
136
|
<Container>
|
|
144
137
|
<Header
|
|
145
|
-
title=
|
|
138
|
+
title="SWAP"
|
|
146
139
|
suffix={
|
|
147
140
|
<HeaderButtons
|
|
148
141
|
onClickRefresh={!!bestRoute ? fetchBestRoute : undefined}
|
|
@@ -4,10 +4,9 @@ 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';
|
|
8
7
|
import { removeDuplicateFrom } from '../utils/common';
|
|
9
8
|
interface PropTypes {
|
|
10
|
-
supportedSwappers
|
|
9
|
+
supportedSwappers?: string[];
|
|
11
10
|
}
|
|
12
11
|
export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
13
12
|
const swappers = useMetaStore.use.meta().swappers;
|
|
@@ -47,12 +46,10 @@ export function LiquiditySourcePage({ supportedSwappers }: PropTypes) {
|
|
|
47
46
|
<LiquiditySourcesSelector
|
|
48
47
|
toggleAll={toggleAllLiquiditySources}
|
|
49
48
|
list={
|
|
50
|
-
supportedSwappers
|
|
49
|
+
supportedSwappers
|
|
51
50
|
? uniqueSwappersGroups.filter(
|
|
52
51
|
(item) =>
|
|
53
|
-
supportedSwappers.filter(
|
|
54
|
-
(s) => s.title === item.title && s.type === item.type
|
|
55
|
-
).length > 0
|
|
52
|
+
supportedSwappers.filter((s) => s === item.title).length > 0
|
|
56
53
|
)
|
|
57
54
|
: uniqueSwappersGroups
|
|
58
55
|
}
|
|
@@ -4,19 +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';
|
|
8
7
|
|
|
9
8
|
interface PropTypes {
|
|
10
9
|
type: 'from' | 'to';
|
|
11
|
-
supportedChains
|
|
10
|
+
supportedChains?: string[];
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export function SelectChainPage(props: PropTypes) {
|
|
15
14
|
const { type, supportedChains } = props;
|
|
16
|
-
const blockchains =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const blockchains = supportedChains
|
|
16
|
+
? useMetaStore.use
|
|
17
|
+
.meta()
|
|
18
|
+
.blockchains.filter((chain) => supportedChains.includes(chain.name))
|
|
19
|
+
: useMetaStore.use.meta().blockchains;
|
|
20
20
|
const loadingStatus = useMetaStore.use.loadingStatus();
|
|
21
21
|
const fromChain = useBestRouteStore.use.fromChain();
|
|
22
22
|
const toChain = useBestRouteStore.use.toChain();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TokenSelector } from '@rango-dev/ui';
|
|
3
3
|
import { useBestRouteStore } from '../store/bestRoute';
|
|
4
|
-
import { Token } from 'rango-sdk';
|
|
4
|
+
import { Asset, Token } from 'rango-sdk';
|
|
5
5
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
6
6
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
7
7
|
import { tokensAreEqual } from '../utils/wallets';
|
|
@@ -9,7 +9,7 @@ import { useMetaStore } from '../store/meta';
|
|
|
9
9
|
|
|
10
10
|
interface PropTypes {
|
|
11
11
|
type: 'from' | 'to';
|
|
12
|
-
supportedTokens
|
|
12
|
+
supportedTokens?: Asset[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface TokenWithBalance extends Token {
|
|
@@ -25,23 +25,21 @@ export function SelectTokenPage(props: PropTypes) {
|
|
|
25
25
|
const { type, supportedTokens } = props;
|
|
26
26
|
const sourceTokens = useBestRouteStore.use.sourceTokens();
|
|
27
27
|
const destinationTokens = useBestRouteStore.use.destinationTokens();
|
|
28
|
-
const supportedSourceTokens =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
);
|
|
28
|
+
const supportedSourceTokens = supportedTokens
|
|
29
|
+
? sourceTokens.filter((token) =>
|
|
30
|
+
supportedTokens.some((supportedToken) =>
|
|
31
|
+
tokensAreEqual(supportedToken, token)
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
: sourceTokens;
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
);
|
|
36
|
+
const supportedDestinationTokens = supportedTokens
|
|
37
|
+
? destinationTokens.filter((token) =>
|
|
38
|
+
supportedTokens.some((supportedToken) =>
|
|
39
|
+
tokensAreEqual(supportedToken, token)
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
: destinationTokens;
|
|
45
43
|
|
|
46
44
|
const fromToken = useBestRouteStore.use.fromToken();
|
|
47
45
|
const toToken = useBestRouteStore.use.toToken();
|
|
@@ -5,7 +5,6 @@ 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';
|
|
9
8
|
import {
|
|
10
9
|
MAX_SLIPPAGE,
|
|
11
10
|
MIN_SLIPPGAE,
|
|
@@ -13,7 +12,7 @@ import {
|
|
|
13
12
|
} from '../constants/swapSettings';
|
|
14
13
|
import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
15
14
|
interface PropTypes {
|
|
16
|
-
supportedSwappers
|
|
15
|
+
supportedSwappers?: string[];
|
|
17
16
|
}
|
|
18
17
|
export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
19
18
|
const slippage = useSettingsStore.use.slippage();
|
|
@@ -45,8 +44,6 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
|
45
44
|
.find((s) => {
|
|
46
45
|
if (s) {
|
|
47
46
|
for (const type of s.types) {
|
|
48
|
-
if (supportedSwappers !== 'all') {
|
|
49
|
-
}
|
|
50
47
|
uniqueSwappersGroups.push({
|
|
51
48
|
title: s.swapperGroup,
|
|
52
49
|
logo: s.logo,
|
|
@@ -56,23 +53,16 @@ export function SettingsPage({ supportedSwappers }: PropTypes) {
|
|
|
56
53
|
}
|
|
57
54
|
}
|
|
58
55
|
});
|
|
59
|
-
supportedSwappers
|
|
56
|
+
supportedSwappers &&
|
|
60
57
|
uniqueSwappersGroups.filter(
|
|
61
|
-
(item) =>
|
|
62
|
-
supportedSwappers.filter(
|
|
63
|
-
(s) => s.title === item.title && s.type === item.type
|
|
64
|
-
).length > 0
|
|
58
|
+
(item) => supportedSwappers.filter((s) => s === item.title).length > 0
|
|
65
59
|
);
|
|
66
60
|
|
|
67
|
-
const supportedUniqueSwappersGroups =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
(s) => s.title === item.title && s.type === item.type
|
|
73
|
-
).length > 0
|
|
74
|
-
)
|
|
75
|
-
: uniqueSwappersGroups;
|
|
61
|
+
const supportedUniqueSwappersGroups = supportedSwappers
|
|
62
|
+
? uniqueSwappersGroups.filter(
|
|
63
|
+
(item) => supportedSwappers.filter((s) => s === item.title).length > 0
|
|
64
|
+
)
|
|
65
|
+
: uniqueSwappersGroups;
|
|
76
66
|
|
|
77
67
|
return (
|
|
78
68
|
<Settings
|
|
@@ -4,7 +4,7 @@ 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 } from '@rango-dev/ui';
|
|
7
|
+
import { SwapHistory, Spacer } from '@rango-dev/ui';
|
|
8
8
|
import { useUiStore } from '../store/ui';
|
|
9
9
|
import {
|
|
10
10
|
cancelSwap,
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
shouldRetrySwap,
|
|
27
27
|
} from '../utils/swap';
|
|
28
28
|
import { TokenPreview } from '../components/TokenPreview';
|
|
29
|
-
import { Spacer } from '@rango-dev/ui';
|
|
30
29
|
import { numberToString } from '../utils/numbers';
|
|
31
30
|
//@ts-ignore
|
|
32
31
|
import { t } from 'i18next';
|
|
@@ -127,7 +126,7 @@ export function SwapDetailsPage() {
|
|
|
127
126
|
<TokenPreview
|
|
128
127
|
chain={{
|
|
129
128
|
displayName: lastStep?.toBlockchain || '',
|
|
130
|
-
|
|
129
|
+
//@ts-ignore
|
|
131
130
|
logo: lastStep?.toBlockchainLogo || '',
|
|
132
131
|
}}
|
|
133
132
|
token={{
|
|
@@ -141,7 +140,6 @@ export function SwapDetailsPage() {
|
|
|
141
140
|
</>
|
|
142
141
|
}
|
|
143
142
|
//todo: move PendingSwap type to rango-types
|
|
144
|
-
//@ts-ignore
|
|
145
143
|
pendingSwap={swap}
|
|
146
144
|
onCopy={handleCopy}
|
|
147
145
|
isCopied={isCopied}
|
|
@@ -20,7 +20,7 @@ import { Spinner } from '@rango-dev/ui';
|
|
|
20
20
|
import { LoadingFailedAlert } from '@rango-dev/ui';
|
|
21
21
|
|
|
22
22
|
interface PropTypes {
|
|
23
|
-
supportedWallets
|
|
23
|
+
supportedWallets?: WalletType[];
|
|
24
24
|
multiWallets: boolean;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -50,7 +50,7 @@ export function WalletsPage({ supportedWallets, multiWallets }: PropTypes) {
|
|
|
50
50
|
const wallets = getlistWallet(
|
|
51
51
|
state,
|
|
52
52
|
getWalletInfo,
|
|
53
|
-
supportedWallets
|
|
53
|
+
supportedWallets || Object.values(WalletType)
|
|
54
54
|
);
|
|
55
55
|
const walletsRef = useRef<WalletInfo[]>();
|
|
56
56
|
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { RangoClient } from 'rango-sdk';
|
|
2
|
+
import { getConfig } from '../utils/configs';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// this API key is limited and
|
|
5
|
+
// it is only for test purpose
|
|
6
|
+
export const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
7
|
+
|
|
8
|
+
let rango: RangoClient | undefined = undefined;
|
|
9
|
+
|
|
10
|
+
export const httpService = () => {
|
|
11
|
+
if (rango) return rango;
|
|
12
|
+
rango = new RangoClient(getConfig('API_KEY'));
|
|
13
|
+
return rango;
|
|
14
|
+
};
|
package/src/store/bestRoute.ts
CHANGED
|
@@ -249,7 +249,7 @@ const bestRoute = (
|
|
|
249
249
|
let abortController: AbortController | null = null;
|
|
250
250
|
const fetchBestRoute = () => {
|
|
251
251
|
const { fromToken, toToken, inputAmount } = bestRouteStore.getState();
|
|
252
|
-
const { slippage, customSlippage, disabledLiquiditySources } =
|
|
252
|
+
const { slippage, customSlippage, disabledLiquiditySources, affiliateRef } =
|
|
253
253
|
settingsStore.getState();
|
|
254
254
|
if (!fromToken || !toToken || !inputAmount || inputAmount === '0') return;
|
|
255
255
|
abortController?.abort();
|
|
@@ -263,7 +263,7 @@ const bestRoute = (
|
|
|
263
263
|
[],
|
|
264
264
|
disabledLiquiditySources,
|
|
265
265
|
userSlippage,
|
|
266
|
-
|
|
266
|
+
affiliateRef
|
|
267
267
|
);
|
|
268
268
|
if (!bestRouteStore.getState().loading)
|
|
269
269
|
bestRouteStore.setState({
|
|
@@ -272,7 +272,7 @@ const bestRoute = (
|
|
|
272
272
|
outputAmount: null,
|
|
273
273
|
outputUsdValue: new BigNumber(0),
|
|
274
274
|
});
|
|
275
|
-
httpService
|
|
275
|
+
httpService()
|
|
276
276
|
.getBestRoute(requestBody, {
|
|
277
277
|
signal: abortController.signal,
|
|
278
278
|
})
|
|
@@ -296,7 +296,8 @@ const bestRoute = (
|
|
|
296
296
|
const bestRouteParamsListener = () => {
|
|
297
297
|
const { fromToken, toToken, inputAmount, inputUsdValue } =
|
|
298
298
|
useBestRouteStore.getState();
|
|
299
|
-
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0))
|
|
299
|
+
if (!inputAmount || inputAmount === '0' || inputUsdValue.eq(0))
|
|
300
|
+
return bestRouteStore.setState({ loading: false });
|
|
300
301
|
|
|
301
302
|
if (tokensAreEqual(fromToken, toToken))
|
|
302
303
|
return bestRouteStore.setState({
|
package/src/store/meta.ts
CHANGED
|
@@ -18,12 +18,14 @@ export const useMetaStore = createSelectors(
|
|
|
18
18
|
loadingStatus: 'loading',
|
|
19
19
|
fetchMeta: async () => {
|
|
20
20
|
try {
|
|
21
|
-
const response = await httpService.getAllMetadata();
|
|
21
|
+
const response = await httpService().getAllMetadata();
|
|
22
22
|
const chainThatHasTokenInMetaResponse = removeDuplicateFrom(
|
|
23
|
-
response.tokens.map((t) => t.blockchain)
|
|
23
|
+
response.tokens.map((t) => t.blockchain)
|
|
24
24
|
);
|
|
25
25
|
const enabledChains = response.blockchains.filter(
|
|
26
|
-
(chain) =>
|
|
26
|
+
(chain) =>
|
|
27
|
+
chain.enabled &&
|
|
28
|
+
chainThatHasTokenInMetaResponse.includes(chain.name)
|
|
27
29
|
);
|
|
28
30
|
response.blockchains = enabledChains.sort((a, b) => a.sort - b.sort);
|
|
29
31
|
set({ meta: response, loadingStatus: 'success' });
|
|
@@ -31,5 +33,5 @@ export const useMetaStore = createSelectors(
|
|
|
31
33
|
set({ loadingStatus: 'failed' });
|
|
32
34
|
}
|
|
33
35
|
},
|
|
34
|
-
}))
|
|
36
|
+
}))
|
|
35
37
|
);
|
package/src/store/settings.ts
CHANGED
|
@@ -13,12 +13,14 @@ export interface SettingsState {
|
|
|
13
13
|
infiniteApprove: boolean;
|
|
14
14
|
disabledLiquiditySources: string[];
|
|
15
15
|
theme: Theme;
|
|
16
|
+
affiliateRef: string | null;
|
|
16
17
|
setSlippage: (slippage: number) => void;
|
|
17
18
|
setCustomSlippage: (customSlippage: number | null) => void;
|
|
18
19
|
toggleInfiniteApprove: () => void;
|
|
19
20
|
toggleLiquiditySource: (name: string) => void;
|
|
20
21
|
setTheme: (theme: Theme) => void;
|
|
21
22
|
toggleAllLiquiditySources: () => void;
|
|
23
|
+
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export const useSettingsStore = createSelectors(
|
|
@@ -28,6 +30,7 @@ export const useSettingsStore = createSelectors(
|
|
|
28
30
|
slippage: DEFAULT_SLIPPAGE,
|
|
29
31
|
customSlippage: null,
|
|
30
32
|
infiniteApprove: false,
|
|
33
|
+
affiliateRef: null,
|
|
31
34
|
disabledLiquiditySources: [],
|
|
32
35
|
theme: 'auto',
|
|
33
36
|
setSlippage: (slippage) =>
|
|
@@ -38,6 +41,10 @@ export const useSettingsStore = createSelectors(
|
|
|
38
41
|
set(() => ({
|
|
39
42
|
customSlippage: customSlippage,
|
|
40
43
|
})),
|
|
44
|
+
setAffiliateRef: (affiliateRef) =>
|
|
45
|
+
set(() => ({
|
|
46
|
+
affiliateRef,
|
|
47
|
+
})),
|
|
41
48
|
toggleAllLiquiditySources: () =>
|
|
42
49
|
set((state) => {
|
|
43
50
|
const { swappers } = useMetaStore.getState().meta;
|
package/src/store/wallets.ts
CHANGED
|
@@ -81,7 +81,7 @@ export const useWalletsStore = createSelectors(
|
|
|
81
81
|
}));
|
|
82
82
|
accounts.forEach(async (account) => {
|
|
83
83
|
try {
|
|
84
|
-
const response = await httpService.getWalletsDetails([
|
|
84
|
+
const response = await httpService().getWalletsDetails([
|
|
85
85
|
{ address: account.address, blockchain: account.chain },
|
|
86
86
|
]);
|
|
87
87
|
const retrivedBalance = response.wallets[0];
|
|
@@ -142,7 +142,7 @@ export const useWalletsStore = createSelectors(
|
|
|
142
142
|
}
|
|
143
143
|
});
|
|
144
144
|
return {
|
|
145
|
-
selectedWallets: selectedWallets,
|
|
145
|
+
selectedWallets: state.selectedWallets.concat(selectedWallets),
|
|
146
146
|
};
|
|
147
147
|
}),
|
|
148
148
|
setSelectedWallet: (wallet) =>
|
package/src/types/config.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Asset } from 'rango-sdk';
|
|
2
2
|
import { WalletType } from '@rango-dev/wallets-shared';
|
|
3
|
-
export interface Source {
|
|
4
|
-
title: string;
|
|
5
|
-
type: 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
6
|
-
}
|
|
7
3
|
|
|
8
4
|
export type Colors = {
|
|
9
5
|
background?: string;
|
|
@@ -17,28 +13,31 @@ export type Colors = {
|
|
|
17
13
|
warning?: string;
|
|
18
14
|
};
|
|
19
15
|
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
16
|
+
export type Theme = {
|
|
17
|
+
mode?: 'dark' | 'light' | 'auto';
|
|
18
|
+
fontFamily?: string;
|
|
19
|
+
colors?: Colors;
|
|
20
|
+
borderRadius?: number;
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
};
|
|
24
|
+
export type Support = {
|
|
25
|
+
blockchain?: string;
|
|
26
|
+
token?: Asset;
|
|
27
|
+
blockchains?: string[];
|
|
28
|
+
tokens?: Asset[];
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type WidgetConfig = {
|
|
32
|
+
apiKey: string;
|
|
33
|
+
affiliateRef?: string;
|
|
34
|
+
amount?: number;
|
|
35
|
+
from?: Support;
|
|
36
|
+
to?: Support;
|
|
37
|
+
liquiditySources?: string[];
|
|
38
|
+
wallets?: WalletType[];
|
|
39
|
+
multiWallets?: boolean;
|
|
40
|
+
customAddress?: boolean;
|
|
41
|
+
language?: string;
|
|
42
|
+
theme?: Theme;
|
|
44
43
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface Configs {
|
|
2
|
+
API_KEY: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
|
|
6
|
+
|
|
7
|
+
let configs: Configs = {
|
|
8
|
+
API_KEY: RANGO_PUBLIC_API_KEY,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function getConfig(name: keyof Configs) {
|
|
12
|
+
return configs[name];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setConfig(name: keyof Configs, value: any) {
|
|
16
|
+
configs[name] = value;
|
|
17
|
+
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function initConfig(nextConfigs: Configs) {
|
|
22
|
+
configs = structuredClone(nextConfigs);
|
|
23
|
+
return configs;
|
|
24
|
+
}
|