forked from Iguana-DEX/frontend-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmartRouter.ts
55 lines (46 loc) · 1.71 KB
/
smartRouter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { atom, useAtom, useAtomValue } from 'jotai'
import { userSingleHopAtom } from '@pancakeswap/utils/user'
import atomWithStorageWithErrorCatch from 'utils/atomWithStorageWithErrorCatch'
const userUseStableSwapAtom = atomWithStorageWithErrorCatch<boolean>('pcs:useStableSwap', true)
const userUseV2SwapAtom = atomWithStorageWithErrorCatch<boolean>('pcs:useV2Swap', true)
const userUseV3SwapAtom = atomWithStorageWithErrorCatch<boolean>('pcs:useV3Swap', true)
const userUserSplitRouteAtom = atomWithStorageWithErrorCatch<boolean>('pcs:useSplitRouting', true)
export function useUserStableSwapEnable() {
return useAtom(userUseStableSwapAtom)
}
export function useUserV2SwapEnable() {
return useAtom(userUseV2SwapAtom)
}
export function useUserV3SwapEnable() {
return useAtom(userUseV3SwapAtom)
}
export function useUserSplitRouteEnable() {
return useAtom(userUserSplitRouteAtom)
}
const derivedOnlyOneAMMSourceEnabledAtom = atom((get) => {
return [get(userUseStableSwapAtom), get(userUseV2SwapAtom), get(userUseV3SwapAtom)].filter(Boolean).length === 1
})
export function useOnlyOneAMMSourceEnabled() {
return useAtomValue(derivedOnlyOneAMMSourceEnabledAtom)
}
const derivedRoutingSettingChangedAtom = atom(
(get) => {
return [
get(userUseStableSwapAtom),
get(userUseV2SwapAtom),
get(userUseV3SwapAtom),
get(userUserSplitRouteAtom),
!get(userSingleHopAtom),
].some((x) => x === false)
},
(_, set) => {
set(userUseStableSwapAtom, true)
set(userUseV2SwapAtom, true)
set(userUseV3SwapAtom, true)
set(userUserSplitRouteAtom, true)
set(userSingleHopAtom, false)
},
)
export function useRoutingSettingChanged() {
return useAtom(derivedRoutingSettingChangedAtom)
}