FIX: When selecting to send MAX on part or a X is shown in amount. #2412

This commit is contained in:
Marcos Rodriguez Vélez 2021-08-27 14:06:39 -04:00
parent 499b6b4b23
commit c55cb44b01
3 changed files with 37 additions and 22 deletions

View file

@ -2,9 +2,9 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import BigNumber from 'bignumber.js';
import { Text } from 'react-native-elements';
import { Image, StyleSheet, TextInput, TouchableOpacity, TouchableWithoutFeedback, View } from 'react-native';
import { Image, Pressable, StyleSheet, TextInput, TouchableOpacity, TouchableWithoutFeedback, View } from 'react-native';
import { useTheme } from '@react-navigation/native';
import confirm from '../helpers/confirm';
import { BitcoinUnit } from '../models/bitcoinUnits';
import loc, { formatBalanceWithoutSuffix, formatBalancePlain, removeTrailingZeros } from '../loc';
const currency = require('../blue_modules/currency');
@ -162,6 +162,12 @@ class AmountInput extends Component {
this.props.onChangeText(text);
};
resetAmount = async () => {
if (await confirm(loc.send.reset_amount, loc.send.reset_amount_confirm)) {
this.props.onChangeText();
}
};
render() {
const { colors, disabled, unit } = this.props;
const amount = this.props.amount || 0;
@ -206,26 +212,32 @@ class AmountInput extends Component {
{unit === BitcoinUnit.LOCAL_CURRENCY && amount !== BitcoinUnit.MAX && (
<Text style={[styles.localCurrency, stylesHook.localCurrency]}>{currency.getCurrencySymbol() + ' '}</Text>
)}
<TextInput
{...this.props}
testID="BitcoinAmountInput"
keyboardType="numeric"
adjustsFontSizeToFit
onChangeText={this.handleChangeText}
onBlur={() => {
if (this.props.onBlur) this.props.onBlur();
}}
onFocus={() => {
if (this.props.onFocus) this.props.onFocus();
}}
placeholder="0"
maxLength={this.maxLength()}
ref={textInput => (this.textInput = textInput)}
editable={!this.props.isLoading && !disabled}
value={amount === BitcoinUnit.MAX ? loc.units.MAX : parseFloat(amount) >= 0 ? String(amount) : undefined}
placeholderTextColor={disabled ? colors.buttonDisabledTextColor : colors.alternativeTextColor2}
style={[styles.input, stylesHook.input]}
/>
{amount !== BitcoinUnit.MAX ? (
<TextInput
{...this.props}
testID="BitcoinAmountInput"
keyboardType="numeric"
adjustsFontSizeToFit
onChangeText={this.handleChangeText}
onBlur={() => {
if (this.props.onBlur) this.props.onBlur();
}}
onFocus={() => {
if (this.props.onFocus) this.props.onFocus();
}}
placeholder="0"
maxLength={this.maxLength()}
ref={textInput => (this.textInput = textInput)}
editable={!this.props.isLoading && !disabled}
value={amount === BitcoinUnit.MAX ? loc.units.MAX : parseFloat(amount) >= 0 ? String(amount) : undefined}
placeholderTextColor={disabled ? colors.buttonDisabledTextColor : colors.alternativeTextColor2}
style={[styles.input, stylesHook.input]}
/>
) : (
<Pressable onPress={this.resetAmount}>
<Text style={[styles.input, stylesHook.input]}>{BitcoinUnit.MAX}</Text>
</Pressable>
)}
{unit !== BitcoinUnit.LOCAL_CURRENCY && amount !== BitcoinUnit.MAX && (
<Text style={[styles.cryptoCurrency, stylesHook.cryptoCurrency]}>{' ' + loc.units[unit]}</Text>
)}

View file

@ -231,6 +231,8 @@
"psbt_tx_scan": "Scan Signed Transaction",
"qr_error_no_qrcode": "We were unable to find a QR Code in the selected image. Make sure the image contains only a QR Code and no additional content such as text, or buttons.",
"qr_error_no_wallet": "The selected file doesnt contain a wallet that can be imported.",
"reset_amount": "Reset Amount",
"reset_amount_confirm": "Would you like to reset the amount?",
"success_done": "Done",
"txSaved": "The transaction file ({filePath}) has been saved in your Downloads folder.",
"problem_with_psbt": "Problem with PSBT"

View file

@ -861,6 +861,7 @@ const SendDetails = () => {
id: SendDetails.actionKeys.AddRecipient,
text: loc.send.details_add_rec_add,
icon: SendDetails.actionIcons.AddRecipient,
disabled: isSendMaxUsed,
});
actions.push({
id: SendDetails.actionKeys.RemoveRecipient,