Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd committed Feb 14, 2024
1 parent 14c31d0 commit 7b6ed75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/lnd/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "github.com/charmbracelet/bubbles/list"
type NodeData struct {
NodeInfo Node
Channels []Channel
PendingChannels []PendingChannel
Payments []Payment
}

Expand Down
13 changes: 9 additions & 4 deletions internal/lnd/pending_channel.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package lnd

import (
"math"

"github.com/btcsuite/btcd/btcutil"
"github.com/charmbracelet/bubbles/progress"
"github.com/lightninglabs/lndclient"
)

// ChannelType represents the type of Lightning network channel.
Expand Down Expand Up @@ -39,5 +35,14 @@ func (c PendingChannel) Title() string {
}

func (c PendingChannel) Description() string {
switch c.Type {
case PendingOpen:
return "Opening"
case CooperativeClosure:
return "Closing"
case ForceClosure:
return "Force Closing"
}

return ""
}
9 changes: 6 additions & 3 deletions internal/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ func GetData(service *lndclient.GrpcLndServices, ctx context.Context) lnd.NodeDa
nodeData.Payments = paymentsSlice

// Load Channels
nodeData.Channels = GetChannelListItems(service, ctx)
nodeData.Channels = getChannelListItems(service, ctx)

// Load Pending channels
nodeData.PendingChannels = getPendingChannels(service, ctx)

// Load node data
nodeData.NodeInfo = lnd.GetDataFromAPI(service, ctx)
Expand All @@ -58,7 +61,7 @@ func GetData(service *lndclient.GrpcLndServices, ctx context.Context) lnd.NodeDa
}

// Get list of pending channels
func GetPendingChannels(service *lndclient.GrpcLndServices, ctx context.Context) []lnd.PendingChannel {
func getPendingChannels(service *lndclient.GrpcLndServices, ctx context.Context) []lnd.PendingChannel {
var pendingChannels []lnd.PendingChannel
channels, err := service.Client.PendingChannels(ctx)
if err != nil {
Expand Down Expand Up @@ -120,7 +123,7 @@ func getNodeAliasFromPubKey(service *lndclient.GrpcLndServices, ctx context.Cont
return node.Alias
}

func GetChannelListItems(service *lndclient.GrpcLndServices, ctx context.Context) []lnd.Channel {
func getChannelListItems(service *lndclient.GrpcLndServices, ctx context.Context) []lnd.Channel {
var channels []lnd.Channel
infos, err := service.Client.ListChannels(ctx, false, false)
if err != nil {
Expand Down

0 comments on commit 7b6ed75

Please sign in to comment.