feat: add localized ledger explorer dashboard
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
//go:embed assets/favicon.ico
|
||||
var favicon []byte
|
||||
|
||||
func (h *Handler) favicon(response http.ResponseWriter, request *http.Request) {
|
||||
response.Header().Set("Cache-Control", "public, max-age=86400")
|
||||
http.ServeContent(response, request, "favicon.ico", time.Time{}, bytes.NewReader(favicon))
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,317 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
_ "time/tzdata"
|
||||
|
||||
"gl/application/explorer"
|
||||
"gl/domain/ledger"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
type Explorer interface {
|
||||
Dashboard(context.Context) (explorer.Dashboard, error)
|
||||
Assets(context.Context) (explorer.Assets, error)
|
||||
Transactions(context.Context, explorer.TransactionFilter) (explorer.TransactionListing, error)
|
||||
Transaction(context.Context, string) ([]ledger.Journal, error)
|
||||
Account(context.Context, ledger.AccountReference) (explorer.Account, error)
|
||||
Holder(context.Context, explorer.HolderReference) (explorer.HolderAccount, error)
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
explorer Explorer
|
||||
routes *http.ServeMux
|
||||
}
|
||||
|
||||
type TransactionPageData struct {
|
||||
Query string
|
||||
Journals []ledger.Journal
|
||||
Listing *explorer.TransactionListing
|
||||
Error string
|
||||
}
|
||||
|
||||
type AccountInput struct {
|
||||
Class string
|
||||
OwnerType string
|
||||
OwnerID string
|
||||
AssetID string
|
||||
}
|
||||
|
||||
type AccountPageData struct {
|
||||
Input AccountInput
|
||||
Account *explorer.Account
|
||||
Error string
|
||||
}
|
||||
|
||||
type HolderPageData struct {
|
||||
Account *explorer.HolderAccount
|
||||
Error string
|
||||
}
|
||||
|
||||
func NewHandler(service Explorer) *Handler {
|
||||
handler := &Handler{explorer: service, routes: http.NewServeMux()}
|
||||
handler.routes.HandleFunc("GET /favicon.ico", handler.favicon)
|
||||
handler.routes.HandleFunc("GET /{$}", handler.dashboard)
|
||||
handler.routes.HandleFunc("GET /assets", handler.assets)
|
||||
handler.routes.HandleFunc("GET /transactions", handler.transaction)
|
||||
handler.routes.HandleFunc("GET /transactions/{reference}", handler.transaction)
|
||||
handler.routes.HandleFunc("GET /accounts", handler.account)
|
||||
handler.routes.HandleFunc("GET /holders", handler.holder)
|
||||
return handler
|
||||
}
|
||||
|
||||
func (h *Handler) assets(response http.ResponseWriter, request *http.Request) {
|
||||
locale := localeForRequest(response, request)
|
||||
data, err := h.explorer.Assets(request.Context())
|
||||
if err != nil {
|
||||
h.renderFailure(response, request, locale, tr(locale, "assets_unavailable"), err)
|
||||
return
|
||||
}
|
||||
h.render(response, request, http.StatusOK, locale, tr(locale, "title_assets"), "assets", AssetsContent(data, locale))
|
||||
}
|
||||
|
||||
func (h *Handler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
|
||||
response.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
response.Header().Set("Referrer-Policy", "same-origin")
|
||||
response.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; base-uri 'self'; frame-ancestors 'none'")
|
||||
h.routes.ServeHTTP(response, request)
|
||||
}
|
||||
|
||||
func (h *Handler) dashboard(response http.ResponseWriter, request *http.Request) {
|
||||
locale := localeForRequest(response, request)
|
||||
data, err := h.explorer.Dashboard(request.Context())
|
||||
if err != nil {
|
||||
h.renderFailure(response, request, locale, tr(locale, "dashboard_unavailable"), err)
|
||||
return
|
||||
}
|
||||
h.render(response, request, http.StatusOK, locale, tr(locale, "title_overview"), "dashboard", DashboardContent(data, locale))
|
||||
}
|
||||
|
||||
func (h *Handler) transaction(response http.ResponseWriter, request *http.Request) {
|
||||
locale := localeForRequest(response, request)
|
||||
query := strings.TrimSpace(request.PathValue("reference"))
|
||||
if query == "" {
|
||||
query = strings.TrimSpace(request.URL.Query().Get("q"))
|
||||
}
|
||||
data := TransactionPageData{Query: query}
|
||||
showLatest := query == ""
|
||||
if query != "" {
|
||||
journals, err := h.explorer.Transaction(request.Context(), query)
|
||||
switch {
|
||||
case err == nil:
|
||||
data.Journals = journals
|
||||
case requestEnded(request, err):
|
||||
return
|
||||
case explorer.IsNotFound(err):
|
||||
data.Error = tr(locale, "transaction_missing")
|
||||
showLatest = true
|
||||
default:
|
||||
data.Error = tr(locale, "transaction_lookup_error")
|
||||
}
|
||||
}
|
||||
if showLatest {
|
||||
page, parseErr := strconv.Atoi(strings.TrimSpace(request.URL.Query().Get("page")))
|
||||
if parseErr != nil || page < 1 {
|
||||
page = 1
|
||||
}
|
||||
listing, err := h.explorer.Transactions(request.Context(), explorer.TransactionFilter{
|
||||
Page: page,
|
||||
Wallet: request.URL.Query().Get("wallet"),
|
||||
EffectKind: request.URL.Query().Get("effect"),
|
||||
})
|
||||
if requestEnded(request, err) {
|
||||
return
|
||||
} else if err != nil {
|
||||
h.renderFailure(response, request, locale, tr(locale, "transactions_unavailable"), err)
|
||||
return
|
||||
}
|
||||
data.Listing = &listing
|
||||
}
|
||||
h.render(response, request, http.StatusOK, locale, tr(locale, "title_transactions"), "transactions", TransactionContent(data, locale))
|
||||
}
|
||||
|
||||
func (h *Handler) account(response http.ResponseWriter, request *http.Request) {
|
||||
locale := localeForRequest(response, request)
|
||||
data := AccountPageData{Input: AccountInput{
|
||||
Class: strings.TrimSpace(request.URL.Query().Get("class")),
|
||||
OwnerType: strings.TrimSpace(request.URL.Query().Get("owner_type")),
|
||||
OwnerID: strings.TrimSpace(request.URL.Query().Get("owner_id")),
|
||||
AssetID: strings.TrimSpace(request.URL.Query().Get("asset_id")),
|
||||
}}
|
||||
if request.URL.Query().Has("class") {
|
||||
assetID, err := strconv.ParseInt(data.Input.AssetID, 10, 64)
|
||||
if err != nil || assetID <= 0 {
|
||||
data.Error = tr(locale, "asset_positive")
|
||||
} else {
|
||||
result, lookupErr := h.explorer.Account(request.Context(), ledger.AccountReference{
|
||||
Class: ledger.AccountClass(data.Input.Class),
|
||||
OwnerType: data.Input.OwnerType,
|
||||
OwnerID: data.Input.OwnerID,
|
||||
AssetID: assetID,
|
||||
})
|
||||
if requestEnded(request, lookupErr) {
|
||||
return
|
||||
} else if lookupErr != nil {
|
||||
data.Error = tr(locale, "account_lookup_error")
|
||||
} else {
|
||||
data.Account = &result
|
||||
}
|
||||
}
|
||||
}
|
||||
h.render(response, request, http.StatusOK, locale, tr(locale, "title_accounts"), "accounts", AccountContent(data, locale))
|
||||
}
|
||||
|
||||
func (h *Handler) holder(response http.ResponseWriter, request *http.Request) {
|
||||
locale := localeForRequest(response, request)
|
||||
data := HolderPageData{}
|
||||
assetID, err := strconv.ParseInt(strings.TrimSpace(request.URL.Query().Get("asset_id")), 10, 64)
|
||||
reference := explorer.HolderReference{
|
||||
OwnerType: strings.TrimSpace(request.URL.Query().Get("owner_type")),
|
||||
OwnerID: strings.TrimSpace(request.URL.Query().Get("owner_id")),
|
||||
AssetID: assetID,
|
||||
}
|
||||
if err != nil || reference.OwnerType == "" || reference.OwnerID == "" || reference.AssetID <= 0 {
|
||||
data.Error = tr(locale, "holder_reference_invalid")
|
||||
} else {
|
||||
result, lookupErr := h.explorer.Holder(request.Context(), reference)
|
||||
if requestEnded(request, lookupErr) {
|
||||
return
|
||||
} else if lookupErr != nil {
|
||||
data.Error = tr(locale, "account_lookup_error")
|
||||
} else {
|
||||
data.Account = &result
|
||||
}
|
||||
}
|
||||
h.render(response, request, http.StatusOK, locale, tr(locale, "title_holder"), "assets", HolderContent(data, locale))
|
||||
}
|
||||
|
||||
func (h *Handler) render(response http.ResponseWriter, request *http.Request, status int, locale Locale, title, active string, content templ.Component) {
|
||||
component := Page(title, active, locale, localeURL(request, LocaleEnglish), localeURL(request, LocalePersian), content)
|
||||
if request.Header.Get("HX-Request") == "true" && request.Header.Get("HX-History-Restore-Request") != "true" {
|
||||
component = content
|
||||
}
|
||||
response.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
response.WriteHeader(status)
|
||||
if err := component.Render(request.Context(), response); err != nil {
|
||||
if requestEnded(request, err) {
|
||||
return
|
||||
}
|
||||
slog.Error("render explorer", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) renderFailure(response http.ResponseWriter, request *http.Request, locale Locale, title string, err error) {
|
||||
if requestEnded(request, err) {
|
||||
return
|
||||
}
|
||||
slog.Error("explorer request failed", "error", err)
|
||||
h.render(response, request, http.StatusInternalServerError, locale, title, "", FailureContent(title, tr(locale, "read_model_unavailable"), locale))
|
||||
}
|
||||
|
||||
func requestEnded(request *http.Request, err error) bool {
|
||||
return request.Context().Err() != nil ||
|
||||
errors.Is(err, context.Canceled) ||
|
||||
errors.Is(err, syscall.EPIPE) ||
|
||||
errors.Is(err, syscall.ECONNRESET)
|
||||
}
|
||||
|
||||
func accountClasses() []ledger.AccountClass {
|
||||
return []ledger.AccountClass{
|
||||
ledger.AccountClassUserAvailable,
|
||||
ledger.AccountClassUserFrozen,
|
||||
ledger.AccountClassExternalBlockchain,
|
||||
ledger.AccountClassTreasury,
|
||||
ledger.AccountClassMarketClearing,
|
||||
ledger.AccountClassIPGClearing,
|
||||
ledger.AccountClassCommissionRevenue,
|
||||
}
|
||||
}
|
||||
|
||||
func formatTime(value time.Time) string {
|
||||
if value.IsZero() || value.Unix() == 0 {
|
||||
return "—"
|
||||
}
|
||||
return value.In(defaultTimezone).Format("02 Jan 2006 · 15:04:05") + " Asia/Tehran"
|
||||
}
|
||||
|
||||
func short(value string, size int) string {
|
||||
if len(value) <= size {
|
||||
return value
|
||||
}
|
||||
left := size / 2
|
||||
return value[:left] + "…" + value[len(value)-(size-left):]
|
||||
}
|
||||
|
||||
func count(value int64) string {
|
||||
text := strconv.FormatInt(value, 10)
|
||||
for index := len(text) - 3; index > 0; index -= 3 {
|
||||
text = text[:index] + "," + text[index:]
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
func transactionName(journal ledger.Journal, locale Locale) string {
|
||||
if journal.Blockchain.TransactionHash != "" {
|
||||
return short(journal.Blockchain.TransactionHash, 22)
|
||||
}
|
||||
return tr(locale, "internal") + " · " + short(journal.ID, 14)
|
||||
}
|
||||
|
||||
func transactionReference(journal ledger.Journal) string {
|
||||
if journal.Blockchain.TransactionHash != "" {
|
||||
return journal.Blockchain.TransactionHash
|
||||
}
|
||||
return journal.ID
|
||||
}
|
||||
|
||||
func transactionURL(reference string) string {
|
||||
return "/transactions/" + url.PathEscape(reference)
|
||||
}
|
||||
|
||||
func transactionPageURL(filter explorer.TransactionFilter, page int) string {
|
||||
values := url.Values{"page": []string{strconv.Itoa(page)}}
|
||||
if filter.Wallet != "" {
|
||||
values.Set("wallet", filter.Wallet)
|
||||
}
|
||||
if filter.EffectKind != "" {
|
||||
values.Set("effect", filter.EffectKind)
|
||||
}
|
||||
return "/transactions?" + values.Encode()
|
||||
}
|
||||
|
||||
func accountURL(account ledger.AccountReference) string {
|
||||
values := url.Values{
|
||||
"class": []string{string(account.Class)},
|
||||
"owner_type": []string{account.OwnerType},
|
||||
"owner_id": []string{account.OwnerID},
|
||||
"asset_id": []string{strconv.FormatInt(account.AssetID, 10)},
|
||||
}
|
||||
return "/accounts?" + values.Encode()
|
||||
}
|
||||
|
||||
func holderURL(holder explorer.Holder) string {
|
||||
values := url.Values{
|
||||
"owner_type": []string{holder.OwnerType},
|
||||
"owner_id": []string{holder.OwnerID},
|
||||
"asset_id": []string{strconv.FormatInt(holder.AssetID, 10)},
|
||||
}
|
||||
return "/holders?" + values.Encode()
|
||||
}
|
||||
|
||||
func accountName(account ledger.AccountReference, locale Locale) string {
|
||||
owner := account.OwnerID
|
||||
if owner == "" {
|
||||
owner = tr(locale, "system")
|
||||
}
|
||||
return fmt.Sprintf("%s / %s", account.Class, owner)
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gl/application/explorer"
|
||||
"gl/domain/ledger"
|
||||
)
|
||||
|
||||
type explorerStub struct {
|
||||
dashboard explorer.Dashboard
|
||||
dashboardErr error
|
||||
assets explorer.Assets
|
||||
assetsErr error
|
||||
listing explorer.TransactionListing
|
||||
listingErr error
|
||||
transaction []ledger.Journal
|
||||
transactionErr error
|
||||
account explorer.Account
|
||||
accountErr error
|
||||
holder explorer.HolderAccount
|
||||
holderErr error
|
||||
lastHash string
|
||||
lastFilter explorer.TransactionFilter
|
||||
lastAccount ledger.AccountReference
|
||||
}
|
||||
|
||||
func (s *explorerStub) Dashboard(context.Context) (explorer.Dashboard, error) {
|
||||
return s.dashboard, s.dashboardErr
|
||||
}
|
||||
|
||||
func (s *explorerStub) Assets(context.Context) (explorer.Assets, error) {
|
||||
return s.assets, s.assetsErr
|
||||
}
|
||||
|
||||
func (s *explorerStub) Transactions(_ context.Context, filter explorer.TransactionFilter) (explorer.TransactionListing, error) {
|
||||
s.lastFilter = filter
|
||||
return s.listing, s.listingErr
|
||||
}
|
||||
|
||||
func (s *explorerStub) Transaction(_ context.Context, hash string) ([]ledger.Journal, error) {
|
||||
s.lastHash = hash
|
||||
return s.transaction, s.transactionErr
|
||||
}
|
||||
|
||||
func (s *explorerStub) Account(_ context.Context, account ledger.AccountReference) (explorer.Account, error) {
|
||||
s.lastAccount = account
|
||||
return s.account, s.accountErr
|
||||
}
|
||||
|
||||
func (s *explorerStub) Holder(_ context.Context, reference explorer.HolderReference) (explorer.HolderAccount, error) {
|
||||
s.holder.Reference = reference
|
||||
return s.holder, s.holderErr
|
||||
}
|
||||
|
||||
func TestDashboardRendersFullTemplPage(t *testing.T) {
|
||||
service := &explorerStub{dashboard: explorer.Dashboard{
|
||||
Stats: explorer.Stats{JournalCount: 1234, LastRecordedAt: time.Unix(10, 0).UTC()},
|
||||
Journals: []ledger.Journal{{
|
||||
ID: "journal-1", EffectKind: "deposit", SourceService: "wallet",
|
||||
Blockchain: ledger.BlockchainReference{TransactionHash: "abc123"},
|
||||
}},
|
||||
}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
body := response.Body.String()
|
||||
for _, expected := range []string{"<!doctype html>", "DARANO", "1,234", "abc123", "htmx.org@2.0.10", "class=\"mark\" src=\"/favicon.ico\"", "#F5F5F5", "#DFF1F1", "#BBD5DA", "#FF0000"} {
|
||||
if !strings.Contains(body, expected) {
|
||||
t.Fatalf("response did not contain %q", expected)
|
||||
}
|
||||
}
|
||||
if response.Header().Get("Content-Security-Policy") == "" {
|
||||
t.Fatal("expected content security policy")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardLinksInternalTransactionsByJournalID(t *testing.T) {
|
||||
const journalID = "5c1e31b0-0000-4000-8000-0000084accc8"
|
||||
service := &explorerStub{dashboard: explorer.Dashboard{Journals: []ledger.Journal{{ID: journalID}}}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
if !strings.Contains(response.Body.String(), `href="/transactions/`+journalID+`"`) {
|
||||
t.Fatalf("internal transaction was not linked: %s", response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssetsPageRendersLinkedTopAssetHolders(t *testing.T) {
|
||||
balance, err := ledger.ParseAmount("987.25")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service := &explorerStub{assets: explorer.Assets{TopHolders: []explorer.Holder{{
|
||||
Rank: 1, OwnerType: "user", OwnerID: "holder-42", AssetID: 7, Balance: balance,
|
||||
}}}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/assets", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
body := response.Body.String()
|
||||
for _, expected := range []string{"Top asset holders", "holder-42", "Asset 7", "987.25", "/holders?asset_id=7&owner_id=holder-42&owner_type=user"} {
|
||||
if !strings.Contains(body, expected) {
|
||||
t.Fatalf("top holder response did not contain %q: %s", expected, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHolderPageLoadsAggregateAccountDetail(t *testing.T) {
|
||||
balance, err := ledger.ParseAmount("42.5")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service := &explorerStub{holder: explorer.HolderAccount{Balance: balance}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/holders?owner_type=user&owner_id=holder-42&asset_id=7", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
body := response.Body.String()
|
||||
for _, expected := range []string{"holder-42", "Asset 7", "42.5", "AVAILABLE + FROZEN"} {
|
||||
if !strings.Contains(body, expected) {
|
||||
t.Fatalf("holder response did not contain %q: %s", expected, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardDefaultsToEnglishAndSupportsPersian(t *testing.T) {
|
||||
service := &explorerStub{}
|
||||
handler := NewHandler(service)
|
||||
|
||||
englishRequest := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
englishResponse := httptest.NewRecorder()
|
||||
handler.ServeHTTP(englishResponse, englishRequest)
|
||||
if !strings.Contains(englishResponse.Body.String(), `lang="en" dir="ltr"`) || !strings.Contains(englishResponse.Body.String(), "Every movement") {
|
||||
t.Fatalf("dashboard did not default to English: %s", englishResponse.Body.String())
|
||||
}
|
||||
|
||||
persianRequest := httptest.NewRequest(http.MethodGet, "/?lang=fa", nil)
|
||||
persianResponse := httptest.NewRecorder()
|
||||
handler.ServeHTTP(persianResponse, persianRequest)
|
||||
if !strings.Contains(persianResponse.Body.String(), `lang="fa" dir="rtl"`) || !strings.Contains(persianResponse.Body.String(), "هر جابهجایی") {
|
||||
t.Fatalf("dashboard did not render Persian: %s", persianResponse.Body.String())
|
||||
}
|
||||
if !strings.Contains(persianResponse.Header().Get("Set-Cookie"), "gl_locale=fa") {
|
||||
t.Fatal("Persian locale was not persisted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDashboardUsesLocaleCookie(t *testing.T) {
|
||||
request := httptest.NewRequest(http.MethodGet, "/transactions", nil)
|
||||
request.AddCookie(&http.Cookie{Name: localeCookie, Value: "fa"})
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(&explorerStub{}).ServeHTTP(response, request)
|
||||
|
||||
if !strings.Contains(response.Body.String(), "کاوشگر تراکنش") {
|
||||
t.Fatalf("locale cookie was ignored: %s", response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFaviconIsServedFromEmbeddedBrandAsset(t *testing.T) {
|
||||
request := httptest.NewRequest(http.MethodGet, "/favicon.ico", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(&explorerStub{}).ServeHTTP(response, request)
|
||||
|
||||
if response.Code != http.StatusOK || response.Body.Len() < 1000 {
|
||||
t.Fatalf("unexpected favicon response: status=%d bytes=%d", response.Code, response.Body.Len())
|
||||
}
|
||||
if !strings.Contains(response.Header().Get("Content-Type"), "image/") {
|
||||
t.Fatalf("unexpected favicon content type: %s", response.Header().Get("Content-Type"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransactionHTMXRequestRendersOnlyExplorerContent(t *testing.T) {
|
||||
service := &explorerStub{transaction: []ledger.Journal{{
|
||||
ID: "journal-1", EffectKind: "withdrawal",
|
||||
Blockchain: ledger.BlockchainReference{TransactionHash: "tx-hash"},
|
||||
}}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/transactions?q=tx-hash", nil)
|
||||
request.Header.Set("HX-Request", "true")
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
body := response.Body.String()
|
||||
if strings.Contains(body, "<!doctype html>") || !strings.Contains(body, `id="explorer-content"`) {
|
||||
t.Fatalf("unexpected HTMX fragment: %s", body)
|
||||
}
|
||||
if service.lastHash != "tx-hash" || !strings.Contains(body, "COMMITTED") {
|
||||
t.Fatalf("transaction was not rendered: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransactionsPageShowsLatestTransactionsWithPagination(t *testing.T) {
|
||||
service := &explorerStub{listing: explorer.TransactionListing{
|
||||
Journals: []ledger.Journal{{ID: "latest-journal", EffectKind: "transfer"}},
|
||||
Filter: explorer.TransactionFilter{Page: 2, Wallet: "wallet-42", EffectKind: "transfer"},
|
||||
HasPrevious: true, HasNext: true,
|
||||
}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/transactions?page=2&wallet=wallet-42&effect=transfer", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
body := response.Body.String()
|
||||
for _, expected := range []string{"Latest transactions", "latest-journal", "value=\"wallet-42\"", "value=\"transfer\"", "/transactions?effect=transfer&page=1&wallet=wallet-42", "/transactions?effect=transfer&page=3&wallet=wallet-42"} {
|
||||
if !strings.Contains(body, expected) {
|
||||
t.Fatalf("transaction listing did not contain %q: %s", expected, body)
|
||||
}
|
||||
}
|
||||
if service.lastFilter.Page != 2 || service.lastFilter.Wallet != "wallet-42" || service.lastFilter.EffectKind != "transfer" {
|
||||
t.Fatalf("unexpected transaction filter: %+v", service.lastFilter)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMissingTransactionShowsLatestTransactions(t *testing.T) {
|
||||
service := &explorerStub{
|
||||
transactionErr: ledger.ErrNotFound,
|
||||
listing: explorer.TransactionListing{Journals: []ledger.Journal{{ID: "latest-journal"}}, Filter: explorer.TransactionFilter{Page: 1}},
|
||||
}
|
||||
request := httptest.NewRequest(http.MethodGet, "/transactions?q=missing", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
body := response.Body.String()
|
||||
if !strings.Contains(body, "No committed transaction matches") || !strings.Contains(body, "latest-journal") {
|
||||
t.Fatalf("missing transaction did not include latest activity: %s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccountExplorerParsesStableAccountIdentity(t *testing.T) {
|
||||
balance, err := ledger.ParseAmount("42.5")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
service := &explorerStub{account: explorer.Account{Balance: balance, Reference: ledger.AccountReference{
|
||||
Class: ledger.AccountClassUserAvailable, OwnerType: "user", OwnerID: "17", AssetID: 9,
|
||||
}}}
|
||||
request := httptest.NewRequest(http.MethodGet, "/accounts?class=USER_AVAILABLE&owner_type=user&owner_id=17&asset_id=9", nil)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
if service.lastAccount.OwnerID != "17" || service.lastAccount.AssetID != 9 {
|
||||
t.Fatalf("unexpected account lookup: %+v", service.lastAccount)
|
||||
}
|
||||
if !strings.Contains(response.Body.String(), "42.5") {
|
||||
t.Fatal("account balance was not rendered")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanceledDashboardRequestDoesNotRenderAnErrorPage(t *testing.T) {
|
||||
service := &explorerStub{dashboardErr: context.Canceled}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
request := httptest.NewRequest(http.MethodGet, "/", nil).WithContext(ctx)
|
||||
response := httptest.NewRecorder()
|
||||
|
||||
NewHandler(service).ServeHTTP(response, request)
|
||||
|
||||
if response.Body.Len() != 0 {
|
||||
t.Fatalf("expected canceled request to produce no response, got %q", response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatTimeUsesTehranTimezone(t *testing.T) {
|
||||
value := time.Date(2026, time.August, 14, 0, 0, 0, 0, time.UTC)
|
||||
if got := formatTime(value); got != "14 Aug 2026 · 03:30:00 Asia/Tehran" {
|
||||
t.Fatalf("unexpected localized time: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Locale string
|
||||
|
||||
const (
|
||||
LocaleEnglish Locale = "en"
|
||||
LocalePersian Locale = "fa"
|
||||
localeCookie = "gl_locale"
|
||||
)
|
||||
|
||||
var defaultTimezone = mustLoadLocation("Asia/Tehran")
|
||||
|
||||
func mustLoadLocation(name string) *time.Location {
|
||||
location, err := time.LoadLocation(name)
|
||||
if err != nil {
|
||||
panic("load dashboard timezone: " + err.Error())
|
||||
}
|
||||
return location
|
||||
}
|
||||
|
||||
func localeForRequest(response http.ResponseWriter, request *http.Request) Locale {
|
||||
if locale, ok := validLocale(request.URL.Query().Get("lang")); ok {
|
||||
http.SetCookie(response, &http.Cookie{
|
||||
Name: localeCookie,
|
||||
Value: string(locale),
|
||||
Path: "/",
|
||||
MaxAge: 365 * 24 * 60 * 60,
|
||||
SameSite: http.SameSiteLaxMode,
|
||||
})
|
||||
return locale
|
||||
}
|
||||
if cookie, err := request.Cookie(localeCookie); err == nil {
|
||||
if locale, ok := validLocale(cookie.Value); ok {
|
||||
return locale
|
||||
}
|
||||
}
|
||||
return LocaleEnglish
|
||||
}
|
||||
|
||||
func validLocale(value string) (Locale, bool) {
|
||||
switch Locale(value) {
|
||||
case LocaleEnglish:
|
||||
return LocaleEnglish, true
|
||||
case LocalePersian:
|
||||
return LocalePersian, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
|
||||
func (l Locale) Direction() string {
|
||||
if l == LocalePersian {
|
||||
return "rtl"
|
||||
}
|
||||
return "ltr"
|
||||
}
|
||||
|
||||
func localeURL(request *http.Request, locale Locale) string {
|
||||
query := cloneQuery(request.URL.Query())
|
||||
query.Set("lang", string(locale))
|
||||
return request.URL.Path + "?" + query.Encode()
|
||||
}
|
||||
|
||||
func cloneQuery(source url.Values) url.Values {
|
||||
result := make(url.Values, len(source))
|
||||
for key, values := range source {
|
||||
result[key] = append([]string(nil), values...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func tr(locale Locale, key string) string {
|
||||
if locale == LocalePersian {
|
||||
if value, ok := persian[key]; ok {
|
||||
return value
|
||||
}
|
||||
}
|
||||
if value, ok := english[key]; ok {
|
||||
return value
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
var english = map[string]string{
|
||||
"site_name": "DARANO",
|
||||
"site_subtitle": "LEDGER NETWORK",
|
||||
"overview": "Overview",
|
||||
"transactions": "Transactions",
|
||||
"assets": "Assets",
|
||||
"accounts": "Accounts",
|
||||
"read_only": "READ ONLY",
|
||||
"general_ledger_explorer": "General ledger explorer",
|
||||
"hero_line_one": "Every movement.",
|
||||
"hero_line_two": "One durable record.",
|
||||
"hero_description": "Inspect committed journals, trace blockchain transaction hashes, and reconstruct any ledger account without touching the write path.",
|
||||
"transaction_placeholder": "Enter a transaction hash or journal ID",
|
||||
"transaction_hash": "Transaction hash",
|
||||
"explore_transaction": "Explore transaction",
|
||||
"committed_journals": "Committed journals",
|
||||
"ledger_entries": "Ledger entries",
|
||||
"tracked_accounts": "Tracked accounts",
|
||||
"last_recorded": "Last recorded",
|
||||
"latest_activity": "Latest ledger activity",
|
||||
"newest_first": "NEWEST FIRST",
|
||||
"top_asset_holders": "Top asset holders",
|
||||
"holder_balance_scope": "AVAILABLE + FROZEN · RECENT ASSETS",
|
||||
"no_asset_holders": "No positive user holdings yet.",
|
||||
"assets_explorer": "Asset explorer",
|
||||
"track_asset_ownership": "Track asset ownership.",
|
||||
"assets_description": "Review the leading positive user balances for the most recently active ledger assets.",
|
||||
"rank": "Rank",
|
||||
"holder": "Holder",
|
||||
"balance": "Balance",
|
||||
"holder_account": "Holder account",
|
||||
"inspect_holder": "Inspect a holder.",
|
||||
"holder_description": "This account combines the holder's available and frozen balances and activity for one asset.",
|
||||
"combined_balance": "Combined balance",
|
||||
"available_and_frozen": "AVAILABLE + FROZEN",
|
||||
"holder_reference_invalid": "A holder identity and positive asset ID are required.",
|
||||
"transaction": "Transaction",
|
||||
"effect": "Effect",
|
||||
"source": "Source",
|
||||
"entries": "Entries",
|
||||
"recorded": "Recorded",
|
||||
"no_journals": "No committed journals yet.",
|
||||
"network": "NETWORK",
|
||||
"transaction_explorer": "Transaction explorer",
|
||||
"trace_settlement": "Trace a settlement.",
|
||||
"transaction_description": "Search an exact blockchain hash or internal journal ID retained on committed ledger journals.",
|
||||
"transaction_not_found": "Transaction not found",
|
||||
"transaction_missing": "No committed transaction matches that hash or journal ID.",
|
||||
"transaction_lookup_error": "The transaction could not be loaded. Try again shortly.",
|
||||
"enter_hash": "Enter a hash or journal ID to inspect its balanced financial effects.",
|
||||
"latest_transactions": "Latest transactions",
|
||||
"page": "PAGE",
|
||||
"pagination": "Transaction pages",
|
||||
"previous": "Previous",
|
||||
"next": "Next",
|
||||
"user_wallet": "User / wallet",
|
||||
"user_wallet_placeholder": "Exact owner or wallet ID",
|
||||
"effect_type": "Effect type",
|
||||
"effect_type_placeholder": "Exact effect type",
|
||||
"apply_filters": "Apply filters",
|
||||
"clear_filters": "Clear",
|
||||
"committed": "COMMITTED",
|
||||
"journal_id": "Journal ID",
|
||||
"ledger_sequence": "Ledger sequence",
|
||||
"balanced_entries": "Balanced entries",
|
||||
"asset": "Asset",
|
||||
"internal": "internal",
|
||||
"system": "system",
|
||||
"account_explorer": "Account explorer",
|
||||
"rebuild_account": "Rebuild an account.",
|
||||
"account_description": "Select the stable ledger identity and asset to calculate its current balance from immutable entries.",
|
||||
"account_class": "Account class",
|
||||
"owner_type": "Owner type",
|
||||
"owner_id": "Owner ID",
|
||||
"stable_owner_id": "Stable owner ID",
|
||||
"asset_id": "Asset ID",
|
||||
"explore": "Explore",
|
||||
"account_unavailable": "Account unavailable",
|
||||
"asset_positive": "Asset ID must be a positive integer.",
|
||||
"account_lookup_error": "The account could not be loaded. Check its identity and try again.",
|
||||
"ledger_identity": "Ledger identity",
|
||||
"current_balance": "Current balance",
|
||||
"account_activity": "Account activity",
|
||||
"journals": "JOURNALS",
|
||||
"choose_account": "Choose an account class, owner, and asset to begin.",
|
||||
"explorer_error": "Explorer error",
|
||||
"dashboard_unavailable": "Dashboard unavailable",
|
||||
"assets_unavailable": "Assets unavailable",
|
||||
"transactions_unavailable": "Transactions unavailable",
|
||||
"read_model_unavailable": "The ledger read model could not be reached. Try again shortly.",
|
||||
"footer_description": "Darano General Ledger · immutable financial history",
|
||||
"timezone_notice": "All times shown in Asia/Tehran",
|
||||
"title_overview": "Network overview",
|
||||
"title_transactions": "Transaction explorer",
|
||||
"title_assets": "Asset explorer",
|
||||
"title_accounts": "Account explorer",
|
||||
"title_holder": "Holder account",
|
||||
}
|
||||
|
||||
var persian = map[string]string{
|
||||
"site_name": "دارانو",
|
||||
"site_subtitle": "شبکه دفتر کل",
|
||||
"overview": "نمای کلی",
|
||||
"transactions": "تراکنشها",
|
||||
"assets": "داراییها",
|
||||
"accounts": "حسابها",
|
||||
"read_only": "فقط خواندنی",
|
||||
"general_ledger_explorer": "کاوشگر دفتر کل",
|
||||
"hero_line_one": "هر جابهجایی.",
|
||||
"hero_line_two": "یک سابقه ماندگار.",
|
||||
"hero_description": "دفاتر ثبتشده را ببینید، هش تراکنشهای بلاکچین را ردیابی کنید و هر حساب دفتر کل را بدون دسترسی به مسیر نوشتن بازسازی کنید.",
|
||||
"transaction_placeholder": "هش تراکنش یا شناسه دفتر را وارد کنید",
|
||||
"transaction_hash": "هش تراکنش",
|
||||
"explore_transaction": "جستوجوی تراکنش",
|
||||
"committed_journals": "دفاتر ثبتشده",
|
||||
"ledger_entries": "ردیفهای دفتر کل",
|
||||
"tracked_accounts": "حسابهای ردیابیشده",
|
||||
"last_recorded": "آخرین ثبت",
|
||||
"latest_activity": "آخرین فعالیت دفتر کل",
|
||||
"newest_first": "جدیدترین ابتدا",
|
||||
"top_asset_holders": "دارندگان برتر دارایی",
|
||||
"holder_balance_scope": "در دسترس + مسدود · داراییهای اخیر",
|
||||
"no_asset_holders": "هنوز موجودی مثبت کاربری ثبت نشده است.",
|
||||
"assets_explorer": "کاوشگر دارایی",
|
||||
"track_asset_ownership": "مالکیت دارایی را ردیابی کنید.",
|
||||
"assets_description": "بالاترین موجودیهای مثبت کاربران را برای داراییهای فعال اخیر دفتر کل بررسی کنید.",
|
||||
"rank": "رتبه",
|
||||
"holder": "دارنده",
|
||||
"balance": "موجودی",
|
||||
"holder_account": "حساب دارنده",
|
||||
"inspect_holder": "دارنده را بررسی کنید.",
|
||||
"holder_description": "این حساب موجودی و فعالیت در دسترس و مسدود دارنده را برای یک دارایی ترکیب میکند.",
|
||||
"combined_balance": "موجودی ترکیبی",
|
||||
"available_and_frozen": "در دسترس + مسدود",
|
||||
"holder_reference_invalid": "شناسه دارنده و شناسه مثبت دارایی الزامی است.",
|
||||
"transaction": "تراکنش",
|
||||
"effect": "اثر",
|
||||
"source": "منبع",
|
||||
"entries": "ردیفها",
|
||||
"recorded": "زمان ثبت",
|
||||
"no_journals": "هنوز دفتری ثبت نشده است.",
|
||||
"network": "شبکه",
|
||||
"transaction_explorer": "کاوشگر تراکنش",
|
||||
"trace_settlement": "تسویه را ردیابی کنید.",
|
||||
"transaction_description": "هش دقیق بلاکچین یا شناسه دفتر داخلی را در دفاتر قطعی جستوجو کنید.",
|
||||
"transaction_not_found": "تراکنش پیدا نشد",
|
||||
"transaction_missing": "هیچ تراکنش قطعی با این هش یا شناسه دفتر پیدا نشد.",
|
||||
"transaction_lookup_error": "بارگذاری تراکنش ممکن نشد. کمی بعد دوباره تلاش کنید.",
|
||||
"enter_hash": "برای مشاهده اثرهای مالی تراز، هش یا شناسه دفتر را وارد کنید.",
|
||||
"latest_transactions": "آخرین تراکنشها",
|
||||
"page": "صفحه",
|
||||
"pagination": "صفحههای تراکنش",
|
||||
"previous": "قبلی",
|
||||
"next": "بعدی",
|
||||
"user_wallet": "کاربر / کیف پول",
|
||||
"user_wallet_placeholder": "شناسه دقیق مالک یا کیف پول",
|
||||
"effect_type": "نوع اثر",
|
||||
"effect_type_placeholder": "نوع دقیق اثر",
|
||||
"apply_filters": "اعمال فیلترها",
|
||||
"clear_filters": "پاککردن",
|
||||
"committed": "ثبتشده",
|
||||
"journal_id": "شناسه دفتر",
|
||||
"ledger_sequence": "شماره دفتر",
|
||||
"balanced_entries": "ردیفهای تراز",
|
||||
"asset": "دارایی",
|
||||
"internal": "داخلی",
|
||||
"system": "سیستم",
|
||||
"account_explorer": "کاوشگر حساب",
|
||||
"rebuild_account": "یک حساب را بازسازی کنید.",
|
||||
"account_description": "شناسه پایدار حساب و دارایی را انتخاب کنید تا موجودی فعلی از ردیفهای تغییرناپذیر محاسبه شود.",
|
||||
"account_class": "نوع حساب",
|
||||
"owner_type": "نوع مالک",
|
||||
"owner_id": "شناسه مالک",
|
||||
"stable_owner_id": "شناسه پایدار مالک",
|
||||
"asset_id": "شناسه دارایی",
|
||||
"explore": "جستوجو",
|
||||
"account_unavailable": "حساب در دسترس نیست",
|
||||
"asset_positive": "شناسه دارایی باید یک عدد صحیح مثبت باشد.",
|
||||
"account_lookup_error": "بارگذاری حساب ممکن نشد. شناسه آن را بررسی و دوباره تلاش کنید.",
|
||||
"ledger_identity": "شناسه دفتر کل",
|
||||
"current_balance": "موجودی فعلی",
|
||||
"account_activity": "فعالیت حساب",
|
||||
"journals": "دفتر",
|
||||
"choose_account": "برای شروع، نوع حساب، مالک و دارایی را انتخاب کنید.",
|
||||
"explorer_error": "خطای کاوشگر",
|
||||
"dashboard_unavailable": "داشبورد در دسترس نیست",
|
||||
"assets_unavailable": "داراییها در دسترس نیستند",
|
||||
"transactions_unavailable": "تراکنشها در دسترس نیستند",
|
||||
"read_model_unavailable": "مدل خواندنی دفتر کل در دسترس نیست. کمی بعد دوباره تلاش کنید.",
|
||||
"footer_description": "دفتر کل دارانو · تاریخچه مالی تغییرناپذیر",
|
||||
"timezone_notice": "همه زمانها بر پایه منطقه زمانی تهران نمایش داده میشوند",
|
||||
"title_overview": "نمای کلی شبکه",
|
||||
"title_transactions": "کاوشگر تراکنش",
|
||||
"title_assets": "کاوشگر دارایی",
|
||||
"title_accounts": "کاوشگر حساب",
|
||||
"title_holder": "حساب دارنده",
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLocaleURLPreservesExplorerQuery(t *testing.T) {
|
||||
request := httptest.NewRequest("GET", "/accounts?class=USER_AVAILABLE&asset_id=9", nil)
|
||||
value := localeURL(request, LocalePersian)
|
||||
for _, expected := range []string{"/accounts?", "class=USER_AVAILABLE", "asset_id=9", "lang=fa"} {
|
||||
if !strings.Contains(value, expected) {
|
||||
t.Fatalf("locale URL %q did not preserve %q", value, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslationFallsBackToEnglish(t *testing.T) {
|
||||
if got := tr(Locale("invalid"), "overview"); got != "Overview" {
|
||||
t.Fatalf("unexpected fallback translation: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
Host string
|
||||
Port int
|
||||
ReadHeaderTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
}
|
||||
|
||||
func Run(ctx context.Context, cfg ServerConfig, handler http.Handler) error {
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
|
||||
Handler: handler,
|
||||
ReadHeaderTimeout: cfg.ReadHeaderTimeout,
|
||||
}
|
||||
serveErr := make(chan error, 1)
|
||||
go func() { serveErr <- server.ListenAndServe() }()
|
||||
|
||||
select {
|
||||
case err := <-serveErr:
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("serve explorer: %w", err)
|
||||
case <-ctx.Done():
|
||||
}
|
||||
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), cfg.ShutdownTimeout)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(shutdownCtx); err != nil {
|
||||
_ = server.Close()
|
||||
return fmt.Errorf("shut down explorer: %w", err)
|
||||
}
|
||||
err := <-serveErr
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
return fmt.Errorf("serve explorer: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gl/application/explorer"
|
||||
"gl/domain/ledger"
|
||||
)
|
||||
|
||||
templ Page(title string, active string, locale Locale, englishURL string, persianURL string, content templ.Component) {
|
||||
<!doctype html>
|
||||
<html lang={ string(locale) } dir={ locale.Direction() }>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<meta name="description" content={ tr(locale, "general_ledger_explorer") }/>
|
||||
<meta name="htmx-config" content='{"historyRestoreAsHxRequest":false,"selfRequestsOnly":true}'/>
|
||||
<title>{ title } · { tr(locale, "site_name") }</title>
|
||||
<link rel="icon" href="/favicon.ico" sizes="any"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/htmx.org@2.0.10/dist/htmx.min.js" integrity="sha384-H5SrcfygHmAuTDZphMHqBJLc3FhssKjG7w/CeCpFReSfwBWDTKpkzPP8c+cLsK+V" crossorigin="anonymous"></script>
|
||||
<style>
|
||||
:root { --ink:#1f2a2c; --muted:rgba(31,42,44,.68); --paper:#F5F5F5; --surface:#DFF1F1; --card:#ffffff; --line:rgba(31,42,44,.15); --teal:#BBD5DA; --accent:#FF0000; --shadow:0 18px 50px rgba(31,42,44,.10); }
|
||||
* { box-sizing:border-box; }
|
||||
html { background:var(--paper); color:var(--ink); font-family:Inter,Tahoma,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
|
||||
body { margin:0; min-height:100vh; background:radial-gradient(circle at 78% 0%,rgba(187,213,218,.48),transparent 30rem),radial-gradient(circle at 5% 30%,rgba(255,0,0,.04),transparent 24rem),var(--paper); }
|
||||
a { color:inherit; }
|
||||
.shell { width:min(1180px,calc(100% - 40px)); margin:0 auto; }
|
||||
.topbar { min-height:76px; display:flex; align-items:center; justify-content:space-between; border-bottom:1px solid var(--line); }
|
||||
.brand { display:flex; align-items:center; gap:12px; text-decoration:none; font-weight:850; letter-spacing:-.03em; }
|
||||
.mark { width:35px; height:35px; display:block; flex:none; object-fit:contain; }
|
||||
.brand small { display:block; color:var(--muted); font-size:9px; letter-spacing:.2em; margin-top:2px; }
|
||||
.nav { display:flex; gap:6px; align-items:center; }
|
||||
.nav a { padding:10px 13px; border-radius:999px; text-decoration:none; color:var(--muted); font-size:13px; font-weight:700; }
|
||||
.nav a:hover,.nav a.active { color:var(--ink); background:var(--surface); }
|
||||
.live { display:flex; align-items:center; gap:8px; margin-inline-start:10px; padding:8px 11px; border:1px solid var(--line); border-radius:999px; font:700 11px/1 ui-monospace,SFMono-Regular,monospace; background:rgba(255,255,255,.62); }
|
||||
.dot { width:7px; height:7px; background:var(--teal); border-radius:50%; box-shadow:0 0 0 4px rgba(187,213,218,.35); }
|
||||
.language-switch { display:flex; padding:3px; margin-inline-start:8px; border:1px solid var(--line); border-radius:999px; background:rgba(255,255,255,.62); direction:ltr; }
|
||||
.language-switch a { padding:6px 8px; font:800 10px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.language-switch a.active { background:var(--ink); color:white; }
|
||||
main { padding:62px 0 90px; }
|
||||
.eyebrow { display:flex; align-items:center; gap:9px; color:var(--teal); text-transform:uppercase; letter-spacing:.14em; font:800 11px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.eyebrow:before { content:""; width:26px; height:2px; background:var(--accent); }
|
||||
h1 { max-width:830px; margin:20px 0 14px; font-size:clamp(42px,7vw,82px); line-height:.94; letter-spacing:-.065em; font-weight:850; }
|
||||
.lede { max-width:660px; margin:0; color:var(--muted); font-size:17px; line-height:1.65; }
|
||||
.search { display:flex; gap:10px; margin:34px 0 46px; padding:9px; border:1px solid var(--line); border-radius:16px; background:rgba(255,255,255,.88); box-shadow:var(--shadow); }
|
||||
.search input { flex:1; min-width:0; border:0; outline:0; background:transparent; padding:9px 12px; color:var(--ink); font:500 14px/1.4 ui-monospace,SFMono-Regular,monospace; }
|
||||
.search button,.button { border:0; border-radius:10px; background:var(--accent); color:white; padding:13px 18px; font-weight:800; cursor:pointer; }
|
||||
.search button:hover,.button:hover { background:var(--ink); }
|
||||
.stats { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin-bottom:46px; }
|
||||
.stat { min-height:136px; padding:22px; border:1px solid var(--line); border-radius:16px; background:rgba(255,255,255,.78); }
|
||||
.stat.accent { background:var(--accent); border-color:var(--accent); color:white; }
|
||||
.stat.accent .stat-label { color:rgba(255,255,255,.78); }
|
||||
.stat-label { color:var(--muted); text-transform:uppercase; letter-spacing:.13em; font:750 10px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.stat strong { display:block; margin-top:21px; font-size:32px; line-height:1; letter-spacing:-.05em; }
|
||||
.stat time { display:block; margin-top:18px; font:650 12px/1.5 ui-monospace,SFMono-Regular,monospace; }
|
||||
.section-head { display:flex; align-items:end; justify-content:space-between; margin:0 0 14px; }
|
||||
.section-head h2 { margin:0; font-size:22px; letter-spacing:-.035em; }
|
||||
.section-head span { color:var(--muted); font:600 11px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.dashboard-section { margin-top:46px; }
|
||||
.panel { overflow:hidden; border:1px solid var(--line); border-radius:18px; background:var(--card); box-shadow:0 8px 25px rgba(28,35,29,.04); }
|
||||
table { width:100%; border-collapse:collapse; }
|
||||
th { padding:14px 18px; background:var(--surface); color:var(--ink); text-align:start; text-transform:uppercase; letter-spacing:.1em; font:750 9px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
td { padding:17px 18px; border-top:1px solid var(--line); font-size:13px; vertical-align:middle; }
|
||||
tr:first-child td { border-top:0; }
|
||||
tr:hover td { background:rgba(223,241,241,.72); }
|
||||
.mono { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:12px; direction:ltr; unicode-bidi:isolate; }
|
||||
.hash-link { font-weight:750; text-decoration:none; border-bottom:1px solid var(--teal); }
|
||||
.pill { display:inline-flex; padding:6px 9px; border-radius:999px; background:var(--surface); font:750 10px/1 ui-monospace,SFMono-Regular,monospace; text-transform:uppercase; }
|
||||
.holder-id { max-width:330px; overflow-wrap:anywhere; font-weight:750; }
|
||||
.holder-id small { display:block; margin-top:5px; color:var(--muted); font:650 10px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.empty { padding:45px 24px; text-align:center; color:var(--muted); }
|
||||
.notice + .transaction-list { margin-top:46px; }
|
||||
.pagination { display:flex; align-items:center; justify-content:center; gap:8px; margin-top:18px; direction:ltr; }
|
||||
.pagination a,.pagination span { min-width:42px; padding:10px 13px; border:1px solid var(--line); border-radius:10px; text-align:center; text-decoration:none; font:750 11px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.pagination a { background:var(--card); }
|
||||
.pagination a:hover { background:var(--surface); }
|
||||
.pagination .current { background:var(--ink); color:white; border-color:var(--ink); }
|
||||
.pagination .disabled { color:var(--muted); opacity:.45; }
|
||||
.transaction-filters { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr) auto auto; gap:10px; margin-bottom:14px; padding:14px; border:1px solid var(--line); border-radius:14px; background:var(--card); }
|
||||
.transaction-filters .field input { height:40px; }
|
||||
.transaction-filters .button { align-self:end; height:40px; padding-block:0; }
|
||||
.transaction-filters .clear-filter { display:flex; align-items:center; align-self:end; height:40px; padding:0 12px; color:var(--muted); font-weight:750; text-decoration:none; }
|
||||
.page-title h1 { font-size:clamp(42px,6vw,68px); }
|
||||
.breadcrumb { margin-bottom:25px; color:var(--muted); font:650 11px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.breadcrumb a { text-decoration:none; }
|
||||
.result-stack { display:grid; gap:18px; margin-top:34px; }
|
||||
.journal { border:1px solid var(--line); border-radius:18px; background:var(--card); overflow:hidden; box-shadow:var(--shadow); }
|
||||
.journal-head { padding:22px; display:flex; gap:20px; align-items:flex-start; justify-content:space-between; border-bottom:1px solid var(--line); }
|
||||
.journal-head h2 { margin:8px 0 0; max-width:770px; overflow-wrap:anywhere; font:750 14px/1.5 ui-monospace,SFMono-Regular,monospace; }
|
||||
.status { flex:none; padding:7px 10px; border-radius:999px; background:var(--teal); color:var(--ink); font:800 10px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.detail-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:1px; background:var(--line); border-bottom:1px solid var(--line); }
|
||||
.detail { min-width:0; padding:18px 22px; background:var(--card); }
|
||||
.detail label { display:block; margin-bottom:8px; color:var(--muted); text-transform:uppercase; letter-spacing:.1em; font:750 9px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.detail div { overflow-wrap:anywhere; font-size:13px; }
|
||||
.entries { padding:18px 22px 22px; }
|
||||
.entries h3 { margin:0 0 12px; font-size:13px; }
|
||||
.entry { display:grid; grid-template-columns:46px minmax(0,1fr) 170px; gap:15px; align-items:center; padding:13px 0; border-top:1px solid var(--line); }
|
||||
.entry:first-of-type { border-top:0; }
|
||||
.entry-number { color:var(--muted); font:650 11px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.entry-account a { font-weight:700; text-decoration:none; }
|
||||
.entry-account small { display:block; color:var(--muted); margin-top:4px; }
|
||||
.amount { text-align:end; direction:ltr; font:800 13px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.amount.positive { color:#497f82; }
|
||||
.amount.negative { color:var(--accent); }
|
||||
.notice { margin-top:28px; padding:20px; border:1px solid rgba(255,0,0,.32); border-radius:14px; background:rgba(255,0,0,.06); color:var(--ink); }
|
||||
.notice strong { display:block; margin-bottom:5px; }
|
||||
.account-form { display:grid; grid-template-columns:1.25fr 1fr 1.2fr .65fr auto; gap:10px; margin:34px 0; padding:14px; border:1px solid var(--line); border-radius:16px; background:var(--card); box-shadow:var(--shadow); }
|
||||
.field label { display:block; margin:0 0 7px 3px; color:var(--muted); text-transform:uppercase; letter-spacing:.09em; font:750 9px/1 ui-monospace,SFMono-Regular,monospace; }
|
||||
.field input,.field select { width:100%; height:43px; border:1px solid var(--line); border-radius:9px; outline:0; padding:0 11px; background:white; color:var(--ink); }
|
||||
.field input:focus,.field select:focus { border-color:var(--teal); box-shadow:0 0 0 3px rgba(187,213,218,.42); }
|
||||
.account-form button { align-self:end; height:43px; }
|
||||
.account-card { display:grid; grid-template-columns:1.35fr .65fr; gap:1px; background:var(--line); border:1px solid var(--line); border-radius:18px; overflow:hidden; margin-bottom:30px; }
|
||||
.account-card > div { padding:25px; background:var(--card); }
|
||||
.account-card h2 { margin:8px 0 0; font:800 16px/1.5 ui-monospace,SFMono-Regular,monospace; overflow-wrap:anywhere; }
|
||||
.balance { font-size:34px; line-height:1; font-weight:850; letter-spacing:-.04em; overflow-wrap:anywhere; }
|
||||
.htmx-request .search-label { display:none; }
|
||||
.htmx-request button:after { content:" …"; }
|
||||
footer { padding:24px 0 38px; border-top:1px solid var(--line); color:var(--muted); display:flex; justify-content:space-between; font-size:11px; }
|
||||
html[dir="rtl"] body { letter-spacing:0; }
|
||||
html[dir="rtl"] h1 { letter-spacing:-.035em; }
|
||||
html[dir="rtl"] .search input { font-family:Tahoma,ui-sans-serif,system-ui,sans-serif; }
|
||||
@media (max-width:850px) { .stats{grid-template-columns:repeat(2,1fr)} .account-form{grid-template-columns:1fr 1fr} .account-form button{grid-column:1/-1} .transaction-filters{grid-template-columns:1fr 1fr} .detail-grid{grid-template-columns:1fr 1fr} .nav>a{display:none} }
|
||||
@media (max-width:620px) { .shell{width:min(100% - 24px,1180px)} .topbar{min-height:66px} .live{display:none} main{padding-top:42px} .stats{grid-template-columns:1fr 1fr} .stat{min-height:115px;padding:17px}.stat strong{font-size:25px} .search{display:grid}.search button{width:100%} .transaction-filters{grid-template-columns:1fr}.panel{overflow-x:auto} table{min-width:720px} .journal-head{display:block}.status{display:inline-flex;margin-top:14px}.detail-grid{grid-template-columns:1fr}.entry{grid-template-columns:32px minmax(0,1fr)}.amount{grid-column:2;text-align:start}.account-form{grid-template-columns:1fr}.account-form button{grid-column:auto}.account-card{grid-template-columns:1fr} footer{display:block;line-height:1.8} }
|
||||
</style>
|
||||
</head>
|
||||
<body hx-boost="true" hx-target="#explorer-content" hx-select="#explorer-content" hx-swap="outerHTML show:top" hx-push-url="true">
|
||||
<header class="shell topbar">
|
||||
<a class="brand" href="/" hx-target="body" hx-select="body">
|
||||
<img class="mark" src="/favicon.ico" alt="" width="35" height="35" aria-hidden="true"/>
|
||||
<span>{ tr(locale, "site_name") } <small>{ tr(locale, "site_subtitle") }</small></span>
|
||||
</a>
|
||||
<nav class="nav" aria-label="Main navigation" hx-target="body" hx-select="body">
|
||||
if active == "dashboard" {
|
||||
<a class="active" href="/">{ tr(locale, "overview") }</a>
|
||||
} else {
|
||||
<a href="/">{ tr(locale, "overview") }</a>
|
||||
}
|
||||
if active == "transactions" {
|
||||
<a class="active" href="/transactions">{ tr(locale, "transactions") }</a>
|
||||
} else {
|
||||
<a href="/transactions">{ tr(locale, "transactions") }</a>
|
||||
}
|
||||
if active == "assets" {
|
||||
<a class="active" href="/assets">{ tr(locale, "assets") }</a>
|
||||
} else {
|
||||
<a href="/assets">{ tr(locale, "assets") }</a>
|
||||
}
|
||||
if active == "accounts" {
|
||||
<a class="active" href="/accounts">{ tr(locale, "accounts") }</a>
|
||||
} else {
|
||||
<a href="/accounts">{ tr(locale, "accounts") }</a>
|
||||
}
|
||||
<span class="live"><span class="dot"></span> { tr(locale, "read_only") }</span>
|
||||
<span class="language-switch" aria-label="Language">
|
||||
if locale == LocaleEnglish {
|
||||
<a class="active" href={ templ.URL(englishURL) } hx-boost="false" lang="en">EN</a>
|
||||
} else {
|
||||
<a href={ templ.URL(englishURL) } hx-boost="false" lang="en">EN</a>
|
||||
}
|
||||
if locale == LocalePersian {
|
||||
<a class="active" href={ templ.URL(persianURL) } hx-boost="false" lang="fa">فا</a>
|
||||
} else {
|
||||
<a href={ templ.URL(persianURL) } hx-boost="false" lang="fa">فا</a>
|
||||
}
|
||||
</span>
|
||||
</nav>
|
||||
</header>
|
||||
@content
|
||||
<footer class="shell">
|
||||
<span>{ tr(locale, "footer_description") }</span>
|
||||
<span>{ tr(locale, "timezone_notice") }</span>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
templ TransactionSearch(value string, locale Locale) {
|
||||
<form class="search" action="/transactions" method="get" hx-get="/transactions" hx-target="#explorer-content" hx-push-url="true">
|
||||
<input name="q" value={ value } placeholder={ tr(locale, "transaction_placeholder") } aria-label={ tr(locale, "transaction_hash") } autocomplete="off" required/>
|
||||
<button type="submit"><span class="search-label">{ tr(locale, "explore_transaction") }</span></button>
|
||||
</form>
|
||||
}
|
||||
|
||||
templ DashboardContent(data explorer.Dashboard, locale Locale) {
|
||||
<main id="explorer-content" class="shell">
|
||||
<section>
|
||||
<div class="eyebrow">{ tr(locale, "general_ledger_explorer") }</div>
|
||||
<h1>{ tr(locale, "hero_line_one") }<br/>{ tr(locale, "hero_line_two") }</h1>
|
||||
<p class="lede">{ tr(locale, "hero_description") }</p>
|
||||
@TransactionSearch("", locale)
|
||||
</section>
|
||||
<section class="stats" aria-label={ tr(locale, "general_ledger_explorer") }>
|
||||
<div class="stat accent"><span class="stat-label">{ tr(locale, "committed_journals") }</span><strong>{ count(data.Stats.JournalCount) }</strong></div>
|
||||
<div class="stat"><span class="stat-label">{ tr(locale, "ledger_entries") }</span><strong>{ count(data.Stats.EntryCount) }</strong></div>
|
||||
<div class="stat"><span class="stat-label">{ tr(locale, "tracked_accounts") }</span><strong>{ count(data.Stats.AccountCount) }</strong></div>
|
||||
<div class="stat"><span class="stat-label">{ tr(locale, "last_recorded") }</span><time>{ formatTime(data.Stats.LastRecordedAt) }</time></div>
|
||||
</section>
|
||||
<section>
|
||||
<div class="section-head"><h2>{ tr(locale, "latest_activity") }</h2><span>{ tr(locale, "newest_first") }</span></div>
|
||||
@JournalTable(data.Journals, locale)
|
||||
</section>
|
||||
</main>
|
||||
}
|
||||
|
||||
templ AssetsContent(data explorer.Assets, locale Locale) {
|
||||
<main id="explorer-content" class="shell">
|
||||
<div class="breadcrumb"><a href="/">{ tr(locale, "network") }</a> / { tr(locale, "assets") }</div>
|
||||
<section class="page-title">
|
||||
<div class="eyebrow">{ tr(locale, "assets_explorer") }</div>
|
||||
<h1>{ tr(locale, "track_asset_ownership") }</h1>
|
||||
<p class="lede">{ tr(locale, "assets_description") }</p>
|
||||
</section>
|
||||
<section class="dashboard-section">
|
||||
<div class="section-head"><h2>{ tr(locale, "top_asset_holders") }</h2><span>{ tr(locale, "holder_balance_scope") }</span></div>
|
||||
@HolderTable(data.TopHolders, locale)
|
||||
</section>
|
||||
</main>
|
||||
}
|
||||
|
||||
templ HolderTable(holders []explorer.Holder, locale Locale) {
|
||||
<div class="panel">
|
||||
if len(holders) == 0 {
|
||||
<div class="empty">{ tr(locale, "no_asset_holders") }</div>
|
||||
} else {
|
||||
<table>
|
||||
<thead><tr><th>{ tr(locale, "asset") }</th><th>{ tr(locale, "rank") }</th><th>{ tr(locale, "holder") }</th><th>{ tr(locale, "balance") }</th></tr></thead>
|
||||
<tbody>
|
||||
for _, holder := range holders {
|
||||
<tr>
|
||||
<td><span class="pill">{ tr(locale, "asset") } { strconv.FormatInt(holder.AssetID, 10) }</span></td>
|
||||
<td class="mono">#{ strconv.FormatInt(holder.Rank, 10) }</td>
|
||||
<td class="holder-id mono"><a class="hash-link" href={ templ.URL(holderURL(holder)) }>{ holder.OwnerID }</a><small>{ holder.OwnerType }</small></td>
|
||||
<td class="amount positive">{ holder.Balance.String() }</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
templ HolderContent(data HolderPageData, locale Locale) {
|
||||
<main id="explorer-content" class="shell">
|
||||
<div class="breadcrumb"><a href="/">{ tr(locale, "network") }</a> / <a href="/assets">{ tr(locale, "assets") }</a> / { tr(locale, "holder") }</div>
|
||||
<section class="page-title">
|
||||
<div class="eyebrow">{ tr(locale, "holder_account") }</div>
|
||||
<h1>{ tr(locale, "inspect_holder") }</h1>
|
||||
<p class="lede">{ tr(locale, "holder_description") }</p>
|
||||
</section>
|
||||
if data.Error != "" {
|
||||
<div class="notice"><strong>{ tr(locale, "account_unavailable") }</strong>{ data.Error }</div>
|
||||
} else if data.Account != nil {
|
||||
<div class="account-card result-stack">
|
||||
<div><span class="stat-label">{ tr(locale, "holder") }</span><h2 class="mono">{ data.Account.Reference.OwnerID }</h2><p class="mono">{ data.Account.Reference.OwnerType } · { tr(locale, "asset") } { strconv.FormatInt(data.Account.Reference.AssetID, 10) }</p></div>
|
||||
<div><span class="stat-label">{ tr(locale, "combined_balance") }</span><div class="balance">{ data.Account.Balance.String() }</div></div>
|
||||
</div>
|
||||
<section class="dashboard-section">
|
||||
<div class="section-head"><h2>{ tr(locale, "account_activity") }</h2><span>{ tr(locale, "available_and_frozen") }</span></div>
|
||||
@JournalTable(data.Account.Journals, locale)
|
||||
</section>
|
||||
}
|
||||
</main>
|
||||
}
|
||||
|
||||
templ JournalTable(journals []ledger.Journal, locale Locale) {
|
||||
<div class="panel">
|
||||
if len(journals) == 0 {
|
||||
<div class="empty">{ tr(locale, "no_journals") }</div>
|
||||
} else {
|
||||
<table>
|
||||
<thead><tr><th>{ tr(locale, "transaction") }</th><th>{ tr(locale, "effect") }</th><th>{ tr(locale, "source") }</th><th>{ tr(locale, "entries") }</th><th>{ tr(locale, "recorded") }</th></tr></thead>
|
||||
<tbody>
|
||||
for _, journal := range journals {
|
||||
<tr>
|
||||
<td class="mono">
|
||||
<a class="hash-link" href={ templ.URL(transactionURL(transactionReference(journal))) }>{ transactionName(journal, locale) }</a>
|
||||
</td>
|
||||
<td><span class="pill">{ journal.EffectKind }</span></td>
|
||||
<td>{ journal.SourceService }</td>
|
||||
<td>{ strconv.Itoa(len(journal.Entries)) }</td>
|
||||
<td class="mono">{ formatTime(journal.RecordedAt) }</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
templ TransactionContent(data TransactionPageData, locale Locale) {
|
||||
<main id="explorer-content" class="shell">
|
||||
<div class="breadcrumb"><a href="/">{ tr(locale, "network") }</a> / { tr(locale, "transactions") }</div>
|
||||
<section class="page-title">
|
||||
<div class="eyebrow">{ tr(locale, "transaction_explorer") }</div>
|
||||
<h1>{ tr(locale, "trace_settlement") }</h1>
|
||||
<p class="lede">{ tr(locale, "transaction_description") }</p>
|
||||
@TransactionSearch(data.Query, locale)
|
||||
</section>
|
||||
if data.Error != "" {
|
||||
<div class="notice"><strong>{ tr(locale, "transaction_not_found") }</strong>{ data.Error }</div>
|
||||
}
|
||||
if data.Query != "" && data.Error == "" {
|
||||
<div class="result-stack">
|
||||
for _, journal := range data.Journals {
|
||||
@JournalCard(journal, locale)
|
||||
}
|
||||
</div>
|
||||
}
|
||||
if data.Listing != nil {
|
||||
<section class="transaction-list">
|
||||
<div class="section-head"><h2>{ tr(locale, "latest_transactions") }</h2><span>{ tr(locale, "page") } { strconv.Itoa(data.Listing.Filter.Page) }</span></div>
|
||||
<form class="transaction-filters" action="/transactions" method="get" hx-get="/transactions" hx-target="#explorer-content" hx-push-url="true">
|
||||
<div class="field"><label for="wallet">{ tr(locale, "user_wallet") }</label><input id="wallet" name="wallet" value={ data.Listing.Filter.Wallet } placeholder={ tr(locale, "user_wallet_placeholder") } autocomplete="off"/></div>
|
||||
<div class="field"><label for="effect">{ tr(locale, "effect_type") }</label><input id="effect" name="effect" value={ data.Listing.Filter.EffectKind } placeholder={ tr(locale, "effect_type_placeholder") } autocomplete="off"/></div>
|
||||
<button class="button" type="submit">{ tr(locale, "apply_filters") }</button>
|
||||
<a class="clear-filter" href="/transactions">{ tr(locale, "clear_filters") }</a>
|
||||
</form>
|
||||
@JournalTable(data.Listing.Journals, locale)
|
||||
@Pagination(*data.Listing, locale)
|
||||
</section>
|
||||
}
|
||||
</main>
|
||||
}
|
||||
|
||||
templ Pagination(listing explorer.TransactionListing, locale Locale) {
|
||||
<nav class="pagination" aria-label={ tr(locale, "pagination") }>
|
||||
if listing.HasPrevious {
|
||||
<a href={ templ.URL(transactionPageURL(listing.Filter, listing.Filter.Page - 1)) } rel="prev">{ tr(locale, "previous") }</a>
|
||||
} else {
|
||||
<span class="disabled">{ tr(locale, "previous") }</span>
|
||||
}
|
||||
<span class="current" aria-current="page">{ strconv.Itoa(listing.Filter.Page) }</span>
|
||||
if listing.HasNext {
|
||||
<a href={ templ.URL(transactionPageURL(listing.Filter, listing.Filter.Page + 1)) } rel="next">{ tr(locale, "next") }</a>
|
||||
} else {
|
||||
<span class="disabled">{ tr(locale, "next") }</span>
|
||||
}
|
||||
</nav>
|
||||
}
|
||||
|
||||
templ JournalCard(journal ledger.Journal, locale Locale) {
|
||||
<article class="journal">
|
||||
<header class="journal-head">
|
||||
<div>
|
||||
if journal.Blockchain.TransactionHash != "" {
|
||||
<span class="stat-label">{ tr(locale, "transaction_hash") }</span>
|
||||
} else {
|
||||
<span class="stat-label">{ tr(locale, "journal_id") }</span>
|
||||
}
|
||||
<h2 class="mono">{ transactionReference(journal) }</h2>
|
||||
</div>
|
||||
<span class="status">{ tr(locale, "committed") }</span>
|
||||
</header>
|
||||
<div class="detail-grid">
|
||||
<div class="detail"><label>{ tr(locale, "effect") }</label><div><span class="pill">{ journal.EffectKind }</span></div></div>
|
||||
<div class="detail"><label>{ tr(locale, "journal_id") }</label><div class="mono">{ journal.ID }</div></div>
|
||||
<div class="detail"><label>{ tr(locale, "recorded") }</label><div>{ formatTime(journal.RecordedAt) }</div></div>
|
||||
<div class="detail"><label>{ tr(locale, "source") }</label><div>{ journal.SourceService } · { journal.SourceTransactionID }</div></div>
|
||||
<div class="detail"><label>{ tr(locale, "network") }</label><div>{ journal.Blockchain.Network }</div></div>
|
||||
<div class="detail"><label>{ tr(locale, "ledger_sequence") }</label><div class="mono">{ journal.Blockchain.LedgerSequence }</div></div>
|
||||
</div>
|
||||
<div class="entries">
|
||||
<h3>{ tr(locale, "balanced_entries") }</h3>
|
||||
for _, entry := range journal.Entries {
|
||||
<div class="entry">
|
||||
<span class="entry-number">#{ strconv.FormatUint(uint64(entry.LineNumber), 10) }</span>
|
||||
<div class="entry-account"><a href={ templ.URL(accountURL(entry.Account)) }>{ accountName(entry.Account, locale) }</a><small>{ tr(locale, "asset") } { strconv.FormatInt(entry.Account.AssetID, 10) } · { entry.Account.OwnerType }</small></div>
|
||||
if len(entry.Amount.String()) > 0 && entry.Amount.String()[0] == '-' {
|
||||
<div class="amount negative">{ entry.Amount.String() }</div>
|
||||
} else {
|
||||
<div class="amount positive">+{ entry.Amount.String() }</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</article>
|
||||
}
|
||||
|
||||
templ AccountContent(data AccountPageData, locale Locale) {
|
||||
<main id="explorer-content" class="shell">
|
||||
<div class="breadcrumb"><a href="/">{ tr(locale, "network") }</a> / { tr(locale, "accounts") }</div>
|
||||
<section class="page-title">
|
||||
<div class="eyebrow">{ tr(locale, "account_explorer") }</div>
|
||||
<h1>{ tr(locale, "rebuild_account") }</h1>
|
||||
<p class="lede">{ tr(locale, "account_description") }</p>
|
||||
</section>
|
||||
<form class="account-form" action="/accounts" method="get" hx-get="/accounts" hx-target="#explorer-content" hx-push-url="true">
|
||||
<div class="field"><label for="class">{ tr(locale, "account_class") }</label><select id="class" name="class" required>
|
||||
for _, class := range accountClasses() {
|
||||
if string(class) == data.Input.Class {
|
||||
<option value={ string(class) } selected>{ string(class) }</option>
|
||||
} else {
|
||||
<option value={ string(class) }>{ string(class) }</option>
|
||||
}
|
||||
}
|
||||
</select></div>
|
||||
<div class="field"><label for="owner_type">{ tr(locale, "owner_type") }</label><input id="owner_type" name="owner_type" value={ data.Input.OwnerType } placeholder="user"/></div>
|
||||
<div class="field"><label for="owner_id">{ tr(locale, "owner_id") }</label><input id="owner_id" name="owner_id" value={ data.Input.OwnerID } placeholder={ tr(locale, "stable_owner_id") }/></div>
|
||||
<div class="field"><label for="asset_id">{ tr(locale, "asset_id") }</label><input id="asset_id" name="asset_id" value={ data.Input.AssetID } inputmode="numeric" placeholder="1" required/></div>
|
||||
<button class="button" type="submit">{ tr(locale, "explore") }</button>
|
||||
</form>
|
||||
if data.Error != "" {
|
||||
<div class="notice"><strong>{ tr(locale, "account_unavailable") }</strong>{ data.Error }</div>
|
||||
} else if data.Account != nil {
|
||||
<div class="account-card">
|
||||
<div><span class="stat-label">{ tr(locale, "ledger_identity") }</span><h2>{ accountName(data.Account.Reference, locale) }</h2><p class="mono">{ data.Account.Reference.OwnerType } · { tr(locale, "asset") } { strconv.FormatInt(data.Account.Reference.AssetID, 10) }</p></div>
|
||||
<div><span class="stat-label">{ tr(locale, "current_balance") }</span><div class="balance">{ data.Account.Balance.String() }</div></div>
|
||||
</div>
|
||||
<div class="section-head"><h2>{ tr(locale, "account_activity") }</h2><span>{ strconv.Itoa(len(data.Account.Journals)) } { tr(locale, "journals") }</span></div>
|
||||
@JournalTable(data.Account.Journals, locale)
|
||||
} else {
|
||||
<div class="panel empty">{ tr(locale, "choose_account") }</div>
|
||||
}
|
||||
</main>
|
||||
}
|
||||
|
||||
templ FailureContent(title string, message string, locale Locale) {
|
||||
<main id="explorer-content" class="shell">
|
||||
<section class="page-title"><div class="eyebrow">{ tr(locale, "explorer_error") }</div><h1>{ title }</h1><p class="lede">{ message }</p></section>
|
||||
</main>
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user