diff --git a/packages/extension-koni-ui/src/Popup/Home/Airdrop/index.tsx b/packages/extension-koni-ui/src/Popup/Home/Airdrop/index.tsx index 6dd0db33ec..e6f5969890 100644 --- a/packages/extension-koni-ui/src/Popup/Home/Airdrop/index.tsx +++ b/packages/extension-koni-ui/src/Popup/Home/Airdrop/index.tsx @@ -23,24 +23,41 @@ const AirdropComponent: React.FC = ({ className }) => { const [airdropCampaign, setAirdropCampaign] = useState(apiSDK.airdropCampaignList); const orderAirdropCampaign = useMemo(() => { - return [...airdropCampaign].sort((a, b) => { - if (a.start === null && b.start === null) { - return 0; + const futureList: AirdropCampaign[] = []; + const nowList: AirdropCampaign[] = []; + const pastList: AirdropCampaign[] = []; + + airdropCampaign.forEach((campaign) => { + const now = Date.now(); + const start = new Date(campaign.start).getTime(); + const end = new Date(campaign.end).getTime(); + + if (now < start) { + futureList.push(campaign); + } else if (now > end) { + pastList.push(campaign); + } else { + nowList.push(campaign); } + }); - if (a.start === null) { - return -1; + function sortByStart (a: AirdropCampaign, b: AirdropCampaign) { + if (!a.start || !b.start) { + return 0; } - if (b.start === null) { - return 1; + return new Date(a.start).getTime() - new Date(b.start).getTime(); + } + + function sortByStartDesc (a: AirdropCampaign, b: AirdropCampaign) { + if (!a.start || !b.start) { + return 0; } - const aTime = new Date(a.end).getTime(); - const bTime = new Date(b.end).getTime(); + return new Date(b.start).getTime() - new Date(a.start).getTime(); + } - return bTime - aTime; - }); + return [...nowList.sort(sortByStartDesc), ...futureList.sort(sortByStart), ...pastList]; }, [airdropCampaign]); const onExplore = useCallback((campaignId: number) => {