Skip to content

Commit

Permalink
Updated onBarCodeRead in App.js to properly format and set a scanned …
Browse files Browse the repository at this point in the history
…transaction.

Added a condition to SendTransaction's componentDidMount to check for a pre-set/requested transaction amount.
  • Loading branch information
coreyphillips committed Dec 31, 2019
1 parent 672d801 commit 645d287
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
11 changes: 11 additions & 0 deletions src/components/SendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 645d287

Please sign in to comment.