const [policyView, setPolicyView] = useState(null); const daoId = props.daoId ?? "cityhall.sputnik-dao.near"; const policy = Near.view(daoId, "get_policy"); if (policy === null) { return "Loading DAO policy..."; } const deposit = policy.proposal_bond; const newPolicy = { roles: [ { name: "all", kind: "Everyone", permissions: ["*:AddProposal"], vote_policy: {}, }, { name: "Community", kind: { Group: ["james.near"], }, permissions: ["*:AddProposal", "vote:*"], }, { kind: { Group: ["james.near"], }, name: "Admin", permissions: ["*:*"], vote_policy: { quorum: "0", threshold: [1, 3], weight_kind: "RoleWeight", }, }, { kind: { Group: ["james.near"], }, name: "Council", permissions: ["*:*"], }, ], default_vote_policy: { quorum: "0", threshold: [1, 2], weight_kind: "RoleWeight", }, proposal_bond: "100000000000000000000000", proposal_period: "604800000000000", bounty_bond: "100000000000000000000000", bounty_forgiveness_period: "604800000000000", }; const handleProposal = () => { Near.call([ { contractName: daoId, methodName: "add_proposal", args: { proposal: { description: "reconfigure policy", kind: { ChangePolicy: { policy: newPolicy, }, }, }, }, gas: 300000000000000, deposit: deposit, }, ]); }; const handlePolicyToggle = (view) => { setPolicyView(policyView === view ? null : view); }; return ( <div> <button disabled={!daoId} className="btn btn-sm btn-dark m-1" onClick={handleProposal} > Propose Changes </button> <button className={`btn btn-outline-dark btn-sm m-1`} onClick={() => handlePolicyToggle("current")} > {policyView === "current" ? "Hide" : "Show"} Current Policy </button> <button className={`btn btn-outline-dark btn-sm m-1`} onClick={() => handlePolicyToggle("new")} > {policyView === "new" ? "Hide" : "Show"} New Policy </button> <div className="m-1 mt-3"> {policyView === "current" && ( <> <h5>Current Policy</h5> <pre style={{ backgroundColor: "#f8f9fa", border: "1px solid", borderRadius: "0.375rem", padding: "1rem", fontSize: "0.888rem", }} > {JSON.stringify(policy, null, 2)} </pre> </> )} {policyView === "new" && ( <> <h5>New Policy</h5> <pre style={{ backgroundColor: "#f8f9fa", border: "1px solid", borderRadius: "0.375rem", padding: "1rem", fontSize: "0.888rem", }} > {JSON.stringify(newPolicy, null, 2)} </pre> </> )} </div> </div> );