Skip to content

Commit

Permalink
Merge pull request #135 from QuickSwap/hotfix/move-minus-time-syrup-e…
Browse files Browse the repository at this point in the history
…nded

Move syrups with minus time remaining to ended
  • Loading branch information
sameepsi authored Apr 29, 2022
2 parents c2d20d8 + c0026c2 commit 36a643f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
11 changes: 5 additions & 6 deletions src/pages/DragonPage/DragonsSyrup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const EARNED_COLUMN = 4;
const DragonsSyrup: React.FC = () => {
const { palette, breakpoints } = useTheme();
const isMobile = useMediaQuery(breakpoints.down('xs'));
const [pageLoading, setPageLoading] = useState(false); //this is used for not loading syrups immediately when user is on dragons page
const [isEndedSyrup, setIsEndedSyrup] = useState(false);
const [pageIndex, setPageIndex] = useState(0);
const [sortBy, setSortBy] = useState(0);
Expand All @@ -49,14 +48,14 @@ const DragonsSyrup: React.FC = () => {

const addedStakingSyrupInfos = useSyrupInfo(
null,
pageLoading || isEndedSyrup ? 0 : undefined,
pageLoading || isEndedSyrup ? 0 : undefined,
isEndedSyrup ? 0 : undefined,
isEndedSyrup ? 0 : undefined,
{ search: syrupSearch, isStaked: stakedOnly },
);
const addedOldSyrupInfos = useOldSyrupInfo(
null,
pageLoading || isEndedSyrup ? undefined : 0,
pageLoading || isEndedSyrup ? undefined : 0,
isEndedSyrup ? undefined : 0,
isEndedSyrup ? undefined : 0,
{ search: syrupSearch, isStaked: stakedOnly },
);

Expand Down Expand Up @@ -306,7 +305,7 @@ const DragonsSyrup: React.FC = () => {
))}
</Box>
)}
{syrupInfos && !pageLoading ? (
{syrupInfos ? (
syrupInfos.map((syrup, ind) => (
<SyrupCard key={ind} syrup={syrup} dQUICKAPY={dQUICKAPY} />
))
Expand Down
70 changes: 35 additions & 35 deletions src/state/stake/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
CurrencyAmount,
JSBI,
Token,
TokenAmount,
Price,
Pair,
} from '@uniswap/sdk';
import { CurrencyAmount, JSBI, Token, TokenAmount, Pair } from '@uniswap/sdk';
import dayjs from 'dayjs';
import { useMemo, useEffect /** , useState */ } from 'react';
import { usePairs } from 'data/Reserves';
Expand Down Expand Up @@ -188,23 +181,22 @@ export function useSyrupInfo(
filter?: { search: string; isStaked: boolean },
): SyrupInfo[] {
const { chainId, account } = useActiveWeb3React();
const currentTimestamp = dayjs().unix();

const info = useMemo(
() =>
chainId
? returnSyrupInfo()
[chainId]?.slice(startIndex, endIndex)
.filter((stakingRewardInfo) =>
tokenToFilterBy === undefined || tokenToFilterBy === null
? getSearchFiltered(
stakingRewardInfo,
filter ? filter.search : '',
)
: tokenToFilterBy.equals(stakingRewardInfo.token) &&
tokenToFilterBy.equals(stakingRewardInfo.token),
.filter(
(syrupInfo) =>
syrupInfo.ending > currentTimestamp &&
(tokenToFilterBy === undefined || tokenToFilterBy === null
? getSearchFiltered(syrupInfo, filter ? filter.search : '')
: tokenToFilterBy.equals(syrupInfo.token)),
) ?? []
: [],
[chainId, tokenToFilterBy, startIndex, endIndex, filter],
[chainId, tokenToFilterBy, startIndex, endIndex, filter, currentTimestamp],
);

const uni = chainId ? GlobalValue.tokens.UNI[chainId] : undefined;
Expand Down Expand Up @@ -392,23 +384,31 @@ export function useOldSyrupInfo(
filter?: { search: string; isStaked: boolean },
): SyrupInfo[] {
const { chainId, account } = useActiveWeb3React();
const info = useMemo(
() =>
chainId
? returnSyrupInfo(true)
[chainId]?.slice(startIndex, endIndex)
?.filter((stakingRewardInfo) =>
tokenToFilterBy === undefined || tokenToFilterBy === null
? getSearchFiltered(
stakingRewardInfo,
filter ? filter.search : '',
)
: tokenToFilterBy.equals(stakingRewardInfo.token) &&
tokenToFilterBy.equals(stakingRewardInfo.token),
) ?? []
: [],
[chainId, tokenToFilterBy, startIndex, endIndex, filter],
);
const currentTimestamp = dayjs().unix();

const info = useMemo(() => {
if (!chainId) return [];
const endedSyrupInfos =
returnSyrupInfo(false)[chainId]?.filter(
(syrupInfo) => syrupInfo.ending <= currentTimestamp,
) ?? [];
const oldSyrupInfos = returnSyrupInfo(true)[chainId] ?? [];
const allOldSyrupInfos = endedSyrupInfos.concat(oldSyrupInfos);
return allOldSyrupInfos
.slice(startIndex, endIndex)
.filter((syrupInfo) =>
tokenToFilterBy === undefined || tokenToFilterBy === null
? getSearchFiltered(syrupInfo, filter ? filter.search : '')
: tokenToFilterBy.equals(syrupInfo.token),
);
}, [
chainId,
tokenToFilterBy,
startIndex,
endIndex,
filter,
currentTimestamp,
]);

const uni = chainId ? GlobalValue.tokens.UNI[chainId] : undefined;

Expand Down Expand Up @@ -539,7 +539,7 @@ export function useOldSyrupInfo(
memo.push({
stakingRewardAddress: rewardsAddress,
token: syrupInfo.token,
ended: syrupInfo.ended,
ended: true,
name: syrupInfo.name,
lp: syrupInfo.lp,
periodFinish: periodFinishMs,
Expand Down

0 comments on commit 36a643f

Please sign in to comment.