commit b83a3745eb98ccab02977657d405e6de1e26459d
parent 3123014b404de5c30a8531f0a7a6d9f825440bc8
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Wed, 6 Dec 2023 20:37:16 +0100
Towards localized currency display
Diffstat:
4 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/go.mod b/go.mod
@@ -5,6 +5,7 @@ go 1.18
require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
+ golang.org/x/text v0.14.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
taler.net/taler-go.git v0.0.0-20231206131418-346a54653b41 // indirect
)
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
@@ -28,11 +28,15 @@ import (
"io"
"net/http"
"os"
+ "strconv"
"strings"
"time"
"github.com/gorilla/mux"
"github.com/skip2/go-qrcode"
+ "golang.org/x/text/currency"
+ "golang.org/x/text/language"
+ "golang.org/x/text/message"
"gopkg.in/ini.v1"
"taler.net/taler-go.git/pkg/merchant"
talerutil "taler.net/taler-go.git/pkg/util"
@@ -43,7 +47,7 @@ type RegistrationMetadata struct {
Expiration uint64 `json:"expiration"`
Paid bool `json:"paid"`
OrderID string `json:"order_id"`
- NeedsPaymentUntil time.Time `json:"needs_payment_until"`
+ NeedsPaymentUntil time.Time `json:"needs_payment_until"`
}
type IdentityInfo struct {
@@ -143,6 +147,22 @@ func (t *Registrar) configResponse(w http.ResponseWriter, r *http.Request) {
w.Write(response)
}
+// FIXME: Implement https://docs.taler.net/design-documents/051-fractional-digits.html and move to taler-go
+func (t *Registrar) localizedAmountString() (string) {
+ p := message.NewPrinter(language.English)
+ costStr := t.RegistrationCost.String()
+ costSplit := strings.Split(costStr, ":")
+ left := costSplit[0]
+ right := costSplit[1]
+ cur, err := currency.ParseISO(left)
+ if nil != err {
+ return fmt.Sprintf("%s %s", right, left)
+ }
+ amf, _ := strconv.ParseFloat(right, 8)
+ v := currency.Symbol(cur.Amount(amf))
+ return p.Sprint(v)
+}
+
func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
@@ -354,7 +374,7 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
"fulfillmentUrl": template.URL(t.BaseUrl + "/name/" + vars["label"]),
"label": vars["label"],
"error": errorMsg,
- "cost": t.RegistrationCost,
+ "cost": t.localizedAmountString(),
"suffixHint": t.SuffixHint,
}
t.BuyTpl.Execute(w, fullData)
@@ -362,7 +382,7 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
}
func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *NamestoreRecord) (*RegistrationMetadata, error) {
- var regMetadata RegistrationMetadata
+ var regMetadata RegistrationMetadata
var haveMetadata = false
for _, record := range nsRecord.Records {
if record.RecordType == "TXT" {
@@ -480,7 +500,7 @@ func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
fullData := map[string]interface{}{
"label": vars["label"],
"error": r.URL.Query().Get("error"),
- "cost": t.RegistrationCost,
+ "cost": t.localizedAmountString(),
"available": regMetadata == nil,
"currentValue": value,
"suffixHint": t.SuffixHint,
diff --git a/web/templates/landing.html b/web/templates/landing.html
@@ -9,13 +9,19 @@
</head>
<body>
<div class="container pt-5">
- <h1 class="text-center mb-5">.{{.suffixHint}} is {{.zoneKey}}</h1>
- <form action="/search" method="get">
- <label for="label" class="form-label">Check availability:</label>
- <div class="input-group mb-2 w-50">
- <input id="label" name="label" class="form-control form-control-lg text-end" maxlength="63" type="text" aria-describedby="reg-suffix" required autofocus>
- <span class="input-group-text" id="reg-suffix">.{{.suffixHint}}</span>
- <input class="btn btn-primary" type="submit" value="Check!">
+ <h1 class="text-center mb-5">GNUnet GNS Registrar<br/>
+ <span class="text-center fs-5 text-secondary">Zone: {{.zoneKey}}</span>
+ </h1>
+ <form action="/search" method="get" class="row">
+ <div class="row">
+ <div class="col-lg-6 offset-lg-3">
+ <label for="label" class="form-label">Check name availability:</label>
+ <div class="input-group mb-2">
+ <input id="label" name="label" class="form-control form-control-lg text-end" maxlength="63" type="text" aria-describedby="reg-suffix" required autofocus>
+ <span class="input-group-text" id="reg-suffix">.{{.suffixHint}}</span>
+ <input class="btn btn-primary" type="submit" value="Check!">
+ </div>
+ </div>
</div>
</form>
</div>
diff --git a/web/templates/name.html b/web/templates/name.html
@@ -30,10 +30,14 @@
{{if .available}}
<h1 class="mb-5"><i class="text-primary">{{.label}}</i> is still <span class="text-success">available</span> for registration.</h1>
<form action="/name/{{.label}}/buy" method="get" class="align-items-center">
- <div class="input-group mb-2 w-75">
- <span class="input-group-text" id="reg-prefix"><i class="text-primary">{{.label}}</i>.<i class="text-secondary">{{.suffixHint}}</i>: </span>
- <input name="zkey" class="form-control form-control-lg" maxlength="63" type="text" placeholder="Enter your zone key here!" required autofocus>
- <input class="btn btn-primary" type="submit" value="Register for {{.cost}}">
+ <div class="row">
+ <div class="col-lg-8 offset-lg-2">
+ <div class="input-group mb-2">
+ <span class="input-group-text" id="reg-prefix"><i class="text-primary">{{.label}}</i>.<i class="text-secondary">{{.suffixHint}}</i>: </span>
+ <input name="zkey" class="form-control form-control-lg" maxlength="63" type="text" placeholder="Enter your zone key here!" required autofocus>
+ <input class="btn btn-primary" type="submit" value="Register for {{.cost}}">
+ </div>
+ </div>
</div>
</form>
{{else}}