From 9b0633196aff06879fa9faaae1c4e00ef909ec17 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:10:04 +0200 Subject: [PATCH 1/2] feat(r/gnoland/home): option to override the homepage Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/r/gnoland/home/home.gno | 20 ++++++++++++++++ .../r/gnoland/home/overide_filetest.gno | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 examples/gno.land/r/gnoland/home/overide_filetest.gno diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index aca1007036e..dac1bcc2225 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -3,6 +3,7 @@ package home import ( "std" + "gno.land/p/demo/ownable" "gno.land/p/demo/ufmt" "gno.land/p/demo/ui" blog "gno.land/r/gnoland/blog" @@ -12,7 +13,26 @@ import ( // XXX: use an updatable block system to update content from a DAO // XXX: var blocks avl.Tree +var ( + override string + admin = ownable.NewWithAddress("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") +) + +func AdminSetOverride(content string) { + admin.AssertCallerIsOwner() + override = content +} + +func AdminTransferOwnership(newAdmin std.Address) { + admin.AssertCallerIsOwner() + admin.TransferOwnership(newAdmin) +} + func Render(_ string) string { + if override != "" { + return override + } + dom := ui.DOM{Prefix: "r/gnoland/home:"} dom.Title = "Welcome to gno.land" dom.Classes = []string{"gno-tmpl-section"} diff --git a/examples/gno.land/r/gnoland/home/overide_filetest.gno b/examples/gno.land/r/gnoland/home/overide_filetest.gno new file mode 100644 index 00000000000..34356b93349 --- /dev/null +++ b/examples/gno.land/r/gnoland/home/overide_filetest.gno @@ -0,0 +1,24 @@ +package main + +import ( + "std" + + "gno.land/p/demo/testutils" + "gno.land/r/gnoland/home" +) + +func main() { + std.TestSetOrigCaller("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") + home.AdminSetOverride("Hello World!") + println(home.Render("")) + home.AdminTransferOwnership(testutils.TestAddress("newAdmin")) + defer func() { + r := recover() + println("r: ", r) + }() + home.AdminSetOverride("Not admin anymore") +} + +// Output: +// Hello World! +// r: unauthorized; caller is not owner From 5524a304a679ec28624e6f9b0fe4ebcba21562f2 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 14 Jul 2024 10:16:35 +0200 Subject: [PATCH 2/2] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- examples/gno.land/r/gnoland/home/gno.mod | 1 + examples/gno.land/r/gnoland/home/home.gno | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/gno.land/r/gnoland/home/gno.mod b/examples/gno.land/r/gnoland/home/gno.mod index 2864958930c..cb2ec58b665 100644 --- a/examples/gno.land/r/gnoland/home/gno.mod +++ b/examples/gno.land/r/gnoland/home/gno.mod @@ -1,6 +1,7 @@ module gno.land/r/gnoland/home require ( + gno.land/p/demo/ownable v0.0.0-latest gno.land/p/demo/ufmt v0.0.0-latest gno.land/p/demo/ui v0.0.0-latest gno.land/r/gnoland/blog v0.0.0-latest diff --git a/examples/gno.land/r/gnoland/home/home.gno b/examples/gno.land/r/gnoland/home/home.gno index dac1bcc2225..62984711d79 100644 --- a/examples/gno.land/r/gnoland/home/home.gno +++ b/examples/gno.land/r/gnoland/home/home.gno @@ -15,19 +15,9 @@ import ( var ( override string - admin = ownable.NewWithAddress("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") + admin = ownable.NewWithAddress("g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq") // @manfred by default ) -func AdminSetOverride(content string) { - admin.AssertCallerIsOwner() - override = content -} - -func AdminTransferOwnership(newAdmin std.Address) { - admin.AssertCallerIsOwner() - admin.TransferOwnership(newAdmin) -} - func Render(_ string) string { if override != "" { return override @@ -287,3 +277,13 @@ func discoverLinks() ui.Element { `), } } + +func AdminSetOverride(content string) { + admin.AssertCallerIsOwner() + override = content +} + +func AdminTransferOwnership(newAdmin std.Address) { + admin.AssertCallerIsOwner() + admin.TransferOwnership(newAdmin) +}