FIX: show effective balance for UseAllFunds button when limited utxo is selected

This commit is contained in:
Ivan Vershigora 2020-11-09 11:25:11 +03:00
parent 80e2c88974
commit 2bf5c26252
3 changed files with 23 additions and 16 deletions

View File

@ -1061,14 +1061,11 @@ export class BlueList extends Component {
export class BlueUseAllFundsButton extends Component {
static InputAccessoryViewID = 'useMaxInputAccessoryViewID';
static propTypes = {
wallet: PropTypes.shape().isRequired,
balance: PropTypes.string.isRequired,
canUseAll: PropTypes.bool.isRequired,
onUseAllPressed: PropTypes.func.isRequired,
};
static defaultProps = {
unit: BitcoinUnit.BTC,
};
render() {
const inputView = (
<View
@ -1096,11 +1093,11 @@ export class BlueUseAllFundsButton extends Component {
>
{loc.send.input_total}
</Text>
{this.props.wallet.allowSendMax() && this.props.wallet.getBalance() > 0 ? (
{this.props.canUseAll ? (
<BlueButtonLink
onPress={this.props.onUseAllPressed}
style={{ marginLeft: 8, paddingRight: 0, paddingLeft: 0, paddingTop: 12, paddingBottom: 12 }}
title={`${formatBalanceWithoutSuffix(this.props.wallet.getBalance(), BitcoinUnit.BTC, true).toString()} ${BitcoinUnit.BTC}`}
title={`${this.props.balance} ${BitcoinUnit.BTC}`}
/>
) : (
<Text
@ -1115,7 +1112,7 @@ export class BlueUseAllFundsButton extends Component {
paddingBottom: 12,
}}
>
{formatBalanceWithoutSuffix(this.props.wallet.getBalance(), BitcoinUnit.BTC, true).toString()} {BitcoinUnit.BTC}
{this.props.balance} {BitcoinUnit.BTC}
</Text>
)}
</View>
@ -1128,6 +1125,7 @@ export class BlueUseAllFundsButton extends Component {
</View>
</View>
);
if (Platform.OS === 'ios') {
return <InputAccessoryView nativeID={BlueUseAllFundsButton.InputAccessoryViewID}>{inputView}</InputAccessoryView>;
} else {

View File

@ -148,8 +148,4 @@ export class HDLegacyP2PKHWallet extends AbstractHDElectrumWallet {
return psbt;
}
allowSendMax() {
return true;
}
}

View File

@ -42,7 +42,7 @@ import { HDSegwitBech32Wallet, LightningCustodianWallet, MultisigHDWallet, Watch
import { BitcoinTransaction } from '../../models/bitcoinTransactionInfo';
import DocumentPicker from 'react-native-document-picker';
import DeeplinkSchemaMatch from '../../class/deeplink-schema-match';
import loc from '../../loc';
import loc, { formatBalanceWithoutSuffix } from '../../loc';
import { BlueCurrentTheme } from '../../components/themes';
import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electrum-wallet';
import { BlueStorageContext } from '../../blue_modules/storage-context';
@ -1298,7 +1298,8 @@ export default class SendDetails extends Component {
};
render() {
if (this.state.isLoading || typeof this.state.fromWallet === 'undefined') {
const { fromWallet, utxo } = this.state;
if (this.state.isLoading || typeof fromWallet === 'undefined') {
return (
<View style={styles.loading}>
<BlueLoading />
@ -1306,6 +1307,10 @@ export default class SendDetails extends Component {
);
}
// if utxo is limited we use it to calculate available balance
const balance = utxo ? utxo.reduce((prev, curr) => prev + curr.value, 0) : fromWallet.getBalance();
const allBalance = formatBalanceWithoutSuffix(balance, BitcoinUnit.BTC, true);
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.root} onLayout={this.onLayout}>
@ -1360,10 +1365,18 @@ export default class SendDetails extends Component {
<BlueDismissKeyboardInputAccessory />
{Platform.select({
ios: (
<BlueUseAllFundsButton unit={this.state.amountUnit} onUseAllPressed={this.onUseAllPressed} wallet={this.state.fromWallet} />
<BlueUseAllFundsButton
canUseAll={fromWallet.allowSendMax() && fromWallet.getBalance() > 0}
onUseAllPressed={this.onUseAllPressed}
balance={allBalance}
/>
),
android: this.state.isAmountToolbarVisibleForAndroid && (
<BlueUseAllFundsButton unit={this.state.amountUnit} onUseAllPressed={this.onUseAllPressed} wallet={this.state.fromWallet} />
<BlueUseAllFundsButton
canUseAll={fromWallet.allowSendMax() && fromWallet.getBalance() > 0}
onUseAllPressed={this.onUseAllPressed}
balance={allBalance}
/>
),
})}