Skip to content

Commit

Permalink
fix: multiple alerts shown to QR reading (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliomir authored Nov 16, 2023
1 parent 2e8fee7 commit b34e6b0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/screens/SendScanQRCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ const mapStateToProps = (state) => ({
});

class SendScanQRCode extends React.Component {
constructor() {
super();
this.state = {
isWaitingForUserInput: false,
}
}

showAlertError = (message) => {
this.setState({ isWaitingForUserInput: true });
Alert.alert(
t`Invalid QR code`,
message,
Expand All @@ -32,13 +40,19 @@ class SendScanQRCode extends React.Component {
onPress: () => {
// To avoid being stuck on an invalid QR code loop, navigate back.
this.props.navigation.goBack();
this.setState({ isWaitingForUserInput: false });
} },
],
{ cancelable: false },
);
}

onSuccess = async (e) => {
if (this.state.isWaitingForUserInput) {
// Avoid multiple calls to this function while waiting for user input
return;
}

const qrcode = parseQRCode(e.data);
if (!qrcode.isValid) {
this.showAlertError(qrcode.error);
Expand Down

0 comments on commit b34e6b0

Please sign in to comment.