|
| 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