Skip to content

Commit

Permalink
added more stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd committed Jan 6, 2024
1 parent 7616acd commit 57ee794
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
32 changes: 32 additions & 0 deletions internal/tui/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,35 @@ func (m ChannelModel) getChannelStateView() string {
return stateText + "\n" + m.styles.SubKeyword("Pending HTLCs: ") + fmt.Sprintf("%d", m.channel.Info.NumPendingHtlcs)
}

func (m ChannelModel) getChannelStats() string {
totalReceived := m.channel.Info.TotalReceived
totalSent := m.channel.Info.TotalSent
totalSum := totalReceived + totalSent
unsettledBalance := m.channel.Info.UnsettledBalance

var (
channelType,
openType string
)
if m.channel.Info.Private {
channelType = "Private"
} else {
channelType = "Public"
}

if m.channel.Info.Initiator {
openType = "Local"
} else {
openType = "Remove"
}

return m.styles.Keyword("Stats\n") + m.styles.SubKeyword("Total Transactions: ") + totalSum.String() + "\n" +
m.styles.SubKeyword("Unsettled Balance: ") + unsettledBalance.String() + "\n" +
m.styles.SubKeyword("Channel Type: ") + channelType + "\n" +
m.styles.SubKeyword("Channel Opener: ") + openType

}

func (m ChannelModel) View() string {
s := m.styles
channelInfoView := lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(
Expand All @@ -123,9 +152,12 @@ func (m ChannelModel) View() string {

topView := lipgloss.JoinHorizontal(lipgloss.Left, channelInfoView, channelStateView)

statsView := lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(m.getChannelStats()))

htlcTableView := lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(s.Keyword("Pending HTLCs\n\n")+m.htlcTable.View()))

return lipgloss.JoinVertical(lipgloss.Left,
topView,
statsView,
htlcTableView)
}
3 changes: 2 additions & 1 deletion internal/tui/styling.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ func NewStyles(lg *lipgloss.Renderer) *Styles {

// Return a function that will colorize the foreground of a given string.
func makeFgStyle(color string) func(string) string {
return termenv.Style{}.Foreground(term.Color(color)).Styled
return termenv.Style{}.Foreground(term.Color(color)).
Styled
}

0 comments on commit 57ee794

Please sign in to comment.