Skip to content

Commit

Permalink
Merge pull request #7 from YoubetDao/feat/support-donate-and-reward
Browse files Browse the repository at this point in the history
feat: support donation and reward distribution
  • Loading branch information
wfnuser authored Aug 26, 2024
2 parents 0b34f31 + bd58591 commit 939251e
Show file tree
Hide file tree
Showing 14 changed files with 547 additions and 78 deletions.
67 changes: 46 additions & 21 deletions examples/simple-react/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import './App.css'
import "./App.css";

import { ContractOwner } from './components/sections/ContractOwner'
import { AllGoals } from './components/sections/AllGoals'
import { GoalDetails } from './components/sections/GoalDetails'
import { UserGoals } from './components/sections/UserGoals'
import { ContractOwner } from "./components/sections/ContractOwner";
import { AllGoals } from "./components/sections/AllGoals";
import { GoalDetails } from "./components/sections/GoalDetails";
import { UserGoals } from "./components/sections/UserGoals";

import { CreateGoal } from './components/sections/CreateGoal'
import { CreateGoalSolo } from './components/sections/CreateGoalSolo'
import { ClaimStake } from './components/sections/ClaimStake'
import { StakeAndUnlockGoal } from './components/sections/StakeAndUnlockGoal'
import { ConfirmTaskCompletion } from './components/sections/ConfirmTaskCompletion'
import { SettleGoal } from './components/sections/SettleGoal'
import { CreateTask } from './components/sections/CreateTask'
import { LinkWallet } from './components/sections/LinkWallet'
import { AllTasks } from './components/sections/AllTasks'
import { ConfirmTask } from './components/sections/ConfirmTask'
import { AllUnconfirmedTasks } from './components/sections/AllUnconfirmedTasks'
import { UserPoints } from './components/sections/UserPoints'
import { CreateGoal } from "./components/sections/CreateGoal";
import { CreateGoalSolo } from "./components/sections/CreateGoalSolo";
import { ClaimStake } from "./components/sections/ClaimStake";
import { StakeAndUnlockGoal } from "./components/sections/StakeAndUnlockGoal";
import { ConfirmTaskCompletion } from "./components/sections/ConfirmTaskCompletion";
import { SettleGoal } from "./components/sections/SettleGoal";
import { CreateTask } from "./components/sections/CreateTask";
import { LinkWallet } from "./components/sections/LinkWallet";
import { AllTasks } from "./components/sections/AllTasks";
import { ConfirmTask } from "./components/sections/ConfirmTask";
import { AllUnconfirmedTasks } from "./components/sections/AllUnconfirmedTasks";
import { UserPoints } from "./components/sections/UserPoints";
import { DonateToProject } from "./components/sections/DonateToProject";
import { ClaimReward } from "./components/sections/ClaimReward";
import { GetClaimedRewards } from "./components/sections/GetClaimedRewards";
import { GetTotalRewards } from "./components/sections/GetTotalRewards";
import { AllProjects } from "./components/sections/AllProjects";
import { GetProjectParticipants } from "./components/sections/GetProjectParticipants";
// import { GoalCreated } from './components/sections/GoalCreated'

function App() {
return (
<>
<header className="header">
<img className="logo" src="/logo.png" alt="logo" width={28} height={28} />
<img
className="logo"
src="/logo.png"
alt="logo"
width={28}
height={28}
/>
<span>YouBet SDK</span>
</header>
<main className="main">
Expand All @@ -46,13 +58,26 @@ function App() {
<CreateTask />
<ConfirmTask />
<LinkWallet />
<DonateToProject />
<ClaimReward />
<GetTotalRewards />
<GetClaimedRewards />
<AllProjects />
<GetProjectParticipants />
{/* <GoalCreated /> */}
</main>
<footer className="footer">
Powered By <a href="https://youbetdao.github.io/" target="_blank" rel="noreferrer noopener">YouBet</a>
Powered By{" "}
<a
href="https://youbetdao.github.io/"
target="_blank"
rel="noreferrer noopener"
>
YouBet
</a>
</footer>
</>
)
);
}

export default App
export default App;
27 changes: 27 additions & 0 deletions examples/simple-react/src/components/sections/AllProjects.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";

import { Section } from "../Section";
import { Button } from "../Button";

export function AllProjects() {
const [value, setValue] = useState<any[]>([]);

const tryMe = async () => {
const result = await sdk.client.getAllProjectIds();
setValue(result);
};

return (
<>
<Section title="All Project Ids">
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
{value.map((data) => {
return <div key={data}>{data}</div>;
})}
</Section>
</>
);
}
17 changes: 17 additions & 0 deletions examples/simple-react/src/components/sections/ClaimReward.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { sdk } from '../../lib/youbet-sdk'
import { Section } from '../Section'
import { Button } from '../Button'

export function ClaimReward() {
const tryMe = async () => {
await sdk.contract.claimReward()
}

return (<>
<Section title="Claim Reward">
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
</Section>
</>)
}
4 changes: 2 additions & 2 deletions examples/simple-react/src/components/sections/ConfirmTask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Section } from "../Section";
import { Button } from "../Button";

export function ConfirmTask() {
const [taskId, setTaskId] = useState(1);
const [taskId, setTaskId] = useState("2460577971");
const [github, setGithub] = useState("wfnuser");

const tryMe = async () => {
Expand All @@ -19,7 +19,7 @@ export function ConfirmTask() {
<label>TaskId</label>
<input
value={taskId}
onChange={(e) => setTaskId(Number(e.target.value))}
onChange={(e) => setTaskId(e.target.value)}
/>
</div>
<div>
Expand Down
32 changes: 32 additions & 0 deletions examples/simple-react/src/components/sections/CreateProject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";
import { Section } from "../Section";
import { Button } from "../Button";

export function CreateProject() {
const [id, setId] = useState("829893564");
const [name, setName] = useState("YoubetDao/youbet-test-repo/issues/12");

const tryMe = async () => {
const taskInfo = await sdk.contract.createProject(id, name);
console.log(taskInfo);
};

return (
<>
<Section title="Create Project">
<div>
<label>Id: github id</label>
<input value={id} onChange={(e) => setId(e.target.value)} />
</div>
<div>
<label>Name: related to github issue</label>
<input value={name} onChange={(e) => setName(e.target.value)} />
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
</Section>
</>
);
}
55 changes: 35 additions & 20 deletions examples/simple-react/src/components/sections/CreateTask.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import { useState } from 'react'
import { sdk } from '../../lib/youbet-sdk'
import { Section } from '../Section'
import { Button } from '../Button'
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";
import { Section } from "../Section";
import { Button } from "../Button";

export function CreateTask() {
const [sub, setSub] = useState('YoubetDao/youbet-web3-allin/issues/1')
const [id, setId] = useState("2460577971");
const [name, setName] = useState("YoubetDao/youbet-test-repo/issues/12");
const [projectId, setProjectId] = useState("829893564");

const tryMe = async () => {
const taskInfo = await sdk.contract.createTask(sub)
console.log(taskInfo)
}
const taskInfo = await sdk.contract.createTask(id, name, projectId);
console.log(taskInfo);
};

return (<>
<Section title="Create Task">
<div>
<label>Sub: related to github issue</label>
<input value={sub} onChange={(e) => setSub(e.target.value)} />
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
</Section>
</>)
}
return (
<>
<Section title="Create Task">
<div>
<label>Id: github id</label>
<input value={id} onChange={(e) => setId(e.target.value)} />
</div>
<div>
<label>Name: related to github issue</label>
<input value={name} onChange={(e) => setName(e.target.value)} />
</div>
<div>
<label>ProjectId: github id</label>
<input
value={projectId}
onChange={(e) => setProjectId(e.target.value)}
/>
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
</Section>
</>
);
}
30 changes: 30 additions & 0 deletions examples/simple-react/src/components/sections/DonateToProject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";
import { Section } from "../Section";
import { Button } from "../Button";

export function DonateToProject() {
const [projectId, setProjectId] = useState("829893564");

const tryMe = async () => {
const taskInfo = await sdk.contract.donateToProject(projectId, "0.0003");
console.log(taskInfo);
};

return (
<>
<Section title="Donate To Project">
<div>
<label>ProjectId</label>
<input
value={projectId}
onChange={(e) => setProjectId(e.target.value)}
/>
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
</Section>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";
import { Section } from "../Section";
import { Button } from "../Button";

export function GetClaimedRewards() {
const [user, setUser] = useState(
"0x4808df9a90196d41459a3fe37d76dca32f795338"
);
const [value, setValue] = useState(0);

const tryMe = async () => {
const result = await sdk.client.getClaimedRewards(user);
setValue(result);
console.log(result);
};

return (
<>
<Section title="Get Claimed Rewards">
<div>
<label>User wallet address</label>
<input value={user} onChange={(e) => setUser(e.target.value)} />
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
{
<div>
<textarea disabled value={value}></textarea>
</div>
}
</Section>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";
import { Section } from "../Section";
import { Button } from "../Button";

export function GetProjectParticipants() {
const [projectId, setProjectId] = useState("829893564");
const [value, setValue] = useState<string[]>([]);

const tryMe = async () => {
const result = await sdk.client.getProjectParticipants(projectId);
setValue(result);
};

return (
<>
<Section title="Get Project Participants">
<div>
<label>ProjectId</label>
<input
value={projectId}
onChange={(e) => setProjectId(e.target.value)}
/>
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
{value.map((data) => {
return <div key={data}>address: {data}</div>;
})}
</Section>
</>
);
}
35 changes: 35 additions & 0 deletions examples/simple-react/src/components/sections/GetTotalRewards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useState } from "react";
import { sdk } from "../../lib/youbet-sdk";
import { Section } from "../Section";
import { Button } from "../Button";

export function GetTotalRewards() {
const [user, setUser] = useState(
"0x4808df9a90196d41459a3fe37d76dca32f795338"
);
const [value, setValue] = useState(0);

const tryMe = async () => {
const result = await sdk.client.getTotalRewards(user);
setValue(result);
};

return (
<>
<Section title="Get Total Rewards">
<div>
<label>User wallet address</label>
<input value={user} onChange={(e) => setUser(e.target.value)} />
</div>
<div>
<Button onClick={tryMe}>Try Me!</Button>
</div>
{
<div>
<textarea disabled value={value}></textarea>
</div>
}
</Section>
</>
);
}
Loading

0 comments on commit 939251e

Please sign in to comment.