Skip to content

Commit

Permalink
feat(zkappWorker.ts): add getAPI function to handle dynamic import of…
Browse files Browse the repository at this point in the history
… 'o1js' library and return API object to ensure worker api is availble after import
  • Loading branch information
ymekuria committed Sep 25, 2024
1 parent 7a78b97 commit 27db157
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions examples/zkapps/04-zkapp-browser-ui/ui/app/zkappWorker.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Mina, PublicKey, fetchAccount } from 'o1js';
import * as Comlink from "comlink";
import type { Add } from '../../contracts/src/Add';

type Transaction = Awaited<ReturnType<typeof Mina.transaction>>;

const getAPI = async () => {
const { Mina, PublicKey, fetchAccount } = await import('o1js');
type Transaction = Awaited<ReturnType<typeof Mina.transaction>>;


const state = {
Add: null as null | typeof Add,
zkapp: null as null | Add,
transaction: null as null | Transaction,
};

export const api = {
const api = {
async setActiveInstanceToDevnet() {
const Network = Mina.Network('https://api.minascan.io/node/devnet/v1/graphql');
Mina.setActiveInstance(Network);
Expand Down Expand Up @@ -48,7 +51,13 @@ export const api = {
async getTransactionJSON() {
return state.transaction!.toJSON();
},

};
return api;


}

const api = await getAPI();
// Expose the API to be used by the main thread
Comlink.expose(api);

0 comments on commit 27db157

Please sign in to comment.