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

chore: refactor txlink in order to extend it #3289

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
12 changes: 6 additions & 6 deletions examples/gno.land/p/moul/txlink/txlink.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// flexible arguments, allowing users to build dynamic links that integrate
// seamlessly with various Gno clients.
//
// The primary function, URL, is designed to produce markdown links for
// The primary function, Call, is designed to produce markdown links for
// transaction functions in the current "relative realm". By specifying a custom
// Realm, you can generate links that either use the current realm path or a
// fully qualified path for another realm.
Expand All @@ -21,10 +21,10 @@ import (

const chainDomain = "gno.land" // XXX: std.ChainDomain (#2911)

// URL returns a URL for the specified function with optional key-value
// Call returns a URL for the specified function with optional key-value
// arguments, for the current realm.
func URL(fn string, args ...string) string {
return Realm("").URL(fn, args...)
func Call(fn string, args ...string) string {
return Realm("").Call(fn, args...)
}

// Realm represents a specific realm for generating tx links.
Expand All @@ -48,9 +48,9 @@ func (r Realm) prefix() string {
return "https://" + string(r)
}

// URL returns a URL for the specified function with optional key-value
// Call returns a URL for the specified function with optional key-value
// arguments.
func (r Realm) URL(fn string, args ...string) string {
func (r Realm) Call(fn string, args ...string) string {
// Start with the base query
url := r.prefix() + "$help&func=" + fn

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/p/moul/txlink/txlink_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"gno.land/p/demo/urequire"
)

func TestURL(t *testing.T) {
func TestCall(t *testing.T) {
tests := []struct {
fn string
args []string
Expand All @@ -30,7 +30,7 @@ func TestURL(t *testing.T) {
for _, tt := range tests {
title := tt.fn
t.Run(title, func(t *testing.T) {
got := tt.realm.URL(tt.fn, tt.args...)
got := tt.realm.Call(tt.fn, tt.args...)
urequire.Equal(t, tt.want, got)
})
}
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/demo/boards/board.gno
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ func (board *Board) GetURLFromThreadAndReplyID(threadID, replyID PostID) string
}

func (board *Board) GetPostFormURL() string {
return txlink.URL("CreateThread", "bid", board.id.String())
return txlink.Call("CreateThread", "bid", board.id.String())
}
6 changes: 3 additions & 3 deletions examples/gno.land/r/demo/boards/post.gno
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,22 @@ func (post *Post) GetURL() string {
}

func (post *Post) GetReplyFormURL() string {
return txlink.URL("CreateReply",
return txlink.Call("CreateReply",
"bid", post.board.id.String(),
"threadid", post.threadID.String(),
"postid", post.id.String(),
)
}

func (post *Post) GetRepostFormURL() string {
return txlink.URL("CreateRepost",
return txlink.Call("CreateRepost",
"bid", post.board.id.String(),
"postid", post.id.String(),
)
}

func (post *Post) GetDeleteFormURL() string {
return txlink.URL("DeletePost",
return txlink.Call("DeletePost",
"bid", post.board.id.String(),
"threadid", post.threadID.String(),
"postid", post.id.String(),
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/docs/adder/adder.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Render(path string) string {
result += "Last Updated: " + formatTimestamp(lastUpdate) + "\n\n"

// Generate a transaction link to call Add with 42 as the default parameter
txLink := txlink.URL("Add", "n", "42")
txLink := txlink.Call("Add", "n", "42")
result += "[Increase Number](" + txLink + ")\n"

return result
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/r/gov/dao/v2/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ func renderActionBar(p dao.Proposal, idx int) string {
out += "### Actions\n\n"
if p.Status() == dao.Active {
out += ufmt.Sprintf("#### [[Vote YES](%s)] - [[Vote NO](%s)] - [[Vote ABSTAIN](%s)]",
txlink.URL("VoteOnProposal", "id", strconv.Itoa(idx), "option", "YES"),
txlink.URL("VoteOnProposal", "id", strconv.Itoa(idx), "option", "NO"),
txlink.URL("VoteOnProposal", "id", strconv.Itoa(idx), "option", "ABSTAIN"),
txlink.Call("VoteOnProposal", "id", strconv.Itoa(idx), "option", "YES"),
txlink.Call("VoteOnProposal", "id", strconv.Itoa(idx), "option", "NO"),
txlink.Call("VoteOnProposal", "id", strconv.Itoa(idx), "option", "ABSTAIN"),
)
} else {
out += "The voting period for this proposal is over."
Expand Down
10 changes: 5 additions & 5 deletions examples/gno.land/r/leon/hof/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func (i Item) Render(dashboard bool) string {
out += ufmt.Sprintf("Submitted at Block #%d\n\n", i.blockNum)

out += ufmt.Sprintf("#### [%d👍](%s) - [%d👎](%s)\n\n",
i.upvote.Size(), txlink.URL("Upvote", "pkgpath", i.pkgpath),
i.downvote.Size(), txlink.URL("Downvote", "pkgpath", i.pkgpath),
i.upvote.Size(), txlink.Call("Upvote", "pkgpath", i.pkgpath),
i.downvote.Size(), txlink.Call("Downvote", "pkgpath", i.pkgpath),
)

if dashboard {
out += ufmt.Sprintf("[Delete](%s)", txlink.URL("Delete", "pkgpath", i.pkgpath))
out += ufmt.Sprintf("[Delete](%s)", txlink.Call("Delete", "pkgpath", i.pkgpath))
}

return out
Expand All @@ -83,9 +83,9 @@ func renderDashboard() string {
out += ufmt.Sprintf("Exhibition admin: %s\n\n", owner.Owner().String())

if !exhibition.IsPaused() {
out += ufmt.Sprintf("[Pause exhibition](%s)\n\n", txlink.URL("Pause"))
out += ufmt.Sprintf("[Pause exhibition](%s)\n\n", txlink.Call("Pause"))
} else {
out += ufmt.Sprintf("[Unpause exhibition](%s)\n\n", txlink.URL("Unpause"))
out += ufmt.Sprintf("[Unpause exhibition](%s)\n\n", txlink.Call("Unpause"))
}

out += "---\n\n"
Expand Down
Loading