Skip to content

Commit

Permalink
refactor: improve counter (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor authored Nov 22, 2023
1 parent 6ed9d40 commit 5314348
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const StatsCard = ({ title, stats }: any) => {
<Typography variant="h3">{convertToMoney(counterValue)}</Typography>
)}
{title === t("supporting networks") && (
<Typography variant="h3">{convertToMoney(counterValue)}</Typography>
<Typography variant="h3">
{Math.floor(counterValue as number)}
</Typography>
)}
</Box>
);
Expand Down
8 changes: 6 additions & 2 deletions src/screens/staking/components/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ export const useCounter = (targetValue: unknown) => {
if (typeof targetValue === "number") {
setCounterValue(0);

divisor.current = Math.ceil(targetValue / 200);
divisor.current = targetValue * (targetValue > 100 ? 0.01 : 0.006);

clearInterval();

let pending = false;
intervalId.current = window.setInterval(() => {
if (pending) return;
pending = true;
window.requestAnimationFrame(() => {
pending = false;
setCounterValue((prev: unknown) => {
if (
typeof prev !== "number" ||
Expand All @@ -44,7 +48,7 @@ export const useCounter = (targetValue: unknown) => {
return newValue;
});
});
}, 16);
});
} else {
setCounterValue(targetValue);
}
Expand Down

0 comments on commit 5314348

Please sign in to comment.