From 2fd8ce7146010d2695f296feebb866e5cdcf9214 Mon Sep 17 00:00:00 2001 From: Px <> Date: Thu, 15 Jul 2021 12:44:11 +0200 Subject: [PATCH] Fix max-timelock issue #118 --- src/components/Farming/Deposit/index.js | 10 ++++++++-- src/components/Farming/DepositModal/index.js | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Farming/Deposit/index.js b/src/components/Farming/Deposit/index.js index e2721927..22668866 100644 --- a/src/components/Farming/Deposit/index.js +++ b/src/components/Farming/Deposit/index.js @@ -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() @@ -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 } diff --git a/src/components/Farming/DepositModal/index.js b/src/components/Farming/DepositModal/index.js index c21b1c10..e5cdcae2 100644 --- a/src/components/Farming/DepositModal/index.js +++ b/src/components/Farming/DepositModal/index.js @@ -200,6 +200,7 @@ const DepositModal = props => { amount={amount} days={days} maxDays={maxDays} + startTime={props.poolInfo.startTime} // time farming started onTransactionComplete={handleTransactionComplete} onError={handleError} />