Skip to content

Commit

Permalink
Merge pull request #23 from zkonduit/fix-artifact-paths
Browse files Browse the repository at this point in the history
fix: update artifacts paths + mobile UI
  • Loading branch information
ethan-crypto authored Nov 22, 2023
2 parents 8d77b3b + 27688da commit 5e65752
Show file tree
Hide file tree
Showing 43 changed files with 8,893 additions and 5,443 deletions.
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"jsxSingleQuote": true
}
208 changes: 87 additions & 121 deletions README.md

Large diffs are not rendered by default.

76 changes: 40 additions & 36 deletions app/EngineContext.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
// Initialize the engine and util imports in the SharedResourcesProvider component:
// Note: must import Uitls as a module instead of a component for engine to work (or else you will get 'self' is undefined wasm errors)
'use client'
import React, { createContext, useContext, useState, useEffect } from 'react';
type Utils = typeof import("./Utils")
type Engine = typeof import("@ezkljs/engine/web/ezkl")
import React, { createContext, useContext, useState, useEffect } from 'react'
type Utils = typeof import('./Utils')
type Engine = typeof import('@ezkljs/engine/web/ezkl')

interface SharedResources {
engine: Engine;
utils: Utils;
engine: Engine
utils: Utils
}

const SharedResourcesContext = createContext<SharedResources | null>(null);
const SharedResourcesContext = createContext<SharedResources | null>(null)
export const useSharedResources = (): SharedResources => {
const context = useContext(SharedResourcesContext);
if (!context) {
throw new Error('useSharedResources must be used within a SharedResourcesProvider');
}
return context;
};
const context = useContext(SharedResourcesContext)
if (!context) {
throw new Error(
'useSharedResources must be used within a SharedResourcesProvider',
)
}
return context
}

interface SharedResourcesProviderProps {
children: React.ReactNode;
children: React.ReactNode
}

export const SharedResourcesProvider: React.FC<SharedResourcesProviderProps> = ({ children }) => {
const [engine, setEngine] = useState<any>(null); // Replace 'any' with the actual type of 'engine'
const [utils, setUtils] = useState<any>(null); // Replace 'any' with the actual type of 'utils'
export const SharedResourcesProvider: React.FC<
SharedResourcesProviderProps
> = ({ children }) => {
const [engine, setEngine] = useState<any>(null) // Replace 'any' with the actual type of 'engine'
const [utils, setUtils] = useState<any>(null) // Replace 'any' with the actual type of 'utils'

useEffect(() => {
async function initializeResources() {
// Initialize the WASM module
const engine = await import("@ezkljs/engine/web/ezkl.js");
setEngine(engine)
await (engine as any).default()
// For human readable wasm debug errors call this function
engine.init_panic_hook()
// Initialize the utils module
const utils = await import("./Utils");
setUtils(utils)
}
initializeResources();
}, []);
useEffect(() => {
async function initializeResources() {
// Initialize the WASM module
const engine = await import('@ezkljs/engine/web/ezkl.js')
setEngine(engine)
await (engine as any).default(undefined, new WebAssembly.Memory({ initial: 20, maximum: 4096, shared: true }))
// For human readable wasm debug errors call this function
engine.init_panic_hook()
// Initialize the utils module
const utils = await import('./Utils')
setUtils(utils)
}
initializeResources()
}, [])

return (
<SharedResourcesContext.Provider value={{ engine, utils }}>
{children}
</SharedResourcesContext.Provider>
);
};
return (
<SharedResourcesContext.Provider value={{ engine, utils }}>
{children}
</SharedResourcesContext.Provider>
)
}
Loading

0 comments on commit 5e65752

Please sign in to comment.