Skip to content

Commit e883abe

Browse files
committed
feat(index.page.tsx): instantiate ZkappWorkerClient
1 parent 4ce9dd5 commit e883abe

File tree

1 file changed

+77
-74
lines changed

1 file changed

+77
-74
lines changed

examples/zkapps/04-zkapp-browser-ui/ui/src/pages/index.page.tsx

+77-74
Original file line numberDiff line numberDiff line change
@@ -27,81 +27,84 @@ export default function Home() {
2727
// Do Setup
2828

2929
useEffect(() => {
30-
async function timeout(seconds: number): Promise<void> {
31-
return new Promise<void>((resolve) => {
32-
setTimeout(() => {
33-
resolve();
34-
}, seconds * 1000);
35-
});
36-
}
37-
38-
const zkappWorkerClient = new ZkappWorkerClient();
30+
// async function timeout(seconds: number): Promise<void> {
31+
// return new Promise<void>((resolve) => {
32+
// setTimeout(() => {
33+
// resolve();
34+
// }, seconds * 1000);
35+
// });
36+
// }
37+
38+
const zkappWorkerClient = new ZkappWorkerClient();
3939
setState(prev => ({ ...prev, zkappWorkerClient }));
40-
41-
(async () => {
42-
if (!state.hasBeenSetup) {
43-
setDisplayText('Loading web worker...');
44-
console.log('Loading web worker...');
45-
const zkappWorkerClient = new ZkappWorkerClient();
46-
await timeout(5);
47-
48-
setDisplayText('Done loading web worker');
49-
console.log('Done loading web worker');
50-
51-
await zkappWorkerClient.setActiveInstanceToDevnet();
52-
53-
const mina = (window as any).mina;
54-
55-
if (mina == null) {
56-
setState({ ...state, hasWallet: false });
57-
return;
58-
}
59-
60-
const publicKeyBase58: string = (await mina.requestAccounts())[0];
61-
const publicKey = PublicKey.fromBase58(publicKeyBase58);
62-
63-
console.log(`Using key:${publicKey.toBase58()}`);
64-
setDisplayText(`Using key:${publicKey.toBase58()}`);
65-
66-
setDisplayText('Checking if fee payer account exists...');
67-
console.log('Checking if fee payer account exists...');
68-
69-
const res = await zkappWorkerClient.fetchAccount({
70-
publicKey: publicKey!,
71-
});
72-
const accountExists = res.error == null;
73-
74-
await zkappWorkerClient.loadContract();
75-
76-
console.log('Compiling zkApp...');
77-
setDisplayText('Compiling zkApp...');
78-
await zkappWorkerClient.compileContract();
79-
console.log('zkApp compiled');
80-
setDisplayText('zkApp compiled...');
81-
82-
const zkappPublicKey = PublicKey.fromBase58(ZKAPP_ADDRESS);
83-
84-
await zkappWorkerClient.initZkappInstance(zkappPublicKey);
85-
86-
console.log('Getting zkApp state...');
87-
setDisplayText('Getting zkApp state...');
88-
await zkappWorkerClient.fetchAccount({ publicKey: zkappPublicKey });
89-
const currentNum = await zkappWorkerClient.getNum();
90-
console.log(`Current state in zkApp: ${currentNum.toString()}`);
91-
setDisplayText('');
92-
93-
setState({
94-
...state,
95-
zkappWorkerClient,
96-
hasWallet: true,
97-
hasBeenSetup: true,
98-
publicKey,
99-
zkappPublicKey,
100-
accountExists,
101-
currentNum,
102-
});
103-
}
104-
})();
40+
41+
const setup = async () => {
42+
43+
};
44+
// (async () => {
45+
// if (!state.hasBeenSetup) {
46+
// setDisplayText('Loading web worker...');
47+
// console.log('Loading web worker...');
48+
// const zkappWorkerClient = new ZkappWorkerClient();
49+
// await timeout(5);
50+
51+
// setDisplayText('Done loading web worker');
52+
// console.log('Done loading web worker');
53+
54+
// await zkappWorkerClient.setActiveInstanceToDevnet();
55+
56+
// const mina = (window as any).mina;
57+
58+
// if (mina == null) {
59+
// setState({ ...state, hasWallet: false });
60+
// return;
61+
// }
62+
63+
// const publicKeyBase58: string = (await mina.requestAccounts())[0];
64+
// const publicKey = PublicKey.fromBase58(publicKeyBase58);
65+
66+
// console.log(`Using key:${publicKey.toBase58()}`);
67+
// setDisplayText(`Using key:${publicKey.toBase58()}`);
68+
69+
// setDisplayText('Checking if fee payer account exists...');
70+
// console.log('Checking if fee payer account exists...');
71+
72+
// const res = await zkappWorkerClient.fetchAccount({
73+
// publicKey: publicKey!,
74+
// });
75+
// const accountExists = res.error == null;
76+
77+
// await zkappWorkerClient.loadContract();
78+
79+
// console.log('Compiling zkApp...');
80+
// setDisplayText('Compiling zkApp...');
81+
// await zkappWorkerClient.compileContract();
82+
// console.log('zkApp compiled');
83+
// setDisplayText('zkApp compiled...');
84+
85+
// const zkappPublicKey = PublicKey.fromBase58(ZKAPP_ADDRESS);
86+
87+
// await zkappWorkerClient.initZkappInstance(zkappPublicKey);
88+
89+
// console.log('Getting zkApp state...');
90+
// setDisplayText('Getting zkApp state...');
91+
// await zkappWorkerClient.fetchAccount({ publicKey: zkappPublicKey });
92+
// const currentNum = await zkappWorkerClient.getNum();
93+
// console.log(`Current state in zkApp: ${currentNum.toString()}`);
94+
// setDisplayText('');
95+
96+
// setState({
97+
// ...state,
98+
// zkappWorkerClient,
99+
// hasWallet: true,
100+
// hasBeenSetup: true,
101+
// publicKey,
102+
// zkappPublicKey,
103+
// accountExists,
104+
// currentNum,
105+
// });
106+
// }
107+
// })();
105108
}, []);
106109

107110
// -------------------------------------------------------

0 commit comments

Comments
 (0)