From 0e75c94a8b22adf20ad2d330c6713bb094480ae3 Mon Sep 17 00:00:00 2001 From: abdegenius Date: Tue, 15 Oct 2024 13:35:41 +0100 Subject: [PATCH 1/3] Updates --- src/store/protocols.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/store/protocols.ts b/src/store/protocols.ts index b9504d7..a970550 100644 --- a/src/store/protocols.ts +++ b/src/store/protocols.ts @@ -217,7 +217,11 @@ const SORT_OPTIONS = ['DEFAULT', 'APR', 'TVL', 'RISK'] as const; export const sortAtom = atom>([ { - field: SORT_OPTIONS[0], + field: SORT_OPTIONS[1], + order: 'desc', + }, + { + field: SORT_OPTIONS[3], order: 'asc', }, ]); @@ -241,6 +245,12 @@ export const sortPoolsAtom = atom((get) => { : Math.round(b.additional.riskFactor) - Math.round(a.additional.riskFactor); } + // else { + // result = + // sortItem.order === 'asc' + // ? b.apr - a.apr + // : a.additional.riskFactor - b.additional.riskFactor; + // } if (result !== 0) return result; } return 0; From 4f5509f081448d5f8f9b8096661f5e5ecbc5274c Mon Sep 17 00:00:00 2001 From: abdegenius Date: Tue, 15 Oct 2024 13:45:35 +0100 Subject: [PATCH 2/3] Updates --- src/store/protocols.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/store/protocols.ts b/src/store/protocols.ts index a970550..15a9f62 100644 --- a/src/store/protocols.ts +++ b/src/store/protocols.ts @@ -215,7 +215,7 @@ export const allPoolsAtomWithStrategiesUnSorted = atom((get) => { const SORT_OPTIONS = ['DEFAULT', 'APR', 'TVL', 'RISK'] as const; -export const sortAtom = atom>([ +const defaultSortAtom = atom>([ { field: SORT_OPTIONS[1], order: 'desc', @@ -226,10 +226,19 @@ export const sortAtom = atom>([ }, ]); +export const sortAtom = atom>([ + // { + // field: SORT_OPTIONS[0], + // order: 'asc', + // }, +]); + export const sortPoolsAtom = atom((get) => { const sort = get(sortAtom); + const default_sort = get(defaultSortAtom); const pools = get(allPoolsAtomWithStrategiesUnSorted); - const sortCriteria = [...sort].reverse(); + const sortCriteria = + sort.length > 0 ? [...sort].reverse() : [...default_sort].reverse(); const sortedPools = [...pools].sort((a, b) => { for (const sortItem of sortCriteria) { let result = 0; @@ -245,18 +254,10 @@ export const sortPoolsAtom = atom((get) => { : Math.round(b.additional.riskFactor) - Math.round(a.additional.riskFactor); } - // else { - // result = - // sortItem.order === 'asc' - // ? b.apr - a.apr - // : a.additional.riskFactor - b.additional.riskFactor; - // } if (result !== 0) return result; } return 0; }); - // localStorage.setItem('sort', JSON.stringify(sortCriteria)); - return sortedPools; }); From f3c8c74804487b716ead80e62f4a5a0972fc2709 Mon Sep 17 00:00:00 2001 From: abdegenius Date: Tue, 15 Oct 2024 14:10:06 +0100 Subject: [PATCH 3/3] Updates --- src/components/Pools.tsx | 23 ++++++++++++++++++----- src/components/YieldCard.tsx | 13 +++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/components/Pools.tsx b/src/components/Pools.tsx index a9190b6..9fcf1a3 100755 --- a/src/components/Pools.tsx +++ b/src/components/Pools.tsx @@ -48,12 +48,22 @@ export default function Pools() { }, [_filteredPools, currentPage, sort]); const handleSortChange = (field: string) => (order: 'asc' | 'desc') => { - setSort((prev) => { - const updatedSort = prev.filter((s) => s.field !== field); - return [...updatedSort, { field, order }]; - }); + if (field == 'RISK') { + setSort((prev) => { + const updatedSort = prev.filter((s) => s.field !== field); + return [...updatedSort, { field, order }]; + }); + } else if (field == 'APR' || field == 'TVL') { + const riskIndex = sort.findIndex((s) => s.field === 'RISK'); + const new_sort: any = []; + if (riskIndex >= 0) { + new_sort.push({ field: 'RISK', order: sort[riskIndex].order }); + } + new_sort.push({ field, order }); + setSort(new_sort); + } + localStorage.setItem('sort', JSON.stringify(sort)); }; - return ( @@ -113,6 +123,7 @@ export default function Pools() { mainColor="color2Text" inActiveColor="#d9d9f726" onClick={handleSortChange('APR')} + // disabled={false} /> @@ -121,6 +132,7 @@ export default function Pools() { mainColor="color2Text" inActiveColor="#d9d9f726" onClick={handleSortChange('RISK')} + // disabled={false} /> @@ -129,6 +141,7 @@ export default function Pools() { mainColor="color2Text" inActiveColor="#d9d9f726" onClick={handleSortChange('TVL')} + // disabled={false} /> diff --git a/src/components/YieldCard.tsx b/src/components/YieldCard.tsx index 8e774e6..11a3042 100644 --- a/src/components/YieldCard.tsx +++ b/src/components/YieldCard.tsx @@ -529,6 +529,7 @@ export function HeaderSorter(props: { mainColor: string; inActiveColor: string; onClick: (order: 'asc' | 'desc') => void; + disabled?: boolean; }) { const [isAscending, setIsAscending] = useState(false); const [isDescending, setIsDescending] = useState(false); @@ -555,10 +556,18 @@ export function HeaderSorter(props: { {props.heading.toUpperCase()}