@rango-dev/widget-embedded 0.17.1-next.25 → 0.17.1-next.27
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/components/ConfirmWalletsModal/ConfirmWallets.styles.d.ts +3 -3
- package/dist/components/HeaderButtons/HomeButtons.d.ts.map +1 -1
- package/dist/components/Layout/Layout.d.ts.map +1 -1
- package/dist/components/NoResult/NoResult.d.ts.map +1 -1
- package/dist/components/Quote/Quote.styles.d.ts +1 -1
- package/dist/components/Slippage/Slippage.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.helpers.d.ts +2 -2
- package/dist/components/TokenList/TokenList.helpers.d.ts.map +1 -1
- package/dist/components/TokenList/TokenList.types.d.ts +3 -9
- package/dist/components/TokenList/TokenList.types.d.ts.map +1 -1
- package/dist/components/TokenList/index.d.ts +0 -1
- package/dist/components/TokenList/index.d.ts.map +1 -1
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/hooks/useLanguage.d.ts.map +1 -1
- package/dist/hooks/useSyncStoresWithConfig.d.ts.map +1 -1
- package/dist/hooks/useTheme.d.ts +1 -1
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/pages/ConfirmSwapPage.d.ts.map +1 -1
- package/dist/pages/Home.d.ts.map +1 -1
- package/dist/pages/LiquiditySourcePage.d.ts.map +1 -1
- package/dist/pages/SelectSwapItemsPage.d.ts.map +1 -1
- package/dist/pages/SettingsPage.d.ts.map +1 -1
- package/dist/pages/ThemePage.d.ts.map +1 -1
- package/dist/store/AppStore.d.ts +37 -1
- package/dist/store/AppStore.d.ts.map +1 -1
- package/dist/store/app.d.ts +39 -2
- package/dist/store/app.d.ts.map +1 -1
- package/dist/store/quote.d.ts +4 -5
- package/dist/store/quote.d.ts.map +1 -1
- package/dist/store/slices/settings.d.ts +39 -0
- package/dist/store/slices/settings.d.ts.map +1 -0
- package/dist/store/wallets.d.ts +5 -2
- package/dist/store/wallets.d.ts.map +1 -1
- package/dist/types/config.d.ts +28 -9
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/wallets.d.ts +15 -1
- package/dist/types/wallets.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +4 -1
- package/dist/utils/settings.d.ts.map +1 -1
- package/dist/utils/wallets.d.ts +6 -8
- package/dist/utils/wallets.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/HeaderButtons/HomeButtons.tsx +28 -18
- package/src/components/Layout/Layout.tsx +11 -1
- package/src/components/NoResult/NoResult.tsx +2 -5
- package/src/components/QuoteWarningsAndErrors/SlippageWariningModal.tsx +2 -2
- package/src/components/Slippage/Slippage.tsx +3 -5
- package/src/components/TokenList/TokenList.helpers.ts +2 -2
- package/src/components/TokenList/TokenList.tsx +10 -12
- package/src/components/TokenList/TokenList.types.ts +3 -10
- package/src/components/TokenList/index.ts +0 -1
- package/src/containers/App/App.tsx +0 -2
- package/src/containers/Wallets/Wallets.tsx +3 -3
- package/src/hooks/useConfirmSwap/useConfirmSwap.ts +4 -4
- package/src/hooks/useLanguage.ts +2 -3
- package/src/hooks/usePrepareBlockchainList/usePrepareBlockchainList.ts +2 -2
- package/src/hooks/useSwapInput.ts +4 -4
- package/src/hooks/useSyncStoresWithConfig.ts +1 -2
- package/src/hooks/useTheme.ts +4 -5
- package/src/pages/ConfirmSwapPage.tsx +2 -3
- package/src/pages/Home.tsx +9 -33
- package/src/pages/LiquiditySourcePage.tsx +3 -3
- package/src/pages/SelectSwapItemsPage.tsx +3 -6
- package/src/pages/SettingsPage.tsx +22 -11
- package/src/pages/ThemePage.tsx +2 -3
- package/src/store/AppStore.tsx +7 -1
- package/src/store/app.ts +31 -5
- package/src/store/quote.ts +2 -3
- package/src/store/slices/settings.ts +168 -0
- package/src/store/wallets.ts +56 -29
- package/src/types/config.ts +38 -8
- package/src/types/wallets.ts +18 -1
- package/src/utils/settings.ts +11 -5
- package/src/utils/wallets.ts +80 -134
- package/dist/store/settings.d.ts +0 -83
- package/dist/store/settings.d.ts.map +0 -1
- package/src/store/settings.ts +0 -161
|
@@ -14,17 +14,15 @@ import {
|
|
|
14
14
|
MIN_SLIPPGAE,
|
|
15
15
|
SLIPPAGES,
|
|
16
16
|
} from '../../constants/swapSettings';
|
|
17
|
-
import {
|
|
17
|
+
import { useAppStore } from '../../store/AppStore';
|
|
18
18
|
import { getContainer } from '../../utils/common';
|
|
19
19
|
|
|
20
20
|
import { BaseContainer, Head, SlippageChipsContainer } from './Slippage.styles';
|
|
21
21
|
import { SlippageTooltipContent } from './SlippageTooltipContent';
|
|
22
22
|
|
|
23
23
|
export function Slippage() {
|
|
24
|
-
const slippage =
|
|
25
|
-
|
|
26
|
-
const customSlippage = useSettingsStore.use.customSlippage();
|
|
27
|
-
const setCustomSlippage = useSettingsStore.use.setCustomSlippage();
|
|
24
|
+
const { slippage, setSlippage, customSlippage, setCustomSlippage } =
|
|
25
|
+
useAppStore();
|
|
28
26
|
|
|
29
27
|
return (
|
|
30
28
|
<BaseContainer>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Token } from 'rango-sdk';
|
|
2
2
|
|
|
3
3
|
import { containsText } from '../../utils/common';
|
|
4
4
|
|
|
5
|
-
export const filterTokens = (list:
|
|
5
|
+
export const filterTokens = (list: Token[], searchedFor: string) =>
|
|
6
6
|
list.filter(
|
|
7
7
|
(token) =>
|
|
8
8
|
containsText(token.symbol, searchedFor) ||
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
RenderDescProps,
|
|
5
|
-
TokenWithBalance,
|
|
6
|
-
} from './TokenList.types';
|
|
2
|
+
import type { PropTypes, RenderDescProps } from './TokenList.types';
|
|
3
|
+
import type { Token } from 'rango-sdk';
|
|
7
4
|
import type { CommonProps } from 'react-window';
|
|
8
5
|
|
|
9
6
|
import { i18n } from '@lingui/core';
|
|
@@ -24,6 +21,7 @@ import React, { forwardRef, useEffect, useState } from 'react';
|
|
|
24
21
|
import { useAppStore } from '../../store/AppStore';
|
|
25
22
|
import { useWalletsStore } from '../../store/wallets';
|
|
26
23
|
import { generateRangeColors } from '../../utils/colors';
|
|
24
|
+
import { formatBalance } from '../../utils/wallets';
|
|
27
25
|
|
|
28
26
|
import { LoadingTokenList } from './LoadingTokenList';
|
|
29
27
|
import {
|
|
@@ -85,11 +83,11 @@ const renderDesc = (props: RenderDescProps) => {
|
|
|
85
83
|
export function TokenList(props: PropTypes) {
|
|
86
84
|
const { list, searchedFor = '', onChange, selectedBlockchain } = props;
|
|
87
85
|
|
|
88
|
-
const [tokens, setTokens] = useState<
|
|
86
|
+
const [tokens, setTokens] = useState<Token[]>(list);
|
|
89
87
|
const fetchStatus = useAppStore().fetchStatus;
|
|
90
88
|
const blockchains = useAppStore().blockchains();
|
|
91
89
|
const [hasNextPage, setHasNextPage] = useState<boolean>(true);
|
|
92
|
-
const loadingWallet = useWalletsStore
|
|
90
|
+
const { getBalanceFor, loading: loadingWallet } = useWalletsStore();
|
|
93
91
|
const { isTokenPinned } = useAppStore();
|
|
94
92
|
|
|
95
93
|
// eslint-disable-next-line react/display-name
|
|
@@ -134,7 +132,7 @@ export function TokenList(props: PropTypes) {
|
|
|
134
132
|
<VirtualizedList
|
|
135
133
|
Item={({ index, style }) => {
|
|
136
134
|
const token = tokens[index];
|
|
137
|
-
|
|
135
|
+
const tokenBalance = formatBalance(getBalanceFor(token));
|
|
138
136
|
const address = token.address || '';
|
|
139
137
|
const blockchain = blockchains.find(
|
|
140
138
|
(blockchain) => blockchain.name === token.blockchain
|
|
@@ -229,18 +227,18 @@ export function TokenList(props: PropTypes) {
|
|
|
229
227
|
<Skeleton variant="text" size="medium" width={50} />
|
|
230
228
|
</End>
|
|
231
229
|
) : (
|
|
232
|
-
|
|
230
|
+
tokenBalance && (
|
|
233
231
|
<BalanceContainer>
|
|
234
232
|
<Typography variant="title" size="small">
|
|
235
|
-
{
|
|
233
|
+
{tokenBalance.amount}
|
|
236
234
|
</Typography>
|
|
237
235
|
<div />
|
|
238
|
-
{
|
|
236
|
+
{tokenBalance.usdValue && (
|
|
239
237
|
<Typography
|
|
240
238
|
variant="body"
|
|
241
239
|
className="usd-value"
|
|
242
240
|
size="xsmall">
|
|
243
|
-
{`$${
|
|
241
|
+
{`$${tokenBalance.usdValue}`}
|
|
244
242
|
</Typography>
|
|
245
243
|
)}
|
|
246
244
|
</BalanceContainer>
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import type { Token } from 'rango-sdk';
|
|
2
2
|
|
|
3
|
-
export interface TokenWithBalance extends Token {
|
|
4
|
-
balance?: {
|
|
5
|
-
amount: string;
|
|
6
|
-
usdValue: string;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
3
|
export interface PropTypes {
|
|
11
|
-
list:
|
|
4
|
+
list: Token[];
|
|
12
5
|
searchedFor?: string;
|
|
13
|
-
onChange: (token:
|
|
6
|
+
onChange: (token: Token) => void;
|
|
14
7
|
selectedBlockchain?: string;
|
|
15
8
|
}
|
|
16
9
|
|
|
@@ -22,7 +15,7 @@ export interface RenderDescProps {
|
|
|
22
15
|
name?: string | null;
|
|
23
16
|
address: string;
|
|
24
17
|
url: string;
|
|
25
|
-
token:
|
|
18
|
+
token: Token;
|
|
26
19
|
customCssForTag: TagCSS;
|
|
27
20
|
customCssForTagTitle: TitleCSS;
|
|
28
21
|
}
|
|
@@ -11,7 +11,6 @@ import { useLanguage } from '../../hooks/useLanguage';
|
|
|
11
11
|
import { useTheme } from '../../hooks/useTheme';
|
|
12
12
|
import { useAppStore } from '../../store/AppStore';
|
|
13
13
|
import { useNotificationStore } from '../../store/notification';
|
|
14
|
-
import { useSettingsStore } from '../../store/settings';
|
|
15
14
|
import { WidgetContext } from '../Wallets';
|
|
16
15
|
|
|
17
16
|
import { MainContainer } from './App.styles';
|
|
@@ -29,7 +28,6 @@ export function Main() {
|
|
|
29
28
|
|
|
30
29
|
useEffect(() => {
|
|
31
30
|
void fetchMeta().catch();
|
|
32
|
-
void useSettingsStore.persist.rehydrate();
|
|
33
31
|
void useNotificationStore.persist.rehydrate();
|
|
34
32
|
widgetContext.onConnectWallet(setLastConnectedWalletWithNetwork);
|
|
35
33
|
}, []);
|
|
@@ -28,21 +28,21 @@ export const WidgetContext = createContext<WidgetContextInterface>({
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
function Main(props: PropsWithChildren<PropTypes>) {
|
|
31
|
-
const updateConfig = useAppStore()
|
|
31
|
+
const { updateConfig, updateSettings } = useAppStore();
|
|
32
32
|
const blockchains = useAppStore().blockchains();
|
|
33
33
|
const tokens = useAppStore().tokens();
|
|
34
34
|
const walletOptions: ProvidersOptions = {
|
|
35
35
|
walletConnectProjectId: props.config?.walletConnectProjectId,
|
|
36
36
|
};
|
|
37
37
|
const { providers } = useWalletProviders(props.config.wallets, walletOptions);
|
|
38
|
-
const disconnectWallet = useWalletsStore
|
|
39
|
-
const connectWallet = useWalletsStore.use.connectWallet();
|
|
38
|
+
const { connectWallet, disconnectWallet } = useWalletsStore();
|
|
40
39
|
const onConnectWalletHandler = useRef<OnConnectHandler>();
|
|
41
40
|
useSyncStoresWithConfig();
|
|
42
41
|
|
|
43
42
|
useEffect(() => {
|
|
44
43
|
if (props.config) {
|
|
45
44
|
updateConfig(props.config);
|
|
45
|
+
updateSettings(props.config);
|
|
46
46
|
}
|
|
47
47
|
}, [props.config]);
|
|
48
48
|
|
|
@@ -7,8 +7,8 @@ import { useEffect } from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { useAppStore } from '../../store/AppStore';
|
|
9
9
|
import { useQuoteStore } from '../../store/quote';
|
|
10
|
-
import { useSettingsStore } from '../../store/settings';
|
|
11
10
|
import { useWalletsStore } from '../../store/wallets';
|
|
11
|
+
import { isFeatureEnabled } from '../../utils/settings';
|
|
12
12
|
import { createQuoteRequestBody, getWalletsForNewSwap } from '../../utils/swap';
|
|
13
13
|
import { useFetchQuote } from '../useFetchQuote';
|
|
14
14
|
|
|
@@ -36,11 +36,11 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
36
36
|
affiliateRef,
|
|
37
37
|
affiliateWallets,
|
|
38
38
|
disabledLiquiditySources,
|
|
39
|
-
} =
|
|
39
|
+
} = useAppStore();
|
|
40
40
|
const { connectedWallets } = useWalletsStore();
|
|
41
41
|
const blockchains = useAppStore().blockchains();
|
|
42
42
|
const tokens = useAppStore().tokens();
|
|
43
|
-
const {
|
|
43
|
+
const { features } = useAppStore().config;
|
|
44
44
|
const { enableNewLiquiditySources } = useAppStore().config;
|
|
45
45
|
|
|
46
46
|
const userSlippage = customSlippage || slippage;
|
|
@@ -78,7 +78,7 @@ export function useConfirmSwap(): ConfirmSwap {
|
|
|
78
78
|
initialQuote: initialQuote ?? undefined,
|
|
79
79
|
destination: customDestination,
|
|
80
80
|
});
|
|
81
|
-
if (
|
|
81
|
+
if (isFeatureEnabled('experimentalRoute', features)) {
|
|
82
82
|
requestBody.experimental = true;
|
|
83
83
|
}
|
|
84
84
|
let currentQuote: BestRouteResponse;
|
package/src/hooks/useLanguage.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { LanguageItem } from '../constants/languages';
|
|
|
3
3
|
import { type Language } from '@rango-dev/ui';
|
|
4
4
|
|
|
5
5
|
import { DEFAULT_LANGUAGE, LANGUAGES } from '../constants/languages';
|
|
6
|
-
import {
|
|
6
|
+
import { useAppStore } from '../store/AppStore';
|
|
7
7
|
|
|
8
8
|
interface UseLanguage {
|
|
9
9
|
languages: LanguageItem[];
|
|
@@ -13,8 +13,7 @@ interface UseLanguage {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function useLanguage(): UseLanguage {
|
|
16
|
-
const language =
|
|
17
|
-
const setLanguage = useSettingsStore.use.setLanguage();
|
|
16
|
+
const { setLanguage, language } = useAppStore();
|
|
18
17
|
const languages = LANGUAGES;
|
|
19
18
|
const defaultLanguage = DEFAULT_LANGUAGE;
|
|
20
19
|
|
|
@@ -6,7 +6,7 @@ import type { BlockchainMeta } from 'rango-sdk';
|
|
|
6
6
|
|
|
7
7
|
import { useEffect } from 'react';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { useAppStore } from '../../store/AppStore';
|
|
10
10
|
|
|
11
11
|
import { isInVisibleList, prepare } from './usePrepareBlockchainList.helpers';
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ export function usePrepareBlockchainList(
|
|
|
20
20
|
blockchains: BlockchainMeta[],
|
|
21
21
|
options?: PrepareListOptions
|
|
22
22
|
): UsePrepareList {
|
|
23
|
-
const { preferredBlockchains, addPreferredBlockchain } =
|
|
23
|
+
const { preferredBlockchains, addPreferredBlockchain } = useAppStore();
|
|
24
24
|
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
if (options?.selected) {
|
|
@@ -5,11 +5,11 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
5
5
|
|
|
6
6
|
import { useAppStore } from '../store/AppStore';
|
|
7
7
|
import { useQuoteStore } from '../store/quote';
|
|
8
|
-
import { useSettingsStore } from '../store/settings';
|
|
9
8
|
import { QuoteErrorType } from '../types';
|
|
10
9
|
import { debounce } from '../utils/common';
|
|
11
10
|
import { isPositiveNumber } from '../utils/numbers';
|
|
12
11
|
import { generateQuoteWarnings } from '../utils/quote';
|
|
12
|
+
import { isFeatureEnabled } from '../utils/settings';
|
|
13
13
|
import { createQuoteRequestBody } from '../utils/swap';
|
|
14
14
|
import { tokensAreEqual } from '../utils/wallets';
|
|
15
15
|
|
|
@@ -40,7 +40,7 @@ type UseSwapInput = {
|
|
|
40
40
|
*/
|
|
41
41
|
export function useSwapInput(): UseSwapInput {
|
|
42
42
|
const { fetch: fetchQuote, cancelFetch } = useFetchQuote();
|
|
43
|
-
const { liquiditySources, enableNewLiquiditySources,
|
|
43
|
+
const { liquiditySources, enableNewLiquiditySources, features } =
|
|
44
44
|
useAppStore().config;
|
|
45
45
|
const tokens = useAppStore().tokens();
|
|
46
46
|
const {
|
|
@@ -58,7 +58,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
58
58
|
affiliateRef,
|
|
59
59
|
affiliateWallets,
|
|
60
60
|
disabledLiquiditySources,
|
|
61
|
-
} =
|
|
61
|
+
} = useAppStore();
|
|
62
62
|
const [loading, setLoading] = useState(false);
|
|
63
63
|
const [error, setError] = useState<QuoteError | null>(null);
|
|
64
64
|
const [warning, setWarning] = useState<QuoteWarning | null>(null);
|
|
@@ -105,7 +105,7 @@ export function useSwapInput(): UseSwapInput {
|
|
|
105
105
|
affiliatePercent,
|
|
106
106
|
affiliateWallets,
|
|
107
107
|
});
|
|
108
|
-
if (
|
|
108
|
+
if (isFeatureEnabled('experimentalRoute', features)) {
|
|
109
109
|
requestBody.experimental = true;
|
|
110
110
|
}
|
|
111
111
|
fetchQuote(requestBody)
|
|
@@ -4,7 +4,6 @@ import { useEffect, useLayoutEffect, useMemo, useRef } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { useAppStore } from '../store/AppStore';
|
|
6
6
|
import { useQuoteStore } from '../store/quote';
|
|
7
|
-
import { useSettingsStore } from '../store/settings';
|
|
8
7
|
import { tokensAreEqual } from '../utils/wallets';
|
|
9
8
|
|
|
10
9
|
export function useSyncStoresWithConfig() {
|
|
@@ -26,7 +25,7 @@ export function useSyncStoresWithConfig() {
|
|
|
26
25
|
const tokens = useAppStore().tokens();
|
|
27
26
|
|
|
28
27
|
const { setAffiliateRef, setAffiliatePercent, setAffiliateWallets } =
|
|
29
|
-
|
|
28
|
+
useAppStore();
|
|
30
29
|
|
|
31
30
|
const fromTokensConfig = useMemo(
|
|
32
31
|
() => config?.from?.tokens,
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-magic-numbers */
|
|
2
|
-
import type { WidgetTheme } from '../types';
|
|
3
|
-
|
|
4
2
|
import {
|
|
5
3
|
createTheme,
|
|
6
4
|
darkTheme as defaultDarkTheme,
|
|
@@ -8,7 +6,8 @@ import {
|
|
|
8
6
|
} from '@rango-dev/ui';
|
|
9
7
|
import { useEffect, useState } from 'react';
|
|
10
8
|
|
|
11
|
-
import {
|
|
9
|
+
import { useAppStore } from '../store/AppStore';
|
|
10
|
+
import { type WidgetTheme } from '../types';
|
|
12
11
|
import {
|
|
13
12
|
DEFAULT_FONT_FAMILY,
|
|
14
13
|
DEFAULT_PRIMARY_RADIUS,
|
|
@@ -26,8 +25,8 @@ export function useTheme(props: WidgetTheme) {
|
|
|
26
25
|
} = props;
|
|
27
26
|
|
|
28
27
|
const [OSTheme, setOSTheme] = useState('light');
|
|
29
|
-
|
|
30
|
-
const setTheme =
|
|
28
|
+
|
|
29
|
+
const { setTheme, theme } = useAppStore();
|
|
31
30
|
|
|
32
31
|
const { dark, light } = customizedThemeTokens(colors);
|
|
33
32
|
|
|
@@ -30,8 +30,8 @@ import { navigationRoutes } from '../constants/navigationRoutes';
|
|
|
30
30
|
import { getQuoteUpdateWarningMessage } from '../constants/warnings';
|
|
31
31
|
import { QuoteInfo } from '../containers/QuoteInfo';
|
|
32
32
|
import { useConfirmSwap } from '../hooks/useConfirmSwap';
|
|
33
|
+
import { useAppStore } from '../store/AppStore';
|
|
33
34
|
import { useQuoteStore } from '../store/quote';
|
|
34
|
-
import { useSettingsStore } from '../store/settings';
|
|
35
35
|
import { useUiStore } from '../store/ui';
|
|
36
36
|
import { useWalletsStore } from '../store/wallets';
|
|
37
37
|
import { QuoteWarningType } from '../types';
|
|
@@ -89,8 +89,7 @@ export function ConfirmSwapPage() {
|
|
|
89
89
|
const showWalletsOnInit = !quoteWalletsConfirmed;
|
|
90
90
|
const [showWallets, setShowWallets] = useState(false);
|
|
91
91
|
const setSelectedSwap = useUiStore.use.setSelectedSwap();
|
|
92
|
-
const disabledLiquiditySources =
|
|
93
|
-
useSettingsStore.use.disabledLiquiditySources();
|
|
92
|
+
const disabledLiquiditySources = useAppStore().disabledLiquiditySources;
|
|
94
93
|
const prevDisabledLiquiditySources = useRef(disabledLiquiditySources);
|
|
95
94
|
const { manager } = useManager();
|
|
96
95
|
const {
|
package/src/pages/Home.tsx
CHANGED
|
@@ -9,8 +9,6 @@ import { SwitchFromAndToButton } from '../components/SwitchFromAndTo';
|
|
|
9
9
|
import { errorMessages } from '../constants/errors';
|
|
10
10
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
11
11
|
import {
|
|
12
|
-
BALANCE_MAX_DECIMALS,
|
|
13
|
-
BALANCE_MIN_DECIMALS,
|
|
14
12
|
PERCENTAGE_CHANGE_MAX_DECIMALS,
|
|
15
13
|
PERCENTAGE_CHANGE_MIN_DECIMALS,
|
|
16
14
|
TOKEN_AMOUNT_MAX_DECIMALS,
|
|
@@ -27,7 +25,7 @@ import { useWalletsStore } from '../store/wallets';
|
|
|
27
25
|
import { numberToString } from '../utils/numbers';
|
|
28
26
|
import { getPriceImpact, getPriceImpactLevel } from '../utils/quote';
|
|
29
27
|
import { canComputePriceImpact, getSwapButtonState } from '../utils/swap';
|
|
30
|
-
import {
|
|
28
|
+
import { formatBalance } from '../utils/wallets';
|
|
31
29
|
|
|
32
30
|
const Container = styled('div', {
|
|
33
31
|
display: 'flex',
|
|
@@ -73,7 +71,7 @@ export function Home() {
|
|
|
73
71
|
|
|
74
72
|
const fetchMetaStatus = useAppStore().fetchStatus;
|
|
75
73
|
|
|
76
|
-
const connectedWallets = useWalletsStore
|
|
74
|
+
const { connectedWallets, getBalanceFor } = useWalletsStore();
|
|
77
75
|
const setCurrentPage = useUiStore.use.setCurrentPage();
|
|
78
76
|
const [showQuoteWarningModal, setShowQuoteWarningModal] = useState(false);
|
|
79
77
|
const layoutRef = useRef<HTMLDivElement>(null);
|
|
@@ -103,36 +101,14 @@ export function Home() {
|
|
|
103
101
|
needsToWarnEthOnPath,
|
|
104
102
|
});
|
|
105
103
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
connectedWallets,
|
|
111
|
-
fromBlockchain?.name,
|
|
112
|
-
fromToken?.symbol,
|
|
113
|
-
fromToken?.address
|
|
114
|
-
)?.amount || '0',
|
|
115
|
-
BALANCE_MIN_DECIMALS,
|
|
116
|
-
BALANCE_MAX_DECIMALS
|
|
117
|
-
)
|
|
118
|
-
: '0';
|
|
104
|
+
const fromTokenBalance = fromToken ? getBalanceFor(fromToken) : null;
|
|
105
|
+
|
|
106
|
+
const fromTokenFormattedBalance =
|
|
107
|
+
formatBalance(fromTokenBalance)?.amount ?? '0';
|
|
119
108
|
|
|
120
109
|
const tokenBalanceReal =
|
|
121
110
|
!!fromBlockchain && !!fromToken
|
|
122
|
-
? numberToString(
|
|
123
|
-
getBalanceFromWallet(
|
|
124
|
-
connectedWallets,
|
|
125
|
-
fromBlockchain?.name,
|
|
126
|
-
fromToken?.symbol,
|
|
127
|
-
fromToken?.address
|
|
128
|
-
)?.amount || '0',
|
|
129
|
-
getBalanceFromWallet(
|
|
130
|
-
connectedWallets,
|
|
131
|
-
fromBlockchain?.name,
|
|
132
|
-
fromToken?.symbol,
|
|
133
|
-
fromToken?.address
|
|
134
|
-
)?.decimal
|
|
135
|
-
)
|
|
111
|
+
? numberToString(fromTokenBalance?.amount, fromTokenBalance?.decimals)
|
|
136
112
|
: '0';
|
|
137
113
|
|
|
138
114
|
useEffect(() => {
|
|
@@ -194,7 +170,7 @@ export function Home() {
|
|
|
194
170
|
label={i18n.t('From')}
|
|
195
171
|
mode="From"
|
|
196
172
|
onInputChange={setInputAmount}
|
|
197
|
-
balance={
|
|
173
|
+
balance={fromTokenFormattedBalance}
|
|
198
174
|
chain={{
|
|
199
175
|
displayName: fromBlockchain?.displayName || '',
|
|
200
176
|
image: fromBlockchain?.logo || '',
|
|
@@ -220,7 +196,7 @@ export function Home() {
|
|
|
220
196
|
disabled={fetchMetaStatus === 'failed'}
|
|
221
197
|
loading={fetchMetaStatus === 'loading'}
|
|
222
198
|
onSelectMaxBalance={() => {
|
|
223
|
-
if (
|
|
199
|
+
if (fromTokenFormattedBalance !== '0') {
|
|
224
200
|
setInputAmount(tokenBalanceReal.split(',').join(''));
|
|
225
201
|
}
|
|
226
202
|
}}
|
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
SettingsContainer,
|
|
25
25
|
} from '../components/SettingsContainer';
|
|
26
26
|
import { useAppStore } from '../store/AppStore';
|
|
27
|
-
import { useSettingsStore } from '../store/settings';
|
|
28
27
|
import { containsText } from '../utils/numbers';
|
|
29
28
|
import { getUniqueSwappersGroups } from '../utils/settings';
|
|
30
29
|
|
|
@@ -35,10 +34,11 @@ interface PropTypes {
|
|
|
35
34
|
export function LiquiditySourcePage({ sourceType }: PropTypes) {
|
|
36
35
|
const fetchStatus = useAppStore().fetchStatus;
|
|
37
36
|
const swappers = useAppStore().swappers();
|
|
37
|
+
const disabledLiquiditySources = useAppStore().disabledLiquiditySources;
|
|
38
38
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
39
|
-
const toggleLiquiditySource =
|
|
39
|
+
const toggleLiquiditySource = useAppStore().toggleLiquiditySource;
|
|
40
40
|
const supportedUniqueSwappersGroups: Array<UniqueSwappersGroupType> =
|
|
41
|
-
getUniqueSwappersGroups(swappers);
|
|
41
|
+
getUniqueSwappersGroups(swappers, disabledLiquiditySources);
|
|
42
42
|
|
|
43
43
|
const validTypes: Array<LiquiditySourceType> = [];
|
|
44
44
|
if (sourceType === 'Exchanges') {
|
|
@@ -14,7 +14,7 @@ import { useNavigateBack } from '../hooks/useNavigateBack';
|
|
|
14
14
|
import { useAppStore } from '../store/AppStore';
|
|
15
15
|
import { useQuoteStore } from '../store/quote';
|
|
16
16
|
import { useWalletsStore } from '../store/wallets';
|
|
17
|
-
import {
|
|
17
|
+
import { sortTokensByBalance } from '../utils/wallets';
|
|
18
18
|
|
|
19
19
|
interface PropTypes {
|
|
20
20
|
type: 'source' | 'destination';
|
|
@@ -32,7 +32,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
32
32
|
setFromBlockchain,
|
|
33
33
|
setToBlockchain,
|
|
34
34
|
} = useQuoteStore();
|
|
35
|
-
const
|
|
35
|
+
const getBalanceFor = useWalletsStore.use.getBalanceFor();
|
|
36
36
|
const [searchedFor, setSearchedFor] = useState<string>('');
|
|
37
37
|
|
|
38
38
|
const selectedBlockchain = type === 'source' ? fromBlockchain : toBlockchain;
|
|
@@ -47,10 +47,7 @@ export function SelectSwapItemsPage(props: PropTypes) {
|
|
|
47
47
|
blockchain: selectedBlockchainName,
|
|
48
48
|
searchFor: searchedFor,
|
|
49
49
|
});
|
|
50
|
-
const tokensList =
|
|
51
|
-
tokens,
|
|
52
|
-
connectedWallets
|
|
53
|
-
);
|
|
50
|
+
const tokensList = sortTokensByBalance(tokens, getBalanceFor);
|
|
54
51
|
|
|
55
52
|
// Actions
|
|
56
53
|
const updateBlockchain = (blockchain: BlockchainMeta) => {
|
|
@@ -19,20 +19,31 @@ import { Slippage } from '../components/Slippage';
|
|
|
19
19
|
import { SlippageTooltipContainer as TooltipContainer } from '../components/Slippage/Slippage.styles';
|
|
20
20
|
import { navigationRoutes } from '../constants/navigationRoutes';
|
|
21
21
|
import { useAppStore } from '../store/AppStore';
|
|
22
|
-
import { useSettingsStore } from '../store/settings';
|
|
23
22
|
import { getContainer } from '../utils/common';
|
|
24
|
-
import { getUniqueSwappersGroups } from '../utils/settings';
|
|
23
|
+
import { getUniqueSwappersGroups, isFeatureHidden } from '../utils/settings';
|
|
25
24
|
|
|
26
25
|
export function SettingsPage() {
|
|
27
26
|
const navigate = useNavigate();
|
|
28
27
|
const { theme } = useAppStore().config;
|
|
29
28
|
const fetchStatus = useAppStore().fetchStatus;
|
|
30
29
|
const swappers = useAppStore().swappers();
|
|
30
|
+
const disabledLiquiditySources = useAppStore().disabledLiquiditySources;
|
|
31
|
+
const {
|
|
32
|
+
config: { features },
|
|
33
|
+
} = useAppStore();
|
|
34
|
+
const isThemeHidden = isFeatureHidden('theme', features);
|
|
31
35
|
|
|
32
|
-
const
|
|
33
|
-
const toggleInfiniteApprove = useSettingsStore.use.toggleInfiniteApprove();
|
|
36
|
+
const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
|
|
34
37
|
|
|
35
|
-
const
|
|
38
|
+
const isLanguageHidden = isFeatureHidden('language', features);
|
|
39
|
+
|
|
40
|
+
const infiniteApprove = useAppStore().infiniteApprove;
|
|
41
|
+
const toggleInfiniteApprove = useAppStore().toggleInfiniteApprove;
|
|
42
|
+
|
|
43
|
+
const supportedUniqueSwappersGroups = getUniqueSwappersGroups(
|
|
44
|
+
swappers,
|
|
45
|
+
disabledLiquiditySources
|
|
46
|
+
);
|
|
36
47
|
|
|
37
48
|
const bridgeSources = supportedUniqueSwappersGroups.filter(
|
|
38
49
|
(uniqueItem) =>
|
|
@@ -156,12 +167,12 @@ export function SettingsPage() {
|
|
|
156
167
|
onClick: toggleInfiniteApprove,
|
|
157
168
|
};
|
|
158
169
|
|
|
159
|
-
const settingItems = [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// languageItem
|
|
163
|
-
|
|
164
|
-
if (!theme?.singleTheme) {
|
|
170
|
+
const settingItems = isLiquidityHidden ? [] : [bridgeItem, exchangeItem];
|
|
171
|
+
|
|
172
|
+
if (!isLanguageHidden) {
|
|
173
|
+
// settingItems.push(languageItem);
|
|
174
|
+
}
|
|
175
|
+
if (!theme?.singleTheme && !isThemeHidden) {
|
|
165
176
|
settingItems.push(themeItem);
|
|
166
177
|
}
|
|
167
178
|
settingItems.push(infiniteApprovalItem);
|
package/src/pages/ThemePage.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import React from 'react';
|
|
|
13
13
|
|
|
14
14
|
import { Layout } from '../components/Layout';
|
|
15
15
|
import { SettingsContainer } from '../components/SettingsContainer';
|
|
16
|
-
import {
|
|
16
|
+
import { useAppStore } from '../store/AppStore';
|
|
17
17
|
|
|
18
18
|
type Theme = 'dark' | 'light' | 'auto';
|
|
19
19
|
|
|
@@ -24,8 +24,7 @@ enum Mode {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function ThemePage() {
|
|
27
|
-
const theme =
|
|
28
|
-
const setTheme = useSettingsStore.use.setTheme();
|
|
27
|
+
const { setTheme, theme } = useAppStore();
|
|
29
28
|
|
|
30
29
|
const themesList = [
|
|
31
30
|
{
|
package/src/store/AppStore.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WidgetConfig } from '../types';
|
|
2
2
|
import type { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
-
import React, { createContext, useContext, useRef } from 'react';
|
|
4
|
+
import React, { createContext, useContext, useEffect, useRef } from 'react';
|
|
5
5
|
|
|
6
6
|
import { createAppStore } from './app';
|
|
7
7
|
|
|
@@ -13,6 +13,12 @@ export const AppStoreContext = createContext<AppStore | null>(null);
|
|
|
13
13
|
export function useAppStore() {
|
|
14
14
|
const store = useContext(AppStoreContext);
|
|
15
15
|
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (store && !store.persist.hasHydrated()) {
|
|
18
|
+
void store.persist.rehydrate();
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
16
22
|
if (!store) {
|
|
17
23
|
throw new Error('Missing AppStoreContext.Provider in the tree');
|
|
18
24
|
}
|
package/src/store/app.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { ConfigSlice } from './slices/config';
|
|
2
2
|
import type { DataSlice } from './slices/data';
|
|
3
|
+
import type { SettingsSlice } from './slices/settings';
|
|
3
4
|
import type { WidgetConfig } from '../types';
|
|
4
5
|
import type { StateCreator } from 'zustand';
|
|
5
6
|
|
|
6
7
|
import { create } from 'zustand';
|
|
8
|
+
import { persist } from 'zustand/middleware';
|
|
7
9
|
|
|
8
10
|
import { createConfigSlice } from './slices/config';
|
|
9
11
|
import { createDataSlice } from './slices/data';
|
|
12
|
+
import { createSettingsSlice } from './slices/settings';
|
|
10
13
|
|
|
11
14
|
export type StateCreatorWithInitialData<
|
|
12
15
|
T extends Partial<WidgetConfig>,
|
|
@@ -17,11 +20,34 @@ export type StateCreatorWithInitialData<
|
|
|
17
20
|
...rest: Parameters<StateCreator<R, [], [], V>>
|
|
18
21
|
) => ReturnType<StateCreator<R, [], [], V>>;
|
|
19
22
|
|
|
20
|
-
export type AppStoreState = DataSlice & ConfigSlice;
|
|
23
|
+
export type AppStoreState = DataSlice & ConfigSlice & SettingsSlice;
|
|
21
24
|
|
|
22
25
|
export function createAppStore(initialData?: WidgetConfig) {
|
|
23
|
-
return create<AppStoreState>()(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
return create<AppStoreState>()(
|
|
27
|
+
persist(
|
|
28
|
+
(...a) => ({
|
|
29
|
+
...createDataSlice(...a),
|
|
30
|
+
...createSettingsSlice(...a),
|
|
31
|
+
...createConfigSlice(initialData, ...a),
|
|
32
|
+
}),
|
|
33
|
+
{
|
|
34
|
+
name: 'user-settings',
|
|
35
|
+
skipHydration: true,
|
|
36
|
+
partialize: (state) => {
|
|
37
|
+
return {
|
|
38
|
+
theme: state.theme,
|
|
39
|
+
language: state.language,
|
|
40
|
+
affiliatePercent: state.affiliatePercent,
|
|
41
|
+
affiliateRef: state.affiliateRef,
|
|
42
|
+
affiliateWallets: state.affiliateWallets,
|
|
43
|
+
slippage: state.slippage,
|
|
44
|
+
customSlippage: state.customSlippage,
|
|
45
|
+
infiniteApprove: state.infiniteApprove,
|
|
46
|
+
preferredBlockchains: state.preferredBlockchains,
|
|
47
|
+
disabledLiquiditySources: state.disabledLiquiditySources,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
);
|
|
27
53
|
}
|
package/src/store/quote.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { TokenWithBalance } from '../components/TokenList';
|
|
2
1
|
import type { Wallet } from '../types';
|
|
3
2
|
import type { PendingSwap } from '@rango-dev/queue-manager-rango-preset/dist/shared';
|
|
4
3
|
import type {
|
|
@@ -38,8 +37,8 @@ export interface QuoteState {
|
|
|
38
37
|
inputUsdValue: BigNumber | null;
|
|
39
38
|
outputAmount: BigNumber | null;
|
|
40
39
|
outputUsdValue: BigNumber | null;
|
|
41
|
-
fromToken:
|
|
42
|
-
toToken:
|
|
40
|
+
fromToken: Token | null;
|
|
41
|
+
toToken: Token | null;
|
|
43
42
|
quoteWalletsConfirmed: boolean;
|
|
44
43
|
selectedWallets: Wallet[];
|
|
45
44
|
quoteWarningsConfirmed: boolean;
|