From 05783db1ba7e6e3adffd96b70c119941a9de20cc Mon Sep 17 00:00:00 2001 From: Jeremy Kauffman Date: Thu, 10 Aug 2017 23:02:36 -0400 Subject: [PATCH] set precision to 2, improve rendering of amounts below precision --- ui/js/component/common.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ui/js/component/common.js b/ui/js/component/common.js index 61980a15b..91919b32f 100644 --- a/ui/js/component/common.js +++ b/ui/js/component/common.js @@ -72,26 +72,28 @@ export class CreditAmount extends React.PureComponent { }; static defaultProps = { - precision: 3, + precision: 2, label: true, showFree: false, look: "indicator", }; render() { - const formattedAmount = formatCredits( - this.props.amount, - this.props.precision - ); + const minimumRenderableAmount = Math.pow(10, -1 * this.props.precision); + const { amount, precision } = this.props; + + let formattedAmount = amount > 0 && amount < minimumRenderableAmount + ? "<" + minimumRenderableAmount + : formatCredits(amount, precision); let amountText; - if (this.props.showFree && parseFloat(formattedAmount) === 0) { + if (this.props.showFree && parseFloat(this.props.amount) === 0) { amountText = __("free"); } else if (this.props.label) { amountText = formattedAmount + " " + - (parseFloat(formattedAmount) == 1 ? __("credit") : __("credits")); + (parseFloat(amount) == 1 ? __("credit") : __("credits")); } else { amountText = formattedAmount; }