Skip to content

Commit

Permalink
feat(fix): Render timeleft on end time update (#2320)
Browse files Browse the repository at this point in the history
  • Loading branch information
rossbulat authored Nov 7, 2024
1 parent f55229f commit fd7c52b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useEraTimeLeft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useEraTimeLeft = () => {
? new BigNumber(0)
: new BigNumber(100).minus(percentRemaining);

return { timeleft, percentSurpassed, percentRemaining };
return { timeleft, end, percentSurpassed, percentRemaining };
};

return { get };
Expand Down
7 changes: 4 additions & 3 deletions src/pages/Overview/Stats/ActiveEraTimeLeft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ export const ActiveEraStat = () => {
const { get: getEraTimeleft } = useEraTimeLeft();
const { timeleft, setFromNow } = useTimeLeft();

const timeleftResult = getEraTimeleft();
const dateFrom = fromUnixTime(Date.now() / 1000);
const dateTo = fromNow(getEraTimeleft().timeleft.toNumber());
const dateTo = fromNow(timeleftResult.timeleft.toNumber());

// re-set timer on era change (also covers network change).
useEffect(() => {
setFromNow(dateFrom, dateTo);
}, [activeEra]);
}, [activeEra, timeleftResult.end.toString()]);

// NOTE: this maybe should be called in an interval. Needs more testing.
const { percentSurpassed, percentRemaining } = getEraTimeleft();
const { percentSurpassed, percentRemaining } = timeleftResult;

const params = {
label: t('overview.timeRemainingThisEra'),
Expand Down

0 comments on commit fd7c52b

Please sign in to comment.