From baf3df987f30f8a8e9b727d84a437fa1f88abc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Ar=C3=A9jula=20A=C3=ADsa?= Date: Fri, 18 Jul 2025 15:03:51 +0200 Subject: [PATCH 1/6] create page --- pages/faucet.html | 74 ++++++++++++++++++++++++++++++++++++++++ router/faucet_handler.go | 18 ++++++++++ router/main.go | 1 + 3 files changed, 93 insertions(+) create mode 100644 pages/faucet.html diff --git a/pages/faucet.html b/pages/faucet.html new file mode 100644 index 0000000..61099cd --- /dev/null +++ b/pages/faucet.html @@ -0,0 +1,74 @@ + + + + + + + Faucet + + + + + +
+

Faucet

+

Get your Bitcoin!

+
+
+ + +
+
+ + +
+ +
+
+
+ + + + + diff --git a/router/faucet_handler.go b/router/faucet_handler.go index 33168e4..25f139f 100644 --- a/router/faucet_handler.go +++ b/router/faucet_handler.go @@ -2,6 +2,7 @@ package router import ( "encoding/json" + "html/template" "io" "net/http" ) @@ -123,3 +124,20 @@ func parseRequestBody(body io.ReadCloser) map[string]interface{} { return decodedBody } + +// HandleRegistryRequest will return an HTML page that will allow us to interact with the faucet endpoints +func (r *Router) HandleFaucetPage(res http.ResponseWriter, _ *http.Request) { + filepath := "pages/faucet.html" + + // Parse the HTML file + tmpl, err := template.ParseFiles(filepath) + if err != nil { + http.Error(res, "Page not found", http.StatusNotFound) + return + } + // Render the template + err = tmpl.Execute(res, nil) + if err != nil { + http.Error(res, "Failed to render page", http.StatusInternalServerError) + } +} diff --git a/router/main.go b/router/main.go index af96355..fdcdb05 100644 --- a/router/main.go +++ b/router/main.go @@ -52,6 +52,7 @@ func NewRouter(config cfg.Config) *Router { faucet := faucet.NewFaucet(config.RPCServerURL(), rpcClient) r.Faucet = faucet r.HandleFunc("/faucet", r.HandleFaucetRequest).Methods(http.MethodPost, http.MethodOptions) + r.HandleFunc("/faucet/ui", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) if config.Chain() == "liquid" { registry, _ := helpers.NewRegistry(config.RegistryPath()) r.Registry = registry From 0de590737fdf605373ef43e228dcbd64e596577c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Ar=C3=A9jula=20A=C3=ADsa?= Date: Fri, 18 Jul 2025 17:24:27 +0200 Subject: [PATCH 2/6] remove /ui from URL --- router/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/main.go b/router/main.go index fdcdb05..7f4f4a5 100644 --- a/router/main.go +++ b/router/main.go @@ -52,7 +52,7 @@ func NewRouter(config cfg.Config) *Router { faucet := faucet.NewFaucet(config.RPCServerURL(), rpcClient) r.Faucet = faucet r.HandleFunc("/faucet", r.HandleFaucetRequest).Methods(http.MethodPost, http.MethodOptions) - r.HandleFunc("/faucet/ui", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) + r.HandleFunc("/faucet", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) if config.Chain() == "liquid" { registry, _ := helpers.NewRegistry(config.RegistryPath()) r.Registry = registry From 2ee75f0fdbcc0ad76ba370bcde2107916605c5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Ar=C3=A9jula=20A=C3=ADsa?= Date: Fri, 18 Jul 2025 19:13:02 +0200 Subject: [PATCH 3/6] fix typo --- router/faucet_handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/faucet_handler.go b/router/faucet_handler.go index 25f139f..11c28d5 100644 --- a/router/faucet_handler.go +++ b/router/faucet_handler.go @@ -125,7 +125,7 @@ func parseRequestBody(body io.ReadCloser) map[string]interface{} { return decodedBody } -// HandleRegistryRequest will return an HTML page that will allow us to interact with the faucet endpoints +// HandleFaucetPage will return an HTML page that will allow us to interact with the faucet endpoints func (r *Router) HandleFaucetPage(res http.ResponseWriter, _ *http.Request) { filepath := "pages/faucet.html" From fe2d0730e934418a4b5f3f7c29f2469c8dfcb728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Ar=C3=A9jula=20A=C3=ADsa?= Date: Fri, 18 Jul 2025 19:24:34 +0200 Subject: [PATCH 4/6] add liquird suport --- pages/faucet.html | 6 ++++-- router/faucet_handler.go | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pages/faucet.html b/pages/faucet.html index 61099cd..9d63128 100644 --- a/pages/faucet.html +++ b/pages/faucet.html @@ -1,3 +1,4 @@ + @@ -12,7 +13,8 @@

Faucet

-

Get your Bitcoin!

+

Network: {{ .Network }}

+
@@ -26,7 +28,7 @@

Faucet

diff --git a/router/faucet_handler.go b/router/faucet_handler.go index 11c28d5..c28bc32 100644 --- a/router/faucet_handler.go +++ b/router/faucet_handler.go @@ -135,8 +135,25 @@ func (r *Router) HandleFaucetPage(res http.ResponseWriter, _ *http.Request) { http.Error(res, "Page not found", http.StatusNotFound) return } + + // define a struct with fileds network and asset + type PageData struct { + Network string + Asset string + } + network := r.Config.Chain() + asset := "BTC" + if network == "liquid" { + asset = "L-BTC" + } + + data := PageData{ + Network: network, + Asset: asset, + } + // Render the template - err = tmpl.Execute(res, nil) + err = tmpl.Execute(res, data) if err != nil { http.Error(res, "Failed to render page", http.StatusInternalServerError) } From b2612a5747f9b3809a5ce4fc734e5fc498e74d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Ar=C3=A9jula=20A=C3=ADsa?= Date: Fri, 18 Jul 2025 19:33:41 +0200 Subject: [PATCH 5/6] improve html template --- pages/faucet.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/faucet.html b/pages/faucet.html index 9d63128..337d33c 100644 --- a/pages/faucet.html +++ b/pages/faucet.html @@ -56,8 +56,8 @@

Faucet

let txId = data.txId; messageDiv.textContent = txId - ? `✅ Tokens sent successfully! TxID: ${txId}` - : "✅ Tokens sent successfully!"; + ? `{{.Asset}} sent successfully! TxID: ${txId}` + : "{{.Asset}} sent successfully!"; messageDiv.className = "mt-4 text-green-600 text-center break-words"; } else { messageDiv.textContent = data.error || "❌ Something went wrong."; From 01fa414e4ff8544768235a7f690c9bdf9d9c5f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Ar=C3=A9jula=20A=C3=ADsa?= Date: Fri, 18 Jul 2025 19:38:40 +0200 Subject: [PATCH 6/6] remove commenst --- router/faucet_handler.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/router/faucet_handler.go b/router/faucet_handler.go index c28bc32..0d0c96f 100644 --- a/router/faucet_handler.go +++ b/router/faucet_handler.go @@ -129,14 +129,12 @@ func parseRequestBody(body io.ReadCloser) map[string]interface{} { func (r *Router) HandleFaucetPage(res http.ResponseWriter, _ *http.Request) { filepath := "pages/faucet.html" - // Parse the HTML file tmpl, err := template.ParseFiles(filepath) if err != nil { http.Error(res, "Page not found", http.StatusNotFound) return } - // define a struct with fileds network and asset type PageData struct { Network string Asset string @@ -152,7 +150,6 @@ func (r *Router) HandleFaucetPage(res http.ResponseWriter, _ *http.Request) { Asset: asset, } - // Render the template err = tmpl.Execute(res, data) if err != nil { http.Error(res, "Failed to render page", http.StatusInternalServerError)