Skip to content

Commit

Permalink
add 2 new tab default sort
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoYhun committed Oct 3, 2023
1 parent 6c517d7 commit e061d22
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/pages/TrueSightV2/constants/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export enum SORT_FIELD {
FIRST_DISCOVER_ON = 'trending_discovered_on',
FUNDING_RATE = 'funding_rate',
PRICE_CHANGE_24H = 'percent_change_24h',
KYBER_SCORE_DELTA = 'kyber_score_delta',
}

export const DEFAULT_PARAMS_BY_TAB: Partial<{ [tab in KyberAIListType]: Record<string, string> }> = {
Expand All @@ -97,6 +98,8 @@ export const DEFAULT_PARAMS_BY_TAB: Partial<{ [tab in KyberAIListType]: Record<s
[KyberAIListType.TOP_TRADED]: { sort: `${SORT_FIELD.VOLUME_24H}:${SORT_DIRECTION.DESC}` },
[KyberAIListType.TRENDING]: { trendingTypes: 'trending' },
[KyberAIListType.TRENDING_SOON]: { trendingTypes: 'trending-soon' },
[KyberAIListType.FUNDING_RATE]: { sort: `${SORT_FIELD.FUNDING_RATE}:${SORT_DIRECTION.DESC}` },
[KyberAIListType.KYBERSWAP_DELTA]: { sort: `${SORT_FIELD.KYBER_SCORE_DELTA}:${SORT_DIRECTION.DESC}` },
}

export enum KYBERAI_CHART_ID {
Expand Down
22 changes: 16 additions & 6 deletions src/pages/TrueSightV2/hooks/useKyberAIData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ const kyberAIApi = createApi({
method: 'POST',
params: { assetId },
}),
async onQueryStarted({ userWatchlistId, assetId }, { dispatch }) {
dispatch(
async onQueryStarted({ userWatchlistId, assetId }, { dispatch, queryFulfilled }) {
const patchResult = dispatch(
kyberAIApi.util.updateQueryData('getWatchlistInformation', undefined, draft => {
draft.totalUniqueAssetNumber += 1
const watchlists = draft.watchlists.find(item => item.id === userWatchlistId)
Expand All @@ -257,8 +257,13 @@ const kyberAIApi = createApi({
}
}),
)
try {
await queryFulfilled
} catch {
patchResult.undo()
}
},
invalidatesTags: ['watchlistsInfo'],
invalidatesTags: (result, error) => (error ? [] : ['watchlistsInfo']),
}),
//20.
removeFromWatchlist: builder.mutation({
Expand All @@ -267,8 +272,8 @@ const kyberAIApi = createApi({
method: 'DELETE',
params: { assetId },
}),
async onQueryStarted({ userWatchlistId, assetId }, { dispatch }) {
dispatch(
async onQueryStarted({ userWatchlistId, assetId }, { dispatch, queryFulfilled }) {
const patchResult = dispatch(
kyberAIApi.util.updateQueryData('getWatchlistInformation', undefined, draft => {
draft.totalUniqueAssetNumber -= 1
const watchlists = draft.watchlists.find(item => item.id === userWatchlistId)
Expand All @@ -281,8 +286,13 @@ const kyberAIApi = createApi({
}
}),
)
try {
await queryFulfilled
} catch {
patchResult.undo()
}
},
invalidatesTags: ['watchlistsInfo'],
invalidatesTags: (result, error) => (error ? [] : ['watchlistsInfo']),
}),
//21.
createCustomWatchlist: builder.mutation({
Expand Down
4 changes: 2 additions & 2 deletions src/pages/TrueSightV2/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ export enum KyberAIListType {
TOP_CEX_OUTFLOW = 'top_cex_outflow',
TOP_TRADED = 'top_traded',
TRENDING_SOON = 'trendingsoon',
FUNDING_RATE = 'funding_rate_asc',
KYBERSWAP_DELTA = 'kyber_score_delta_asc',
FUNDING_RATE = 'funding_rate',
KYBERSWAP_DELTA = 'kyber_score_delta',
}

export type QueryTokenParams = {
Expand Down

0 comments on commit e061d22

Please sign in to comment.