Skip to content

Commit

Permalink
fix: display vesting time issue
Browse files Browse the repository at this point in the history
  • Loading branch information
viet-nv committed Jul 18, 2023
1 parent 0a07d22 commit 186d8cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/Vesting/RewardLockerSchedules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand All @@ -183,7 +186,7 @@ const RewardLockerSchedules = ({
}

return acc
}, endTimestampFromBlock || 0)
}, endTimestampFromBlock || currentTimestamp + blockDiff * ((networkInfo as EVMNetworkInfo).averageBlockTimeInSeconds || 0))

return <VestingCard info={info} endTime={endTime} remainTime={endTime - currentTimestamp} onClaimAll={onClaimAll} />
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Vesting/VestingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 186d8cd

Please sign in to comment.