add commas to formatCredits

This commit is contained in:
Sean Yesmunt 2019-09-30 17:58:15 -04:00
parent a9bdf53dee
commit b998637435
5 changed files with 26 additions and 17 deletions

16
dist/bundle.es.js vendored
View file

@ -1290,8 +1290,6 @@ function doDismissError() {
};
}
//
const selectState$1 = state => state.wallet || {};
const selectWalletState = selectState$1;
@ -1339,7 +1337,7 @@ const selectTransactionsById = reselect.createSelector(selectState$1, state => s
const selectSupportsByOutpoint = reselect.createSelector(selectState$1, state => state.supports || {});
const selectTotalSupports = reselect.createSelector(selectSupportsByOutpoint, byOutpoint => {
let total = parseFloat("0.0");
let total = parseFloat('0.0');
Object.values(byOutpoint).forEach(support => {
const { amount } = support;
@ -1869,22 +1867,28 @@ const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(sele
const selectMyStreamUrlsCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length);
function numberWithCommas(x) {
var parts = x.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}
function formatCredits(amount, precision, shortFormat = false) {
let actualAmount = parseFloat(amount),
suffix = '';
if (Number.isNaN(actualAmount)) return '0';
if (shortFormat) {
if (actualAmount >= 1000000) {
if (actualAmount >= 1000000 && precision <= 7) {
actualAmount = actualAmount / 1000000;
suffix = 'M';
} else if (actualAmount >= 1000) {
} else if (actualAmount >= 1000 && precision <= 4) {
actualAmount = actualAmount / 1000;
suffix = 'K';
}
}
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
return numberWithCommas(actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '')) + suffix;
}
function formatFullPrice(amount, precision = 1) {

View file

@ -1,2 +1,2 @@
// @flow
declare function __(a: string, b?: string | number): string;
declare function __(a: string, b?: {}): string;

2
flow-typed/i18n.js vendored
View file

@ -1,2 +1,2 @@
// @flow
declare function __(a: string, b?: string | number): string;
declare function __(a: string, b?: {}): string;

View file

@ -1,5 +1,3 @@
// @flow
import { createSelector } from 'reselect';
import * as TRANSACTIONS from 'constants/transaction_types';
import { PAGE_SIZE } from 'constants/transaction_list';
@ -116,7 +114,7 @@ export const selectSupportsByOutpoint = createSelector(
export const selectTotalSupports = createSelector(
selectSupportsByOutpoint,
byOutpoint => {
let total = parseFloat("0.0");
let total = parseFloat('0.0');
Object.values(byOutpoint).forEach(support => {
const { amount } = support;
@ -299,15 +297,16 @@ export const selectFilteredTransactions = createSelector(
return transactions.filter(transaction => {
return filter === TRANSACTIONS.ALL || filter === transaction.type;
});
});
}
);
export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<any> =>
createSelector(
selectFilteredTransactions,
filteredTransactions => {
const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = (Number(page) * Number(PAGE_SIZE));
return (filteredTransactions && filteredTransactions.length)
const end = Number(page) * Number(PAGE_SIZE);
return filteredTransactions && filteredTransactions.length
? filteredTransactions.slice(start, end)
: [];
}

View file

@ -1,19 +1,25 @@
function numberWithCommas(x) {
var parts = x.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}
export function formatCredits(amount, precision, shortFormat = false) {
let actualAmount = parseFloat(amount),
suffix = '';
if (Number.isNaN(actualAmount)) return '0';
if (shortFormat) {
if (actualAmount >= 1000000) {
if (actualAmount >= 1000000 && precision <= 7) {
actualAmount = actualAmount / 1000000;
suffix = 'M';
} else if (actualAmount >= 1000) {
} else if (actualAmount >= 1000 && precision <= 4) {
actualAmount = actualAmount / 1000;
suffix = 'K';
}
}
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
return numberWithCommas(actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '')) + suffix;
}
export function formatFullPrice(amount, precision = 1) {