Skip to content

Commit

Permalink
chore: enhance nxp sig check result message
Browse files Browse the repository at this point in the history
  • Loading branch information
whitedogg13 committed May 25, 2023
1 parent 2bda686 commit 258c7b2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Screens/TagKit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,21 @@ function TagKitScreen(props) {
`https://badge-api.revtel2.com/badge/v2/nxp-sig-check?uid=${uid}&sig=${sig}`,
);

if (resp.status !== 200) {
throw {
status: resp.status,
error: await resp.json(),
};
if (resp.status === 400) {
throw new Error('invalid-nxp-sig');
} else if (resp.status !== 200) {
throw new Error('unknown-nxp-sig');
}

return resp.json();
}

const tag = await NfcProxy.readNxpSigNtag2xx();

if (!tag) {
return;
}

const uid = tag.id;
const sig = tag.nxpBytes.reduce((acc, byte) => {
// eslint-disable-next-line no-bitwise
Expand All @@ -127,7 +131,14 @@ function TagKitScreen(props) {
await checkNxpSig({uid, sig});
Alert.alert('Success', 'NXP signature is correct');
} catch (ex) {
Alert.alert('Failure', 'NXP signature is invalid');
if (ex?.message === 'invalid-nxp-sig') {
Alert.alert('Failure', 'NXP signature is invalid');
} else {
Alert.alert(
'Warning',
'cannot verify NXP signature right now, please try again later',
);
}
console.warn(ex);
}
}}
Expand Down

0 comments on commit 258c7b2

Please sign in to comment.