diff --git a/BlueComponents.js b/BlueComponents.js index 4226ca1e9..c68c0c4d8 100644 --- a/BlueComponents.js +++ b/BlueComponents.js @@ -2290,19 +2290,19 @@ export class BlueBitcoinAmount extends Component { secondaryDisplayCurrency = formatBalanceWithoutSuffix(sat, BitcoinUnit.LOCAL_CURRENCY, false); break; case BitcoinUnit.SATS: - secondaryDisplayCurrency = formatBalanceWithoutSuffix(amount.toString(), BitcoinUnit.LOCAL_CURRENCY, false); + secondaryDisplayCurrency = formatBalanceWithoutSuffix((isNaN(amount) ? 0 : amount).toString(), BitcoinUnit.LOCAL_CURRENCY, false); break; case BitcoinUnit.LOCAL_CURRENCY: - secondaryDisplayCurrency = currency.fiatToBTC(parseFloat(amount)); - if (BlueBitcoinAmount.conversionCache[amount + BitcoinUnit.LOCAL_CURRENCY]) { - // cache hit! we reuse old value that supposedly doesnt have rounding errors - const sats = BlueBitcoinAmount.conversionCache[amount + BitcoinUnit.LOCAL_CURRENCY]; + secondaryDisplayCurrency = currency.fiatToBTC(parseFloat(isNaN(amount) ? 0 : amount)); + if (BlueBitcoinAmount.conversionCache[isNaN(amount) ? 0 : amount + BitcoinUnit.LOCAL_CURRENCY]) { + // cache hit! we reuse old value that supposedly doesn't have rounding errors + const sats = BlueBitcoinAmount.conversionCache[isNaN(amount) ? 0 : amount + BitcoinUnit.LOCAL_CURRENCY]; secondaryDisplayCurrency = currency.satoshiToBTC(sats); } break; } - if (amount === BitcoinUnit.MAX) secondaryDisplayCurrency = ''; // we dont want to display NaN + if (amount === BitcoinUnit.MAX) secondaryDisplayCurrency = ''; // we don't want to display NaN return ( this.textInput.focus()}> @@ -2342,16 +2342,12 @@ export class BlueBitcoinAmount extends Component { } else { text = `${parseInt(split[0], 10)}`; } + text = this.state.unit === BitcoinUnit.BTC ? text.replace(/[^0-9.]/g, '') : text.replace(/[^0-9]/g, ''); - text = text.replace(/(\..*)\./g, '$1'); if (text.startsWith('.')) { text = '0.'; } - text = text.replace(/(0{1,}.)\./g, '$1'); - if (this.state.unit !== BitcoinUnit.BTC) { - text = text.replace(/[^0-9.]/g, ''); - } } else if (this.state.unit === BitcoinUnit.LOCAL_CURRENCY) { text = text.replace(/,/gi, ''); if (text.split('.').length > 2) { @@ -2367,9 +2363,9 @@ export class BlueBitcoinAmount extends Component { } text = rez; } - text = text.replace(/[^\d.,-]/g, ''); // remove all but numberd, dots & commas + text = text.replace(/[^\d.,-]/g, ''); // remove all but numbers, dots & commas + text = text.replace(/(\..*)\./g, '$1'); } - this.props.onChangeText(text); }} onBlur={() => { @@ -2382,7 +2378,7 @@ export class BlueBitcoinAmount extends Component { maxLength={this.maxLength()} ref={textInput => (this.textInput = textInput)} editable={!this.props.isLoading && !this.props.disabled} - value={parseFloat(amount) > 0 || amount === BitcoinUnit.MAX ? amount : undefined} + value={parseFloat(amount) >= 0 || amount === BitcoinUnit.MAX ? amount : undefined} placeholderTextColor={ this.props.disabled ? BlueCurrentTheme.colors.buttonDisabledTextColor : BlueCurrentTheme.colors.alternativeTextColor2 }