-
Notifications
You must be signed in to change notification settings - Fork 406
feat: govdao v3 better rendering #4164
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,9 +122,8 @@ func TestCreateProposalAndVote(t *testing.T) { | |
// }) | ||
dao.MustVoteOnProposalSimple(0, "NO") | ||
|
||
urequire.Equal(t, true, contains(dao.Render(""), "Proposal open for votes")) | ||
urequire.Equal(t, true, contains(dao.Render(""), "15.789473684210526%")) | ||
urequire.Equal(t, true, contains(dao.Render(""), "52.63157894736842%")) | ||
urequire.Equal(t, true, strings.Contains(dao.Render(""), "Prop #0 - New Member Proposal")) | ||
urequire.Equal(t, true, strings.Contains(dao.Render(""), "Author: "+m1.String())) | ||
|
||
urequire.PanicsWithMessage(t, "proposal didn't reach supermajority yet: 66", func() { | ||
dao.ExecuteProposal(dao.ProposalID(0)) | ||
|
@@ -140,50 +139,7 @@ func TestCreateProposalAndVote(t *testing.T) { | |
accepted := dao.ExecuteProposal(dao.ProposalID(0)) | ||
urequire.Equal(t, false, accepted) | ||
|
||
urequire.Equal(t, true, contains(dao.Render(""), "**PROPOSAL HAS BEEN DENIED**")) | ||
urequire.Equal(t, true, contains(dao.Render(""), "NO PERCENT: 68.42105263157895%")) | ||
} | ||
|
||
func TestProposalPagination(t *testing.T) { | ||
loadMembers() | ||
portfolio := "### This is my portfolio:\n\n- THINGS" | ||
|
||
testing.SetOriginCaller(m1) | ||
|
||
nm1 := testutils.TestAddress("nm1") | ||
|
||
var pid dao.ProposalID | ||
|
||
pid = dao.MustCreateProposal(NewAddMemberRequest(nm1, memberstore.T2, portfolio)) | ||
// TODO: tests keep the same vm state: https://github.com/gnolang/gno/issues/1982 | ||
urequire.Equal(t, 1, int(pid)) | ||
|
||
pid = dao.MustCreateProposal(NewAddMemberRequest(nm1, memberstore.T2, portfolio)) | ||
urequire.Equal(t, 2, int(pid)) | ||
|
||
pid = dao.MustCreateProposal(NewAddMemberRequest(nm1, memberstore.T2, portfolio)) | ||
urequire.Equal(t, 3, int(pid)) | ||
|
||
pid = dao.MustCreateProposal(NewAddMemberRequest(nm1, memberstore.T2, portfolio)) | ||
urequire.Equal(t, 4, int(pid)) | ||
|
||
pid = dao.MustCreateProposal(NewAddMemberRequest(nm1, memberstore.T2, portfolio)) | ||
urequire.Equal(t, 5, int(pid)) | ||
|
||
pid = dao.MustCreateProposal(NewAddMemberRequest(nm1, memberstore.T2, portfolio)) | ||
urequire.Equal(t, 6, int(pid)) | ||
|
||
urequire.Equal(t, true, contains(dao.Render(""), "## Proposal with id: 6")) | ||
urequire.Equal(t, true, contains(dao.Render(""), "## Proposal with id: 5")) | ||
urequire.Equal(t, true, contains(dao.Render(""), "## Proposal with id: 4")) | ||
|
||
urequire.Equal(t, true, contains(dao.Render("/?page=2"), "## Proposal with id: 3")) | ||
urequire.Equal(t, true, contains(dao.Render("/?page=2"), "## Proposal with id: 2")) | ||
urequire.Equal(t, true, contains(dao.Render("/?page=2"), "## Proposal with id: 1")) | ||
|
||
urequire.Equal(t, true, contains(dao.Render("/?page=3"), "## Proposal with id: 0")) | ||
} | ||
println(dao.Render("")) | ||
|
||
func contains(s, substr string) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
return strings.Index(s, substr) >= 0 | ||
urequire.Equal(t, true, strings.Contains(dao.Render(""), "Status: REJECTED")) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,9 @@ import ( | |
"gno.land/p/demo/avl/pager" | ||
"gno.land/p/demo/mux" | ||
"gno.land/p/demo/ufmt" | ||
"gno.land/p/moul/helplink" | ||
"gno.land/r/gov/dao" | ||
"gno.land/r/sys/users" | ||
) | ||
|
||
type render struct { | ||
|
@@ -24,16 +26,12 @@ func NewRender(d *GovDAO) *render { | |
|
||
r := mux.NewRouter() | ||
|
||
r.HandleFunc("/", func(rw *mux.ResponseWriter, req *mux.Request) { | ||
rw.Write(ren.renderActiveProposals(req.RawPath, d)) | ||
}) | ||
Comment on lines
-27
to
-29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this checks for |
||
|
||
r.HandleFunc("", func(rw *mux.ResponseWriter, req *mux.Request) { | ||
rw.Write(ren.renderActiveProposals(req.RawPath, d)) | ||
}) | ||
|
||
r.HandleFunc("{pid}", func(rw *mux.ResponseWriter, req *mux.Request) { | ||
rw.Write(ren.renderProposal(req.GetVar("pid"), d)) | ||
rw.Write(ren.renderProposalPage(req.GetVar("pid"), d)) | ||
}) | ||
|
||
r.HandleFunc("{pid}/votes", func(rw *mux.ResponseWriter, req *mux.Request) { | ||
|
@@ -56,40 +54,61 @@ func (ren *render) Render(path string, pkg string) string { | |
} | ||
|
||
func (ren *render) renderActiveProposals(url string, d *GovDAO) string { | ||
out := "# Active Proposals:\n" | ||
|
||
page, err := ren.pssPager.GetPageByPath(url) | ||
if err != nil { | ||
out += ufmt.Sprintf("Error getting selected page: %v", err.Error()) | ||
return out | ||
} | ||
out := "# GovDAO Proposals\n" | ||
|
||
page := ren.pssPager.MustGetPageByPath(url) | ||
for _, item := range page.Items { | ||
out += ren.renderProposal(item.Key, d) | ||
out += ren.renderProposalListItem(item.Key, d) | ||
out += "---\n\n" | ||
} | ||
|
||
out += page.Picker("") | ||
|
||
return out | ||
} | ||
|
||
func (ren *render) renderProposal(sPid string, d *GovDAO) string { | ||
func (ren *render) renderProposalPage(sPid string, d *GovDAO) string { | ||
pid, err := strconv.Atoi(sPid) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
ps := d.pss.GetStatus(dao.ProposalID(pid)) | ||
|
||
p := dao.MustGetProposal(dao.ProposalID(pid)) | ||
out := ufmt.Sprintf("## Prop #%v - %v\n", sPid, p.Title()) | ||
|
||
out := "" | ||
out += ufmt.Sprintf("## Proposal with id: %v", sPid) | ||
out += StringifyProposal(p) | ||
out += p.Description() | ||
out += "\n\n" | ||
|
||
out += "Author: " + tryResolveAddr(p.Author()) + "\n\n" | ||
|
||
out += ps.String() | ||
out += ufmt.Sprintf("- [Go to votes list](%v:%v/votes).", ren.relativeRealmPath, sPid) | ||
out += "\n" | ||
out += ufmt.Sprintf("[Detailed voting list](%v:%v/votes)", ren.relativeRealmPath, sPid) | ||
out += "\n\n---\n\n" | ||
|
||
out += renderActionBar(sPid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this not missing the eligible tiers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's given out by |
||
|
||
return out | ||
} | ||
|
||
func (ren *render) renderProposalListItem(sPid string, d *GovDAO) string { | ||
pid, err := strconv.Atoi(sPid) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
|
||
ps := d.pss.GetStatus(dao.ProposalID(pid)) | ||
p := dao.MustGetProposal(dao.ProposalID(pid)) | ||
out := ufmt.Sprintf("### [Prop #%v - %v](%v:%v)\n", sPid, p.Title(), ren.relativeRealmPath, sPid) | ||
out += ufmt.Sprintf("Author: %s\n\n", p.Author()) | ||
|
||
out += "Status: " + getPropStatus(ps) | ||
out += "\n\n" | ||
|
||
out += "Tiers eligible to vote: " | ||
out += strings.Join(ps.TiersAllowedToVote, ", ") | ||
|
||
out += "\n\n" | ||
return out | ||
} | ||
|
||
|
@@ -101,8 +120,42 @@ func (ren *render) renderVotesForProposal(sPid string, d *GovDAO) string { | |
ps := d.pss.GetStatus(dao.ProposalID(pid)) | ||
|
||
out := "" | ||
out += ufmt.Sprintf("## Voters for Proposal with id: %v\n\n", sPid) | ||
out += ufmt.Sprintf("# Proposal #%v - Vote List\n\n", sPid) | ||
out += StringifyVotes(ps) | ||
|
||
return out | ||
} | ||
|
||
func isPropActive(ps *proposalStatus) bool { | ||
return !ps.Accepted && !ps.Denied | ||
} | ||
|
||
func getPropStatus(ps *proposalStatus) string { | ||
if ps.Accepted { | ||
return "ACCEPTED" | ||
} else if ps.Denied { | ||
return "REJECTED" | ||
} | ||
return "ACTIVE" | ||
} | ||
|
||
func renderActionBar(sPid string) string { | ||
out := "### Actions\n" | ||
|
||
proxy := helplink.Realm("gno.land/r/gov/dao") | ||
out += proxy.Func("Vote YES", "MustVoteOnProposalSimple", "pid", sPid, "option", "YES") + " | " | ||
out += proxy.Func("Vote NO", "MustVoteOnProposalSimple", "pid", sPid, "option", "NO") + " | " | ||
out += proxy.Func("Vote ABSTAIN", "MustVoteOnProposalSimple", "pid", sPid, "option", "ABSTAIN") | ||
|
||
out += "\n\n" | ||
out += "WARN: Please double check transaction data before voting." | ||
return out | ||
} | ||
|
||
func tryResolveAddr(addr std.Address) string { | ||
userData := users.ResolveAddress(addr) | ||
if userData == nil { | ||
return addr.String() | ||
} | ||
return userData.RenderLink("") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to test this, its tested in
p/demo/avl/pager
already