Skip to content

Commit

Permalink
TW-830: Collectibles Manage dropdown. Fix QA. 2 decimals for unletter…
Browse files Browse the repository at this point in the history
…ed numbers
  • Loading branch information
alex-tsx committed Jul 10, 2023
1 parent 4b72ec6 commit 9c7b2f7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion public/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@
"message": "Es wurden keine passenden dApps gefunden"
},
"thousandFormat": {
"message": "$thousand$k",
"message": "$thousand$K",
"placeholders": {
"thousand": {
"content": "$1"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@
"message": "No matching dApps were found"
},
"thousandFormat": {
"message": "$thousand$k",
"message": "$thousand$K",
"placeholders": {
"thousand": {
"content": "$1"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/pt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@
"message": "Não foram encontrados dApps correspondentes"
},
"thousandFormat": {
"message": "$thousand$k",
"message": "$thousand$K",
"placeholders": {
"thousand": {
"content": "$1"
Expand Down
2 changes: 1 addition & 1 deletion public/_locales/tr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@
"message": "Eşleşen dApps bulunamadı"
},
"thousandFormat": {
"message": "$thousand$k",
"message": "$thousand$K",
"placeholders": {
"thousand": {
"content": "$1"
Expand Down
2 changes: 1 addition & 1 deletion src/app/atoms/Money.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Money = memo<MoneyProps>(
);
}

if (!fiat && decimalsLength > cryptoDecimals && !shortened) {
if (!fiat && !shortened && decimalsLength > cryptoDecimals) {
return (
<MoneyWithoutFormat
tooltip={tooltip}
Expand Down
20 changes: 12 additions & 8 deletions src/lib/i18n/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,23 @@ export function toLocalFixed(value: BigNumber.Value, decimalPlaces?: number, rou

export function toShortened(value: BigNumber.Value) {
let bn = new BigNumber(value);
if (bn.abs().lt(1)) {
return toLocalFixed(bn.toPrecision(1));
}
const target = bn.abs().decimalPlaces(2);

if (target.lt(0.01)) return toLocalFixed(bn.toPrecision(2));

if (target.lt(10_000)) return toLocalFixed(bn, 2);

bn = bn.integerValue();

const formats: TID[] = ['thousandFormat', 'millionFormat', 'billionFormat'];

let formatIndex = -1;
while (bn.abs().gte(1000) && formatIndex < formats.length - 1) {
formatIndex++;
bn = bn.div(1000);
}
bn = bn.decimalPlaces(1, BigNumber.ROUND_FLOOR);
if (formatIndex === -1) {
return toLocalFixed(bn);
}
return t(formats[formatIndex], toLocalFixed(bn));

if (formatIndex === -1) return toLocalFixed(bn, 2);

return t(formats[formatIndex], toLocalFixed(bn, 0));
}

0 comments on commit 9c7b2f7

Please sign in to comment.