Search Apps Documentation Source Content File Folder Download Copy Actions Download

render.gno

1.98 Kb ยท 102 lines
  1package coinflip
  2
  3import (
  4	"chain"
  5	"strconv"
  6
  7	"gno.land/p/moul/md"
  8	"gno.land/p/moul/txlink"
  9	"gno.land/r/sys/users"
 10)
 11
 12var (
 13	githubUsername    string
 14	pocInnovationName string
 15)
 16
 17func init() {
 18	githubUsername = "dujardin09"
 19	pocInnovationName = "PoCInnovation"
 20}
 21
 22func renderResult(address address, result bool, amount chain.Coin) string {
 23	addressFmt := "**" + address.String()[:30] + "**: "
 24	resultFmt := "lost"
 25	amountFmt := " **" + amount.String() + "** "
 26	emoji := "๐Ÿ“‰"
 27
 28	data := users.ResolveAddress(address)
 29	if data != nil {
 30		addressFmt = "**" + data.RenderLink("") + "**: "
 31	}
 32
 33	if result == true {
 34		resultFmt = "won"
 35		emoji = "๐Ÿ“ˆ"
 36	}
 37
 38	return addressFmt + resultFmt + amountFmt + emoji
 39}
 40
 41func renderLatestResults() string {
 42	size := latestBets.Size()
 43
 44	if size == 0 {
 45		return "No results yet"
 46	}
 47
 48	entries := latestBets.Entries()
 49
 50	var out string
 51	for i := size - 1; i >= 0; i-- {
 52		bet := entries[i].(Bet)
 53		out += md.BulletItem(renderResult(bet.Address, bet.Result, bet.Amount))
 54	}
 55	return out
 56}
 57
 58func renderGame() string {
 59	out := "# "
 60	out += md.Link("Heads", txlink.Call("Heads")) + " or "
 61	out += md.Link("Tails", txlink.Call("Tails")) + " ?\n"
 62
 63	out += md.H3("Latests Results:\n\n")
 64	out += renderLatestResults()
 65
 66	return out
 67}
 68
 69func renderRight() string {
 70	out := md.Image("Coin Flip Illustration", "https://ipfs.io/ipfs/QmVZxCKz3J5iMHrACNLfFWpfpfcKT2aSmZMfvZsCQnMWbf")
 71	out += "\n"
 72	out += renderBalance()
 73	return out
 74}
 75
 76func renderFooter() string {
 77	out := md.HorizontalRule()
 78	out += md.BulletList([]string{
 79		md.Link("Home", "home"),
 80		md.Link("GitHub: @"+githubUsername, "https://github.com/"+githubUsername),
 81		md.Link("PoC-Innovation", "https://github.com/"+pocInnovationName),
 82	})
 83	return out
 84}
 85
 86func renderBalance() string {
 87	balance := strconv.Itoa(int(GetRealmBalance(cross)))
 88	out := md.H2("Balance: " + balance + denom + "\n")
 89
 90	return out
 91}
 92
 93func Render(_ string) string {
 94	out := md.Columns([]string{
 95		renderGame(),
 96		renderRight(),
 97	}, false)
 98
 99	out += renderFooter()
100
101	return out
102}