Skip to content

Commit 9c046ea

Browse files
feat(gno/dao): enhance render daokit/basedao (#1508)
Co-authored-by: n0izn0iz <n0izn0iz@users.noreply.github.com>
1 parent f228e26 commit 9c046ea

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

gno/p/basedao/render.gno

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
PROPOSAL_HISTORY_PATH = "history"
1717
MEMBER_DETAIL_PATH = "member/{address}"
1818
PROPOSAL_DETAIL_PATH = "proposal/{id}"
19+
FALLBACK_DISPLAY_NAME = "Anon"
1920
)
2021

2122
func (d *DAO) initRenderingRouter() {
@@ -37,20 +38,19 @@ func (d *DAO) renderHomePage(res *mux.ResponseWriter, req *mux.Request) {
3738
name := d.GetProfileString(d.Realm.Addr(), "DisplayName", "DAO")
3839
description := d.GetProfileString(d.Realm.Addr(), "Bio", "Created with daokit")
3940
pkgPath := d.Realm.PkgPath()
40-
linkPath := ""
41-
slashIdx := strings.IndexRune(pkgPath, '/')
42-
if slashIdx != 1 {
43-
linkPath = pkgPath[slashIdx:]
44-
}
41+
linkPath := getLinkPath(pkgPath)
4542

46-
res.Write(ufmt.Sprintf("# %s - %s\n\n", name, std.CurrentRealm().Addr().String()))
47-
res.Write(ufmt.Sprintf("> Description: %s\n\n", description))
43+
res.Write(ufmt.Sprintf("# %s\n\n", name))
44+
res.Write(ufmt.Sprintf("%s\n\n", description))
45+
res.Write(ufmt.Sprintf("> Realm address: %s\n\n", d.Realm.Addr()))
4846
res.Write(ufmt.Sprintf("Discover more about this DAO on the [configuration page ⚙️](%s:%s)\n\n", linkPath, CONFIG_PATH))
4947

5048
res.Write(ufmt.Sprintf("## Members 👤 \n\n"))
5149
i := 1
5250
d.Members.Members.Iterate("", "", func(key string, value interface{}) bool {
5351
res.Write(ufmt.Sprintf("- **Member %d: [%s](%s:%s/%s)**\n\n", i, key, linkPath, "member", key))
52+
res.Write(ufmt.Sprintf(" - **Profile:** %s\n", d.GetProfileString(std.Address(key), "DisplayName", FALLBACK_DISPLAY_NAME)))
53+
res.Write(ufmt.Sprintf(" - **Roles:** %s\n\n", strings.Join(d.Members.GetMemberRoles(key), ", ")))
5454
i += 1
5555
return false
5656
})
@@ -109,11 +109,7 @@ func (d *DAO) renderConfigPage(res *mux.ResponseWriter, req *mux.Request) {
109109
func (d *DAO) renderProposalHistoryPage(res *mux.ResponseWriter, req *mux.Request) {
110110
name := d.GetProfileString(d.Realm.Addr(), "DisplayName", "DAO")
111111
pkgPath := d.Realm.PkgPath()
112-
linkPath := ""
113-
slashIdx := strings.IndexRune(pkgPath, '/')
114-
if slashIdx != 1 {
115-
linkPath = pkgPath[slashIdx:]
116-
}
112+
linkPath := getLinkPath(pkgPath)
117113

118114
res.Write(ufmt.Sprintf("# %s - Proposal History\n\n", name))
119115
res.Write(ufmt.Sprintf("## Proposals 🗳️\n\n"))
@@ -134,23 +130,31 @@ func (d *DAO) renderProposalHistoryPage(res *mux.ResponseWriter, req *mux.Reques
134130

135131
func (d *DAO) renderMemberDetailPage(res *mux.ResponseWriter, req *mux.Request) {
136132
name := d.GetProfileString(d.Realm.Addr(), "DisplayName", "DAO")
133+
pkgPath := d.Realm.PkgPath()
134+
linkPath := getLinkPath(pkgPath)
137135

138-
res.Write(ufmt.Sprintf("# %s - Member Detail - %s\n\n", name, req.GetVar("address")))
136+
res.Write(ufmt.Sprintf("# %s - Member Detail\n\n", name))
139137
roles := d.Members.GetMemberRoles(req.GetVar("address"))
138+
displayName := d.GetProfileString(std.Address(req.GetVar("address")), "DisplayName", FALLBACK_DISPLAY_NAME)
139+
bio := d.GetProfileString(std.Address(req.GetVar("address")), "Bio", "No bio")
140+
pp := d.GetProfileString(std.Address(req.GetVar("address")), "Avatar", "")
141+
res.Write(ufmt.Sprintf("## Profile 👤\n\n"))
142+
res.Write(ufmt.Sprintf("- **Display Name:** %s\n\n", displayName))
143+
res.Write(ufmt.Sprintf("- **Bio:** %s\n\n", bio))
144+
if pp != "" {
145+
res.Write(ufmt.Sprintf("![Avatar](%s)\n\n", pp))
146+
}
140147
res.Write(ufmt.Sprintf("## Roles 🏷️\n\n"))
141148
for _, role := range roles {
142149
res.Write(ufmt.Sprintf("- %s\n\n", role))
143150
}
151+
res.Write(ufmt.Sprintf("> Learn more about the roles on the [configuration page ⚙️](%s:%s)\n\n", linkPath, CONFIG_PATH))
144152
}
145153

146154
func (d *DAO) renderProposalDetailPage(res *mux.ResponseWriter, req *mux.Request) {
147155
name := d.GetProfileString(d.Realm.Addr(), "DisplayName", "DAO")
148156
pkgPath := d.Realm.PkgPath()
149-
linkPath := ""
150-
slashIdx := strings.IndexRune(pkgPath, '/')
151-
if slashIdx != 1 {
152-
linkPath = pkgPath[slashIdx:]
153-
}
157+
linkPath := getLinkPath(pkgPath)
154158

155159
id, err := seqid.FromString(req.GetVar("id"))
156160
if err != nil {
@@ -161,7 +165,7 @@ func (d *DAO) renderProposalDetailPage(res *mux.ResponseWriter, req *mux.Request
161165
res.Write(ufmt.Sprintf("## Title - %s 📜\n\n", proposal.Title))
162166
res.Write(ufmt.Sprintf("## Description 📝\n\n%s\n\n", proposal.Description))
163167
res.Write(ufmt.Sprintf("## Resource - %s 📦\n\n", proposal.Message.Type()))
164-
res.Write(proposal.Message.String())
168+
res.Write(proposal.Message.String() + "\n\n")
165169
if proposal.Status == daokit.ProposalStatusOpen {
166170
res.Write(ufmt.Sprintf("## Status - Open 🟡\n\n"))
167171
res.Write(ufmt.Sprintf("[Vote on this proposal 🗳️](%s$help)\n\n", linkPath))
@@ -180,3 +184,11 @@ func (d *DAO) renderProposalDetailPage(res *mux.ResponseWriter, req *mux.Request
180184
res.Write(ufmt.Sprintf("## Votes 🗳️\n\n"))
181185
res.Write(ufmt.Sprintf("%s\n\n", proposal.ConditionState.RenderJSON(proposal.Votes)))
182186
}
187+
188+
func getLinkPath(pkgPath string) string {
189+
slashIdx := strings.IndexRune(pkgPath, '/')
190+
if slashIdx != 1 {
191+
return pkgPath[slashIdx:]
192+
}
193+
return ""
194+
}

gno/r/govdao/govdao.gno

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ func init() {
3737
{Address: "g16jv3rpz7mkt0gqulxas56se2js7v5vmc6n6e0r", Roles: []string{Tier3}},
3838
}
3939
dao = basedao.New(&basedao.Config{
40-
Name: "GovDAO",
41-
Description: "This is a GovDAO demo",
40+
Name: "GovDAO",
41+
Description: "GovDAO is the autonomous, decentralized organization in charge of " +
42+
"securing the Gnoland network and ecosystem. It is made up of members " +
43+
"who have made a significant contribution to the emergence of the " +
44+
"Gnoland language, network and ecosystem. The only way to become a " +
45+
"member of GovDAO is to actively participate in coding, tooling, " +
46+
"improving, securing or expanding Gnoland and its common tools.",
4247
NoDefaultHandlers: true,
4348
Members: basedao.NewMembersStore(initialRoles, initialMembers),
49+
SetProfileString: profile.SetStringField,
4450
GetProfileString: profile.GetStringField,
4551
})
4652

0 commit comments

Comments
 (0)