Skip to content

Commit

Permalink
time fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Aug 22, 2023
1 parent 20b4552 commit 64f42ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
31 changes: 24 additions & 7 deletions src/sections/yield/YieldStatsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,46 @@ const YieldStatsSection = ({

const [formattedDuration, setFormattedDuration] = React.useState('');

const [epochEndTime,setEpochEndTime] = React.useState<number>();

const calculateEpochEndDuration = () =>{
const epochEndSeconds = poolStats.epochEndTime;
const epochEndTimeStamp = new Date().getTime() + epochEndSeconds * 1000;
setEpochEndTime(epochEndTimeStamp);

}

React.useEffect(()=>{
if(poolStats){
calculateEpochEndDuration()
}

},[poolStats])

const getFormattedDuration = () => {
if (poolStats?.epochEndTimestamp) {
const epochEndTimestamp = poolStats.epochEndTimestamp.toNumber();

const duration = epochEndTimestamp - Math.floor(new Date() / 1000);
const now = new Date().getTime();
const timeRemaining = epochEndTime - now;

if (duration < 0) {
if (timeRemaining < 0) {
setPoolStats(null);
getLpPoolStats();
}

const day = parseInt(duration / 86400);
const hour = parseInt((duration - day * 86400) / 3600);

const minutes = parseInt((duration - (day * 86400 + hour * 3600)) / 60);
const seconds = duration - (day * 86400 + hour * 3600 + minutes * 60);
const day = Math.floor(timeRemaining / (1000 * 60 * 60 * 24));
const hour = Math.floor((timeRemaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);

setFormattedDuration(`${day}D ${hour}H ${minutes}M ${seconds}S`);
}
};

React.useEffect(() => {
setTimeout(() => {
console.log("Running")
getFormattedDuration();
}, 1000);
});
Expand Down
21 changes: 16 additions & 5 deletions src/singletons/YieldFarmingDataStoreV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class YieldFarmingDataStoreV2 {
// init
init = (account, staking, pushToken, pushCoreV2, yieldFarmingLP, uniswapV2Router02) => {
// set account
this.state.account = account;
this.state.account = account;
this.state.staking = staking;
this.state.pushToken = pushToken;
this.state.pushCoreV2 = pushCoreV2;
Expand Down Expand Up @@ -106,11 +106,21 @@ export default class YieldFarmingDataStoreV2 {
const pushStakedAmount = tokenBNtoNumber(await pushCoreV2.totalStakedAmount());
const totalValueLocked = pushStakedAmount * pushPrice + lpNextPoolSize * uniLpPrice;


//calculating epoch Duration
const epochDuration = await yieldFarmingLP.epochDuration();
const epochDurations = await yieldFarmingLP.epochDuration();
const epochStart = await yieldFarmingLP.epochStart();
const start = epochStart.add(currentEpochLP.sub(1).mul(epochDuration));
const epochEndTimestamp = start.add(epochDuration);
const start = epochStart.add(currentEpochLP.sub(1).mul(epochDurations));
const epochEndTimestamp = start.add(epochDurations);


let currentBlockNumber = await provider.getBlock('latest');
currentBlockNumber = currentBlockNumber.number;
const genesisEpoch = await pushCoreV2.genesisEpoch();
const epochDuration = await pushCoreV2.epochDuration();
const remainingBlocks = epochDuration.toNumber() - ( (currentBlockNumber - genesisEpoch.toNumber() ) % epochDuration.toNumber() ) ;
let epochEndTime = (remainingBlocks * 12.6)+3600;
epochEndTime = Math.round(epochEndTime);

//calculation total distributed amount
const pushTotalDistributedAmount = tokenToBn(ethers.BigNumber.from(this.state.annualPushReward));
Expand All @@ -124,6 +134,7 @@ export default class YieldFarmingDataStoreV2 {
pushPrice,
lpToPushRatio,
epochEndTimestamp,
epochEndTime,
totalValueLocked,
totalDistributedAmount,
pushRewardsDistributed,
Expand Down Expand Up @@ -510,4 +521,4 @@ export default class YieldFarmingDataStoreV2 {
// };


}
}

0 comments on commit 64f42ce

Please sign in to comment.