Skip to content

Commit

Permalink
feat: gno cockpit init (#1275)
Browse files Browse the repository at this point in the history
* feat: add gnodev make rule

Signed-off-by: Norman Meier <[email protected]>

* feat: gno cockpit init

Signed-off-by: Norman Meier <[email protected]>

* chore: reduce func complexity

Signed-off-by: Norman Meier <[email protected]>

* chore: use profile constant

Signed-off-by: Norman Meier <[email protected]>

* feat: add bio

Signed-off-by: Norman Meier <[email protected]>

* tmp: improve

Signed-off-by: Norman Meier <[email protected]>

* tmp: improve

Signed-off-by: Norman Meier <[email protected]>

* chore: bio placeholder

Signed-off-by: Norman Meier <[email protected]>

* fix: support gnobro

Signed-off-by: Norman Meier <[email protected]>

* chore: address last and compact

Signed-off-by: Norman Meier <[email protected]>

* feat: dynamic examples

Signed-off-by: Norman Meier <[email protected]>

---------

Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz authored Sep 13, 2024
1 parent 6cc67c5 commit 31a1651
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ P2E_DOCKER_IMAGE=$(DOCKER_REGISTRY)/p2e-update-leaderboard:$(shell git rev-parse
FEED_DOCKER_IMAGE=$(DOCKER_REGISTRY)/feed-clean-pinata-keys:$(shell git rev-parse --short HEAD)
MULTISIG_DOCKER_IMAGE=$(DOCKER_REGISTRY)/cosmos-multisig-backend:$(shell git rev-parse --short HEAD)

GNODEV=gnodev --add-account g193vp9tjhfpldvgg3gn433ayv8pn7rtfv8shyeq $$(find gno -name gno.mod -type f -exec dirname {} \;)
GNODEV_E2E=$(GNODEV) --unsafe-api --server-mode


ARCH := $(shell uname -m)

Expand Down Expand Up @@ -431,9 +434,13 @@ generate.internal-contracts-clients: node_modules
install-gno: node_modules
yarn install-gno

.PHONY: start.gnodev
start.gnodev:
$(GNODEV)

.PHONY: start.gnodev-e2e
start.gnodev-e2e:
gnodev --unsafe-api --server-mode --add-account g193vp9tjhfpldvgg3gn433ayv8pn7rtfv8shyeq $$(find gno -name gno.mod -type f -exec dirname {} \;)
$(GNODEV_E2E)

.PHONY: clone-gno
clone-gno:
Expand Down
9 changes: 9 additions & 0 deletions gno/r/cockpit/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module gno.land/r/teritori/cockpit

require (
gno.land/p/demo/mux v0.0.0-latest
gno.land/p/demo/users v0.0.0-latest
gno.land/r/demo/profile v0.0.0-latest
gno.land/r/demo/users v0.0.0-latest
gno.land/r/gnoland/ghverify v0.0.0-latest
)
82 changes: 82 additions & 0 deletions gno/r/cockpit/render.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cockpit

import (
"std"

"gno.land/p/demo/mux"
"gno.land/p/demo/users"
"gno.land/r/demo/profile"
rusers "gno.land/r/demo/users"
"gno.land/r/gnoland/ghverify"
)

const (
chainId = "test4"
pkgPath = "r/teritori/cockpit"
userSlug = "u"
usersRealm = "r/demo/users"
ghLinkHint = "r/gnoland/ghverify?help&__func=RequestVerification"
ghProfileHint = "/r/demo/profile:u/"
)

func Render(reqPath string) string {
router := mux.NewRouter()

router.HandleFunc("", renderHome)
router.HandleFunc(userSlug+"/{aon}", renderUser)

return router.Render(reqPath)
}

func renderHome(res *mux.ResponseWriter, req *mux.Request) {
res.Write("# Cockpit\n\n")
res.Write("See `:" + userSlug + "/{addressOrName}`\n\n")
res.Write("Examples:\n")
elems := rusers.ListUsersByPrefix("", 20)
for _, elem := range elems {
res.Write("- [ " + elem + " ](./" + pkgPath + ":" + userSlug + "/@" + elem + ")\n")
}
}

func renderUser(res *mux.ResponseWriter, req *mux.Request) {
addr, username, ok := resolveUserBasics(req.GetVar("aon"))
if !ok {
res.Write("404")
return
}

// FIXME: markdown injection, spam
res.Write("# " + profile.GetStringField(addr, profile.DisplayName, "Anon") + "\n")

if username != "" {
res.Write("- Username: [" + username + "](/" + usersRealm + ":" + username + ")\n")
} else {
res.Write("- Username: [Not registered](/" + usersRealm + "?help&__func=Register)\n")
}

handle := ghverify.GetHandleByAddress(addr.String())
if handle != "" {
res.Write("- GitHub: [" + handle + "](https://github.com/" + handle + ")\n")
} else {
res.Write("- GitHub: [Not linked](/" + ghLinkHint + ")\n")
}

res.Write("- Address: [" + addr.String() + "](https://gnoscan.io/accounts/" + addr.String() + "?chainId=" + chainId + ")\n\n")

// FIXME: markdown injection, spam
res.Write("```\n" + profile.GetStringField(addr, profile.Bio, "No bio") + "\n```\n[Full profile / edit](" + ghProfileHint + addr.String() + ")\n")
}

func resolveUserBasics(aon string) (std.Address, string, bool) {
user := rusers.GetUserByAddressOrName(users.AddressOrName(aon))
if user != nil {
return user.Address, user.Name, true
}

addr := std.Address(aon)
if addr.IsValid() {
return addr, "", true
}

return addr, "", false
}

0 comments on commit 31a1651

Please sign in to comment.