add commas to formatCredits
This commit is contained in:
parent
a9bdf53dee
commit
b998637435
5 changed files with 26 additions and 17 deletions
16
dist/bundle.es.js
vendored
16
dist/bundle.es.js
vendored
|
@ -1290,8 +1290,6 @@ function doDismissError() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
const selectState$1 = state => state.wallet || {};
|
const selectState$1 = state => state.wallet || {};
|
||||||
|
|
||||||
const selectWalletState = selectState$1;
|
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 selectSupportsByOutpoint = reselect.createSelector(selectState$1, state => state.supports || {});
|
||||||
|
|
||||||
const selectTotalSupports = reselect.createSelector(selectSupportsByOutpoint, byOutpoint => {
|
const selectTotalSupports = reselect.createSelector(selectSupportsByOutpoint, byOutpoint => {
|
||||||
let total = parseFloat("0.0");
|
let total = parseFloat('0.0');
|
||||||
|
|
||||||
Object.values(byOutpoint).forEach(support => {
|
Object.values(byOutpoint).forEach(support => {
|
||||||
const { amount } = support;
|
const { amount } = support;
|
||||||
|
@ -1869,22 +1867,28 @@ const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(sele
|
||||||
|
|
||||||
const selectMyStreamUrlsCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length);
|
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) {
|
function formatCredits(amount, precision, shortFormat = false) {
|
||||||
let actualAmount = parseFloat(amount),
|
let actualAmount = parseFloat(amount),
|
||||||
suffix = '';
|
suffix = '';
|
||||||
if (Number.isNaN(actualAmount)) return '0';
|
if (Number.isNaN(actualAmount)) return '0';
|
||||||
|
|
||||||
if (shortFormat) {
|
if (shortFormat) {
|
||||||
if (actualAmount >= 1000000) {
|
if (actualAmount >= 1000000 && precision <= 7) {
|
||||||
actualAmount = actualAmount / 1000000;
|
actualAmount = actualAmount / 1000000;
|
||||||
suffix = 'M';
|
suffix = 'M';
|
||||||
} else if (actualAmount >= 1000) {
|
} else if (actualAmount >= 1000 && precision <= 4) {
|
||||||
actualAmount = actualAmount / 1000;
|
actualAmount = actualAmount / 1000;
|
||||||
suffix = 'K';
|
suffix = 'K';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '') + suffix;
|
return numberWithCommas(actualAmount.toFixed(precision || 1).replace(/\.?0+$/, '')) + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatFullPrice(amount, precision = 1) {
|
function formatFullPrice(amount, precision = 1) {
|
||||||
|
|
2
dist/flow-typed/i18n.js
vendored
2
dist/flow-typed/i18n.js
vendored
|
@ -1,2 +1,2 @@
|
||||||
// @flow
|
// @flow
|
||||||
declare function __(a: string, b?: string | number): string;
|
declare function __(a: string, b?: {}): string;
|
||||||
|
|
2
flow-typed/i18n.js
vendored
2
flow-typed/i18n.js
vendored
|
@ -1,2 +1,2 @@
|
||||||
// @flow
|
// @flow
|
||||||
declare function __(a: string, b?: string | number): string;
|
declare function __(a: string, b?: {}): string;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// @flow
|
|
||||||
|
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import * as TRANSACTIONS from 'constants/transaction_types';
|
import * as TRANSACTIONS from 'constants/transaction_types';
|
||||||
import { PAGE_SIZE } from 'constants/transaction_list';
|
import { PAGE_SIZE } from 'constants/transaction_list';
|
||||||
|
@ -116,7 +114,7 @@ export const selectSupportsByOutpoint = createSelector(
|
||||||
export const selectTotalSupports = createSelector(
|
export const selectTotalSupports = createSelector(
|
||||||
selectSupportsByOutpoint,
|
selectSupportsByOutpoint,
|
||||||
byOutpoint => {
|
byOutpoint => {
|
||||||
let total = parseFloat("0.0");
|
let total = parseFloat('0.0');
|
||||||
|
|
||||||
Object.values(byOutpoint).forEach(support => {
|
Object.values(byOutpoint).forEach(support => {
|
||||||
const { amount } = support;
|
const { amount } = support;
|
||||||
|
@ -299,15 +297,16 @@ export const selectFilteredTransactions = createSelector(
|
||||||
return transactions.filter(transaction => {
|
return transactions.filter(transaction => {
|
||||||
return filter === TRANSACTIONS.ALL || filter === transaction.type;
|
return filter === TRANSACTIONS.ALL || filter === transaction.type;
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<any> =>
|
export const makeSelectFilteredTransactionsForPage = (page: number = 1): Array<any> =>
|
||||||
createSelector(
|
createSelector(
|
||||||
selectFilteredTransactions,
|
selectFilteredTransactions,
|
||||||
filteredTransactions => {
|
filteredTransactions => {
|
||||||
const start = (Number(page) - 1) * Number(PAGE_SIZE);
|
const start = (Number(page) - 1) * Number(PAGE_SIZE);
|
||||||
const end = (Number(page) * Number(PAGE_SIZE));
|
const end = Number(page) * Number(PAGE_SIZE);
|
||||||
return (filteredTransactions && filteredTransactions.length)
|
return filteredTransactions && filteredTransactions.length
|
||||||
? filteredTransactions.slice(start, end)
|
? filteredTransactions.slice(start, end)
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
export function formatCredits(amount, precision, shortFormat = false) {
|
||||||
let actualAmount = parseFloat(amount),
|
let actualAmount = parseFloat(amount),
|
||||||
suffix = '';
|
suffix = '';
|
||||||
if (Number.isNaN(actualAmount)) return '0';
|
if (Number.isNaN(actualAmount)) return '0';
|
||||||
|
|
||||||
if (shortFormat) {
|
if (shortFormat) {
|
||||||
if (actualAmount >= 1000000) {
|
if (actualAmount >= 1000000 && precision <= 7) {
|
||||||
actualAmount = actualAmount / 1000000;
|
actualAmount = actualAmount / 1000000;
|
||||||
suffix = 'M';
|
suffix = 'M';
|
||||||
} else if (actualAmount >= 1000) {
|
} else if (actualAmount >= 1000 && precision <= 4) {
|
||||||
actualAmount = actualAmount / 1000;
|
actualAmount = actualAmount / 1000;
|
||||||
suffix = 'K';
|
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) {
|
export function formatFullPrice(amount, precision = 1) {
|
||||||
|
|
Loading…
Reference in a new issue