Skip to content

Commit

Permalink
clean and refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Aug 6, 2024
1 parent 1c858fa commit 79ab7c9
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const HowItWork = () => {

const [openHowItWork, setOpenHowItWork] = useState(false);


return(
<div onClick={() => setOpenHowItWork(!openHowItWork)}
className="max-w-sm cursor-pointer my-5 p-1 m-1 whitespace-pre-line break-words"
Expand Down
5 changes: 0 additions & 5 deletions askeladd-dvm-marketplace/src/app/config-marketplace/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ASKELADD_KINDS, ConfigHandle } from "@/types";
import EventCard from "../components/EventCard";
import { generateContentAndTags } from "../utils/generateAppHandler";
import { HowItWork } from "../components/description";

export default function Home() {
const [publicKey, setPublicKey] = useState<string | undefined>();
const [appKind, setAppKind] = useState<ASKELADD_KINDS | undefined>(ASKELADD_KINDS.KIND_JOB_REQUEST)
Expand All @@ -28,7 +27,6 @@ export default function Home() {
const [isAdmin, setIsAdmin] = useState(false);
const [timestampJob, setTimestampJob] = useState<number | undefined>();
const { fetchEvents, fetchEventsTools, setupSubscriptionNostr } = useFetchEvents()
const { sendNote, publishNote } = useSendNote()

useEffect(() => {
if (isNeedLoadEvents || !isInitialized) {
Expand Down Expand Up @@ -60,7 +58,6 @@ export default function Home() {
setIsNeedLoadEvents(false)
}


/** Connect you */
const connectExtension = async () => {
try {
Expand Down Expand Up @@ -109,7 +106,6 @@ export default function Home() {
setError(undefined);

setTimestampJob(new Date().getTime())
/** Use Nostr extension to send event */
const pool = new SimplePool();
let pubkey;
if (typeof window !== "undefined" && window.nostr) {
Expand All @@ -130,7 +126,6 @@ export default function Home() {
content: content
}) // takes an event object, adds `id`, `pubkey` and `sig` and returns it
// Setup job request to fetch job id

// let eventID = await relay.publish(event as EventNostr);
const eventID = await Promise.any(pool.publish(ASKELADD_RELAY, event as EventNostr));
console.log("eventID", eventID[0])
Expand Down
54 changes: 8 additions & 46 deletions askeladd-dvm-marketplace/src/app/launch-program/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import { useState, useEffect, useMemo } from "react";
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useSendNote } from "@/hooks/useSendNote";
import { useFetchEvents } from "@/hooks/useFetchEvents";
import { APPLICATION_PUBKEY_DVM, ASKELADD_RELAY } from "@/constants/relay";
import { ASKELADD_RELAY } from "@/constants/relay";
import { Event as EventNostr, SimplePool } from "nostr-tools";
import { ASKELADD_KINDS, ConfigHandle, ContractUploadType, IGenerateZKPRequestDVM, IProgramParams, KIND_JOB_ADD_PROGRAM } from "@/types";
import EventCard from "../components/EventCard";
import { generateContentAndTags } from "../utils/generateAppHandler";
import { HowItWork } from "../components/description";
import { PROGRAM_INTERAL_REQUEST } from "@/constants/program";

export default function LaunchProgram() {
const [publicKey, setPublicKey] = useState<string | undefined>();
const [appKind, setAppKind] = useState<ASKELADD_KINDS | undefined>(ASKELADD_KINDS.KIND_JOB_REQUEST)
Expand All @@ -30,7 +26,6 @@ export default function LaunchProgram() {
const [timestampJob, setTimestampJob] = useState<number | undefined>();
const { fetchEvents, fetchEventsTools, setupSubscriptionNostr } = useFetchEvents()
const { sendNote, publishNote } = useSendNote()
const [logSize, setLogSize] = useState<number>(5);
const [claim, setClaim] = useState<number>(443693538);
const [inputIndex, setInputsIndex] = useState(0)
const [isOpenForm, setIsOpenForm] = useState(false)
Expand Down Expand Up @@ -178,28 +173,13 @@ export default function LaunchProgram() {

};

const mockProgram = async () => {
/** Todo better check */
if (!isLoading && !isOpenForm && Object.entries(form).length == 0) return;
setIsLoading(true);
setJobId(undefined)
setProofStatus("pending");
setError(undefined);
const tags = [
['param', 'log_size', logSize.toString()],
['param', 'claim', claim.toString()],
['output', 'text/json']
];

}
const submitProgram = async () => {
try {
setIsLoading(true);
setProofStatus("pending");
setLastConfig(undefined);
setError(undefined);
console.log("formEncrypted", formEncrypted)

let tags: string[][] = []
const inputs: Map<string, string> = new Map<string, string>();
{
Expand Down Expand Up @@ -236,20 +216,13 @@ export default function LaunchProgram() {
}

const content = JSON.stringify({
// request: form as any,
// request: form,
request: Object.fromEntries(inputs),
program: {
contract_name: programParam?.contract_name ?? "test",
// internal_contract_name: programParam?.internal_contract_name ?? "test",
contract_reached: programParam?.contract_reached ?? ContractUploadType.Ipfs,
inputs: Object.fromEntries(inputs),
// inputs_types: Object.fromEntries(inputs),
// inputs_encrypted: Object.fromEntries(inputs_encrypted),
// tags: tags
}
})

console.log("tags", tags)
console.log("content", content)
setTimestampJob(new Date().getTime())
Expand All @@ -272,7 +245,6 @@ export default function LaunchProgram() {
content: content
}) // takes an event object, adds `id`, `pubkey` and `sig` and returns it
// // Setup job request to fetch job id

// // let eventID = await relay.publish(event as EventNostr);
const eventID = await Promise.any(pool.publish(ASKELADD_RELAY, event as EventNostr));
console.log("eventID", eventID[0])
Expand Down Expand Up @@ -307,13 +279,13 @@ export default function LaunchProgram() {

}

const handleAllInputsEncrypted = () => {
Object.entries(form).map(([key, value]) => {
setFormEncrypted({ ...formEncrypted, [value as string]: true })
}
)
// const handleAllInputsEncrypted = () => {
// Object.entries(form).map(([key, value]) => {
// setFormEncrypted({ ...formEncrypted, [value as string]: true })
// }
// )

}
// }

return (
<main className="min-h-screen bg-black text-neon-green font-arcade p-4 pb-16 overflow-hidden">
Expand All @@ -327,8 +299,6 @@ export default function LaunchProgram() {
>
{isLoading ? "PROCESSING..." : "CONNECT"}
</button>


<div className="arcade-cabinet">
<h1 className="text-4xl mb-4 text-center glitch neon-text" data-text="Askeladd DVM Arcade NIP-89">Askeladd DVM</h1>
<p className="text-2xl mb-4 text-center glitch neon-text" data-text="Askeladd DVM Arcade NIP-89">Launch program</p>
Expand Down Expand Up @@ -372,7 +342,6 @@ export default function LaunchProgram() {

}}>X</button>
</div>

</div>
)
})}
Expand All @@ -389,7 +358,6 @@ export default function LaunchProgram() {

<div className="max-w-md mx-auto bg-dark-purple p-6 rounded-lg shadow-neon mt-8 relative game-screen">
<p>Inputs encrypted</p>

<button className="basic-button" onClick={handleLoadFormEncrypted}> Load inputs to continue settings</button>
{formEncrypted && Object.entries(formEncrypted).map(([key, value], i) => {
return (
Expand Down Expand Up @@ -449,13 +417,7 @@ export default function LaunchProgram() {
</div>
{isLoading && <div className="pixel-spinner mt-4 mx-auto"></div>}
</div>
{/* </div> */}
{/* <HowItWork /> */}
{/* <button
className={`block mb-5 font-bold py-2 px-4 rounded bg-blue-500 hover:bg-blue-700 ${isLoading ? "opacity-50 cursor-not-allowed" : ""}`}
disabled={isLoading}
onClick={fetchEventsApp}>{events && events?.length ? "Refresh" : "Load"}</button> */}

<HowItWork />
<div className="marquee">
</div>
</main>
Expand Down
63 changes: 9 additions & 54 deletions askeladd-dvm-marketplace/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
"use client";

import { useState, useEffect, useMemo } from "react";
import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk';
import { useNostrContext } from "@/context/NostrContext";
import { useSendNote } from "@/hooks/useSendNote";
import { ContractUploadType, JobResultProver, KIND_JOB_REQUEST, KIND_JOB_RESULT, ProgramInternalContractName } from "@/types";
import init, { verify_stark_proof, prove_and_verify, prove_and_verify_fib, verify_stark_proof_fib, stark_proof_wide_fibo, verify_stark_proof_wide_fibo } from "../pkg/stwo_wasm";
import { useFetchEvents } from "@/hooks/useFetchEvents";
import { ASKELADD_RELAY } from "@/constants/relay";
import { Relay } from 'nostr-tools/relay';
import { Event as EventNostr, SimplePool } from "nostr-tools";
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { ContractUploadType, ProgramInternalContractName } from "@/types";
import init, { stark_proof_wide_fibo, verify_stark_proof_wide_fibo } from "../pkg/stwo_wasm";
import { Event as EventNostr } from "nostr-tools";
import { useDVMState } from "@/hooks/useDVMState";
import { useSubmitJob } from "@/hooks/useSubmitJob";
export default function Home() {
const [log_n_instances, setLogNInstances] = useState<number>(0);
const [log_fibonacci_size, setLogFibonacciSize] = useState<number>(5);
const [publicKey, setPublicKey] = useState<string | undefined>();
const [error, setError] = useState<string | undefined>()
const [jobEventResult, setJobEventResult] = useState<EventNostr | undefined | NDKEvent>()
const [proofStatus, setProofStatus] = useState<
Expand All @@ -24,9 +17,10 @@ export default function Home() {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isInitialized, setIsInitialized] = useState(false);
const [isFetchJob, setIsFetchJob] = useState(false);
const { eventIdRequest, jobId, setJobId, setIsWaitingJob, fetchJobRequest, proof, fetchEventsProof,
const { eventIdRequest, jobId, setJobId, setIsWaitingJob, fetchJobRequest, proof, fetchEventsProof,
starkProof,
submitJob: submitJobModular, } = useDVMState()
submitJob: submitJobModular,
publicKey } = useDVMState()
// Init wasm module to run_fibonacci_verify
useEffect(() => {
init()
Expand Down Expand Up @@ -104,7 +98,7 @@ export default function Home() {
}
}

let res= await submitJobModular(5600, {
let res = await submitJobModular(5600, {
log_n_instances,
log_fibonacci_size
},
Expand All @@ -116,8 +110,6 @@ export default function Home() {
waitingForJobResult()
timeoutWaitingForJobResult()



} catch (e) {
} finally {
setIsLoading(false);
Expand All @@ -131,7 +123,6 @@ export default function Home() {
setIsLoading(true);
/** Change Wide fibo to default */
const serialised_proof_from_nostr_event = JSON.stringify(starkProof);

if (!log_n_instances && !log_fibonacci_size && !serialised_proof_from_nostr_event) return;
const prove_result = stark_proof_wide_fibo(Number(log_fibonacci_size), Number(log_n_instances));
console.log("wide fibo prove_result", prove_result);
Expand Down Expand Up @@ -169,9 +160,8 @@ export default function Home() {
<p className="text-center blink neon-text-sm">Censorship resistant global proving network</p>
<p className="text-center blink neon-text-sm">Verifiable computation for DVMs</p>
<div className="max-w-md mx-auto bg-dark-purple p-6 rounded-lg shadow-neon mt-8 relative game-screen">

{/* <p>Prove poseidon</p> */}
<p>Wide cci</p>
<p>Wide Fibonacci</p>
<div className="mb-4">
<label className="block mb-2 text-neon-pink">Log Fibonacci Size</label>
<input
Expand All @@ -181,8 +171,6 @@ export default function Home() {
className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2"
/>
</div>


<div className="mb-4">
<label className="block mb-2 text-neon-pink">Log N Instances</label>
<input
Expand All @@ -192,38 +180,6 @@ export default function Home() {
className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2"
/>
</div>

{/* <div className="mb-4">
<label className="block mb-2 text-neon-pink">Claim</label>
<input
type="number"
value={claim}
onChange={(e) => setClaim(Number(e.target.value))}
className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2"
/>
</div> */}


{/* <div className="mb-4">
<label className="block mb-2 text-neon-pink">Log Size</label>
<input
type="number"
value={logSize}
onChange={(e) => setLogSize(Number(e.target.value))}
className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2"
/>
</div>
<div className="mb-4">
<label className="block mb-2 text-neon-pink">Claim</label>
<input
type="number"
value={claim}
onChange={(e) => setClaim(Number(e.target.value))}
className="w-full bg-black text-neon-green px-3 py-2 rounded border-neon-green border-2"
/>
</div> */}

<button
onClick={submitJob}
disabled={isLoading}
Expand All @@ -234,7 +190,6 @@ export default function Home() {
</button>
</div>
{isLoading && <div className="pixel-spinner mt-4 mx-auto"></div>}

{jobId && (
<div className="mt-8 text-center">
<p className="text-neon-orange text-sm sm:text-base">Job ID: <span className="break-all">{jobId}</span></p>
Expand Down
Loading

0 comments on commit 79ab7c9

Please sign in to comment.