set precision to 2, improve rendering of amounts below precision
This commit is contained in:
parent
da497aeaf3
commit
05783db1ba
1 changed files with 9 additions and 7 deletions
|
@ -72,26 +72,28 @@ export class CreditAmount extends React.PureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
precision: 3,
|
precision: 2,
|
||||||
label: true,
|
label: true,
|
||||||
showFree: false,
|
showFree: false,
|
||||||
look: "indicator",
|
look: "indicator",
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const formattedAmount = formatCredits(
|
const minimumRenderableAmount = Math.pow(10, -1 * this.props.precision);
|
||||||
this.props.amount,
|
const { amount, precision } = this.props;
|
||||||
this.props.precision
|
|
||||||
);
|
let formattedAmount = amount > 0 && amount < minimumRenderableAmount
|
||||||
|
? "<" + minimumRenderableAmount
|
||||||
|
: formatCredits(amount, precision);
|
||||||
|
|
||||||
let amountText;
|
let amountText;
|
||||||
if (this.props.showFree && parseFloat(formattedAmount) === 0) {
|
if (this.props.showFree && parseFloat(this.props.amount) === 0) {
|
||||||
amountText = __("free");
|
amountText = __("free");
|
||||||
} else if (this.props.label) {
|
} else if (this.props.label) {
|
||||||
amountText =
|
amountText =
|
||||||
formattedAmount +
|
formattedAmount +
|
||||||
" " +
|
" " +
|
||||||
(parseFloat(formattedAmount) == 1 ? __("credit") : __("credits"));
|
(parseFloat(amount) == 1 ? __("credit") : __("credits"));
|
||||||
} else {
|
} else {
|
||||||
amountText = formattedAmount;
|
amountText = formattedAmount;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue