Search Apps Documentation Source Content File Folder Download Copy Actions Download

render.gno

0.89 Kb · 32 lines
 1package memba_nft_v2
 2
 3import (
 4	"strings"
 5
 6	"gno.land/p/samcrew/grc721"
 7	"gno.land/p/nt/ufmt/v0"
 8)
 9
10func Render(path string) string {
11	if path == "" {
12		return ufmt.Sprintf("# Memba NFT Collections\n\nTotal collections: %d\n", collections.Size())
13	}
14	parts := strings.SplitN(path, "/", 2)
15	id := parts[0]
16	cv, ok := collections.Get(id)
17	if !ok {
18		return "# 404\n\nCollection not found: " + id
19	}
20	col := cv.(*collection)
21	if len(parts) == 1 {
22		return ufmt.Sprintf("# %s\n\nSymbol: %s\nSupply: %d\nRoyalty BPS: %d\nRoyalty Recipient: %s\n",
23			col.nft.Name(), col.nft.Symbol(), col.nft.TokenCount(), col.royaltyBPS, col.royaltyRecip.String())
24	}
25	tid := grc721.TokenID(parts[1])
26	owner, err := col.nft.OwnerOf(tid)
27	if err != nil {
28		return "# 404\n\nToken not found: " + string(tid)
29	}
30	uri, _ := col.nft.TokenURI(tid)
31	return ufmt.Sprintf("# Token %s\n\nOwner: %s\nURI: %s\n", string(tid), owner.String(), uri)
32}