Skip to content
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

feat: upgrade gno dao ui #706

Merged
merged 11 commits into from
Sep 19, 2023
26 changes: 18 additions & 8 deletions networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,16 @@
"testnet": true,
"backendEndpoint": "http://localhost:9090",
"vaultContractAddress": "",
"socialFeedsPkgPath": "gno.land/r/demo/social_feeds_v8",
"socialFeedsDAOPkgPath": "gno.land/r/demo/social_feeds_dao_v2",
"daoRegistryPkgPath": "gno.land/r/demo/teritori/dao_registry",
"socialFeedsPkgPath": "gno.land/r/demo/teritori/social_feeds",
"socialFeedsDAOPkgPath": "gno.land/r/demo/teritori/social_feeds_dao",
"nameServiceContractAddress": "gno.land/r/demo/users",
"groupsPkgPath": "gno.land/r/demo/groups_v9",
"modboardsPkgPath": "gno.land/r/demo/teritori/modboards",
"groupsPkgPath": "gno.land/r/demo/teritori/groups",
"votingGroupPkgPath": "gno.land/p/demo/teritori/dao_voting_group",
"daoProposalSinglePkgPath": "gno.land/p/demo/teritori/dao_proposal_single",
"daoInterfacesPkgPath": "gno.land/p/demo/teritori/dao_interfaces",
"daoCorePkgPath": "gno.land/p/demo/teritori/dao_core",
"nameServiceDefaultImage": "ipfs://bafkreignptjimiu7wuux6mk6uh4hb4odb6ff62ny4bvdokrhes7g67huse",
"gnowebURL": "http://127.0.0.1:8888"
},
Expand Down Expand Up @@ -636,11 +642,15 @@
"vaultContractAddress": "",
"nameServiceContractAddress": "gno.land/r/demo/users",
"nameServiceDefaultImage": "ipfs://bafkreignptjimiu7wuux6mk6uh4hb4odb6ff62ny4bvdokrhes7g67huse",
"daoRegistryPkgPath": "gno.land/r/demo/dao_registry_v5",
"modboardsPkgPath": "gno.land/r/demo/modboards_v3",
"groupsPkgPath": "gno.land/r/demo/groups_v9",
"socialFeedsPkgPath": "gno.land/r/demo/social_feeds_v9",
"socialFeedsDAOPkgPath": "gno.land/r/demo/social_feeds_dao_v3",
"daoRegistryPkgPath": "gno.land/r/demo/teritori/dao_registry_v4",
"socialFeedsPkgPath": "gno.land/r/demo/teritori/social_feeds_v4",
"socialFeedsDAOPkgPath": "gno.land/r/demo/teritori/social_feeds_dao_v2",
"modboardsPkgPath": "gno.land/r/demo/teritori/modboards_v4",
"groupsPkgPath": "gno.land/r/demo/teritori/groups_v4",
"votingGroupPkgPath": "gno.land/p/demo/teritori/dao_voting_group_v2",
"daoProposalSinglePkgPath": "gno.land/p/demo/teritori/dao_proposal_single_v4",
"daoInterfacesPkgPath": "gno.land/p/demo/teritori/dao_interfaces_v5",
"daoCorePkgPath": "gno.land/p/demo/teritori/dao_core_v4",
"gnowebURL": "https://testnet.gno.teritori.com"
}
]
87 changes: 29 additions & 58 deletions packages/components/dao/DAOMembers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ import { useNameSearch } from "../../hooks/search/useNameSearch";
import { useNSUserInfo } from "../../hooks/useNSUserInfo";
import useSelectedWallet from "../../hooks/useSelectedWallet";
import { NetworkKind, getUserId, parseUserId } from "../../networks";
import { toRawURLBase64String } from "../../utils/buffer";
import { adenaVMCall, extractGnoNumber } from "../../utils/gno";
import { adenaVMCall, extractGnoJSONString } from "../../utils/gno";
import { VotingGroupConfig } from "../../utils/gnodao/configs";
import {
GnoAddMemberMessage,
GnoSingleChoiceProposal,
} from "../../utils/gnodao/messages";
import {
neutral00,
neutral33,
Expand Down Expand Up @@ -552,33 +556,39 @@ const useProposeToAddMembers = (daoId: string | undefined) => {
case NetworkKind.Gno: {
const client = new GnoJSONRPCProvider(network.endpoint);

const groupId = extractGnoNumber(
await client.evaluateExpression(daoAddress, "GetGroupID()")
const moduleConfig: VotingGroupConfig = extractGnoJSONString(
await client.evaluateExpression(
daoAddress,
"daoCore.VotingModule().ConfigJSON()"
)
);
const { groupId } = moduleConfig;

console.log("groupId", groupId);

const b64Messages: string[] = [];
const msgs: GnoAddMemberMessage[] = [];
for (const member of membersToAdd) {
b64Messages.push(
toRawURLBase64String(
encodeAddMember({
groupId,
addr: member,
weight,
metadata: "",
})
)
);
msgs.push({
type: "gno.land/r/demo/teritori/groups.AddMember",
payload: {
groupId,
address: member,
weight,
metadata: "",
},
});
}
const propReq: GnoSingleChoiceProposal = {
title: `Add ${membersToAdd.length} member(s) with weight ${weight}`,
description: "",
messages: msgs,
};
await adenaVMCall(
network.id,
{
caller: senderAddress,
send: "",
pkg_path: daoAddress,
func: "Propose",
args: ["0", "Add members", "", b64Messages.join(",")],
func: "ProposeJSON",
args: ["0", JSON.stringify(propReq)],
},
{ gasWanted: 2000000 }
);
Expand All @@ -590,42 +600,3 @@ const useProposeToAddMembers = (daoId: string | undefined) => {
[daoId, groupAddress, invalidateDAOProposals, makeProposal]
);
};

interface GnoMember {
groupId: number;
addr: string;
weight: number;
metadata: string;
}

const encodeAddMember = (member: GnoMember) => {
const b = Buffer.alloc(16000); // TODO: compute size or concat

let offset = 0;

const type = "AddMember";
b.writeUInt16BE(type.length, offset);
offset += 2;
b.write(type, offset);
offset += type.length;

b.writeUInt32BE(0, offset);
offset += 4;
b.writeUInt32BE(member.groupId, offset);
offset += 4;

b.writeUInt16BE(member.addr.length, offset);
offset += 2;
b.write(member.addr, offset);
offset += member.addr.length;

b.writeUInt32BE(member.weight, offset);
offset += 4;

b.writeUInt16BE(member.metadata.length, offset);
offset += 2;
b.write(member.metadata, offset);
offset += member.metadata.length;

return Buffer.from(b.subarray(0, offset));
};
60 changes: 23 additions & 37 deletions packages/components/dao/DAOProposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
AppProposalResponse,
useDAOProposals,
} from "../../hooks/dao/useDAOProposals";
import { useDAOTotalVotingPower } from "../../hooks/dao/useDAOTotalVotingPower";
import { useNSPrimaryAlias } from "../../hooks/useNSPrimaryAlias";
import { getUserId, parseUserId } from "../../networks";
import {
Expand Down Expand Up @@ -52,7 +51,6 @@ const ProposalRow: React.FC<{
proposal: AppProposalResponse;
}> = ({ daoId, proposal }) => {
const [network] = parseUserId(daoId);
const { daoTotalVotingPower } = useDAOTotalVotingPower(daoId);

const halfGap = 24;
const elemStyle: ViewStyle = {
Expand All @@ -70,7 +68,7 @@ const ProposalRow: React.FC<{
};
weights.voted = weights.approved + weights.declined + weights.abstained;

const totalWeight = parseFloat(daoTotalVotingPower?.power || "0");
const totalWeight = parseFloat(proposal.proposal.total_power);

let thresholdGain = 0;
let quorumGain = 0;
Expand All @@ -88,10 +86,7 @@ const ProposalRow: React.FC<{
}
}

const quorumWeight =
proposal.proposal.status === "open"
? quorumGain * totalWeight
: quorumGain * weights.voted;
const quorumWeight = quorumGain * totalWeight;
const targetWeight = Math.max(weights.voted, quorumWeight);
const thresholdWeight = thresholdGain * targetWeight;

Expand Down Expand Up @@ -182,36 +177,27 @@ const ProposalRow: React.FC<{
justifyContent: "space-between",
}}
>
{proposal.proposal.status === "open" && (
<>
<BrandText
style={[fontSemibold14, { lineHeight: 14, color: neutral77 }]}
numberOfLines={1}
>
Voted:{" "}
<Text style={{ color: "white" }}>
{Math.ceil(weights.voted)}
</Text>
/
<Text style={{ color: "white" }}>
{Math.ceil(quorumWeight)}
</Text>
</BrandText>
<BrandText
style={[fontSemibold14, { lineHeight: 14, color: neutral77 }]}
numberOfLines={1}
>
Yes:{" "}
<Text style={{ color: "white" }}>
{Math.ceil(weights.approved)}
</Text>
/
<Text style={{ color: "white" }}>
{Math.ceil(thresholdWeight)}
</Text>
</BrandText>
</>
)}
<BrandText
style={[fontSemibold14, { lineHeight: 14, color: neutral77 }]}
numberOfLines={1}
>
Voted:{" "}
<Text style={{ color: "white" }}>{Math.ceil(weights.voted)}</Text>
/<Text style={{ color: "white" }}>{Math.ceil(quorumWeight)}</Text>
</BrandText>
<BrandText
style={[fontSemibold14, { lineHeight: 14, color: neutral77 }]}
numberOfLines={1}
>
Yes:{" "}
<Text style={{ color: "white" }}>
{Math.ceil(weights.approved)}
</Text>
/
<Text style={{ color: "white" }}>
{Math.ceil(thresholdWeight)}
</Text>
</BrandText>
</View>
<View
style={{
Expand Down
Loading
Loading