fix(xp): hide decimal point if displayed xp is < 1000 (NadAlaba) (#5448)

* fix(xp): hide the decimal point if displayed xp is an integer < 1000 (NadAlaba)

* fix tests to match new rounding behavior

* if you failed the test change the test

* revert abbreviateNumber() and test changes and move previous changes to formatXp()
This commit is contained in:
Nad Alaba 2024-05-29 15:48:54 +03:00 committed by GitHub
parent 05d6160b2a
commit 2c0002c919
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -300,19 +300,13 @@ export async function update(
details
.find(".level")
.text(xpDetails.level)
.attr("aria-label", `${Numbers.abbreviateNumber(xp)} total xp`);
.attr("aria-label", `${formatXp(xp)} total xp`);
details
.find(".xp")
.text(
`${Numbers.abbreviateNumber(xpToDisplay)}/${Numbers.abbreviateNumber(
xpForLevel
)}`
)
.text(`${formatXp(xpToDisplay)}/${formatXp(xpForLevel)}`)
.attr(
"aria-label",
`${Numbers.abbreviateNumber(
xpForLevel - xpToDisplay
)} xp until next level`
`${formatXp(xpForLevel - xpToDisplay)} xp until next level`
);
details
.find(".xpBar .bar")
@ -445,3 +439,11 @@ function formatTopPercentage(lbRank: SharedTypes.RankAndCount): string {
if (lbRank.rank === 1) return "GOAT";
return "Top " + Numbers.roundTo2((lbRank.rank / lbRank.count) * 100) + "%";
}
function formatXp(xp: number): string {
if (xp < 1000) {
return Math.round(xp).toString();
} else {
return Numbers.abbreviateNumber(xp);
}
}