-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial loading test * loading animations, not working aleo wasm * working webassembly init * removing comments * removing console log * Update website/src/workers/worker.js Co-authored-by: Mike Turner <[email protected]> Signed-off-by: Brent C <[email protected]> --------- Signed-off-by: Brent C <[email protected]> Co-authored-by: Mike Turner <[email protected]>
- Loading branch information
1 parent
429bd68
commit 955697d
Showing
9 changed files
with
175 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
import { useEffect, useState } from "react"; | ||
import init, * as aleo from "@aleohq/wasm"; | ||
|
||
await init(); | ||
export const useAleoWASM = () => { | ||
const [aleo, setAleo] = useState(null); | ||
const [aleoInstance, setAleoInstance] = useState(null); | ||
|
||
useEffect(() => { | ||
if (aleo === null) { | ||
import("@aleohq/wasm").then((module) => setAleo(module)); | ||
if (aleoInstance === null) { | ||
setAleoInstance(aleo); | ||
} | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
return aleo; | ||
return aleoInstance; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from "react"; | ||
|
||
const WorkerContext = React.createContext(null); | ||
|
||
export default WorkerContext; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useEffect, useState } from "react"; | ||
import WorkerContext from "./WorkerContext"; | ||
|
||
const WorkerProvider = ({ children }) => { | ||
const [worker, setWorker] = useState(null); | ||
const [workerReady, setWorkerReady] = useState(false); | ||
|
||
useEffect(() => { | ||
let worker = new Worker(new URL("./worker.js", import.meta.url), { | ||
type: "module", | ||
}); | ||
setWorker(worker); | ||
|
||
worker.onmessage = (event) => { | ||
if (event.data.type === "ALEO_WORKER_READY") { | ||
setWorkerReady(true); | ||
} | ||
}; | ||
|
||
return () => { | ||
worker.terminate(); | ||
}; | ||
}, []); | ||
|
||
if (!workerReady) { | ||
return ( | ||
<> | ||
<div className="spinner"> | ||
<div className="dot1"></div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<WorkerContext.Provider value={worker}> | ||
{children} | ||
</WorkerContext.Provider> | ||
); | ||
}; | ||
|
||
export default WorkerProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters