Skip to content

Commit

Permalink
remove: hardcode watchlist params
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh committed Oct 2, 2023
1 parent faf24dd commit a174589
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
21 changes: 10 additions & 11 deletions src/pages/TrueSightV2/components/KyberAIWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,16 @@ export default function Widget() {
}, [])

const { data, isFetching, isError } = useTokenListQuery(
activeTab === WidgetTab.MyWatchlist
? { type: KyberAIListType.ALL, page: 1, pageSize: 5, watchlist: 'all' }
: {
type: {
[WidgetTab.Bearish]: KyberAIListType.BEARISH,
[WidgetTab.Bullish]: KyberAIListType.BULLISH,
[WidgetTab.TrendingSoon]: KyberAIListType.TRENDING_SOON,
}[activeTab],
page: 1,
pageSize: 5,
},
{
type: {
[WidgetTab.MyWatchlist]: KyberAIListType.MYWATCHLIST,
[WidgetTab.Bearish]: KyberAIListType.BEARISH,
[WidgetTab.Bullish]: KyberAIListType.BULLISH,
[WidgetTab.TrendingSoon]: KyberAIListType.TRENDING_SOON,
}[activeTab],
page: 1,
pageSize: 5,
},
{ refetchOnMountOrArgChange: true, skip: !isWhiteList || !showWidget },
)

Expand Down
1 change: 1 addition & 0 deletions src/pages/TrueSightV2/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export enum SORT_FIELD {

export const DEFAULT_PARAMS_BY_TAB: Partial<{ [tab in KyberAIListType]: Record<string, string> }> = {
[KyberAIListType.ALL]: { sort: `${SORT_FIELD.PRICE_CHANGE_24H}:${SORT_DIRECTION.DESC}` },
[KyberAIListType.MYWATCHLIST]: { watchlist: `all` },
[KyberAIListType.BULLISH]: {
sort: `${SORT_FIELD.KYBER_SCORE}:${SORT_DIRECTION.ASC}`,
kyberScoreTags: ['Very Bullish', 'Bullish'].join(','),
Expand Down
3 changes: 1 addition & 2 deletions src/pages/TrueSightV2/hooks/useKyberAIData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ const kyberAIApi = createApi({
endpoints: builder => ({
//1.
tokenList: builder.query<{ data: ITokenList[]; totalItems: number }, QueryTokenParams>({
query: ({ type, chain, page, pageSize, watchlist, keywords, ...filterSort }) => ({
query: ({ type, chain, page, pageSize, keywords, ...filterSort }) => ({
url: '/assets',
params: {
...DEFAULT_PARAMS_BY_TAB[type as KyberAIListType],
...filterSort,
page: page || 1,
size: pageSize || 10,
watchlist,
keywords,
},
}),
Expand Down
11 changes: 2 additions & 9 deletions src/pages/TrueSightV2/pages/TokenAnalysisList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import KyberScoreChart from '../components/chart/KyberScoreChart'
import TokenAnalysisListShareContent from '../components/shareContent/TokenAnalysisListShareContent'
import { KYBERAI_LISTYPE_TO_MIXPANEL, SORT_FIELD, Z_INDEX_KYBER_AI } from '../constants'
import { useTokenListQuery } from '../hooks/useKyberAIData'
import { IKyberScoreChart, ITokenList, KyberAIListType, QueryTokenParams } from '../types'
import { IKyberScoreChart, ITokenList, KyberAIListType } from '../types'
import { calculateValueToColor, formatLocaleStringNum, formatTokenPrice, navigateToSwapPage } from '../utils'

const SIZE_MOBILE = '1080px'
Expand Down Expand Up @@ -707,14 +707,7 @@ export default function TokenAnalysisList() {
const { page, listTypeParam, filter } = useMemo(() => formatParamsFromUrl(searchParams), [searchParams])

const queryParams = useMemo(() => {
const params: QueryTokenParams = { page, pageSize, ...filter }
if (listTypeParam === KyberAIListType.MYWATCHLIST) {
params.watchlist = filter.watchlist || 'all'
params.type = KyberAIListType.ALL
} else {
params.type = listTypeParam
}
return params
return { page, pageSize, ...filter, type: listTypeParam }
}, [page, listTypeParam, filter])

const { data, isLoading, isFetching, isError } = useTokenListQuery(queryParams)
Expand Down

0 comments on commit a174589

Please sign in to comment.