Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add JJOptimist's Homepage realm to examples #3405

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f76c480
feat: add JJOptimist's Homerealm
JJOptimist Dec 25, 2024
b755bc7
Merge branch 'gnolang:master' into master
JJOptimist Jan 7, 2025
d7fec48
feat: added usage of ownable and art
JJOptimist Jan 10, 2025
6746b48
chore: remove mykey_backup.armor
JJOptimist Jan 10, 2025
c6f2243
Merge branch 'master' into master
leohhhn Jan 14, 2025
26141d3
fix: update based on feedback and registered in HoF
JJOptimist Jan 19, 2025
ae762a4
Merge branch 'master' of https://github.com/JJOptimist/gno
JJOptimist Jan 19, 2025
771ebb2
Merge branch 'master' into master
JJOptimist Jan 19, 2025
4de53c4
fix: clean dependencies
JJOptimist Jan 20, 2025
21cd795
Merge branch 'master' of https://github.com/JJOptimist/gno
JJOptimist Jan 20, 2025
b7f16d4
fix: path fix in gno.mod
JJOptimist Jan 21, 2025
faba174
Update examples/gno.land/r/jjoptimist/home/config.gno
JJOptimist Jan 21, 2025
99a6ff4
Update examples/gno.land/r/jjoptimist/home/home.gno
JJOptimist Jan 21, 2025
7a338dc
Merge branch 'master' into master
JJOptimist Jan 21, 2025
5988bd2
Merge branch 'master' into master
JJOptimist Jan 26, 2025
b30c106
Update examples/gno.land/r/jjoptimist/home/config.gno
JJOptimist Jan 28, 2025
d674a91
fix(home): removed unused import
JJOptimist Jan 28, 2025
4b63d70
Merge branch 'master' of https://github.com/JJOptimist/gno
JJOptimist Jan 28, 2025
51e795c
chore: fix fmt
JJOptimist Jan 28, 2025
b2e6f03
chore(home): move gnomeArt after revert
JJOptimist Jan 28, 2025
209d640
Merge branch 'master' into master
JJOptimist Jan 28, 2025
02c6d6c
chore(home): tidy
JJOptimist Jan 29, 2025
730c5cf
Merge branch 'master' of https://github.com/JJOptimist/gno
JJOptimist Jan 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions examples/gno.land/r/jjoptimist/home/config.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package home

import (
"std"
"gno.land/p/demo/ownable"
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
)

var config = struct {
title string
description string
github string
}{
title: "JJOptimist's Home Realm 🏠",
description: "Exploring Gno and building on-chain",
github: "jjoptimist",
}

var o = ownable.NewWithAddress(std.Address("g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj"))
leohhhn marked this conversation as resolved.
Show resolved Hide resolved

func GetConfig() struct { title string; description string; github string } {
return config
}
leohhhn marked this conversation as resolved.
Show resolved Hide resolved

func UpdateConfig(newTitle, newDescription, newGithub string) {
if !o.CallerIsOwner() {
panic("not authorized")
}
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
config.title = newTitle
config.description = newDescription
config.github = newGithub
}

func GetOwner() std.Address {
return o.Owner()
}
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions examples/gno.land/r/jjoptimist/home/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/r/jjoptimist

require (
gno.land/p/demo/ownable v0.0.0
)
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
80 changes: 80 additions & 0 deletions examples/gno.land/r/jjoptimist/home/home.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package home

import (
"time"
"std"
"strconv"
)

var (
creation time.Time
gnomeArt1 = ` /\
/ \
,,,,,
(o.o)
(\_/)
-"-"-`

gnomeArt2 = ` /\
/ \
,,,,,
(^.^)
(\_/)
-"-`

gnomeArt3 = ` /\
/ \
,,,,,
(*.*)
(\_/)
"-"-"`

gnomeArt4 = ` /\
/ \
,,,,,
(o.~)
(\_/)
-"-`
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
)

func getGnomeArt(height int64) string {
var art string
if height%7 == 0 {
art = gnomeArt4 // winking gnome
} else if height%5 == 0 {
art = gnomeArt3 // starry-eyed gnome
} else if height%3 == 0 {
art = gnomeArt2 // happy gnome
} else if height%2 == 0 {
art = gnomeArt1 // regular gnome
} else {
art = gnomeArt1 // default
}
return "```\n" + art + "\n```\n"
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
}

func init() {
creation = time.Now()
}
leohhhn marked this conversation as resolved.
Show resolved Hide resolved

func Render(path string) string {
cfg := GetConfig()
leohhhn marked this conversation as resolved.
Show resolved Hide resolved
height := std.GetHeight()

output := "# " + cfg.title + "\n\n"

output += "## About Me\n"
output += "- 👋 Hi, I'm JJOptimist\n"
output += getGnomeArt(height)
output += "- 🌱 " + cfg.description + "\n"

output += "## Contact\n"
output += "- 📫 GitHub: [" + cfg.github + "](https://github.com/" + cfg.github + ")\n"

output += "\n---\n"
output += "_Realm created: " + creation.Format("2006-01-02 15:04:05 UTC") + "_\n"
output += "_Owner: " + GetOwner().String() + "_\n"
output += "_Current Block Height: " + strconv.Itoa(int(height)) + "_"

return output
}
41 changes: 41 additions & 0 deletions examples/gno.land/r/jjoptimist/home/home_test.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package home

import (
"std"
"testing"
)

func TestOwnership(t *testing.T) {
owner := GetOwner()
if owner.String() != "g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj" {
t.Errorf("Expected owner to be g16vfw3r7zuz43fhky3xfsuc2hdv9tnhvlkyn0nj, got %s", owner.String())
}

std.TestSetOrigCaller(owner)
if !o.CallerIsOwner() {
t.Error("Owner address should return true for CallerIsOwner check")
}

nonOwner := std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
std.TestSetOrigCaller(nonOwner)
if o.CallerIsOwner() {
t.Error("Non-owner address should return false for CallerIsOwner check")
}
}
leohhhn marked this conversation as resolved.
Show resolved Hide resolved

func TestConfig(t *testing.T) {
cfg := GetConfig()

if cfg.title != "JJOptimist's Home Realm 🏠" {
t.Errorf("Expected title to be 'JJOptimist's Home Realm 🏠', got %s", cfg.title)
}
if cfg.description != "Exploring Gno and building on-chain" {
t.Errorf("Expected description to be 'Exploring Gno and building on-chain', got %s", cfg.description)
}
if cfg.github != "jjoptimist" {
t.Errorf("Expected github to be 'jjoptimist', got %s", cfg.github)
}
if cfg.css != styles {
t.Errorf("Expected css to match styles constant")
}
}
Loading