Skip to content

Commit

Permalink
refactor: added max fee rate option for payments (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd authored Feb 8, 2024
1 parent 5f6b9c7 commit 02247d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 02247d8

Please sign in to comment.