Skip to content

Commit

Permalink
replaced ugly if statements with switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd committed Feb 8, 2024
1 parent 7f320d5 commit ddc9f43
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/tui/pay_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@ func (m PayInvoiceModel) View() string {
s := m.styles
v := strings.TrimSuffix(m.form.View(), "\n")
form := lipgloss.DefaultRenderer().NewStyle().Margin(1, 0).Render(v)
if m.invoiceState == PaymentStateSending {
switch m.invoiceState {
case PaymentStateSending:
return lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(m.getPaymentPendingView()))
} else if m.invoiceState == PaymentStateSettled {
case PaymentStateSettled:
return lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(m.getPaymentSettledView()))
} else if m.invoiceState == PaymentStateDecoded {
case PaymentStateDecoded:
return lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(fmt.Sprintf("\n%s\n", s.HeaderText.Render("Pay Invoice?"))+
"\n"+m.getDecodeInvoiceView()))
} else if m.invoiceState == PaymentStateDecodeError {
case PaymentStateDecodeError:
return lipgloss.JoinVertical(lipgloss.Left, s.BorderedStyle.Render(fmt.Sprintf("\n%s\n", s.HeaderText.Render("Invalid Invoice"))+
"\n"+m.getDecodeInvoiceView()))
}

return lipgloss.JoinVertical(lipgloss.Left, form)
}

Expand Down

0 comments on commit ddc9f43

Please sign in to comment.