Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Refactor claim timestamp hooks (#2127)
Browse files Browse the repository at this point in the history
* New hook useInvestmentDeadline

* New hook useAirdropDeadline

* Refactoring out the unnecessary ternary operators

Co-authored-by: Leandro <[email protected]>
  • Loading branch information
alfetopito and Leandro authored Jan 13, 2022
1 parent f2765ea commit 51cde4f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/custom/state/claim/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,42 @@ function useDeploymentTimestamp(): number | null {
return timestamp
}

/**
* Returns the timestamp of when the investment window closes
*/
export function useInvestmentDeadline(): number | null {
const deploymentTimestamp = useDeploymentTimestamp()

return deploymentTimestamp && deploymentTimestamp + TWO_WEEKS
}

/**
* Returns whether vCOW contract is still open for investments
* Null when not applicable
*
* That is, there has been less than 2 weeks since it was deployed
*/
export function useInvestmentStillAvailable(): boolean {
const investmentDeadline = useInvestmentDeadline()

return Boolean(investmentDeadline && investmentDeadline > Date.now())
}

/**
* Returns the timestamp of when the airdrop window closes
*/
export function useAirdropDeadline(): number | null {
const deploymentTimestamp = useDeploymentTimestamp()

return Boolean(deploymentTimestamp && deploymentTimestamp + TWO_WEEKS > Date.now())
return deploymentTimestamp && deploymentTimestamp + SIX_WEEKS
}

/**
* Returns whether vCOW contract is still open for airdrops
* Null when not applicable
*
* That is, there has been less than 6 weeks since it was deployed
*/
export function useAirdropStillAvailable(): boolean {
const deploymentTimestamp = useDeploymentTimestamp()
const airdropDeadline = useAirdropDeadline()

return Boolean(deploymentTimestamp && deploymentTimestamp + SIX_WEEKS > Date.now())
return Boolean(airdropDeadline && airdropDeadline > Date.now())
}

/**
Expand Down

0 comments on commit 51cde4f

Please sign in to comment.