Skip to content

Commit

Permalink
refactor: removed duplicate code blocks. (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd authored Feb 17, 2024
1 parent ed149e5 commit 6e71d04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
23 changes: 10 additions & 13 deletions internal/tui/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,12 @@ func (m ChannelModel) getChannelParameters() string {

// Update form placeholder values
policyFeeRate = strconv.FormatInt(localNodePolicy.FeeRateMilliMsat, 10)
policyBaseRate = strconv.FormatInt(localNodePolicy.FeeBaseMsat / 1000, 10)
policyBaseRate = strconv.FormatInt(localNodePolicy.FeeBaseMsat/1000, 10)
policyTimeLockDelta = strconv.FormatUint(uint64(localNodePolicy.TimeLockDelta), 10)

localView := fmt.Sprintf("%s\n%s %v\n%s %v\n%s %v\n%s %v\n%s %v", m.styles.Keyword("Local"),
m.styles.SubKeyword("Base"),
localNodePolicy.FeeBaseMsat / 1000, m.styles.SubKeyword("Rate"), localNodePolicy.FeeRateMilliMsat,
localNodePolicy.FeeBaseMsat/1000, m.styles.SubKeyword("Rate"), localNodePolicy.FeeRateMilliMsat,
m.styles.SubKeyword("CLTV Delta"), localNodePolicy.TimeLockDelta,
m.styles.SubKeyword("Max HTLC"), localNodePolicy.MaxHtlcMsat/1000,
m.styles.SubKeyword("Min HTLC"), localNodePolicy.MinHtlcMsat/1000)
Expand Down Expand Up @@ -507,19 +507,16 @@ func (m ChannelModel) View() string {
htlcTableView,
bottomView,
helpView)
} else if m.state == ChannelStateWantForceClose {
v := strings.TrimSuffix(m.channelCloseForm.View(), "\n\n")
form := lipgloss.DefaultRenderer().NewStyle().Margin(1, 0).Render(v)
return lipgloss.JoinVertical(lipgloss.Left, form)
} else if m.state == ChannelStateWantClose {
v := strings.TrimSuffix(m.channelCloseForm.View(), "\n\n")
form := lipgloss.DefaultRenderer().NewStyle().Margin(1, 0).Render(v)
return lipgloss.JoinVertical(lipgloss.Left, form)
} else if m.state == ChannelStateWantForceClose || m.state == ChannelStateWantClose {
return m.getFormView(strings.TrimSuffix(m.channelCloseForm.View(), "\n\n"))
} else if m.state == ChannelPolicyUpdate {
v := strings.TrimSuffix(m.channelPolicyForm.View(), "\n\n")
form := lipgloss.DefaultRenderer().NewStyle().Margin(1, 0).Render(v)
return lipgloss.JoinVertical(lipgloss.Left, form)
return m.getFormView(strings.TrimSuffix(m.channelPolicyForm.View(), "\n\n"))
}

return ""
}

func (m ChannelModel) getFormView(view string) string {
form := lipgloss.DefaultRenderer().NewStyle().Margin(1, 0).Render(view)
return lipgloss.JoinVertical(lipgloss.Left, form)
}
3 changes: 1 addition & 2 deletions internal/tui/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func (m DashboardModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

switch m.focused {
case payments:
m.lists[m.focused], cmd = m.lists[m.focused].Update(msg)
cmds = append(cmds, cmd)
fallthrough

case channels:
m.lists[m.focused], cmd = m.lists[m.focused].Update(msg)
Expand Down

0 comments on commit 6e71d04

Please sign in to comment.