Search Apps Documentation Source Content File Folder Download Copy Actions Download

render.gno

4.04 Kb ยท 190 lines
  1package builders
  2
  3import (
  4	"gno.land/p/jeronimoalbi/mdform"
  5	"gno.land/p/moul/md"
  6	"gno.land/p/moul/txlink"
  7)
  8
  9const realmPath = "/r/g1778y2yphxs2wpuaflsy5y9qwcd4gttn4g5yjx5/buildersv5"
 10
 11func renderSubmission(sub *Submission) string {
 12	out := "### " + string(sub.Applicant) + "\n\n"
 13	out += "- **Status:** " + sub.Status.String() + "\n"
 14	out += "- **Twitter:** " + sub.Twitter + "\n"
 15	out += "- **Discord:** " + sub.Discord + "\n"
 16	out += "- **GitHub:** " + sub.GitHub + "\n"
 17	out += "- **Request Type:** " + sub.RequestType + "\n"
 18	out += "- **Details:** " + sub.Details + "\n"
 19	out += "- **Submitted:** " + sub.SubmittedAt.Format("2006-01-02 15:04:05") + "\n"
 20
 21	if !sub.ReviewedAt.IsZero() {
 22		out += "- **Reviewed:** " + sub.ReviewedAt.Format("2006-01-02 15:04:05") + "\n"
 23	}
 24	if !sub.PaidAt.IsZero() {
 25		out += "- **Paid:** " + sub.PaidAt.Format("2006-01-02 15:04:05") + "\n"
 26	}
 27	if sub.ReviewNote != "" {
 28		out += "- **Note:** " + sub.ReviewNote + "\n"
 29	}
 30
 31	out += "\n"
 32	return out
 33}
 34
 35func renderAdminActions(sub *Submission) string {
 36	approveLink := txlink.NewLink("Approve").
 37		AddArgs(
 38			"addr", string(sub.Applicant),
 39			"note", "approved",
 40		).
 41		URL()
 42
 43	rejectLink := txlink.NewLink("Reject").
 44		AddArgs(
 45			"addr", string(sub.Applicant),
 46			"note", "rejected",
 47		).
 48		URL()
 49
 50	out := md.Link("โœ… Approve", approveLink) + " | " + md.Link("โŒ Reject", rejectLink)
 51
 52	if sub.Status == StatusApproved {
 53		paidLink := txlink.NewLink("MarkPaid").
 54			AddArgs(
 55				"addr", string(sub.Applicant),
 56				"note", "paid",
 57			).
 58			URL()
 59		out += " | " + md.Link("๐Ÿ’ธ Mark Paid", paidLink)
 60	}
 61
 62	return out + "\n"
 63}
 64
 65func renderApplyForm() string {
 66	form := mdform.New(
 67		"exec", "Submit",
 68		"path", realmPath,
 69	)
 70
 71	form.Input(
 72		"twitterHandle",
 73		"placeholder", "@yourhandle",
 74		"description", "Twitter / X handle",
 75		"required", "true",
 76	)
 77
 78	form.Input(
 79		"discordHandle",
 80		"placeholder", "username or username#1234",
 81		"description", "Discord handle",
 82		"required", "true",
 83	)
 84
 85	form.Input(
 86		"githubURL",
 87		"placeholder", "https://github.com/yourname",
 88		"description", "GitHub profile or repo URL",
 89		"required", "true",
 90	)
 91
 92	form.Select(
 93		"requestType",
 94		"initial",
 95		"description", "Request type",
 96		"selected", "true",
 97	)
 98
 99	form.Select(
100		"requestType",
101		"followup",
102	)
103
104	form.Input(
105		"applicationDetails",
106		"placeholder", "What are you building, what do you need funds for, and if this is a follow-up request, what indexer activity should reviewers look at?",
107		"description", "Application details",
108		"required", "true",
109	)
110
111	return form.String()
112}
113
114func Render(path string) string {
115	if path == "apply" {
116		out := "# Apply for Builder Faucet\n\n"
117		out += "Submit your faucet application below.\n\n"
118		out += renderApplyForm()
119		out += "\n"
120		out += md.Link("โ† Back to Registry", realmPath) + "\n"
121		return out
122	}
123
124	if path == "admin" {
125		out := "# Admin Panel\n\n"
126		out += "**Admin:** `" + string(Admin()) + "`\n\n"
127		out += md.Link("โ† Back to Registry", realmPath) + "\n\n"
128
129		if TotalSubmissions() == 0 {
130			out += "No submissions yet.\n"
131			return out
132		}
133
134		out += "## Review Queue\n\n"
135		for i := 0; i < TotalSubmissions(); i++ {
136			sub := SubmissionAt(i)
137			out += renderSubmission(sub)
138			out += renderAdminActions(sub)
139			out += "\n---\n\n"
140		}
141		return out
142	}
143
144	out := "# Builder Faucet Registry\n\n"
145	out += "**Total submissions:** " + itoa(TotalSubmissions()) + "\n\n"
146	out += "**Approved:** " + itoa(TotalApproved()) + "\n\n"
147	out += "**Paid:** " + itoa(TotalPaid()) + "\n\n"
148
149	out += md.Link("๐Ÿ“ Apply for Faucet", realmPath+":apply")
150	out += " | "
151	out += md.Link("๐Ÿ” Admin Panel", realmPath+":admin")
152	out += "\n\n---\n\n"
153
154	if TotalSubmissions() == 0 {
155		out += "No submissions yet.\n"
156		return out
157	}
158
159	out += "## Submissions\n\n"
160	for i := 0; i < TotalSubmissions(); i++ {
161		sub := SubmissionAt(i)
162		out += renderSubmission(sub)
163		out += "---\n\n"
164	}
165
166	return out
167}
168
169func itoa(n int) string {
170	if n == 0 {
171		return "0"
172	}
173
174	neg := false
175	if n < 0 {
176		neg = true
177		n = -n
178	}
179
180	s := ""
181	for n > 0 {
182		s = string(rune('0'+(n%10))) + s
183		n /= 10
184	}
185
186	if neg {
187		return "-" + s
188	}
189	return s
190}