diff --git a/src/components/App.js b/src/components/App.js index 9d5da67..1a9f75d 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1547,8 +1547,14 @@ export default class App extends Component { await this.restartElectrum({coin}); } - //Pass the transaction data forward for use. - this.props.updateTransaction(qrCodeData.data); + //Pass the transaction data forward for use in the SendTransaction component. + let { address, amount } = qrCodeData.data; + //Ensure the amount is correctly formatted in sats + if (amount % 1 !== 0) amount = bitcoinUnits(Number(qrCodeData.data.amount), "BTC").to("satoshi").value(); + //Set amount to 0 if the requested amount is greater than the current balance. + if (amount > this.getCryptoBalance()) amount = 0; + this.props.updateTransaction({ address, amount }); + //Trigger the onSendPress animation to expose the transaction view. this.onSendPress(); }); diff --git a/src/components/SendTransaction.js b/src/components/SendTransaction.js index 76e048f..7815a23 100644 --- a/src/components/SendTransaction.js +++ b/src/components/SendTransaction.js @@ -105,6 +105,17 @@ class SendTransaction extends Component { //Set Maximum Fee (recommendedFee * 4) to prevent any user accidents. //Set Recommended Fee as Starting Fee this.calculateFees(); + + try { + //If a transaction amount is already specified check that the user has enough funds and update the local amount accordingly. + if (this.props.transaction.amount) { + if (this.hasEnoughFunds()) { + this.updateAmount(this.props.transaction.amount); + } else { + alert(`It appears that\nyou do not have enough funds\nto cover the requested transaction.`); + } + } + } catch (e) {} }; if (Platform.OS === "ios") {