Skip to content

Commit

Permalink
webui/scripts,scriptgroup: show notes
Browse files Browse the repository at this point in the history
  • Loading branch information
RaghavSood committed Jun 7, 2024
1 parent 88b060b commit c4ef6c6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
9 changes: 8 additions & 1 deletion templates/script.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{{ define "content" }}
<div class="container mx-auto p-4">
<div class="border rounded-lg border-slate-700 bg-slate-950/30 p-4">
<div class="border rounded-lg border-slate-700 bg-slate-950/30 p-4 mb-4">
<h1 class="text-2xl font-semibold break-words">Script <span class="select-all">{{ .ScriptSummary.Script }}</span></h1>
<h3 class="text-lg text-gray-400 font-mono">Total Lost: {{ .ScriptSummary.TotalLoss.SatoshisToBTC true }} BTC</a></h3>
<h3 class="text-lg text-gray-400 font-mono">Transactions: {{ .ScriptSummary.Transactions }}</a></h3>
</div>
<h3 class="text-lg font-medium mb-2">How did this Script burn BTC?</h3>
<div class="mb-4">
{{ range .Notes }}
{{ template "note" . }}
{{ end }}
</div>

<table class="min-w-full bg-slate-950/30 border border-slate-700">
<thead>
<tr>
Expand Down
9 changes: 8 additions & 1 deletion templates/scriptgroup.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{{ define "content" }}
<div class="container mx-auto p-4">
<div class="border rounded-lg border-slate-700 bg-slate-950/30 p-4">
<div class="border rounded-lg border-slate-700 bg-slate-950/30 p-4 mb-4">
<h1 class="text-2xl font-semibold break-words">Script Group <span class="select-all">{{ .GroupSummary.ScriptGroup }}</span></h1>
<h3 class="text-lg text-gray-400 font-mono">Total Lost: {{ .GroupSummary.TotalLoss.SatoshisToBTC true }} BTC</a></h3>
<h3 class="text-lg text-gray-400 font-mono">Transactions: {{ .GroupSummary.Transactions }}</a></h3>
<h3 class="text-lg text-gray-400 font-mono">Scripts: {{ .GroupSummary.Scripts }}</a></h3>
</div>
<h3 class="text-lg font-medium mb-2">How did this Script burn BTC?</h3>
<div class="mb-4">
{{ range .Notes }}
{{ template "note" . }}
{{ end }}
</div>

<table class="min-w-full bg-slate-950/30 border border-slate-700">
<thead>
<tr>
Expand Down
9 changes: 9 additions & 0 deletions webui/script_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webui
import (
"net/http"

"github.com/RaghavSood/btcsupply/notes"
"github.com/RaghavSood/btcsupply/templates"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
Expand All @@ -25,11 +26,19 @@ func (w *WebUI) ScriptGroup(c *gin.Context) {
return
}

groupNotePointer := notes.NotePointer{
NoteType: notes.ScriptGroup,
PathElements: []string{scriptGroup},
}

notes := notes.ReadNotes([]notes.NotePointer{groupNotePointer})

tmpl := templates.New()
err = tmpl.Render(c.Writer, "scriptgroup.tmpl", map[string]interface{}{
"Title": "Script Group",
"BurnTransactions": burnScriptSummaries,
"GroupSummary": groupSummary,
"Notes": notes,
})
if err != nil {
log.Error().Err(err).Msg("Failed to render template")
Expand Down
14 changes: 14 additions & 0 deletions webui/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webui
import (
"net/http"

"github.com/RaghavSood/btcsupply/notes"
"github.com/RaghavSood/btcsupply/templates"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -39,6 +40,18 @@ func (w *WebUI) Script(c *gin.Context) {
return
}

scriptNotePointer := notes.NotePointer{
NoteType: notes.Script,
PathElements: []string{script},
}

groupNotePointer := notes.NotePointer{
NoteType: notes.ScriptGroup,
PathElements: []string{burnScriptSummary.Group},
}

notes := notes.ReadNotes([]notes.NotePointer{scriptNotePointer, groupNotePointer})

burnTransactions, err := w.db.GetTransactionLossSummaryForScript(script)
if err != nil {
log.Error().Err(err).Msg("Failed to get transactions for script")
Expand All @@ -51,6 +64,7 @@ func (w *WebUI) Script(c *gin.Context) {
"Title": "Script",
"ScriptSummary": burnScriptSummary,
"Transactions": burnTransactions,
"Notes": notes,
})

if err != nil {
Expand Down

0 comments on commit c4ef6c6

Please sign in to comment.