Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: added max fee rate option for payments #34

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions internal/tui/pay_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package tui
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/ardevd/flash/internal/lnd"
"github.com/ardevd/flash/internal/util"
"github.com/btcsuite/btcd/btcutil"
"github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/spinner"
Expand Down Expand Up @@ -50,6 +52,7 @@ const (

// Value container
var invoiceString string
var maxFee string = "10"

// Instantiate model
func newPayInvoiceModel(service *lndclient.GrpcLndServices, base *BaseModel) *PayInvoiceModel {
Expand Down Expand Up @@ -132,7 +135,12 @@ func getInvoicePaymentForm() *huh.Form {
huh.NewInput().
Title("BOLT11 Invoice").
Prompt(">").
Value(&invoiceString)))
Value(&invoiceString),
huh.NewInput().
Title("Max Fee (sats)").
Prompt("$").
Validate(util.IsAmount).
Value(&maxFee)))

form.NextField()
return form
Expand Down Expand Up @@ -209,7 +217,11 @@ func (m PayInvoiceModel) getDecodeInvoiceView() string {

// Pay the invoice
func (m *PayInvoiceModel) payInvoice() tea.Msg {
result := m.lndService.Client.PayInvoice(m.ctx, invoiceString, btcutil.Amount(10), nil)
fee, err := strconv.Atoi(maxFee)
if err != nil {
return paymentError{}
}
result := m.lndService.Client.PayInvoice(m.ctx, invoiceString, btcutil.Amount(fee), nil)
defer close(result)
completion := make(chan tea.Msg)

Expand Down
3 changes: 3 additions & 0 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ var Models []tea.Model

// Message types
type DataLoaded lnd.NodeData
// Payments
type paymentSettled struct{}
type paymentExpired struct{}
type paymentCreated struct{}
type paymentError struct{}



func GetData(service *lndclient.GrpcLndServices, ctx context.Context) lnd.NodeData {
var nodeData lnd.NodeData

Expand Down
Loading