Add UI Support for Faucet Endpoint - #56
Conversation
|
Although my use case only requires Bitcoin, I know that Liquid is also supported by Nigiri. If it's limited to a single network, I can easily inject it into the HTML template. Otherwise, I鈥檇 prefer to add a dropdown menu to allow selecting the network. |
|
the faucet supporst both network yes, based on the address type |
|
But the question is: can I know the network a priori? Looking at the code, it seems like the network is chosen based on the configuration rather than the address. Correct me if I'm wrong: |
There was a problem hiding this comment.
Pull Request Overview
This PR adds UI support for the faucet endpoint by creating a web interface that allows users to interact with the faucet feature through a browser instead of using CLI commands or raw API calls. The implementation provides a user-friendly HTML form for requesting Bitcoin or Liquid Bitcoin from the faucet.
Key Changes
- Added a new HTML template with a responsive form interface for faucet requests
- Registered a GET route handler for
/faucetto serve the UI page - Implemented server-side template rendering with network-specific data
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| router/main.go | Adds GET route handler for /faucet endpoint to serve the UI page |
| router/faucet_handler.go | Implements HandleFaucetPage function to render HTML template with network data |
| pages/faucet.html | Creates responsive HTML interface with form for faucet requests and JavaScript for API calls |
| faucet := faucet.NewFaucet(config.RPCServerURL(), rpcClient) | ||
| r.Faucet = faucet | ||
| r.HandleFunc("/faucet", r.HandleFaucetRequest).Methods(http.MethodPost, http.MethodOptions) | ||
| r.HandleFunc("/faucet", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) |
There was a problem hiding this comment.
Using the same path /faucet for both GET and POST methods could be confusing. Consider using a more specific path like /faucet/ui for the UI page as mentioned in the PR description, which would make the API more self-documenting and avoid potential routing conflicts.
| r.HandleFunc("/faucet", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) | |
| r.HandleFunc("/faucet/ui", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions) |
|
|
||
| // 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" |
There was a problem hiding this comment.
The hardcoded file path "pages/faucet.html" makes the code less maintainable and could fail if the file structure changes. Consider making this configurable or using a constant to define template paths.
| filepath := "pages/faucet.html" | |
| filepath := faucetPageTemplatePath |
| type PageData struct { | ||
| Network string | ||
| Asset string | ||
| } |
There was a problem hiding this comment.
[nitpick] The PageData struct is defined inside the function scope. Consider moving it to package level or using an existing struct type to improve code organization and reusability.
| type PageData struct { | |
| Network string | |
| Asset string | |
| } |
|
Is still under consideration or should I close the Pr? |


This PR adds a new HTML template to support the
/faucetendpoint, enabling a basic frontend interface for the faucet feature. The goal is to provide a user-friendly way to interact with the faucet without using raw API calls or the nigiri CLI.The motivation for this change came while I was developing my wallet using Nigiri to deploy a local Bitcoin test network. Although the CLI-based faucet is effective and scriptable, I found it disruptive to break my workflow or run scripts just to request BTC manually. This new page offers a more accessible alternative that introduces no breaking changes and can coexist with the existing CLI and API methods.
Modified Files:
pages/faucetrouter/main.go/faucet/ui.router/faucet/faucet/ui.How to Test:
Desing
This is how it looks