@lifi/widget 3.32.2 → 3.33.1
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/CHANGELOG.md +14 -0
- package/dist/esm/AppProvider.js +2 -1
- package/dist/esm/AppProvider.js.map +1 -1
- package/dist/esm/components/Header/NavigationHeader.js +4 -1
- package/dist/esm/components/Header/NavigationHeader.js.map +1 -1
- package/dist/esm/components/Tools/Tools.js +1 -1
- package/dist/esm/components/Tools/Tools.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/hooks/useHeader.js +4 -1
- package/dist/esm/hooks/useHeader.js.map +1 -1
- package/dist/esm/hooks/useLanguages.d.ts +2 -3
- package/dist/esm/hooks/useLanguages.js +50 -14
- package/dist/esm/hooks/useLanguages.js.map +1 -1
- package/dist/esm/hooks/useRoutes.js +1 -1
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useSettingMonitor.js +2 -1
- package/dist/esm/hooks/useSettingMonitor.js.map +1 -1
- package/dist/esm/hooks/useTokenBalances.js +2 -1
- package/dist/esm/hooks/useTokenBalances.js.map +1 -1
- package/dist/esm/hooks/useTools.js +2 -1
- package/dist/esm/hooks/useTools.js.map +1 -1
- package/dist/esm/pages/LanguagesPage.js +6 -1
- package/dist/esm/pages/LanguagesPage.js.map +1 -1
- package/dist/esm/pages/SelectEnabledToolsPage.js +1 -1
- package/dist/esm/pages/SelectEnabledToolsPage.js.map +1 -1
- package/dist/esm/pages/SettingsPage/BridgeAndExchangeSettings.js +1 -1
- package/dist/esm/pages/SettingsPage/BridgeAndExchangeSettings.js.map +1 -1
- package/dist/esm/pages/SettingsPage/LanguageSetting.js +7 -2
- package/dist/esm/pages/SettingsPage/LanguageSetting.js.map +1 -1
- package/dist/esm/pages/SettingsPage/SlippageSettings/SlippageSettings.js +1 -1
- package/dist/esm/pages/SettingsPage/SlippageSettings/SlippageSettings.js.map +1 -1
- package/dist/esm/providers/I18nProvider/I18nProvider.js +47 -41
- package/dist/esm/providers/I18nProvider/I18nProvider.js.map +1 -1
- package/dist/esm/providers/I18nProvider/constants.d.ts +3 -0
- package/dist/esm/providers/I18nProvider/constants.js +39 -0
- package/dist/esm/providers/I18nProvider/constants.js.map +1 -0
- package/dist/esm/providers/I18nProvider/enResource.d.ts +2 -0
- package/dist/esm/providers/I18nProvider/enResource.js +4 -0
- package/dist/esm/providers/I18nProvider/enResource.js.map +1 -0
- package/dist/esm/providers/I18nProvider/i18n.d.ts +3 -0
- package/dist/esm/providers/I18nProvider/i18n.js +19 -0
- package/dist/esm/providers/I18nProvider/i18n.js.map +1 -0
- package/dist/esm/providers/I18nProvider/types.d.ts +4 -11
- package/dist/esm/providers/WalletProvider/SDKProviders.js +1 -1
- package/dist/esm/providers/WalletProvider/SDKProviders.js.map +1 -1
- package/dist/esm/stores/bookmarks/createBookmarkStore.d.ts +19 -1
- package/dist/esm/stores/bookmarks/createBookmarkStore.js +3 -3
- package/dist/esm/stores/bookmarks/createBookmarkStore.js.map +1 -1
- package/dist/esm/stores/chains/ChainOrderStore.js +3 -1
- package/dist/esm/stores/chains/ChainOrderStore.js.map +1 -1
- package/dist/esm/stores/chains/createChainOrderStore.d.ts +33 -1
- package/dist/esm/stores/chains/createChainOrderStore.js +3 -3
- package/dist/esm/stores/chains/createChainOrderStore.js.map +1 -1
- package/dist/esm/stores/chains/useChainOrder.js +5 -2
- package/dist/esm/stores/chains/useChainOrder.js.map +1 -1
- package/dist/esm/stores/form/createFormStore.d.ts +1 -1
- package/dist/esm/stores/form/createFormStore.js +3 -3
- package/dist/esm/stores/form/createFormStore.js.map +1 -1
- package/dist/esm/stores/header/useHeaderStore.js +3 -3
- package/dist/esm/stores/header/useHeaderStore.js.map +1 -1
- package/dist/esm/stores/routes/createRouteExecutionStore.d.ts +17 -1
- package/dist/esm/stores/routes/createRouteExecutionStore.js +3 -3
- package/dist/esm/stores/routes/createRouteExecutionStore.js.map +1 -1
- package/dist/esm/stores/settings/SettingsStore.d.ts +9 -0
- package/dist/esm/stores/settings/SettingsStore.js +24 -0
- package/dist/esm/stores/settings/SettingsStore.js.map +1 -0
- package/dist/esm/stores/settings/createSettingsStore.d.ts +51 -0
- package/dist/esm/stores/settings/{useSettingsStore.js → createSettingsStore.js} +38 -11
- package/dist/esm/stores/settings/createSettingsStore.js.map +1 -0
- package/dist/esm/stores/settings/types.d.ts +7 -1
- package/dist/esm/stores/settings/types.js.map +1 -1
- package/dist/esm/stores/settings/useSendToWalletStore.d.ts +1 -1
- package/dist/esm/stores/settings/useSendToWalletStore.js +3 -3
- package/dist/esm/stores/settings/useSendToWalletStore.js.map +1 -1
- package/dist/esm/stores/settings/useSettings.js +1 -1
- package/dist/esm/stores/settings/useSettings.js.map +1 -1
- package/dist/esm/stores/settings/useSettingsActions.d.ts +1 -0
- package/dist/esm/stores/settings/useSettingsActions.js +9 -1
- package/dist/esm/stores/settings/useSettingsActions.js.map +1 -1
- package/dist/esm/stores/settings/useSplitSubvariantStore.js +3 -3
- package/dist/esm/stores/settings/useSplitSubvariantStore.js.map +1 -1
- package/dist/esm/stores/settings/utils/getStateValues.js +1 -0
- package/dist/esm/stores/settings/utils/getStateValues.js.map +1 -1
- package/dist/esm/utils/tokenList.d.ts +1 -1
- package/dist/esm/utils/tokenList.js +3 -3
- package/dist/esm/utils/tokenList.js.map +1 -1
- package/package.json +13 -13
- package/package.json.tmp +15 -15
- package/src/AppProvider.tsx +14 -11
- package/src/components/Header/NavigationHeader.tsx +4 -1
- package/src/components/Tools/Tools.tsx +1 -1
- package/src/config/version.ts +1 -1
- package/src/hooks/useHeader.ts +4 -1
- package/src/hooks/useLanguages.ts +73 -15
- package/src/hooks/useRoutes.ts +1 -1
- package/src/hooks/useSettingMonitor.ts +2 -4
- package/src/hooks/useTokenBalances.ts +2 -1
- package/src/hooks/useTools.ts +3 -1
- package/src/pages/LanguagesPage.tsx +10 -1
- package/src/pages/SelectEnabledToolsPage.tsx +1 -1
- package/src/pages/SettingsPage/BridgeAndExchangeSettings.tsx +1 -1
- package/src/pages/SettingsPage/LanguageSetting.tsx +9 -2
- package/src/pages/SettingsPage/SlippageSettings/SlippageSettings.tsx +1 -1
- package/src/providers/I18nProvider/I18nProvider.tsx +66 -51
- package/src/providers/I18nProvider/constants.ts +41 -0
- package/src/providers/I18nProvider/enResource.ts +4 -0
- package/src/providers/I18nProvider/i18n.ts +26 -0
- package/src/providers/I18nProvider/types.ts +21 -12
- package/src/providers/WalletProvider/SDKProviders.tsx +2 -1
- package/src/stores/bookmarks/createBookmarkStore.ts +3 -5
- package/src/stores/chains/ChainOrderStore.tsx +3 -1
- package/src/stores/chains/createChainOrderStore.ts +3 -5
- package/src/stores/chains/useChainOrder.ts +10 -2
- package/src/stores/form/createFormStore.ts +3 -3
- package/src/stores/header/useHeaderStore.tsx +31 -34
- package/src/stores/routes/createRouteExecutionStore.ts +3 -5
- package/src/stores/settings/SettingsStore.tsx +45 -0
- package/src/stores/settings/createSettingsStore.ts +223 -0
- package/src/stores/settings/types.ts +8 -1
- package/src/stores/settings/useSendToWalletStore.ts +8 -11
- package/src/stores/settings/useSettings.ts +1 -1
- package/src/stores/settings/useSettingsActions.ts +13 -4
- package/src/stores/settings/useSplitSubvariantStore.tsx +9 -12
- package/src/stores/settings/utils/getStateValues.ts +1 -0
- package/src/themes/types.ts +0 -3
- package/src/utils/tokenList.ts +3 -3
- package/dist/esm/i18n/index.d.ts +0 -16
- package/dist/esm/i18n/index.js +0 -17
- package/dist/esm/i18n/index.js.map +0 -1
- package/dist/esm/stores/settings/useSettingsStore.d.ts +0 -5
- package/dist/esm/stores/settings/useSettingsStore.js.map +0 -1
- package/src/i18n/index.ts +0 -17
- package/src/stores/settings/useSettingsStore.ts +0 -185
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { create } from 'zustand'
|
|
2
2
|
import { persist } from 'zustand/middleware'
|
|
3
|
-
import { createWithEqualityFn } from 'zustand/traditional'
|
|
4
3
|
import { widgetEvents } from '../../hooks/useWidgetEvents.js'
|
|
5
4
|
import { WidgetEvent } from '../../types/events.js'
|
|
6
5
|
import type { PersistStoreProps } from '../types.js'
|
|
@@ -19,7 +18,7 @@ const defaultChainState = {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
export const createChainOrderStore = ({ namePrefix }: PersistStoreProps) =>
|
|
22
|
-
|
|
21
|
+
create<ChainOrderState>()(
|
|
23
22
|
persist(
|
|
24
23
|
(set, get) => ({
|
|
25
24
|
chainOrder: defaultChainState,
|
|
@@ -126,6 +125,5 @@ export const createChainOrderStore = ({ namePrefix }: PersistStoreProps) =>
|
|
|
126
125
|
pinnedChains: state.pinnedChains,
|
|
127
126
|
}),
|
|
128
127
|
}
|
|
129
|
-
)
|
|
130
|
-
Object.is
|
|
128
|
+
)
|
|
131
129
|
)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
1
2
|
import type { FormType } from '../form/types.js'
|
|
2
3
|
import { useChainOrderStore } from './ChainOrderStore.js'
|
|
3
4
|
import { maxChainsToOrder } from './createChainOrderStore.js'
|
|
@@ -5,8 +6,15 @@ import { maxChainsToOrder } from './createChainOrderStore.js'
|
|
|
5
6
|
export const useChainOrder = (
|
|
6
7
|
type: FormType
|
|
7
8
|
): [number[], (chainId: number, type: FormType) => void] => {
|
|
8
|
-
|
|
9
|
-
state.chainOrder[type]
|
|
9
|
+
const [chainOrder, setChain] = useChainOrderStore((state) => [
|
|
10
|
+
state.chainOrder[type],
|
|
10
11
|
state.setChain,
|
|
11
12
|
])
|
|
13
|
+
|
|
14
|
+
const limitedChainOrder = useMemo(
|
|
15
|
+
() => chainOrder.slice(0, maxChainsToOrder),
|
|
16
|
+
[chainOrder]
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
return [limitedChainOrder, setChain]
|
|
12
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { create } from 'zustand'
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
4
|
DefaultValues,
|
|
@@ -68,7 +68,7 @@ const mergeDefaultFormValues = (
|
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
export const createFormStore = (defaultValues?: DefaultValues) =>
|
|
71
|
-
|
|
71
|
+
create<FormValuesState>((set, get) => {
|
|
72
72
|
const _defaultValues = valuesToFormValues({
|
|
73
73
|
...formDefaultValues,
|
|
74
74
|
...defaultValues,
|
|
@@ -231,4 +231,4 @@ export const createFormStore = (defaultValues?: DefaultValues) =>
|
|
|
231
231
|
}))
|
|
232
232
|
},
|
|
233
233
|
}
|
|
234
|
-
}
|
|
234
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext, useRef } from 'react'
|
|
2
|
+
import { create } from 'zustand'
|
|
2
3
|
import { useShallow } from 'zustand/shallow'
|
|
3
|
-
import { createWithEqualityFn } from 'zustand/traditional'
|
|
4
4
|
import type { PersistStoreProviderProps } from '../types.js'
|
|
5
5
|
import type { HeaderState, HeaderStore } from './types.js'
|
|
6
6
|
|
|
@@ -55,36 +55,33 @@ export function useSetHeaderHeight() {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const createHeaderStore = () =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}),
|
|
89
|
-
Object.is
|
|
90
|
-
)
|
|
58
|
+
create<HeaderState>((set, get) => ({
|
|
59
|
+
headerHeight: 108, // a basic default height
|
|
60
|
+
setAction: (element) => {
|
|
61
|
+
set(() => ({
|
|
62
|
+
element,
|
|
63
|
+
}))
|
|
64
|
+
return get().removeAction
|
|
65
|
+
},
|
|
66
|
+
setTitle: (title) => {
|
|
67
|
+
set(() => ({
|
|
68
|
+
title,
|
|
69
|
+
}))
|
|
70
|
+
return get().removeTitle
|
|
71
|
+
},
|
|
72
|
+
removeAction: () => {
|
|
73
|
+
set(() => ({
|
|
74
|
+
element: null,
|
|
75
|
+
}))
|
|
76
|
+
},
|
|
77
|
+
removeTitle: () => {
|
|
78
|
+
set(() => ({
|
|
79
|
+
title: undefined,
|
|
80
|
+
}))
|
|
81
|
+
},
|
|
82
|
+
setHeaderHeight: (headerHeight) => {
|
|
83
|
+
set(() => ({
|
|
84
|
+
headerHeight,
|
|
85
|
+
}))
|
|
86
|
+
},
|
|
87
|
+
}))
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Route, RouteExtended } from '@lifi/sdk'
|
|
2
|
-
import
|
|
2
|
+
import { create } from 'zustand'
|
|
3
3
|
import { persist } from 'zustand/middleware'
|
|
4
|
-
import { createWithEqualityFn } from 'zustand/traditional'
|
|
5
4
|
import { hasEnumFlag } from '../../utils/enum.js'
|
|
6
5
|
import type { PersistStoreProps } from '../types.js'
|
|
7
6
|
import type { RouteExecutionState } from './types.js'
|
|
@@ -14,7 +13,7 @@ import {
|
|
|
14
13
|
} from './utils.js'
|
|
15
14
|
|
|
16
15
|
export const createRouteExecutionStore = ({ namePrefix }: PersistStoreProps) =>
|
|
17
|
-
|
|
16
|
+
create<RouteExecutionState>()(
|
|
18
17
|
persist(
|
|
19
18
|
(set, get) => ({
|
|
20
19
|
routes: {},
|
|
@@ -150,6 +149,5 @@ export const createRouteExecutionStore = ({ namePrefix }: PersistStoreProps) =>
|
|
|
150
149
|
return state
|
|
151
150
|
},
|
|
152
151
|
}
|
|
153
|
-
)
|
|
154
|
-
Object.is
|
|
152
|
+
)
|
|
155
153
|
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type PropsWithChildren,
|
|
4
|
+
useContext,
|
|
5
|
+
useRef,
|
|
6
|
+
} from 'react'
|
|
7
|
+
import type { StoreApi } from 'zustand'
|
|
8
|
+
import { useShallow } from 'zustand/shallow'
|
|
9
|
+
import type { UseBoundStoreWithEqualityFn } from 'zustand/traditional'
|
|
10
|
+
import { createSettingsStore } from './createSettingsStore.js'
|
|
11
|
+
import type { SettingsState, SettingsStoreProviderProps } from './types.js'
|
|
12
|
+
|
|
13
|
+
type SettingsStore = UseBoundStoreWithEqualityFn<StoreApi<SettingsState>>
|
|
14
|
+
|
|
15
|
+
const SettingsStoreContext = createContext<SettingsStore | null>(null)
|
|
16
|
+
|
|
17
|
+
export const SettingsStoreProvider = ({
|
|
18
|
+
children,
|
|
19
|
+
config,
|
|
20
|
+
}: PropsWithChildren<SettingsStoreProviderProps>) => {
|
|
21
|
+
const storeRef = useRef<SettingsStore>(null)
|
|
22
|
+
if (!storeRef.current) {
|
|
23
|
+
storeRef.current = createSettingsStore(config)
|
|
24
|
+
}
|
|
25
|
+
return (
|
|
26
|
+
<SettingsStoreContext.Provider value={storeRef.current}>
|
|
27
|
+
{children}
|
|
28
|
+
</SettingsStoreContext.Provider>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function useSettingsStoreContext() {
|
|
33
|
+
const useStore = useContext(SettingsStoreContext)
|
|
34
|
+
if (!useStore) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'You forgot to wrap your component in SettingsStoreContext.'
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
return useStore
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function useSettingsStore<T>(selector: (state: SettingsState) => T): T {
|
|
43
|
+
const useStore = useSettingsStoreContext()
|
|
44
|
+
return useStore(useShallow(selector))
|
|
45
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/** biome-ignore-all lint/correctness/noUnusedVariables: allowed in this store */
|
|
2
|
+
import { create } from 'zustand'
|
|
3
|
+
import { persist } from 'zustand/middleware'
|
|
4
|
+
import { allLanguages } from '../../providers/I18nProvider/constants.js'
|
|
5
|
+
import { loadLocale } from '../../providers/I18nProvider/i18n.js'
|
|
6
|
+
import type { LanguageKey } from '../../providers/I18nProvider/types.js'
|
|
7
|
+
import type { WidgetConfig } from '../../types/widget.js'
|
|
8
|
+
import type { SettingsProps, SettingsState } from './types.js'
|
|
9
|
+
import { SettingsToolTypes } from './types.js'
|
|
10
|
+
import { getStateValues } from './utils/getStateValues.js'
|
|
11
|
+
|
|
12
|
+
export const defaultSlippage = undefined
|
|
13
|
+
|
|
14
|
+
export const defaultConfigurableSettings: Pick<
|
|
15
|
+
SettingsState,
|
|
16
|
+
'routePriority' | 'slippage' | 'gasPrice'
|
|
17
|
+
> = {
|
|
18
|
+
routePriority: 'CHEAPEST',
|
|
19
|
+
slippage: defaultSlippage,
|
|
20
|
+
gasPrice: 'normal',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const defaultSettings: SettingsProps = {
|
|
24
|
+
gasPrice: 'normal',
|
|
25
|
+
enabledAutoRefuel: true,
|
|
26
|
+
disabledBridges: [],
|
|
27
|
+
disabledExchanges: [],
|
|
28
|
+
enabledBridges: [],
|
|
29
|
+
enabledExchanges: [],
|
|
30
|
+
_enabledBridges: {},
|
|
31
|
+
_enabledExchanges: {},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const createSettingsStore = (config: WidgetConfig) =>
|
|
35
|
+
create<SettingsState>()(
|
|
36
|
+
persist(
|
|
37
|
+
(set, get) => ({
|
|
38
|
+
...defaultSettings,
|
|
39
|
+
setValue: (key, value) =>
|
|
40
|
+
set(() => ({
|
|
41
|
+
[key]: value,
|
|
42
|
+
})),
|
|
43
|
+
setValues: (values: Partial<SettingsProps>) =>
|
|
44
|
+
set(() => ({
|
|
45
|
+
...values,
|
|
46
|
+
})),
|
|
47
|
+
getSettings: () => getStateValues(get()),
|
|
48
|
+
getValue: (key) => get()[key],
|
|
49
|
+
initializeTools: (toolType, tools, reset) => {
|
|
50
|
+
if (!tools.length) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
set((state) => {
|
|
54
|
+
const updatedState = { ...state }
|
|
55
|
+
if (!reset) {
|
|
56
|
+
// Add new tools
|
|
57
|
+
tools.forEach((tool) => {
|
|
58
|
+
if (!Object.hasOwn(updatedState[`_enabled${toolType}`], tool)) {
|
|
59
|
+
updatedState[`_enabled${toolType}`][tool] = true
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
// Filter tools we no longer have
|
|
63
|
+
updatedState[`_enabled${toolType}`] = Object.fromEntries(
|
|
64
|
+
Object.entries(updatedState[`_enabled${toolType}`]).filter(
|
|
65
|
+
([key]) => tools.includes(key)
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
} else {
|
|
69
|
+
tools.forEach((tool) => {
|
|
70
|
+
updatedState[`_enabled${toolType}`][tool] = true
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
const enabledToolKeys = Object.keys(
|
|
74
|
+
updatedState[`_enabled${toolType}`]
|
|
75
|
+
)
|
|
76
|
+
updatedState[`enabled${toolType}`] = enabledToolKeys.filter(
|
|
77
|
+
(key) => updatedState[`_enabled${toolType}`][key]
|
|
78
|
+
)
|
|
79
|
+
updatedState[`disabled${toolType}`] = enabledToolKeys.filter(
|
|
80
|
+
(key) => !updatedState[`_enabled${toolType}`][key]
|
|
81
|
+
)
|
|
82
|
+
return updatedState
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
setToolValue: (toolType, tool, value) =>
|
|
86
|
+
set((state) => {
|
|
87
|
+
const enabledTools = {
|
|
88
|
+
...state[`_enabled${toolType}`],
|
|
89
|
+
[tool]: value,
|
|
90
|
+
}
|
|
91
|
+
const enabledToolKeys = Object.keys(enabledTools)
|
|
92
|
+
return {
|
|
93
|
+
[`_enabled${toolType}`]: enabledTools,
|
|
94
|
+
[`enabled${toolType}`]: enabledToolKeys.filter(
|
|
95
|
+
(key) => enabledTools[key]
|
|
96
|
+
),
|
|
97
|
+
[`disabled${toolType}`]: enabledToolKeys.filter(
|
|
98
|
+
(key) => !enabledTools[key]
|
|
99
|
+
),
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
toggleToolKeys: (toolType, toolKeys) =>
|
|
103
|
+
set((state) => {
|
|
104
|
+
const allKeysInCollectionEnabled = toolKeys.every(
|
|
105
|
+
(toolKey) => state[`_enabled${toolType}`][toolKey]
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
// then toggle those keys to false
|
|
109
|
+
const updatedTools = toolKeys.reduce(
|
|
110
|
+
(accum, toolKey) => {
|
|
111
|
+
accum[toolKey] = !allKeysInCollectionEnabled
|
|
112
|
+
return accum
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
...state[`_enabled${toolType}`],
|
|
116
|
+
}
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const enableKeys: string[] = []
|
|
120
|
+
const disabledKeys: string[] = []
|
|
121
|
+
|
|
122
|
+
Object.entries(updatedTools).forEach(([key, value]) => {
|
|
123
|
+
if (value) {
|
|
124
|
+
enableKeys.push(key)
|
|
125
|
+
} else {
|
|
126
|
+
disabledKeys.push(key)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
[`_enabled${toolType}`]: updatedTools,
|
|
132
|
+
[`enabled${toolType}`]: enableKeys,
|
|
133
|
+
[`disabled${toolType}`]: disabledKeys,
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
reset: (bridges, exchanges) => {
|
|
137
|
+
set(() => ({
|
|
138
|
+
...defaultSettings,
|
|
139
|
+
...defaultConfigurableSettings,
|
|
140
|
+
}))
|
|
141
|
+
get().initializeTools('Bridges', bridges, true)
|
|
142
|
+
get().initializeTools('Exchanges', exchanges, true)
|
|
143
|
+
return { ...get() }
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
{
|
|
147
|
+
name: 'li.fi-widget-settings',
|
|
148
|
+
version: 5,
|
|
149
|
+
partialize: (state) => {
|
|
150
|
+
const {
|
|
151
|
+
disabledBridges,
|
|
152
|
+
disabledExchanges,
|
|
153
|
+
enabledBridges,
|
|
154
|
+
enabledExchanges,
|
|
155
|
+
...partializedState
|
|
156
|
+
} = state
|
|
157
|
+
return partializedState
|
|
158
|
+
},
|
|
159
|
+
merge: (persistedState: any, currentState: SettingsState) => {
|
|
160
|
+
const state = { ...currentState, ...persistedState }
|
|
161
|
+
SettingsToolTypes.forEach((toolType) => {
|
|
162
|
+
if (persistedState?.[`_enabled${toolType}`]) {
|
|
163
|
+
const enabledToolKeys = Object.keys(
|
|
164
|
+
persistedState[`_enabled${toolType}`]
|
|
165
|
+
)
|
|
166
|
+
state[`enabled${toolType}`] = enabledToolKeys.filter(
|
|
167
|
+
(key) => persistedState[`_enabled${toolType}`][key]
|
|
168
|
+
)
|
|
169
|
+
state[`disabled${toolType}`] = enabledToolKeys.filter(
|
|
170
|
+
(key) => !persistedState[`_enabled${toolType}`][key]
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
return state
|
|
175
|
+
},
|
|
176
|
+
migrate: (persistedState: any, version) => {
|
|
177
|
+
if (version === 1) {
|
|
178
|
+
persistedState.slippage = defaultConfigurableSettings.slippage
|
|
179
|
+
}
|
|
180
|
+
if (version <= 3) {
|
|
181
|
+
persistedState.routePriority = 'CHEAPEST'
|
|
182
|
+
}
|
|
183
|
+
return persistedState as SettingsState
|
|
184
|
+
},
|
|
185
|
+
onRehydrateStorage: () => {
|
|
186
|
+
const initializeLanguageSettings = async (
|
|
187
|
+
state: SettingsState,
|
|
188
|
+
initialLanguage?: string
|
|
189
|
+
) => {
|
|
190
|
+
const customLanguages = Object.keys(
|
|
191
|
+
config?.languageResources || {}
|
|
192
|
+
).filter((key) => !allLanguages.includes(key as LanguageKey))
|
|
193
|
+
if (
|
|
194
|
+
initialLanguage &&
|
|
195
|
+
// Custom language resources and English are added statically.
|
|
196
|
+
initialLanguage !== 'en' &&
|
|
197
|
+
!customLanguages.includes(initialLanguage)
|
|
198
|
+
) {
|
|
199
|
+
await loadLocale(
|
|
200
|
+
initialLanguage as LanguageKey,
|
|
201
|
+
config?.languageResources?.[initialLanguage as LanguageKey]
|
|
202
|
+
).then((languageResource) => {
|
|
203
|
+
state.setValues({
|
|
204
|
+
language: initialLanguage,
|
|
205
|
+
languageCache: languageResource,
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return (state?: SettingsState) => {
|
|
211
|
+
// Preload translations (from existing translation files)
|
|
212
|
+
if (state) {
|
|
213
|
+
// NB: State always exists unless there is any error
|
|
214
|
+
initializeLanguageSettings(
|
|
215
|
+
state,
|
|
216
|
+
state.getValue('language') || config?.languages?.default
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
}
|
|
222
|
+
)
|
|
223
|
+
)
|
|
@@ -2,7 +2,8 @@ import type { Order } from '@lifi/sdk'
|
|
|
2
2
|
import type { PropsWithChildren } from 'react'
|
|
3
3
|
import type { StoreApi } from 'zustand'
|
|
4
4
|
import type { UseBoundStoreWithEqualityFn } from 'zustand/traditional'
|
|
5
|
-
import type {
|
|
5
|
+
import type { LanguageResource } from '../../providers/I18nProvider/types.js'
|
|
6
|
+
import type { SplitSubvariant, WidgetConfig } from '../../types/widget.js'
|
|
6
7
|
|
|
7
8
|
export type ValueSetter<S> = <K extends keyof S>(
|
|
8
9
|
key: K,
|
|
@@ -17,6 +18,7 @@ export type SettingsToolType = (typeof SettingsToolTypes)[number]
|
|
|
17
18
|
export interface SettingsProps {
|
|
18
19
|
gasPrice?: string
|
|
19
20
|
language?: string
|
|
21
|
+
languageCache?: LanguageResource
|
|
20
22
|
routePriority?: Order
|
|
21
23
|
enabledAutoRefuel: boolean
|
|
22
24
|
slippage?: string
|
|
@@ -30,6 +32,7 @@ export interface SettingsProps {
|
|
|
30
32
|
|
|
31
33
|
export interface SettingsActions {
|
|
32
34
|
setValue: ValueSetter<SettingsProps>
|
|
35
|
+
setValues: (values: Partial<SettingsProps>) => void
|
|
33
36
|
getValue: ValueGetter<SettingsProps>
|
|
34
37
|
getSettings: () => SettingsProps
|
|
35
38
|
initializeTools(
|
|
@@ -67,3 +70,7 @@ export interface SplitSubvariantProps {
|
|
|
67
70
|
|
|
68
71
|
export type SplitSubvariantProviderProps =
|
|
69
72
|
PropsWithChildren<SplitSubvariantProps>
|
|
73
|
+
|
|
74
|
+
export interface SettingsStoreProviderProps {
|
|
75
|
+
config: WidgetConfig
|
|
76
|
+
}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
+
import { create } from 'zustand'
|
|
1
2
|
import { useShallow } from 'zustand/shallow'
|
|
2
|
-
import { createWithEqualityFn } from 'zustand/traditional'
|
|
3
3
|
import type { SendToWalletStore } from './types.js'
|
|
4
4
|
|
|
5
|
-
export const sendToWalletStore =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}),
|
|
13
|
-
Object.is
|
|
14
|
-
)
|
|
5
|
+
export const sendToWalletStore = create<SendToWalletStore>((set) => ({
|
|
6
|
+
showSendToWallet: false,
|
|
7
|
+
setSendToWallet: (value) =>
|
|
8
|
+
set({
|
|
9
|
+
showSendToWallet: value,
|
|
10
|
+
}),
|
|
11
|
+
}))
|
|
15
12
|
|
|
16
13
|
export const useSendToWalletStore = <T>(
|
|
17
14
|
selector: (state: SendToWalletStore) => T
|
|
@@ -4,16 +4,14 @@ import { useWidgetEvents } from '../../hooks/useWidgetEvents.js'
|
|
|
4
4
|
import { WidgetEvent } from '../../types/events.js'
|
|
5
5
|
import type { WidgetConfig } from '../../types/widget.js'
|
|
6
6
|
import { deepEqual } from '../../utils/deepEqual.js'
|
|
7
|
+
import { defaultConfigurableSettings } from './createSettingsStore.js'
|
|
8
|
+
import { useSettingsStore } from './SettingsStore.js'
|
|
7
9
|
import type {
|
|
8
10
|
SettingsActions,
|
|
9
11
|
SettingsProps,
|
|
10
12
|
SettingsToolType,
|
|
11
13
|
ValueSetter,
|
|
12
14
|
} from './types.js'
|
|
13
|
-
import {
|
|
14
|
-
defaultConfigurableSettings,
|
|
15
|
-
useSettingsStore,
|
|
16
|
-
} from './useSettingsStore.js'
|
|
17
15
|
|
|
18
16
|
const emitEventOnChange = <T extends (...args: any[]) => any>(
|
|
19
17
|
emitter: typeof widgetEvents,
|
|
@@ -48,6 +46,7 @@ export const useSettingsActions = () => {
|
|
|
48
46
|
const emitter = useWidgetEvents()
|
|
49
47
|
const actions = useSettingsStore((state) => ({
|
|
50
48
|
setValue: state.setValue,
|
|
49
|
+
setValues: state.setValues,
|
|
51
50
|
getValue: state.getValue,
|
|
52
51
|
getSettings: state.getSettings,
|
|
53
52
|
reset: state.reset,
|
|
@@ -63,6 +62,15 @@ export const useSettingsActions = () => {
|
|
|
63
62
|
[emitter, actions]
|
|
64
63
|
)
|
|
65
64
|
|
|
65
|
+
const setValuesWithEmittedEvent = useCallback(
|
|
66
|
+
(values: Partial<SettingsProps>) => {
|
|
67
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
68
|
+
setValueWithEmittedEvent(key as keyof SettingsProps, value)
|
|
69
|
+
})
|
|
70
|
+
},
|
|
71
|
+
[setValueWithEmittedEvent]
|
|
72
|
+
)
|
|
73
|
+
|
|
66
74
|
const setDefaultSettingsWithEmittedEvents = useCallback(
|
|
67
75
|
(config?: WidgetConfig) => {
|
|
68
76
|
const slippage = actions.getValue('slippage')
|
|
@@ -140,6 +148,7 @@ export const useSettingsActions = () => {
|
|
|
140
148
|
|
|
141
149
|
return {
|
|
142
150
|
setValue: setValueWithEmittedEvent,
|
|
151
|
+
setValues: setValuesWithEmittedEvent,
|
|
143
152
|
setDefaultSettings: setDefaultSettingsWithEmittedEvents,
|
|
144
153
|
resetSettings: resetWithEmittedEvents,
|
|
145
154
|
setToolValue: setToolValueWithEmittedEvents,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext, useRef } from 'react'
|
|
2
|
+
import { create } from 'zustand'
|
|
2
3
|
import { useShallow } from 'zustand/shallow'
|
|
3
|
-
import { createWithEqualityFn } from 'zustand/traditional'
|
|
4
4
|
import type {
|
|
5
5
|
SplitSubvariantProps,
|
|
6
6
|
SplitSubvariantProviderProps,
|
|
@@ -53,14 +53,11 @@ export function useSplitSubvariantStore<T>(
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
const createSplitSubvariantStore = ({ state }: SplitSubvariantProps) =>
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}),
|
|
65
|
-
Object.is
|
|
66
|
-
)
|
|
56
|
+
create<SplitSubvariantState>((set) => ({
|
|
57
|
+
state,
|
|
58
|
+
setState(state) {
|
|
59
|
+
set(() => ({
|
|
60
|
+
state,
|
|
61
|
+
}))
|
|
62
|
+
},
|
|
63
|
+
}))
|
|
@@ -3,6 +3,7 @@ import type { SettingsProps, SettingsState } from '../types.js'
|
|
|
3
3
|
export const getStateValues = (state: SettingsState): SettingsProps => ({
|
|
4
4
|
gasPrice: state.gasPrice,
|
|
5
5
|
language: state.language,
|
|
6
|
+
languageCache: state.languageCache,
|
|
6
7
|
routePriority: state.routePriority,
|
|
7
8
|
enabledAutoRefuel: state.enabledAutoRefuel,
|
|
8
9
|
slippage: state.slippage,
|
package/src/themes/types.ts
CHANGED
|
@@ -10,9 +10,6 @@ import type {} from '@mui/material/themeCssVarsAugmentation'
|
|
|
10
10
|
import type { CSSProperties } from 'react'
|
|
11
11
|
import type { NavigationProps } from '../types/widget.js'
|
|
12
12
|
|
|
13
|
-
// @mui/icons-material ESM issue
|
|
14
|
-
// https://github.com/mui/material-ui/issues/30671
|
|
15
|
-
|
|
16
13
|
// https://mui.com/customization/palette/
|
|
17
14
|
declare module '@mui/material/styles' {
|
|
18
15
|
interface TypographyVariants {
|
package/src/utils/tokenList.ts
CHANGED
|
@@ -14,14 +14,14 @@ const sortByVolume = (a: TokenExtended, b: TokenExtended) =>
|
|
|
14
14
|
|
|
15
15
|
export const processTokenBalances = (
|
|
16
16
|
isBalanceLoading: boolean,
|
|
17
|
-
|
|
17
|
+
noCategories: boolean,
|
|
18
18
|
configTokens?: WidgetTokens,
|
|
19
19
|
selectedChainId?: number,
|
|
20
20
|
tokens?: TokenExtended[],
|
|
21
21
|
tokensWithBalances?: TokenAmount[]
|
|
22
22
|
) => {
|
|
23
23
|
if (isBalanceLoading) {
|
|
24
|
-
if (
|
|
24
|
+
if (noCategories) {
|
|
25
25
|
const sortedTokens = [...(tokens ?? [])].sort(sortByVolume)
|
|
26
26
|
return {
|
|
27
27
|
processedTokens: sortedTokens,
|
|
@@ -54,7 +54,7 @@ export const processTokenBalances = (
|
|
|
54
54
|
})
|
|
55
55
|
.sort(sortByVolume) ?? []
|
|
56
56
|
|
|
57
|
-
if (
|
|
57
|
+
if (noCategories) {
|
|
58
58
|
return {
|
|
59
59
|
processedTokens: [...sortedTokensWithBalances, ...tokensWithoutBalances],
|
|
60
60
|
withCategories: false,
|
package/dist/esm/i18n/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import bn from './bn.json';
|
|
2
|
-
import de from './de.json';
|
|
3
|
-
import en from './en.json';
|
|
4
|
-
import es from './es.json';
|
|
5
|
-
import fr from './fr.json';
|
|
6
|
-
import id from './id.json';
|
|
7
|
-
import it from './it.json';
|
|
8
|
-
import ja from './ja.json';
|
|
9
|
-
import ko from './ko.json';
|
|
10
|
-
import pt from './pt.json';
|
|
11
|
-
import th from './th.json';
|
|
12
|
-
import tr from './tr.json';
|
|
13
|
-
import uk from './uk.json';
|
|
14
|
-
import vi from './vi.json';
|
|
15
|
-
import zh from './zh.json';
|
|
16
|
-
export { bn, de, en, es, fr, id, it, ja, ko, pt, th, tr, uk, vi, zh };
|
package/dist/esm/i18n/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import bn from './bn.json' with { type: 'json' };
|
|
2
|
-
import de from './de.json' with { type: 'json' };
|
|
3
|
-
import en from './en.json' with { type: 'json' };
|
|
4
|
-
import es from './es.json' with { type: 'json' };
|
|
5
|
-
import fr from './fr.json' with { type: 'json' };
|
|
6
|
-
import id from './id.json' with { type: 'json' };
|
|
7
|
-
import it from './it.json' with { type: 'json' };
|
|
8
|
-
import ja from './ja.json' with { type: 'json' };
|
|
9
|
-
import ko from './ko.json' with { type: 'json' };
|
|
10
|
-
import pt from './pt.json' with { type: 'json' };
|
|
11
|
-
import th from './th.json' with { type: 'json' };
|
|
12
|
-
import tr from './tr.json' with { type: 'json' };
|
|
13
|
-
import uk from './uk.json' with { type: 'json' };
|
|
14
|
-
import vi from './vi.json' with { type: 'json' };
|
|
15
|
-
import zh from './zh.json' with { type: 'json' };
|
|
16
|
-
export { bn, de, en, es, fr, id, it, ja, ko, pt, th, tr, uk, vi, zh };
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/i18n/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAChD,OAAO,EAAE,MAAM,WAAW,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAA;AAEhD,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAA"}
|