generated from scaffold-eth/scaffold-eth-2
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bcfd73d
commit 161a611
Showing
6 changed files
with
122 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Proof } from "~~/hooks/noir/useProofGenerator"; | ||
|
||
export const ProofResult = ({ proof }: { proof: Proof | undefined }) => { | ||
return ( | ||
<div className="flex-wrap collapse collapse-arrow mb-2"> | ||
<input type="checkbox" className="min-h-0 peer" /> | ||
<div className="collapse-title text-sm rounded-3xl peer-checked:rounded-b-none min-h-0 bg-secondary py-1.5"> | ||
<strong>Generated proof</strong> | ||
</div> | ||
<div className="collapse-content overflow-auto bg-secondary rounded-t-none rounded-3xl"> | ||
<pre className="text-xs pt-4">{JSON.stringify(proof, null, 2)}</pre> | ||
</div> | ||
</div> | ||
); | ||
}; |
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,48 @@ | ||
import { CircuitName } from "~~/utils/noir/circuit"; | ||
|
||
// TODO: where should this live? | ||
export type Proof = string; | ||
|
||
let isRunning = false; | ||
const circuitProofs: Partial< | ||
Record< | ||
CircuitName, | ||
{ | ||
resultPromise: Promise<Proof>; | ||
result: Proof; | ||
} | ||
> | ||
> = {}; | ||
|
||
const generateProofWrapper = (circuitName: CircuitName, parsedArgs?: any) => { | ||
console.log("generateProofWrapper", circuitName, parsedArgs); | ||
return async () => { | ||
if (isRunning) throw new Error("A proof generation already in progress"); | ||
isRunning = true; | ||
const proofPromise = new Promise<Proof>(resolve => { | ||
setTimeout(() => { | ||
isRunning = false; | ||
const res = "I am a proof result for " + circuitName; | ||
circuitProofs[circuitName]!.result = res; | ||
console.log("proofPromise resolving"); | ||
resolve(res); | ||
}, 2000); | ||
}); | ||
circuitProofs[circuitName]!.resultPromise = proofPromise; | ||
return proofPromise; | ||
}; | ||
}; | ||
|
||
export default function useProofGenerator(circuitName: CircuitName, form: any) { | ||
if (!circuitProofs[circuitName]) { | ||
circuitProofs[circuitName] = { | ||
resultPromise: new Promise(r => r("hej")), | ||
result: "", | ||
}; | ||
} | ||
return { | ||
result: circuitProofs[circuitName]!.result, | ||
isLoading: isRunning, | ||
generateProof: generateProofWrapper(circuitName, form), | ||
}; | ||
} |
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,34 @@ | ||
import { notification } from "~~/utils/scaffold-eth"; | ||
|
||
type TWithNotificationsFunc = (proofGeneration: Promise<string>) => Promise<string>; | ||
|
||
const ProofNotification = ({ message }: { message: string }) => { | ||
return ( | ||
<div className={`flex flex-col ml-1 cursor-default`}> | ||
<p className="my-0">{message}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export const useProvingNotifications = (): TWithNotificationsFunc => { | ||
const fn: TWithNotificationsFunc = async proofGeneration => { | ||
let notificationId = null; | ||
let res = ""; | ||
try { | ||
notificationId = notification.loading(<ProofNotification message="Generating proof..." />); | ||
res = await proofGeneration; | ||
notification.remove(notificationId); | ||
notification.success(<ProofNotification message="Proof generated successfully!" />, { | ||
icon: "🎉", | ||
}); | ||
} catch (error: any) { | ||
if (notificationId) { | ||
notification.remove(notificationId); | ||
} | ||
console.error("⚡️ ~ file: useProvingNotifications.tsx ~ error", error.stack); | ||
notification.error(error.message); | ||
} | ||
return res; | ||
}; | ||
return fn; | ||
}; |