From 9890d3207027484a332f9d24eb71eedb98f60d4c Mon Sep 17 00:00:00 2001 From: leohhhn Date: Fri, 17 Jan 2025 00:19:10 +0100 Subject: [PATCH] update home page, update godoc --- .../gno.land/r/gnoland/users/v1/render.gno | 71 +++++++++++++++---- .../gno.land/r/gnoland/users/v1/users.gno | 7 +- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/examples/gno.land/r/gnoland/users/v1/render.gno b/examples/gno.land/r/gnoland/users/v1/render.gno index 953c2fcfeaf..2377d2abd05 100644 --- a/examples/gno.land/r/gnoland/users/v1/render.gno +++ b/examples/gno.land/r/gnoland/users/v1/render.gno @@ -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() { @@ -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() { @@ -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") diff --git a/examples/gno.land/r/gnoland/users/v1/users.gno b/examples/gno.land/r/gnoland/users/v1/users.gno index acf071853df..e1b58cac200 100644 --- a/examples/gno.land/r/gnoland/users/v1/users.gno +++ b/examples/gno.land/r/gnoland/users/v1/users.gno @@ -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() @@ -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()