improve short format for balance credits >1K and >1M #184
3 changed files with 29 additions and 39 deletions
30
dist/bundle.es.js
vendored
30
dist/bundle.es.js
vendored
|
@ -1711,24 +1711,23 @@ const selectCurrentHeight = reselect.createSelector(selectState$2, state => stat
|
|||
|
||||
const selectTransactionListFilter = reselect.createSelector(selectState$2, state => state.transactionListFilter || '');
|
||||
|
||||
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';
|
||||
|
||||
function formatBigNumberCredits(amount, precision) {
|
||||
const actualAmount = parseFloat(amount);
|
||||
if (Number.isNaN(actualAmount) || actualAmount < 1000) {
|
||||
return formatCredits(amount, precision);
|
||||
if (shortFormat) {
|
||||
if (actualAmount >= 1000000) {
|
||||
actualAmount = actualAmount / 1000000;
|
||||
suffix = 'M';
|
||||
}
|
||||
if (actualAmount >= 1000) {
|
||||
actualAmount = actualAmount / 1000;
|
||||
suffix = 'K';
|
||||
}
|
||||
}
|
||||
|
||||
if (actualAmount > 1000000) {
|
||||
return formatCredits(actualAmount / 1000000, precision) + 'M';
|
||||
}
|
||||
|
||||
if (actualAmount > 1000) {
|
||||
return formatCredits(actualAmount / 1000, precision) + 'K';
|
||||
}
|
||||
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
|
||||
}
|
||||
|
||||
function formatFullPrice(amount, precision = 1) {
|
||||
|
@ -4850,7 +4849,6 @@ exports.doWalletStatus = doWalletStatus;
|
|||
exports.doWalletUnlock = doWalletUnlock;
|
||||
exports.fileInfoReducer = fileInfoReducer;
|
||||
exports.fileReducer = fileReducer;
|
||||
exports.formatBigNumberCredits = formatBigNumberCredits;
|
||||
exports.formatCredits = formatCredits;
|
||||
exports.formatFullPrice = formatFullPrice;
|
||||
exports.isClaimNsfw = isClaimNsfw;
|
||||
|
|
|
@ -116,12 +116,7 @@ export { doToggleBlockChannel } from 'redux/actions/blocked';
|
|||
// utils
|
||||
export { batchActions } from 'util/batch-actions';
|
||||
export { parseQueryParams, toQueryString } from 'util/query-params';
|
||||
export {
|
||||
formatCredits,
|
||||
formatBigNumberCredits,
|
||||
formatFullPrice,
|
||||
creditsToString,
|
||||
} from 'util/format-credits';
|
||||
export { formatCredits, formatFullPrice, creditsToString } from 'util/format-credits';
|
||||
export { isClaimNsfw, createNormalizedClaimSearchKey } from 'util/claim';
|
||||
|
||||
// reducers
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
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';
|
||||
I was trying to avoid having to update all the references to the method, as there are quite a few. I was trying to avoid having to update all the references to the method, as there are quite a few.
Why would you have to update the references if you add an optional 3rd parameter? Why would you have to update the references if you add an optional 3rd parameter?
I suppose I wouldn't have to, now that I think about it. I should be able to roll the functionality into the I suppose I wouldn't have to, now that I think about it. I should be able to roll the functionality into the `formatCredits` method.
|
||||
|
||||
export function formatBigNumberCredits(amount, precision) {
|
||||
const actualAmount = parseFloat(amount);
|
||||
if (Number.isNaN(actualAmount) || actualAmount < 1000) {
|
||||
return formatCredits(amount, precision);
|
||||
if (shortFormat) {
|
||||
if (actualAmount >= 1000000) {
|
||||
actualAmount = actualAmount / 1000000;
|
||||
suffix = 'M';
|
||||
}
|
||||
if (actualAmount >= 1000) {
|
||||
actualAmount = actualAmount / 1000;
|
||||
suffix = 'K';
|
||||
}
|
||||
}
|
||||
|
||||
if (actualAmount > 1000000) {
|
||||
return formatCredits(actualAmount / 1000000, precision) + 'M';
|
||||
}
|
||||
|
||||
if (actualAmount > 1000) {
|
||||
return formatCredits(actualAmount / 1000, precision) + 'K';
|
||||
}
|
||||
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
|
||||
}
|
||||
|
||||
export function formatFullPrice(amount, precision = 1) {
|
||||
|
|
Loading…
Reference in a new issue
Would it make more sense for this functionality to be a parameter to formatCredits rather than a standalone function?