Skip to content

Commit 939251e

Browse files
authored
Merge pull request #7 from YoubetDao/feat/support-donate-and-reward
feat: support donation and reward distribution
2 parents 0b34f31 + bd58591 commit 939251e

14 files changed

+547
-78
lines changed

examples/simple-react/src/App.tsx

+46-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
1-
import './App.css'
1+
import "./App.css";
22

3-
import { ContractOwner } from './components/sections/ContractOwner'
4-
import { AllGoals } from './components/sections/AllGoals'
5-
import { GoalDetails } from './components/sections/GoalDetails'
6-
import { UserGoals } from './components/sections/UserGoals'
3+
import { ContractOwner } from "./components/sections/ContractOwner";
4+
import { AllGoals } from "./components/sections/AllGoals";
5+
import { GoalDetails } from "./components/sections/GoalDetails";
6+
import { UserGoals } from "./components/sections/UserGoals";
77

8-
import { CreateGoal } from './components/sections/CreateGoal'
9-
import { CreateGoalSolo } from './components/sections/CreateGoalSolo'
10-
import { ClaimStake } from './components/sections/ClaimStake'
11-
import { StakeAndUnlockGoal } from './components/sections/StakeAndUnlockGoal'
12-
import { ConfirmTaskCompletion } from './components/sections/ConfirmTaskCompletion'
13-
import { SettleGoal } from './components/sections/SettleGoal'
14-
import { CreateTask } from './components/sections/CreateTask'
15-
import { LinkWallet } from './components/sections/LinkWallet'
16-
import { AllTasks } from './components/sections/AllTasks'
17-
import { ConfirmTask } from './components/sections/ConfirmTask'
18-
import { AllUnconfirmedTasks } from './components/sections/AllUnconfirmedTasks'
19-
import { UserPoints } from './components/sections/UserPoints'
8+
import { CreateGoal } from "./components/sections/CreateGoal";
9+
import { CreateGoalSolo } from "./components/sections/CreateGoalSolo";
10+
import { ClaimStake } from "./components/sections/ClaimStake";
11+
import { StakeAndUnlockGoal } from "./components/sections/StakeAndUnlockGoal";
12+
import { ConfirmTaskCompletion } from "./components/sections/ConfirmTaskCompletion";
13+
import { SettleGoal } from "./components/sections/SettleGoal";
14+
import { CreateTask } from "./components/sections/CreateTask";
15+
import { LinkWallet } from "./components/sections/LinkWallet";
16+
import { AllTasks } from "./components/sections/AllTasks";
17+
import { ConfirmTask } from "./components/sections/ConfirmTask";
18+
import { AllUnconfirmedTasks } from "./components/sections/AllUnconfirmedTasks";
19+
import { UserPoints } from "./components/sections/UserPoints";
20+
import { DonateToProject } from "./components/sections/DonateToProject";
21+
import { ClaimReward } from "./components/sections/ClaimReward";
22+
import { GetClaimedRewards } from "./components/sections/GetClaimedRewards";
23+
import { GetTotalRewards } from "./components/sections/GetTotalRewards";
24+
import { AllProjects } from "./components/sections/AllProjects";
25+
import { GetProjectParticipants } from "./components/sections/GetProjectParticipants";
2026
// import { GoalCreated } from './components/sections/GoalCreated'
2127

2228
function App() {
2329
return (
2430
<>
2531
<header className="header">
26-
<img className="logo" src="/logo.png" alt="logo" width={28} height={28} />
32+
<img
33+
className="logo"
34+
src="/logo.png"
35+
alt="logo"
36+
width={28}
37+
height={28}
38+
/>
2739
<span>YouBet SDK</span>
2840
</header>
2941
<main className="main">
@@ -46,13 +58,26 @@ function App() {
4658
<CreateTask />
4759
<ConfirmTask />
4860
<LinkWallet />
61+
<DonateToProject />
62+
<ClaimReward />
63+
<GetTotalRewards />
64+
<GetClaimedRewards />
65+
<AllProjects />
66+
<GetProjectParticipants />
4967
{/* <GoalCreated /> */}
5068
</main>
5169
<footer className="footer">
52-
Powered By <a href="https://youbetdao.github.io/" target="_blank" rel="noreferrer noopener">YouBet</a>
70+
Powered By{" "}
71+
<a
72+
href="https://youbetdao.github.io/"
73+
target="_blank"
74+
rel="noreferrer noopener"
75+
>
76+
YouBet
77+
</a>
5378
</footer>
5479
</>
55-
)
80+
);
5681
}
5782

58-
export default App
83+
export default App;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
4+
import { Section } from "../Section";
5+
import { Button } from "../Button";
6+
7+
export function AllProjects() {
8+
const [value, setValue] = useState<any[]>([]);
9+
10+
const tryMe = async () => {
11+
const result = await sdk.client.getAllProjectIds();
12+
setValue(result);
13+
};
14+
15+
return (
16+
<>
17+
<Section title="All Project Ids">
18+
<div>
19+
<Button onClick={tryMe}>Try Me!</Button>
20+
</div>
21+
{value.map((data) => {
22+
return <div key={data}>{data}</div>;
23+
})}
24+
</Section>
25+
</>
26+
);
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { sdk } from '../../lib/youbet-sdk'
2+
import { Section } from '../Section'
3+
import { Button } from '../Button'
4+
5+
export function ClaimReward() {
6+
const tryMe = async () => {
7+
await sdk.contract.claimReward()
8+
}
9+
10+
return (<>
11+
<Section title="Claim Reward">
12+
<div>
13+
<Button onClick={tryMe}>Try Me!</Button>
14+
</div>
15+
</Section>
16+
</>)
17+
}

examples/simple-react/src/components/sections/ConfirmTask.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Section } from "../Section";
44
import { Button } from "../Button";
55

66
export function ConfirmTask() {
7-
const [taskId, setTaskId] = useState(1);
7+
const [taskId, setTaskId] = useState("2460577971");
88
const [github, setGithub] = useState("wfnuser");
99

1010
const tryMe = async () => {
@@ -19,7 +19,7 @@ export function ConfirmTask() {
1919
<label>TaskId</label>
2020
<input
2121
value={taskId}
22-
onChange={(e) => setTaskId(Number(e.target.value))}
22+
onChange={(e) => setTaskId(e.target.value)}
2323
/>
2424
</div>
2525
<div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
import { Section } from "../Section";
4+
import { Button } from "../Button";
5+
6+
export function CreateProject() {
7+
const [id, setId] = useState("829893564");
8+
const [name, setName] = useState("YoubetDao/youbet-test-repo/issues/12");
9+
10+
const tryMe = async () => {
11+
const taskInfo = await sdk.contract.createProject(id, name);
12+
console.log(taskInfo);
13+
};
14+
15+
return (
16+
<>
17+
<Section title="Create Project">
18+
<div>
19+
<label>Id: github id</label>
20+
<input value={id} onChange={(e) => setId(e.target.value)} />
21+
</div>
22+
<div>
23+
<label>Name: related to github issue</label>
24+
<input value={name} onChange={(e) => setName(e.target.value)} />
25+
</div>
26+
<div>
27+
<Button onClick={tryMe}>Try Me!</Button>
28+
</div>
29+
</Section>
30+
</>
31+
);
32+
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
1-
import { useState } from 'react'
2-
import { sdk } from '../../lib/youbet-sdk'
3-
import { Section } from '../Section'
4-
import { Button } from '../Button'
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
import { Section } from "../Section";
4+
import { Button } from "../Button";
55

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

911
const tryMe = async () => {
10-
const taskInfo = await sdk.contract.createTask(sub)
11-
console.log(taskInfo)
12-
}
12+
const taskInfo = await sdk.contract.createTask(id, name, projectId);
13+
console.log(taskInfo);
14+
};
1315

14-
return (<>
15-
<Section title="Create Task">
16-
<div>
17-
<label>Sub: related to github issue</label>
18-
<input value={sub} onChange={(e) => setSub(e.target.value)} />
19-
</div>
20-
<div>
21-
<Button onClick={tryMe}>Try Me!</Button>
22-
</div>
23-
</Section>
24-
</>)
25-
}
16+
return (
17+
<>
18+
<Section title="Create Task">
19+
<div>
20+
<label>Id: github id</label>
21+
<input value={id} onChange={(e) => setId(e.target.value)} />
22+
</div>
23+
<div>
24+
<label>Name: related to github issue</label>
25+
<input value={name} onChange={(e) => setName(e.target.value)} />
26+
</div>
27+
<div>
28+
<label>ProjectId: github id</label>
29+
<input
30+
value={projectId}
31+
onChange={(e) => setProjectId(e.target.value)}
32+
/>
33+
</div>
34+
<div>
35+
<Button onClick={tryMe}>Try Me!</Button>
36+
</div>
37+
</Section>
38+
</>
39+
);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
import { Section } from "../Section";
4+
import { Button } from "../Button";
5+
6+
export function DonateToProject() {
7+
const [projectId, setProjectId] = useState("829893564");
8+
9+
const tryMe = async () => {
10+
const taskInfo = await sdk.contract.donateToProject(projectId, "0.0003");
11+
console.log(taskInfo);
12+
};
13+
14+
return (
15+
<>
16+
<Section title="Donate To Project">
17+
<div>
18+
<label>ProjectId</label>
19+
<input
20+
value={projectId}
21+
onChange={(e) => setProjectId(e.target.value)}
22+
/>
23+
</div>
24+
<div>
25+
<Button onClick={tryMe}>Try Me!</Button>
26+
</div>
27+
</Section>
28+
</>
29+
);
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
import { Section } from "../Section";
4+
import { Button } from "../Button";
5+
6+
export function GetClaimedRewards() {
7+
const [user, setUser] = useState(
8+
"0x4808df9a90196d41459a3fe37d76dca32f795338"
9+
);
10+
const [value, setValue] = useState(0);
11+
12+
const tryMe = async () => {
13+
const result = await sdk.client.getClaimedRewards(user);
14+
setValue(result);
15+
console.log(result);
16+
};
17+
18+
return (
19+
<>
20+
<Section title="Get Claimed Rewards">
21+
<div>
22+
<label>User wallet address</label>
23+
<input value={user} onChange={(e) => setUser(e.target.value)} />
24+
</div>
25+
<div>
26+
<Button onClick={tryMe}>Try Me!</Button>
27+
</div>
28+
{
29+
<div>
30+
<textarea disabled value={value}></textarea>
31+
</div>
32+
}
33+
</Section>
34+
</>
35+
);
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
import { Section } from "../Section";
4+
import { Button } from "../Button";
5+
6+
export function GetProjectParticipants() {
7+
const [projectId, setProjectId] = useState("829893564");
8+
const [value, setValue] = useState<string[]>([]);
9+
10+
const tryMe = async () => {
11+
const result = await sdk.client.getProjectParticipants(projectId);
12+
setValue(result);
13+
};
14+
15+
return (
16+
<>
17+
<Section title="Get Project Participants">
18+
<div>
19+
<label>ProjectId</label>
20+
<input
21+
value={projectId}
22+
onChange={(e) => setProjectId(e.target.value)}
23+
/>
24+
</div>
25+
<div>
26+
<Button onClick={tryMe}>Try Me!</Button>
27+
</div>
28+
{value.map((data) => {
29+
return <div key={data}>address: {data}</div>;
30+
})}
31+
</Section>
32+
</>
33+
);
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useState } from "react";
2+
import { sdk } from "../../lib/youbet-sdk";
3+
import { Section } from "../Section";
4+
import { Button } from "../Button";
5+
6+
export function GetTotalRewards() {
7+
const [user, setUser] = useState(
8+
"0x4808df9a90196d41459a3fe37d76dca32f795338"
9+
);
10+
const [value, setValue] = useState(0);
11+
12+
const tryMe = async () => {
13+
const result = await sdk.client.getTotalRewards(user);
14+
setValue(result);
15+
};
16+
17+
return (
18+
<>
19+
<Section title="Get Total Rewards">
20+
<div>
21+
<label>User wallet address</label>
22+
<input value={user} onChange={(e) => setUser(e.target.value)} />
23+
</div>
24+
<div>
25+
<Button onClick={tryMe}>Try Me!</Button>
26+
</div>
27+
{
28+
<div>
29+
<textarea disabled value={value}></textarea>
30+
</div>
31+
}
32+
</Section>
33+
</>
34+
);
35+
}

0 commit comments

Comments
 (0)