Skip to content

Commit e15d366

Browse files
authored
Merge pull request #76 from dOrgTech/documentation_improvements
Adding some recipes + adding hooks to api reference
2 parents 33d03b9 + 696f803 commit e15d366

3 files changed

Lines changed: 114 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ proposals...
6666
- [architecture](./documentation/architecture.md)
6767
- [api](./documentation/api.md)
6868
69+
Check the [demo app!](https://github.com/dOrgTech/arc.react-demo)
70+
6971
# Build & Contribute
7072
7173
## Prerequisites

documentation/api.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const arcConfig = new ArcConfig({
4343
...config,
4444
web3Provider: metamask,
4545
});
46+
arcConfig.initialize();
4647
```
4748

4849
You can also pass in your own configuration values like so:
@@ -58,6 +59,7 @@ const settings: ArcSettings = {
5859
};
5960

6061
const arcConfig = new ArcConfig(settings);
62+
arcConfig.initialize();
6163
```
6264

6365
---
@@ -500,3 +502,35 @@ from?: "DAO" | "Member as proposer"
500502
<Proposals />
501503
</Member>
502504
```
505+
506+
---
507+
508+
## useComponent
509+
510+
As you previously saw, to get the information (`Data` and `Entity`) from every component we need to do, for example with Member:
511+
512+
```html
513+
<Member address="0x" dao="0x">
514+
<Member.Data>
515+
{(member: MemberData) =>
516+
<div>{"Member id: " + member.id}</div>
517+
}
518+
</Member.Data>
519+
</Member>
520+
```
521+
522+
But the library also allows you to do, (this is available for every component of the library):
523+
524+
```jsx
525+
const MyMemberComponent = () => {
526+
const [memberData, memberEntity] = useMember();
527+
return <div>Member id: {memberData?.id}</div>;
528+
};
529+
<Member address="0x" dao="0x">
530+
<MyMemberComponent />
531+
</Member>;
532+
```
533+
534+
Note that you MUST implement the component that has the `useXXX` INSIDE of the component you want to get the data and/or from. Also, you must use the `?` when interacting with the hook because it can be undefined.
535+
536+
[Click here](https://github.com/dOrgTech/arc.react-demo/blob/dev/src/components/Proposals/Create.tsx#L20) to check an example

documentation/recipes.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Recipes
2+
3+
Here are some tricks that you can do when using the library. All these have been implemented in the demo app previously mentioned in the README.
4+
5+
## Showing members with their reputation percentage
6+
7+
```html
8+
<DAO address="0x">
9+
<Members from="DAO">
10+
<DAO.Data>
11+
<Member.Data>
12+
{(daoData: DAOData, memberData: MemberData) => { const memberPercentage
13+
= (Number(memberData.reputation) * 100) /
14+
Number(daoData.reputationTotalSupply) return (
15+
<div>
16+
<p>{memberData.address}</p>
17+
<p>{memberPercentage.toFixed(2)}</p>
18+
</div>
19+
); }}
20+
</Member.Data>
21+
</DAO.Data>
22+
</Members>
23+
</DAO>
24+
```
25+
26+
## Filtering proposals
27+
28+
In this example we are going to show the latest **active** proposals from the DAO, and make a button to vote for them. NOTE: The user must be logged in otherwise the vote will fail
29+
30+
```tsx
31+
const activeProposals = {
32+
where: { stage_in: [2, 3, 4, 5] },
33+
orderBy: "closingAt",
34+
orderDirection: "desc",
35+
};
36+
<Proposals filter={activeProposals} from="DAO">
37+
<Proposal.Data>
38+
<Proposal.Entity>
39+
{(proposalData: ProposalData, proposalEntity: ProposalEntity) => (
40+
<div>
41+
<p> {proposalData.title} </p>
42+
<button
43+
onClick={async (e) => {
44+
await proposalEntity.vote(1).send();
45+
}}
46+
>
47+
Vote for
48+
</button>
49+
</div>
50+
)}
51+
</Proposal.Entity>
52+
</Proposal.Data>
53+
</Proposals>;
54+
```
55+
56+
## Showing the percentage of votes against a proposal
57+
58+
```tsx
59+
const showPercentage = (votes: BN, totalRep: BN) => {
60+
return votes
61+
.muln(100)
62+
.div(totalRep)
63+
.toNumber();
64+
};
65+
<DAO address="0xDAO_Address">
66+
<Proposal id="0xProposal_ID">
67+
<DAO.Data>
68+
<Proposal.Data>
69+
({daoData; DAOData, proposalData: ProposalData) => (
70+
<div>
71+
Votes for: {showPercentage(proposalData.votesFor, DAOData.reputationTotalSupply)} - Votes against: {showPercentage(proposalData.votesAgainst, DAOData.reputationTotalSupply)}
72+
</div>
73+
)})
74+
</Proposal.Data>
75+
</DAO.Data>
76+
</Proposal>
77+
</DAO>
78+
```

0 commit comments

Comments
 (0)