Skip to content

Commit

Permalink
update default live chart
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Jul 20, 2023
1 parent 9f23da6 commit 79450db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/state/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const addSerializedPair = createAction<{ serializedPair: SerializedPair }
export const removeSerializedPair = createAction<{ chainId: number; tokenAAddress: string; tokenBAddress: string }>(
'user/removeSerializedPair',
)
export const toggleLiveChart = createAction<{ chainId: number }>('user/toggleLiveChart')
export const toggleLiveChart = createAction('user/toggleLiveChart')

export const toggleTradeRoutes = createAction<void>('user/toggleTradeRoutes')
export const toggleTokenInfo = createAction<void>('user/toggleTokenInfo')
Expand Down
13 changes: 3 additions & 10 deletions src/state/user/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,8 @@ export function useLiquidityPositionTokenPairs(): [Token, Token][] {

export function useShowLiveChart(): boolean {
const { chainId } = useActiveWeb3React()
let showLiveChart = useSelector((state: AppState) => state.user.showLiveCharts)
if (typeof showLiveChart?.[chainId] !== 'boolean') {
showLiveChart = defaultShowLiveCharts
}

const show = showLiveChart[chainId]

return !!show
const showLiveChart = useSelector((state: AppState) => state.user.showLiveChart)
return typeof showLiveChart !== 'boolean' ? defaultShowLiveCharts[chainId] : showLiveChart
}

export function useShowTradeRoutes(): boolean {
Expand All @@ -383,8 +377,7 @@ export function useUpdateTokenAnalysisSettings(): (payload: string) => void {

export function useToggleLiveChart(): () => void {
const dispatch = useDispatch<AppDispatch>()
const { chainId } = useActiveWeb3React()
return useCallback(() => dispatch(toggleLiveChart({ chainId: chainId })), [dispatch, chainId])
return useCallback(() => dispatch(toggleLiveChart()), [dispatch])
}

export function useToggleTradeRoutes(): () => void {
Expand Down
13 changes: 4 additions & 9 deletions src/state/user/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ interface UserState {
}

timestamp: number
showLiveCharts: {
[chainId: number]: boolean
}
showLiveChart: boolean
showTradeRoutes: boolean
showTokenInfo: boolean
showKyberAIBanner: boolean
Expand Down Expand Up @@ -185,7 +183,7 @@ const initialState: UserState = {
tokens: {},
pairs: {},
timestamp: currentTimestamp(),
showLiveCharts: { ...defaultShowLiveCharts },
showLiveChart: true,
showTradeRoutes: true,
showTokenInfo: true,
showKyberAIBanner: true,
Expand Down Expand Up @@ -307,11 +305,8 @@ export default createReducer(initialState, builder =>
}
state.timestamp = currentTimestamp()
})
.addCase(toggleLiveChart, (state, { payload: { chainId } }) => {
if (typeof state.showLiveCharts?.[chainId] !== 'boolean') {
state.showLiveCharts = { ...defaultShowLiveCharts }
}
state.showLiveCharts[chainId] = !state.showLiveCharts[chainId]
.addCase(toggleLiveChart, state => {
state.showLiveChart = !state.showLiveChart
})
.addCase(toggleTradeRoutes, state => {
state.showTradeRoutes = !state.showTradeRoutes
Expand Down

0 comments on commit 79450db

Please sign in to comment.