Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

render.gno

1.49 Kb · 64 lines
 1package referral
 2
 3import (
 4	"strings"
 5	"time"
 6
 7	"gno.land/p/moul/md/v0"
 8	"gno.land/p/moul/mdtable/v0"
 9	ufmt "gno.land/p/nt/ufmt/v0"
10)
11
12// Render describes referral registration or shows the referral for an address.
13func Render(path string) string {
14	if path == "" {
15		table := mdtable.Table{
16			Headers: []string{"Rule", "Value"},
17			Rows: [][]string{
18				{"Minimum interval between registrations or updates", ufmt.Sprintf("%d hours", MinTimeBetweenUpdates/3600)},
19			},
20		}
21
22		return md.H1("Gnoswap Referrals") +
23			"\n" +
24			md.Paragraph("Authorized protocol contracts register a referrer for each address.") +
25			md.H2("Registration") +
26			"\n" +
27			table.String() +
28			"\n" +
29			md.Paragraph(
30				"Removing a referral bypasses the interval but does not reset the last registration time.\n"+
31					"Address-specific records are available at "+md.InlineCode("address/<address>")+".",
32			)
33	}
34
35	parts := strings.Split(path, "/")
36	if len(parts) != 2 || parts[0] != "address" || parts[1] == "" {
37		return "404\n"
38	}
39
40	addr := parts[1]
41	if !HasReferral(addr) {
42		return "404\n"
43	}
44
45	lastOpTimestamp, err := GetLastOpTimestamp(addr)
46	if err != nil {
47		return "404\n"
48	}
49
50	table := mdtable.Table{
51		Headers: []string{"Field", "Value"},
52		Rows: [][]string{
53			{"Address", addr},
54			{"Referrer", GetReferral(addr)},
55			{"Last registration or update (UTC)", time.Unix(lastOpTimestamp, 0).UTC().Format("2006-01-02 15:04:05")},
56		},
57	}
58
59	return md.H1("Gnoswap Referral") +
60		"\n" +
61		md.H2("Referral record") +
62		"\n" +
63		table.String()
64}