diff --git a/src/components/modals/QrModal/index.js b/src/components/modals/QrModal/index.js index 1eef2b10..25fb353f 100644 --- a/src/components/modals/QrModal/index.js +++ b/src/components/modals/QrModal/index.js @@ -38,11 +38,18 @@ const CameraPlaceholder = styled(P)` padding: 10px 0; `; -const Error = styled(P)` - text-align: center; +const Error = styled.div` padding: 10px 0; +`; + +const ErrorTitle = styled(P)` + text-align: center; color: ${colors.ERROR_PRIMARY}; `; +const ErrorMessage = styled.span` + text-align: center; + color: ${colors.TEXT_PRIMARY}; +`; const StyledQrReader = styled(QrReader)` padding: 10px 0; @@ -95,14 +102,25 @@ class QrModal extends React.Component { } handleError = (err: any) => { - console.log(err); - this.setState({ - error: err, - }); - + // log thrown error + console.error(err); if (this.props.onError) { this.props.onError(err); } + + if (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError') { + this.setState({ + error: 'Permission to access the camera was denied.', + }); + } else if (err.name === 'NotFoundError' || err.name === 'DevicesNotFoundError') { + this.setState({ + error: 'The camera was not recognized.', + }); + } else { + this.setState({ + error: 'Unknown error. See console logs for details.', + }); + } } handleCancel = () => { @@ -123,29 +141,25 @@ class QrModal extends React.Component { /> -

Scan an address from a QR code

- {!this.state.readerLoaded && ( - - Waiting for camera... - - ) - } -
- - +

Scan QR code

+ {!this.state.readerLoaded && !this.state.error && Waiting for camera...} {this.state.error && ( - {this.state.error.toString()} + Oops! Something went wrong! + {this.state.error.toString()} )}
+ {!this.state.error && ( + + )} ); }