From 186d8cd09ab8248a2bdca4535bcc20befef7278f Mon Sep 17 00:00:00 2001 From: viet-nv Date: Tue, 18 Jul 2023 12:18:49 +0700 Subject: [PATCH] fix: display vesting time issue --- src/components/Vesting/RewardLockerSchedules.tsx | 7 +++++-- src/components/Vesting/VestingCard.tsx | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/Vesting/RewardLockerSchedules.tsx b/src/components/Vesting/RewardLockerSchedules.tsx index 2fb6d44de9..fa65d6c21d 100644 --- a/src/components/Vesting/RewardLockerSchedules.tsx +++ b/src/components/Vesting/RewardLockerSchedules.tsx @@ -2,6 +2,7 @@ import { BigNumber } from '@ethersproject/bignumber' import { Token } from '@kyberswap/ks-sdk-core' import { ZERO_ADDRESS } from 'constants/index' +import { EVMNetworkInfo } from 'constants/networks/type' import { NativeCurrencies } from 'constants/tokens' import { useActiveWeb3React } from 'hooks' import useMixpanel, { MIXPANEL_TYPE } from 'hooks/useMixpanel' @@ -28,7 +29,7 @@ const RewardLockerSchedules = ({ const dispatch = useAppDispatch() const currentBlockNumber = useBlockNumber() const currentTimestamp = Math.round(Date.now() / 1000) - const { account, chainId } = useActiveWeb3React() + const { account, chainId, networkInfo } = useActiveWeb3React() const { vestMultipleTokensAtIndices } = useVesting(rewardLockerAddress) const { mixpanelHandler } = useMixpanel() if (!schedules) { @@ -173,6 +174,8 @@ const RewardLockerSchedules = ({ return acc }, currentBlockNumber) + const blockDiff = (maxEndBlock || 0) - (currentBlockNumber || 0) + const endTimestampFromBlock = useTimestampFromBlock(maxEndBlock) const endTime = schedules.reduce((acc, cur) => { @@ -183,7 +186,7 @@ const RewardLockerSchedules = ({ } return acc - }, endTimestampFromBlock || 0) + }, endTimestampFromBlock || currentTimestamp + blockDiff * ((networkInfo as EVMNetworkInfo).averageBlockTimeInSeconds || 0)) return } diff --git a/src/components/Vesting/VestingCard.tsx b/src/components/Vesting/VestingCard.tsx index b51b06e990..20c677bc1d 100644 --- a/src/components/Vesting/VestingCard.tsx +++ b/src/components/Vesting/VestingCard.tsx @@ -17,7 +17,7 @@ import { formatDollarAmount } from 'utils/numbers' const formatRemainTime = (numberOfSeconds: number) => { if (numberOfSeconds < 0) return t`Full unlocked` const days = numberOfSeconds / 60 / 60 / 24 - if (days > 1) return days + ' Days left' + if (days > 1) return days.toFixed(2) + ' Days left' const hours = numberOfSeconds / 60 / 60 if (hours < 24 && hours > 1) return hours.toFixed(0) + ' Hours left'