From 7c690a0e45c8b87dab63020639a7679eb761393e Mon Sep 17 00:00:00 2001 From: tuliomir Date: Tue, 14 Nov 2023 12:34:03 -0300 Subject: [PATCH] fix: multiple alerts shown to QR reading --- src/screens/SendScanQRCode.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/screens/SendScanQRCode.js b/src/screens/SendScanQRCode.js index c1894ea63..0b4727d77 100644 --- a/src/screens/SendScanQRCode.js +++ b/src/screens/SendScanQRCode.js @@ -22,7 +22,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, @@ -31,6 +39,7 @@ 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 }, @@ -38,6 +47,11 @@ class SendScanQRCode extends React.Component { } 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);