Skip to content

Commit

Permalink
refactor(index.page.tsx): improve error handling in account existence…
Browse files Browse the repository at this point in the history
… check function
  • Loading branch information
ymekuria committed Sep 23, 2024
1 parent 0c57586 commit 00fa126
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions examples/zkapps/04-zkapp-browser-ui/ui/src/pages/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default function Home() {
console.log('Loading web worker...');
const zkappWorkerClient = new ZkappWorkerClient();
setZkappWorkerClient(zkappWorkerClient);

await new Promise((resolve) => setTimeout(resolve, 5000));

setDisplayText('Done loading web worker');
Expand All @@ -39,7 +38,6 @@ export default function Home() {
await zkappWorkerClient.setActiveInstanceToDevnet();

const mina = (window as any).mina;

if (mina == null) {
setHasWallet(false);
setDisplayText('Wallet not found.');
Expand Down Expand Up @@ -105,18 +103,22 @@ export default function Home() {
useEffect(() => {
const checkAccountExists = async () => {
if (hasBeenSetup && !accountExists) {
for (;;) {
setDisplayText('Checking if fee payer account exists...');
console.log('Checking if fee payer account exists...');
const res = await zkappWorkerClient!.fetchAccount(publicKeyBase58);
const accountExists = res.error == null;
if (accountExists) {
break;
}
await new Promise((resolve) => setTimeout(resolve, 5000));
}
try {
for (;;) {
setDisplayText('Checking if fee payer account exists...');
console.log('Checking if fee payer account exists...');
const res = await zkappWorkerClient!.fetchAccount(publicKeyBase58);
const accountExists = res.error == null;
if (accountExists) {
break;
}
await new Promise((resolve) => setTimeout(resolve, 5000));
}
} catch (error: any) {
setDisplayText(`Error checking account: ${error.message}`);
}

}
// setDisplayText('');
setAccountExists(true);
};

Expand Down

0 comments on commit 00fa126

Please sign in to comment.