Skip to content

Form for automatic challenge verification #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 75 additions & 7 deletions src/app/challenges/submission/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,82 @@
"use client";
import React from "react";

import TallyForm from "@/components/TallyForm";
import React, { useState } from "react";
import Button from "@/components/Button";

const SubmissionPage = () => {
const [formData, setFormData] = useState({
contract: "",
challenge: ""
});

const [result , setResult] = useState(null)
const [error, setError] = useState("")

const handleInput = (e) => {
const fieldName = e.target.name;
const fieldValue = e.target.value;

setFormData((prevState) => ({
...prevState,
[fieldName]: fieldValue
}));
setError("")
}

const testCode = async (e) => {
e.preventDefault()
const testsUrl = `http://ec2-18-237-163-150.us-west-2.compute.amazonaws.com:3000/run-tests/${formData.challenge}`
const res = await fetch(testsUrl, {
method: "POST",
headers: {'Content-Type': 'text/plain'},
body: formData.contract
})
if (res.status == 200){
setResult(await res.json())
} else {
setError("Tests failed/compilation error: Please run the provided Foundry tests locally from the Github repository to debug and try again!")
}
};

const submitCode = async (e) => {
e.preventDefault()
// display or navigate to Tally form
}

return (
<TallyForm
tallyUrl="https://tally.so/r/wLYDW1"
title="Submit your solution to a Level Up Challenge!"
/>
<div>
{result == null ? <form>
<div>
<label>Challenge</label>
<select name="challenge">
<option value="ERC20">ERC20</option>
<option value="SimpleLending">SimpleLending</option>
</select>
</div>
<div>
<label>Contract Code</label>
<textarea name="contract" onChange={handleInput}></textarea>
</div>
{ error != "" && <text>{error}</text>}
<Button
variant="contained"
onClick={testCode}
>
Test your Code
</Button>
</form>
: <div>
{result ?
<div>
<text>Test passed! Submit your challenge via the button below. </text>
<Button variant="contained" onClick={submitCode}>Submit Challenge</Button>
</div>
:<text>This doesn't seem to pass all the tests, double check your code and try again!</text>
}

</div>
}
</div>

);
};

Expand Down