Skip to content

Conversation

arejula27
Copy link

@arejula27 arejula27 commented Jul 18, 2025

This PR adds a new HTML template to support the /faucet endpoint, 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:

  1. pages/faucet

    • Added an HTML template for the faucet UI.
    • The template includes a form or input (depending on your image) to allow users to trigger the faucet.
  2. router/main.go

    • Registered a new route: /faucet/ui.
    • This route serves the faucet HTML template
  3. router/faucet

    • Implemented a handler to load and render the HTML template.
    • Ensures the template is executed and served correctly when a user accesses /faucet/ui.

How to Test:

  1. Run the server.
  2. Navigate to http://localhost:PORT/faucet/ui.
  3. Ensure the faucet UI renders properly.
  4. Try interacting with the form to confirm that it behaves as expected by setting an amount and a wallet address.

Desing

This is how it looks

image

@arejula27
Copy link
Author

Although my use case only requires Bitcoin, I know that Liquid is also supported by Nigiri.
I would like to specify whether the network providing the tokens is Bitcoin or Liquid. Does a Chopsticks instance support both networks simultaneously, or only one at a time?

If it's limited to a single network, I can easily inject it into the HTML template. Otherwise, I’d prefer to add a dropdown menu to allow selecting the network.

@tiero
Copy link
Member

tiero commented Jul 18, 2025

the faucet supporst both network yes, based on the address type

@arejula27
Copy link
Author

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:

if r.Config.Chain() == "liquid" {
		status, tx, err = r.Faucet.SendLiquidTransaction(address, amount, asset)
	} else {
		status, tx, err = r.Faucet.SendBitcoinTransaction(address, amount)
	}

@arejula27
Copy link
Author

arejula27 commented Jul 18, 2025

new design, it says the network and token
image
image

@tiero tiero requested a review from altafan July 25, 2025 15:43
@tiero tiero requested a review from Copilot August 5, 2025 17:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /faucet to 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)
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
r.HandleFunc("/faucet", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions)
r.HandleFunc("/faucet/ui", r.HandleFaucetPage).Methods(http.MethodGet, http.MethodOptions)

Copilot uses AI. Check for mistakes.


// 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"
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
filepath := "pages/faucet.html"
filepath := faucetPageTemplatePath

Copilot uses AI. Check for mistakes.

Comment on lines +138 to +141
type PageData struct {
Network string
Asset string
}
Copy link

Copilot AI Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
type PageData struct {
Network string
Asset string
}

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants