Skip to content

Commit

Permalink
update home page, update godoc
Browse files Browse the repository at this point in the history
  • Loading branch information
leohhhn committed Jan 16, 2025
1 parent 4e58502 commit 9890d32
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
71 changes: 57 additions & 14 deletions examples/gno.land/r/gnoland/users/v1/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,40 @@ import (
"gno.land/p/demo/ufmt"
"gno.land/p/moul/md"
"gno.land/p/moul/realmpath"
"gno.land/p/moul/txlink"

"gno.land/r/demo/profile"
"gno.land/r/sys/users"
)

var (
connectUrlBase = "https://gno.studio/connect/view/gno.land/r/gnoland/users/v1?network=" + std.GetChainID()
connectRegisterUrl = connectUrlBase + "Register"
connectUpdateNameUrl = connectUrlBase + "UpdateName"
)

func Render(path string) string {
var out string
req := realmpath.Parse(path)

if req.Path == "" {
out += renderHomePage(req.Path)
}

// Render single user page
data, isLatest, isName := resolveUser(req.Path)
if data == nil {
return render404()
return renderHomePage(path)
}

// Otherwise, render the user page
return renderUserPage(data, req.Path, isName, isLatest)
return renderUserPage(req.Path)
}

func renderHomePage(path string) string {
var out string
p := pager.NewPager(users.GetReadonlyAddrStore(), 50, false)
page := p.MustGetPageByPath(path)

out += "# gno.land user registry\n"

out += renderIntroParagraph()

out += md.H2("User list")

p := pager.NewPager(users.GetReadonlyAddrStore(), 20, false)
page := p.MustGetPageByPath(path)
for _, item := range page.Items {
data := item.Value.(*users.UserData)
if !data.IsDeleted() {
Expand All @@ -53,6 +57,39 @@ func renderHomePage(path string) string {
return out
}

func renderIntroParagraph() string {
out := md.Paragraph("Welcome to the gno.land user registry (v1). Please register a username.")
out += md.Paragraph(`Registering a username grants the registering address the right to deploy packages and realms
under that username’s namespace. For example, if an address registers the username ` + md.InlineCode("gnome123") + `, it
will gain permission to deploy packages and realms to package paths with the pattern ` + md.InlineCode("gno.land/{p,r}/gnome123/*") + `.`)

out += md.Paragraph("In V1, usernames must follow these rules, in order to prevent username squatting:")
items := []string{
"Must start with 3 characters",
"Must end with 3 numbers",
"Have a maximum length of 20 characters",
"With the only special character allowed being `_`",
}
out += md.BulletList(items)

out += "\n\n"
out += md.Paragraph("In later versions of the registry, vanity usernames will be allowed through specific mechanisms.")

out += md.H2("Actions\n\n")

items = []string{
"Register: " + ufmt.Sprintf("[gnokey](%s) - [Connect](%s)\n\n", txlink.Call("Register"), connectRegisterUrl),
"Update Name: " + ufmt.Sprintf("[gnokey](%s) - [Connect](%s)\n\n", txlink.Call("UpdateName"), connectUpdateNameUrl),
}

out += md.BulletList(items)

out += md.HorizontalRule()
out += "\n\n"

return out
}

// resolveUser resolves the user based on the path, determining if it's a name or address
func resolveUser(path string) (*users.UserData, bool, bool) {
if std.Address(path).IsValid() {
Expand All @@ -64,16 +101,22 @@ func resolveUser(path string) (*users.UserData, bool, bool) {
}

// renderUserPage generates the user page based on user data and path
func renderUserPage(data *users.UserData, query string, isName, isLatest bool) string {
func renderUserPage(path string) string {
var out string

out += md.H1("User " + data.Name())
// Render single user page
data, isLatest, isName := resolveUser(path)
if data == nil {
return render404()
}

out += md.H1("User - " + md.InlineCode(data.Name()))
out += ufmt.Sprintf("Address: %s\n\n", data.Addr().String())

if isName && !isLatest {
out += md.Paragraph(ufmt.Sprintf(
"Note: `%s` is a previous name of `%s`.",
query, data.Name()))
path, data.Name()))
}

out += md.H2("Bio")
Expand Down
7 changes: 5 additions & 2 deletions examples/gno.land/r/gnoland/users/v1/users.gno
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var reUsername = regexp.MustCompile(reValidUsername)
// Register registers a new username for the caller
// A valid username must start with a minimum of 3 letters,
// end with a minimum of 3 numbers, and be less than 20 chars long.
// All letters must be lowercase, and the only valid special char is `_`
// Only calls from EOAs are supported
// All letters must be lowercase, and the only valid special char is `_`.
// Only calls from EOAs are supported.
func Register(username string) error {
std.AssertOriginCall()

Expand All @@ -41,6 +41,9 @@ func Register(username string) error {
return nil
}

// UpdateName allows a user to update their name.
// The associated address and all previous names of a user that changes a name
// are preserved, and all resolve to the new name.
func UpdateName(newName string) error {
std.AssertOriginCall()

Expand Down

0 comments on commit 9890d32

Please sign in to comment.