Skip to content

Commit

Permalink
fix: animate the invoice payment spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
ardevd committed Feb 8, 2024
1 parent 67ab69e commit 0bfcd2f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions internal/tui/pay_invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func (m *PayInvoiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
// Payment has been decoded and issued.
case paymentCreated:
cmds = append(cmds, m.payInvoice)
// Animate the spinner and pay the invoice
cmds = append(cmds, m.spinner.Tick, m.payInvoice)
// Payment failed
case paymentError:
m.invoiceState = PaymentStateNone
Expand All @@ -99,10 +100,6 @@ func (m *PayInvoiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.invoiceState = PaymentStateSettled
}

// Tick the spinner
m.spinner, cmd = m.spinner.Update(msg)
cmds = append(cmds, cmd)

// Process the invoice form
if m.form != nil {
form, cmd := m.form.Update(msg)
Expand All @@ -122,6 +119,10 @@ func (m *PayInvoiceModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}

// Update the spinner
m.spinner, cmd = m.spinner.Update(msg)
cmds = append(cmds, cmd)

return m, tea.Batch(cmds...)
}

Expand All @@ -142,7 +143,7 @@ func getInvoicePaymentForm() *huh.Form {

// Init
func (m PayInvoiceModel) Init() tea.Cmd {
return m.spinner.Tick
return nil
}

// Model view logic
Expand Down

0 comments on commit 0bfcd2f

Please sign in to comment.