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: removed duplicate code blocks. #44

Merged
merged 1 commit into from
Feb 17, 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
23 changes: 10 additions & 13 deletions internal/tui/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,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 @@ -508,19 +508,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
Loading