@rango-dev/widget-embedded 0.17.1-next.26 → 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/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/Slippage/Slippage.d.ts.map +1 -1
- package/dist/containers/App/App.d.ts.map +1 -1
- package/dist/containers/Wallets/Wallets.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/LiquiditySourcePage.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/slices/settings.d.ts +39 -0
- package/dist/store/slices/settings.d.ts.map +1 -0
- package/dist/types/config.d.ts +28 -9
- package/dist/types/config.d.ts.map +1 -1
- package/dist/utils/settings.d.ts +4 -1
- package/dist/utils/settings.d.ts.map +1 -1
- package/package.json +1 -1
- 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/containers/App/App.tsx +0 -2
- package/src/containers/Wallets/Wallets.tsx +2 -1
- 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/LiquiditySourcePage.tsx +3 -3
- 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/slices/settings.ts +168 -0
- package/src/types/config.ts +38 -8
- package/src/utils/settings.ts +11 -5
- package/dist/store/settings.d.ts +0 -83
- package/dist/store/settings.d.ts.map +0 -1
- package/src/store/settings.ts +0 -161
|
@@ -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 {
|
|
@@ -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') {
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { ConfigSlice } from './config';
|
|
2
|
+
import type { WidgetConfig } from '../../types';
|
|
3
|
+
import type { SwapperMeta } from 'rango-sdk';
|
|
4
|
+
import type { StateCreator } from 'zustand';
|
|
5
|
+
|
|
6
|
+
import { type Language } from '@rango-dev/ui';
|
|
7
|
+
|
|
8
|
+
import { BLOCKCHAIN_LIST_SIZE } from '../../constants/configs';
|
|
9
|
+
import { DEFAULT_LANGUAGE } from '../../constants/languages';
|
|
10
|
+
import { DEFAULT_SLIPPAGE } from '../../constants/swapSettings';
|
|
11
|
+
import { removeDuplicateFrom } from '../../utils/common';
|
|
12
|
+
import { isFeatureHidden } from '../../utils/settings';
|
|
13
|
+
|
|
14
|
+
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
15
|
+
|
|
16
|
+
export interface SettingsSlice {
|
|
17
|
+
theme: ThemeMode;
|
|
18
|
+
language: Language;
|
|
19
|
+
disabledLiquiditySources: string[];
|
|
20
|
+
/** Keeping a history of blockchains that user has selected (in Swap process) */
|
|
21
|
+
preferredBlockchains: string[];
|
|
22
|
+
slippage: number;
|
|
23
|
+
customSlippage: number | null;
|
|
24
|
+
infiniteApprove: boolean;
|
|
25
|
+
affiliateRef: string | null;
|
|
26
|
+
affiliatePercent: number | null;
|
|
27
|
+
affiliateWallets: { [key: string]: string } | null;
|
|
28
|
+
|
|
29
|
+
setSlippage: (slippage: number) => void;
|
|
30
|
+
setCustomSlippage: (customSlippage: number | null) => void;
|
|
31
|
+
toggleInfiniteApprove: () => void;
|
|
32
|
+
toggleLiquiditySource: (name: string) => void;
|
|
33
|
+
setTheme: (theme: ThemeMode) => void;
|
|
34
|
+
setLanguage: (language: Language) => void;
|
|
35
|
+
toggleAllLiquiditySources: (
|
|
36
|
+
swappers: SwapperMeta[],
|
|
37
|
+
shouldReset?: boolean
|
|
38
|
+
) => void;
|
|
39
|
+
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
40
|
+
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
41
|
+
setAffiliateWallets: (
|
|
42
|
+
affiliateWallets: { [key: string]: string } | null
|
|
43
|
+
) => void;
|
|
44
|
+
addPreferredBlockchain: (blockchain: string) => void;
|
|
45
|
+
updateSettings: (config: WidgetConfig) => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const createSettingsSlice: StateCreator<
|
|
49
|
+
SettingsSlice & ConfigSlice,
|
|
50
|
+
[],
|
|
51
|
+
[],
|
|
52
|
+
SettingsSlice
|
|
53
|
+
> = (set, get) => ({
|
|
54
|
+
disabledLiquiditySources: [],
|
|
55
|
+
theme: 'auto',
|
|
56
|
+
language: DEFAULT_LANGUAGE,
|
|
57
|
+
preferredBlockchains: [],
|
|
58
|
+
slippage: DEFAULT_SLIPPAGE,
|
|
59
|
+
customSlippage: null,
|
|
60
|
+
infiniteApprove: false,
|
|
61
|
+
affiliateRef: null,
|
|
62
|
+
affiliatePercent: null,
|
|
63
|
+
affiliateWallets: null,
|
|
64
|
+
|
|
65
|
+
addPreferredBlockchain: (blockchain) => {
|
|
66
|
+
const currentPreferredBlockchains = get().preferredBlockchains;
|
|
67
|
+
|
|
68
|
+
const noNeedToDoAnything = currentPreferredBlockchains.find(
|
|
69
|
+
(preferredBlockchain, index) => {
|
|
70
|
+
const isSameBlockchain = preferredBlockchain === blockchain;
|
|
71
|
+
const isInVisibleList = index <= BLOCKCHAIN_LIST_SIZE - 1;
|
|
72
|
+
|
|
73
|
+
return isSameBlockchain && isInVisibleList;
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (noNeedToDoAnything) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const nextPreferredBlockchains: string[] =
|
|
82
|
+
currentPreferredBlockchains.filter((preferredBlockchain) => {
|
|
83
|
+
const isSameBlockchain = preferredBlockchain === blockchain;
|
|
84
|
+
|
|
85
|
+
return !isSameBlockchain;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
set(() => ({
|
|
89
|
+
preferredBlockchains: [blockchain, ...nextPreferredBlockchains],
|
|
90
|
+
}));
|
|
91
|
+
},
|
|
92
|
+
setSlippage: (slippage) =>
|
|
93
|
+
set(() => ({
|
|
94
|
+
slippage: slippage,
|
|
95
|
+
})),
|
|
96
|
+
setCustomSlippage: (customSlippage) =>
|
|
97
|
+
set(() => ({
|
|
98
|
+
customSlippage: customSlippage,
|
|
99
|
+
})),
|
|
100
|
+
setAffiliateRef: (affiliateRef) =>
|
|
101
|
+
set(() => ({
|
|
102
|
+
affiliateRef,
|
|
103
|
+
})),
|
|
104
|
+
setAffiliatePercent: (affiliatePercent) =>
|
|
105
|
+
set(() => ({
|
|
106
|
+
affiliatePercent,
|
|
107
|
+
})),
|
|
108
|
+
|
|
109
|
+
setAffiliateWallets: (affiliateWallets) =>
|
|
110
|
+
set(() => ({
|
|
111
|
+
affiliateWallets,
|
|
112
|
+
})),
|
|
113
|
+
toggleAllLiquiditySources: (swappers, shouldReset) =>
|
|
114
|
+
set((state) => {
|
|
115
|
+
if (shouldReset) {
|
|
116
|
+
return { disabledLiquiditySources: [] };
|
|
117
|
+
}
|
|
118
|
+
const swappersGroup = removeDuplicateFrom(
|
|
119
|
+
swappers.map((swapper) => swapper.swapperGroup)
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if (swappersGroup.length === state.disabledLiquiditySources.length) {
|
|
123
|
+
return { disabledLiquiditySources: [] };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
disabledLiquiditySources: swappersGroup,
|
|
128
|
+
};
|
|
129
|
+
}),
|
|
130
|
+
toggleInfiniteApprove: () =>
|
|
131
|
+
set((state) => ({
|
|
132
|
+
infiniteApprove: !state.infiniteApprove,
|
|
133
|
+
})),
|
|
134
|
+
toggleLiquiditySource: (name) =>
|
|
135
|
+
set((state) => {
|
|
136
|
+
if (state.disabledLiquiditySources.includes(name)) {
|
|
137
|
+
return {
|
|
138
|
+
disabledLiquiditySources: state.disabledLiquiditySources.filter(
|
|
139
|
+
(liquiditySource) => liquiditySource != name
|
|
140
|
+
),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
disabledLiquiditySources: state.disabledLiquiditySources.concat(name),
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
147
|
+
setTheme: (theme) =>
|
|
148
|
+
set(() => ({
|
|
149
|
+
theme,
|
|
150
|
+
})),
|
|
151
|
+
setLanguage: (language) =>
|
|
152
|
+
set(() => ({
|
|
153
|
+
language,
|
|
154
|
+
})),
|
|
155
|
+
updateSettings: (nextConfig: WidgetConfig) => {
|
|
156
|
+
const { features } = nextConfig;
|
|
157
|
+
|
|
158
|
+
const isThemeHidden = isFeatureHidden('theme', features);
|
|
159
|
+
const isLanguageHidden = isFeatureHidden('language', features);
|
|
160
|
+
const isLiquidityHidden = isFeatureHidden('liquiditySource', features);
|
|
161
|
+
|
|
162
|
+
set({
|
|
163
|
+
...(isThemeHidden && { theme: 'auto' }),
|
|
164
|
+
...(isLanguageHidden && { language: DEFAULT_LANGUAGE }),
|
|
165
|
+
...(isLiquidityHidden && { disabledLiquiditySources: [] }),
|
|
166
|
+
});
|
|
167
|
+
},
|
|
168
|
+
});
|
package/src/types/config.ts
CHANGED
|
@@ -86,14 +86,37 @@ export type BlockchainAndTokenConfig = {
|
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
* `
|
|
89
|
+
* `Features`
|
|
90
90
|
*
|
|
91
|
-
* @property {
|
|
92
|
-
|
|
91
|
+
* @property {'visible' | 'hidden'} [theme]
|
|
92
|
+
* - The visibility state for the theme feature. Optional property.
|
|
93
|
+
*
|
|
94
|
+
* @property {'visible' | 'hidden'} [language]
|
|
95
|
+
* - The visibility state for the language feature. Optional property.
|
|
96
|
+
*
|
|
97
|
+
* @property {'disabled' | 'enabled'} [experimentalRoute]
|
|
98
|
+
* - The enablement state for the experimental route feature. Optional property.
|
|
99
|
+
*
|
|
100
|
+
* @property {'visible' | 'hidden'} [connectWalletButton]
|
|
101
|
+
* - The visibility state for the connect wallet button feature. Optional property.
|
|
102
|
+
*
|
|
103
|
+
* @property {'visible' | 'hidden'} [notification]
|
|
104
|
+
* - The visibility state for the notification feature. Optional property.
|
|
105
|
+
*
|
|
106
|
+
* @property {'visible' | 'hidden'} [liquiditySource]
|
|
107
|
+
* - The visibility state for the liquiditySource feature. Optional property.
|
|
93
108
|
*/
|
|
94
|
-
type
|
|
95
|
-
|
|
96
|
-
|
|
109
|
+
export type Features = Partial<
|
|
110
|
+
Record<
|
|
111
|
+
| 'theme'
|
|
112
|
+
| 'language'
|
|
113
|
+
| 'connectWalletButton'
|
|
114
|
+
| 'notification'
|
|
115
|
+
| 'liquiditySource',
|
|
116
|
+
'visible' | 'hidden'
|
|
117
|
+
>
|
|
118
|
+
> &
|
|
119
|
+
Partial<Record<'experimentalRoute', 'disabled' | 'enabled'>>;
|
|
97
120
|
|
|
98
121
|
/**
|
|
99
122
|
* The type WidgetConfig defines the configuration options for a widget, including API key, affiliate
|
|
@@ -134,7 +157,14 @@ type ExperimentalFeatures = {
|
|
|
134
157
|
* you could use to pin tokens of your choice to the top of the token list.
|
|
135
158
|
* @property {boolean} enableNewLiquiditySources - The `enableNewLiquiditySources` property is a boolean value that when you
|
|
136
159
|
* set it to true, whenever a new liquidity source is added, it will be added to your list as well.
|
|
137
|
-
* @property {
|
|
160
|
+
* @property {Features} features - An optional object for configuring the visibility or enablement of various features.
|
|
161
|
+
* Keys include:
|
|
162
|
+
* - 'notification': Visibility state for the notification icon.
|
|
163
|
+
* - 'theme': Visibility state for the theme.
|
|
164
|
+
* - 'liquiditySource': Visibility state for liquidity source.
|
|
165
|
+
* - 'connectWalletButton': Visibility state for the wallet connect icon.
|
|
166
|
+
* - 'language': Visibility state for the language.
|
|
167
|
+
* - 'experimentalRoute': Enablement state for the experimental route.
|
|
138
168
|
*/
|
|
139
169
|
|
|
140
170
|
export type WidgetConfig = {
|
|
@@ -154,5 +184,5 @@ export type WidgetConfig = {
|
|
|
154
184
|
externalWallets?: boolean;
|
|
155
185
|
pinnedTokens?: Asset[];
|
|
156
186
|
enableNewLiquiditySources?: boolean;
|
|
157
|
-
|
|
187
|
+
features?: Features;
|
|
158
188
|
};
|
package/src/utils/settings.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import type { Features } from '../types';
|
|
1
2
|
import type { SwapperMeta } from 'rango-sdk';
|
|
2
3
|
|
|
3
|
-
import { useSettingsStore } from '../store/settings';
|
|
4
|
-
|
|
5
4
|
import { removeDuplicateFrom } from './common';
|
|
6
5
|
|
|
7
6
|
export type LiquiditySourceType = 'BRIDGE' | 'AGGREGATOR' | 'DEX';
|
|
@@ -15,10 +14,9 @@ export type UniqueSwappersGroupType = {
|
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export function getUniqueSwappersGroups(
|
|
18
|
-
swappers: SwapperMeta[]
|
|
17
|
+
swappers: SwapperMeta[],
|
|
18
|
+
disabledLiquiditySources: string[]
|
|
19
19
|
): UniqueSwappersGroupType[] {
|
|
20
|
-
const disabledLiquiditySources =
|
|
21
|
-
useSettingsStore.use.disabledLiquiditySources();
|
|
22
20
|
const supportedSwappers = swappers.map((swapper) => swapper.swapperGroup);
|
|
23
21
|
|
|
24
22
|
const uniqueSupportedSwappersGroups: Array<UniqueSwappersGroupType> = [];
|
|
@@ -71,3 +69,11 @@ export function sortLiquiditySourcesByGroupTitle(
|
|
|
71
69
|
|
|
72
70
|
return 0;
|
|
73
71
|
}
|
|
72
|
+
|
|
73
|
+
export function isFeatureHidden(feature: keyof Features, features?: Features) {
|
|
74
|
+
return features?.[feature] === 'hidden';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function isFeatureEnabled(feature: keyof Features, features?: Features) {
|
|
78
|
+
return features?.[feature] === 'enabled';
|
|
79
|
+
}
|
package/dist/store/settings.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { SwapperMeta } from 'rango-sdk';
|
|
2
|
-
import { type Language } from '@rango-dev/ui';
|
|
3
|
-
export type ThemeMode = 'auto' | 'dark' | 'light';
|
|
4
|
-
export interface SettingsState {
|
|
5
|
-
/** Keeping a history of blockchains that user has selected (in Swap process) */
|
|
6
|
-
preferredBlockchains: string[];
|
|
7
|
-
slippage: number;
|
|
8
|
-
customSlippage: number | null;
|
|
9
|
-
infiniteApprove: boolean;
|
|
10
|
-
disabledLiquiditySources: string[];
|
|
11
|
-
theme: ThemeMode;
|
|
12
|
-
language: Language;
|
|
13
|
-
affiliateRef: string | null;
|
|
14
|
-
affiliatePercent: number | null;
|
|
15
|
-
affiliateWallets: {
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
} | null;
|
|
18
|
-
setSlippage: (slippage: number) => void;
|
|
19
|
-
setCustomSlippage: (customSlippage: number | null) => void;
|
|
20
|
-
toggleInfiniteApprove: () => void;
|
|
21
|
-
toggleLiquiditySource: (name: string) => void;
|
|
22
|
-
setTheme: (theme: ThemeMode) => void;
|
|
23
|
-
setLanguage: (language: Language) => void;
|
|
24
|
-
toggleAllLiquiditySources: (swappers: SwapperMeta[], shouldReset?: boolean) => void;
|
|
25
|
-
setAffiliateRef: (affiliateRef: string | null) => void;
|
|
26
|
-
setAffiliatePercent: (affiliatePercent: number | null) => void;
|
|
27
|
-
setAffiliateWallets: (affiliateWallets: {
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
} | null) => void;
|
|
30
|
-
addPreferredBlockchain: (blockchain: string) => void;
|
|
31
|
-
}
|
|
32
|
-
export declare const useSettingsStore: {
|
|
33
|
-
(): SettingsState;
|
|
34
|
-
<U>(selector: (state: SettingsState) => U): U;
|
|
35
|
-
<U_1>(selector: (state: SettingsState) => U_1, equalityFn: (a: U_1, b: U_1) => boolean): U_1;
|
|
36
|
-
} & Omit<Omit<import("zustand").StoreApi<SettingsState>, "persist"> & {
|
|
37
|
-
persist: {
|
|
38
|
-
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsState, SettingsState>>) => void;
|
|
39
|
-
clearStorage: () => void;
|
|
40
|
-
rehydrate: () => void | Promise<void>;
|
|
41
|
-
hasHydrated: () => boolean;
|
|
42
|
-
onHydrate: (fn: (state: SettingsState) => void) => () => void;
|
|
43
|
-
onFinishHydration: (fn: (state: SettingsState) => void) => () => void;
|
|
44
|
-
getOptions: () => Partial<import("zustand/middleware").PersistOptions<SettingsState, SettingsState>>;
|
|
45
|
-
};
|
|
46
|
-
}, "subscribe"> & {
|
|
47
|
-
subscribe: {
|
|
48
|
-
(listener: (selectedState: SettingsState, previousSelectedState: SettingsState) => void): () => void;
|
|
49
|
-
<U_2>(selector: (state: SettingsState) => U_2, listener: (selectedState: U_2, previousSelectedState: U_2) => void, options?: {
|
|
50
|
-
equalityFn?: ((a: U_2, b: U_2) => boolean) | undefined;
|
|
51
|
-
fireImmediately?: boolean | undefined;
|
|
52
|
-
} | undefined): () => void;
|
|
53
|
-
};
|
|
54
|
-
} & {
|
|
55
|
-
use: {
|
|
56
|
-
preferredBlockchains: () => string[];
|
|
57
|
-
slippage: () => number;
|
|
58
|
-
customSlippage: () => number | null;
|
|
59
|
-
infiniteApprove: () => boolean;
|
|
60
|
-
disabledLiquiditySources: () => string[];
|
|
61
|
-
theme: () => ThemeMode;
|
|
62
|
-
language: () => "en" | "es" | "ja" | "fr";
|
|
63
|
-
affiliateRef: () => string | null;
|
|
64
|
-
affiliatePercent: () => number | null;
|
|
65
|
-
affiliateWallets: () => {
|
|
66
|
-
[key: string]: string;
|
|
67
|
-
} | null;
|
|
68
|
-
setSlippage: () => (slippage: number) => void;
|
|
69
|
-
setCustomSlippage: () => (customSlippage: number | null) => void;
|
|
70
|
-
toggleInfiniteApprove: () => () => void;
|
|
71
|
-
toggleLiquiditySource: () => (name: string) => void;
|
|
72
|
-
setTheme: () => (theme: ThemeMode) => void;
|
|
73
|
-
setLanguage: () => (language: Language) => void;
|
|
74
|
-
toggleAllLiquiditySources: () => (swappers: SwapperMeta[], shouldReset?: boolean) => void;
|
|
75
|
-
setAffiliateRef: () => (affiliateRef: string | null) => void;
|
|
76
|
-
setAffiliatePercent: () => (affiliatePercent: number | null) => void;
|
|
77
|
-
setAffiliateWallets: () => (affiliateWallets: {
|
|
78
|
-
[key: string]: string;
|
|
79
|
-
} | null) => void;
|
|
80
|
-
addPreferredBlockchain: () => (blockchain: string) => void;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
//# sourceMappingURL=settings.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/store/settings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAW9C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,OAAO,CAAC;IACzB,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,KAAK,EAAE,SAAS,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAEnD,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,iBAAiB,EAAE,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC3D,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,IAAI,CAAC;IAC1C,yBAAyB,EAAE,CACzB,QAAQ,EAAE,WAAW,EAAE,EACvB,WAAW,CAAC,EAAE,OAAO,KAClB,IAAI,CAAC;IACV,eAAe,EAAE,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,mBAAmB,EAAE,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/D,mBAAmB,EAAE,CACnB,gBAAgB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,IAAI,KAC/C,IAAI,CAAC;IACV,sBAAsB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACtD;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sCAlBH,MAAM,KAAK,IAAI;kDACH,MAAM,GAAG,IAAI,KAAK,IAAI;2CAC7B,IAAI;4CACH,MAAM,KAAK,IAAI;gCAC3B,SAAS,KAAK,IAAI;sCACZ,QAAQ,KAAK,IAAI;oDAE7B,WAAW,EAAE,gBACT,OAAO,KAClB,IAAI;8CACuB,MAAM,GAAG,IAAI,KAAK,IAAI;sDACd,MAAM,GAAG,IAAI,KAAK,IAAI;;;qBAGzD,IAAI;mDAC4B,MAAM,KAAK,IAAI;;CAqHrD,CAAC"}
|