Skip to content

Commit

Permalink
Fix max-timelock issue 1Hive#118
Browse files Browse the repository at this point in the history
  • Loading branch information
Px committed Jul 15, 2021
1 parent 1b4969b commit 2fd8ce7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/Farming/Deposit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Deposit = props => {
} = useWallet()
const [visible, setVisible] = useState(false)
const [txHash, setTxHash] = useState('')
const { token, amount, days, maxDays, referrer } = props
const { token, amount, days, maxDays, referrer, startTime } = props
const network = getNetworkConfig(chainId)

const opener = useRef()
Expand All @@ -19,19 +19,25 @@ const Deposit = props => {
const transactionTime = new Date()
transactionTime.setSeconds(transactionTime.getSeconds() + 8)

// get the time farming started to calculated lock time correctly
var startDate = new Date(startTime * 1000)
var hours = startDate.getHours()
var minutes = startDate.getMinutes()

const calculateUnlockTimestamp = days => {
if (days === 0 || !days) {
return 0
}

const date = new Date()
date.setUTCHours(hours, minutes, 0, 0)
let unlockTimestamp = Math.floor(date.setDate(date.getDate() + days) / 1000)
// add or remove 100 seconds on the max/min value to cover for rounding errors
if (days === 1) {
unlockTimestamp += 100
}
if (days === maxDays) {
unlockTimestamp -= 100
unlockTimestamp -= 1000
}
return unlockTimestamp
}
Expand Down
1 change: 1 addition & 0 deletions src/components/Farming/DepositModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const DepositModal = props => {
amount={amount}
days={days}
maxDays={maxDays}
startTime={props.poolInfo.startTime} // time farming started
onTransactionComplete={handleTransactionComplete}
onError={handleError}
/>
Expand Down

0 comments on commit 2fd8ce7

Please sign in to comment.