Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: add better transition for numbers in rewards pool #3064

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const TotalRewardsInfo: FC<TotalRewardsInfoProps> = ({ totalRewards }) => {
setCurrentIndex(prevIndex => {
const nextIndex = (prevIndex + 1) % totalRewards.length;
setAnimate(true);
setTimeout(() => setAnimate(false), 1000);
setTimeout(() => setAnimate(false), 500);
return nextIndex;
});
}, 1500);
}, 1000);

return () => clearInterval(interval);
} else if (totalRewards.length === 1) {
Expand All @@ -33,7 +33,7 @@ const TotalRewardsInfo: FC<TotalRewardsInfoProps> = ({ totalRewards }) => {
return (
<div className="w-fit max-w-full">
<div className="flex h-8 px-2 md:px-4 items-center bg-transparent border border-neutral-10 rounded-[10px] text-[16px] font-bold text-positive-11">
<div className={`flex items-center gap-1 ${animate ? "animate-reveal" : ""}`}>
<div className={`flex items-center gap-1 ${animate ? "animate-flicker-number" : ""}`}>
<p>{formatBalance(formatUnits(currentReward.totalAmount, currentReward.decimals).toString())}</p>{" "}
<p className="uppercase">${currentReward.symbol}</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ const ContestRewardsInfoMobile: FC<ContestRewardsInfoMobileProps> = ({ rewardsMo
setCurrentIndex(prevIndex => {
const nextIndex = (prevIndex + 1) % totalRewards.length;
setAnimate(true);
setTimeout(() => setAnimate(false), 1000);
setTimeout(() => setAnimate(false), 500);
return nextIndex;
});
}, 1500);
}, 1000);

return () => clearInterval(interval);
} else if (totalRewards.length === 1) {
Expand All @@ -120,9 +120,9 @@ const ContestRewardsInfoMobile: FC<ContestRewardsInfoMobileProps> = ({ rewardsMo
className={`flex shrink-0 h-8 p-2 justify-center items-center bg-transparent border border-neutral-10 rounded-[10px] text-[16px] font-bold text-positive-11 overflow-hidden`}
>
<span className="truncate flex items-center">
<div className={`flex items-center ${animate ? "animate-reveal" : ""}`}>
{formatBalance(currentRewardAmount)} $
<span className="uppercase mr-1 truncate inline-block overflow-hidden">{currentReward.symbol}</span>
<div className={`flex items-center gap-1 ${animate ? "animate-flicker-number" : ""}`}>
<p>{formatBalance(currentRewardAmount)}</p>
<p className="uppercase">${currentReward.symbol}</p>
</div>
</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ const ContestRewardsInfo: FC<ContestRewardsInfoProps> = ({ rewardsModuleAddress,
setCurrentIndex(prevIndex => {
const nextIndex = (prevIndex + 1) % flattenedRewards.length;
setAnimate(true);
setTimeout(() => setAnimate(false), 1000);
setTimeout(() => setAnimate(false), 500);
return nextIndex;
});
}, 1500);
}, 1000);

return () => clearInterval(interval);
} else if (flattenedRewards.length === 1) {
Expand Down Expand Up @@ -117,11 +117,11 @@ const ContestRewardsInfo: FC<ContestRewardsInfoProps> = ({ rewardsModuleAddress,
className={`flex shrink-0 h-8 min-w-60 p-4 justify-center items-center bg-transparent border border-neutral-10 rounded-[10px] text-[16px] font-bold text-positive-11 overflow-hidden`}
>
<span className="truncate flex items-center">
<div className={`flex items-center ${animate ? "animate-reveal" : ""}`}>
{formatBalance(currentRewardAmount)} $
<span className="uppercase mr-1 truncate inline-block overflow-hidden">{currentReward.symbol}</span>
<div className={`flex items-center gap-1 ${animate ? "animate-flicker-number" : ""}`}>
<p>{formatBalance(currentRewardAmount)}</p>
<p className="uppercase">${currentReward.symbol}</p>
</div>
<span>
<span className="ml-1">
{currentReward.isReleased ? "paid to" : "to"} {currentReward.ranking}
{returnOnlySuffix(currentReward.ranking)}
</span>{" "}
Expand Down
12 changes: 10 additions & 2 deletions packages/react-app-revamp/helpers/formatBalance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import BigNumber from "bignumber.js";

const MIN_VALUE_FOR_COMMA_SEPARATION = 1000;

export function formatBalance(balance: string): string {
const num = new BigNumber(balance);

Expand All @@ -19,6 +21,12 @@ export function formatBalance(balance: string): string {
}

// handle numbers >= 0.001
// truncate to 3 decimal places without rounding
return num.decimalPlaces(3, BigNumber.ROUND_FLOOR).toString();
const truncated = num.decimalPlaces(3, BigNumber.ROUND_FLOOR);

// add comma separators only for numbers >= 1000
if (truncated.abs().isGreaterThanOrEqualTo(MIN_VALUE_FOR_COMMA_SEPARATION)) {
return truncated.toFormat();
}

return truncated.toString();
}
6 changes: 6 additions & 0 deletions packages/react-app-revamp/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ module.exports = {
opacity: "1",
},
},
"flicker-number": {
"0%": { opacity: "1" },
"50%": { opacity: "0" },
"100%": { opacity: "1" },
},
},
scale: {
120: "1.1",
Expand All @@ -335,6 +340,7 @@ module.exports = {
flicker: "flicker 1s linear",
"flicker-infinite": "flicker 1s linear infinite",
reveal: "reveal 1s ease-in-out",
"flicker-number": "flicker-number 0.5s infinite",
},

height: {
Expand Down
Loading