Skip to content

Commit

Permalink
Update App.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
daoauth committed Oct 23, 2024
1 parent c86e5f9 commit 2237c73
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions packages/verifier/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,29 @@ function App() {
const [isNFC, setIsNFC] = useState<boolean>(false);
const [init, setInit] = useState<boolean>(false);

const handleReset = () => {
const generateRandomNumber = () => {
const number = Math.floor(1000 + Math.random() * 9000);
setRandomNumber(number.toString());
};
generateRandomNumber();
const handleNFCScan = async () => {
try {
const ndef = new (window as any).NDEFReader();
await ndef.scan();
ndef.addEventListener('readingerror', () => {
enqueueSnackbar('Cannot read data from the NFC tag. Try another one?', {
variant: 'error',
});
});

ndef.addEventListener('reading', (data: any) => {
enqueueSnackbar(`> Serial Number: ${JSON.stringify(data)}`, {
variant: 'info',
});
});
enqueueSnackbar('Scan started', {
variant: 'info',
});
} catch (error) {
enqueueSnackbar(`${error}`, {
variant: 'error',
});
}
};

const handleVerification = async (jwt: string) => {
Expand Down Expand Up @@ -63,8 +80,12 @@ function App() {
};

useEffect(() => {
const generateRandomNumber = () => {
const number = Math.floor(1000 + Math.random() * 9000);
setRandomNumber(number.toString());
};
setDisabled(false);
handleReset();
generateRandomNumber();
}, []);

return (
Expand Down Expand Up @@ -95,6 +116,7 @@ function App() {
onClick={() => {
setIsNFC(true);
setInit(true);
handleNFCScan();
}}
>
NFC
Expand Down

0 comments on commit 2237c73

Please sign in to comment.