set precision to 2, improve rendering of amounts below precision

This commit is contained in:
Jeremy Kauffman 2017-08-10 23:02:36 -04:00
parent da497aeaf3
commit 05783db1ba

View file

@ -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;
} }