render.gno
2.72 Kb · 120 lines
1package nftregistry6
2
3import (
4 "gno.land/p/nt/ufmt"
5)
6
7// Render functions
8
9func Render(path string) string {
10 if path == "" {
11 return renderHome()
12 }
13
14 if path == "verified" {
15 return renderVerified()
16 }
17
18 // Render specific category: /art, /gaming, etc.
19 return renderCategory(path)
20}
21
22func renderHome() string {
23 output := "# NFT Registry6\n\n"
24 output += "**The unified NFT collection directory for Gnoland**\n\n"
25 output += "---\n\n"
26 output += ufmt.Sprintf("**Total Collections**: %d\n", GetTotalCollections())
27 output += ufmt.Sprintf("**Verified Collections**: %d\n", GetVerifiedCount())
28 output += ufmt.Sprintf("**Registration Fee**: %d ugnot\n\n", registrationFee)
29
30 output += "## All Collections\n\n"
31
32 if GetTotalCollections() == 0 {
33 output += "_No collections registered yet_\n"
34 return output
35 }
36
37 collections.Iterate("", "", func(key string, value interface{}) bool {
38 info := value.(*CollectionInfo)
39 output += renderCollectionCard(info)
40 return false
41 })
42
43 output += "\n---\n\n"
44 output += "**Views**: [All Collections](/) | [Verified Only](/verified)\n"
45
46 return output
47}
48
49func renderVerified() string {
50 output := "# Verified Collections\n\n"
51 output += ufmt.Sprintf("Showing %d verified collections\n\n", GetVerifiedCount())
52
53 if GetVerifiedCount() == 0 {
54 output += "_No verified collections yet_\n"
55 return output
56 }
57
58 collections.Iterate("", "", func(key string, value interface{}) bool {
59 info := value.(*CollectionInfo)
60 if info.Verified {
61 output += renderCollectionCard(info)
62 }
63 return false
64 })
65
66 return output
67}
68
69func renderCategory(category string) string {
70 output := ufmt.Sprintf("# Category: %s\n\n", category)
71
72 count := 0
73 collections.Iterate("", "", func(key string, value interface{}) bool {
74 info := value.(*CollectionInfo)
75 if info.Category == category {
76 output += renderCollectionCard(info)
77 count++
78 }
79 return false
80 })
81
82 if count == 0 {
83 output += "_No collections in this category_\n"
84 }
85
86 return output
87}
88
89func renderCollectionCard(info *CollectionInfo) string {
90 verified := ""
91 if info.Verified {
92 verified = " ✓"
93 }
94
95 metadata := ""
96 if info.SupportsMetadata {
97 metadata = " 🎭"
98 }
99
100 output := ufmt.Sprintf("### %s (%s)%s%s\n", info.Name, info.Symbol, verified, metadata)
101 output += ufmt.Sprintf("- **Address**: `%s`\n", info.Address)
102 output += ufmt.Sprintf("- **Creator**: `%s`\n", info.Creator)
103
104 if info.Category != "" {
105 output += ufmt.Sprintf("- **Category**: %s\n", info.Category)
106 }
107
108 if info.Description != "" {
109 output += ufmt.Sprintf("- **Description**: %s\n", info.Description)
110 }
111
112 if info.ExternalURL != "" {
113 output += ufmt.Sprintf("- **Website**: %s\n", info.ExternalURL)
114 }
115
116 output += ufmt.Sprintf("- **Registered**: Block #%d\n", info.RegisteredAt)
117 output += "\n"
118
119 return output
120}