improve short format for balance credits >1K and >1M (#184)
This commit is contained in:
parent
d902e0e576
commit
91f0e2ab54
2 changed files with 34 additions and 10 deletions
21
dist/bundle.es.js
vendored
21
dist/bundle.es.js
vendored
|
@ -1724,7 +1724,7 @@ const selectFetchingClaimSearch = reselect.createSelector(selectFetchingClaimSea
|
|||
|
||||
const selectClaimSearchByQuery = reselect.createSelector(selectState$2, state => state.claimSearchByQuery || {});
|
||||
|
||||
const selectClaimSearchByQueryLastPageReached = reselect.createSelector(selectState$1, state => state.claimSearchByQueryLastPageReached || {});
|
||||
const selectClaimSearchByQueryLastPageReached = reselect.createSelector(selectState$2, state => state.claimSearchByQueryLastPageReached || {});
|
||||
|
||||
const makeSelectShortUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.short_url);
|
||||
|
||||
|
@ -1744,9 +1744,22 @@ const makeSelectSupportsForUri = uri => reselect.createSelector(selectSupportsBy
|
|||
return total;
|
||||
});
|
||||
|
||||
function formatCredits(amount, precision) {
|
||||
if (Number.isNaN(parseFloat(amount))) return '0';
|
||||
return parseFloat(amount).toFixed(precision || 1).replace(/\.?0+$/, '');
|
||||
function formatCredits(amount, precision, shortFormat = false) {
|
||||
let actualAmount = parseFloat(amount),
|
||||
suffix = '';
|
||||
if (Number.isNaN(actualAmount)) return '0';
|
||||
|
||||
if (shortFormat) {
|
||||
if (actualAmount >= 1000000) {
|
||||
actualAmount = actualAmount / 1000000;
|
||||
suffix = 'M';
|
||||
} else if (actualAmount >= 1000) {
|
||||
actualAmount = actualAmount / 1000;
|
||||
suffix = 'K';
|
||||
}
|
||||
}
|
||||
|
||||
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
|
||||
}
|
||||
|
||||
function formatFullPrice(amount, precision = 1) {
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
export function formatCredits(amount, precision) {
|
||||
if (Number.isNaN(parseFloat(amount))) return '0';
|
||||
return parseFloat(amount)
|
||||
.toFixed(precision || 1)
|
||||
.replace(/\.?0+$/, '');
|
||||
export function formatCredits(amount, precision, shortFormat = false) {
|
||||
let actualAmount = parseFloat(amount),
|
||||
suffix = '';
|
||||
if (Number.isNaN(actualAmount)) return '0';
|
||||
|
||||
if (shortFormat) {
|
||||
if (actualAmount >= 1000000) {
|
||||
actualAmount = actualAmount / 1000000;
|
||||
suffix = 'M';
|
||||
} else if (actualAmount >= 1000) {
|
||||
actualAmount = actualAmount / 1000;
|
||||
suffix = 'K';
|
||||
}
|
||||
}
|
||||
|
||||
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
|
||||
}
|
||||
|
||||
export function formatFullPrice(amount, precision = 1) {
|
||||
|
@ -13,7 +24,7 @@ export function formatFullPrice(amount, precision = 1) {
|
|||
|
||||
if (fraction) {
|
||||
const decimals = fraction.split('');
|
||||
const first = decimals.filter((number) => number !== '0')[0];
|
||||
const first = decimals.filter(number => number !== '0')[0];
|
||||
const index = decimals.indexOf(first);
|
||||
|
||||
// Set format fraction
|
||||
|
|
Loading…
Add table
Reference in a new issue