1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-27 10:48:22 +00:00

add more user-friendly error messages

This commit is contained in:
slowbackspace 2019-02-20 16:35:28 +01:00
parent 9c974c6415
commit 48c0b2afce

View File

@ -38,11 +38,18 @@ const CameraPlaceholder = styled(P)`
padding: 10px 0; padding: 10px 0;
`; `;
const Error = styled(P)` const Error = styled.div`
text-align: center;
padding: 10px 0; padding: 10px 0;
`;
const ErrorTitle = styled(P)`
text-align: center;
color: ${colors.ERROR_PRIMARY}; color: ${colors.ERROR_PRIMARY};
`; `;
const ErrorMessage = styled.span`
text-align: center;
color: ${colors.TEXT_PRIMARY};
`;
const StyledQrReader = styled(QrReader)` const StyledQrReader = styled(QrReader)`
padding: 10px 0; padding: 10px 0;
@ -95,14 +102,25 @@ class QrModal extends React.Component<Props, State> {
} }
handleError = (err: any) => { handleError = (err: any) => {
console.log(err); // log thrown error
this.setState({ console.error(err);
error: err,
});
if (this.props.onError) { if (this.props.onError) {
this.props.onError(err); 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 = () => { handleCancel = () => {
@ -123,29 +141,25 @@ class QrModal extends React.Component<Props, State> {
/> />
</CloseLink> </CloseLink>
<Padding> <Padding>
<H2>Scan an address from a QR code</H2> <H2>Scan QR code</H2>
{!this.state.readerLoaded && ( {!this.state.readerLoaded && !this.state.error && <CameraPlaceholder>Waiting for camera...</CameraPlaceholder>}
<CameraPlaceholder>
Waiting for camera...
</CameraPlaceholder>
)
}
</Padding>
<StyledQrReader
delay={500}
onError={this.handleError}
onScan={this.handleScan}
onLoad={this.onLoad}
style={{ width: '100%' }}
showViewFinder={false}
/>
<Padding>
{this.state.error && ( {this.state.error && (
<Error> <Error>
{this.state.error.toString()} <ErrorTitle>Oops! Something went wrong!</ErrorTitle>
<ErrorMessage>{this.state.error.toString()}</ErrorMessage>
</Error> </Error>
)} )}
</Padding> </Padding>
{!this.state.error && (
<StyledQrReader
delay={500}
onError={this.handleError}
onScan={this.handleScan}
onLoad={this.onLoad}
style={{ width: '100%' }}
showViewFinder={false}
/>
)}
</Wrapper> </Wrapper>
); );
} }