-
Notifications
You must be signed in to change notification settings - Fork 386
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
JJOptimist
wants to merge
4
commits into
gnolang:master
Choose a base branch
from
JJOptimist:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−0
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package home | ||
|
||
import ( | ||
"std" | ||
"gno.land/p/demo/ownable" | ||
) | ||
|
||
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")) | ||
|
||
func GetConfig() struct { title string; description string; github string } { | ||
return config | ||
} | ||
|
||
func UpdateConfig(newTitle, newDescription, newGithub string) { | ||
if !o.CallerIsOwner() { | ||
panic("not authorized") | ||
} | ||
config.title = newTitle | ||
config.description = newDescription | ||
config.github = newGithub | ||
} | ||
|
||
func GetOwner() std.Address { | ||
return o.Owner() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.~) | ||
(\_/) | ||
-"-` | ||
) | ||
|
||
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" | ||
} | ||
|
||
func init() { | ||
creation = time.Now() | ||
} | ||
|
||
func Render(path string) string { | ||
cfg := GetConfig() | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
|
||
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") | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftover file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes leftover, forgot i added it |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for quick notice, removed it