Skip to content

Commit

Permalink
fix(ui): catch invalid states
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Nov 21, 2024
1 parent 194c3af commit b8e3149
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
26 changes: 21 additions & 5 deletions ui/modal/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
m.transactionModal.State = &msg
m.infoModal.State = &msg

if m.Type == app.TransactionModal && !m.transactionModal.Active {
if msg.Accounts[m.Address].Participation.VoteFirstValid == m.transactionModal.Participation.Key.VoteFirstValid {
m.SetActive(true)
m.infoModal.Active = true
m.SetType(app.InfoModal)
// When the state changes, and we are displaying a valid QR Code/Transaction Modal
if m.Type == app.TransactionModal && m.transactionModal.Participation != nil {
acct, ok := msg.Accounts[m.Address]
// If the previous state is not active
if ok {
if !m.transactionModal.Active {
if acct.Participation != nil &&
acct.Participation.VoteFirstValid == m.transactionModal.Participation.Key.VoteFirstValid {
m.SetActive(true)
m.infoModal.Active = true
m.SetType(app.InfoModal)
}
} else {
if acct.Participation == nil {
m.SetActive(false)
m.infoModal.Active = false
m.transactionModal.Active = false
m.SetType(app.InfoModal)
}
}
}

}

case app.ModalEvent:
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/accounts/testdata/Test_Snapshot/Visible.golden
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
│ │
│ │
│ │
╰────( (g)enerate )─────────────────────────────────────| accounts | keys |────╯
╰────( Insufficient Data )──────────────────────────────| accounts | keys |────╯
6 changes: 5 additions & 1 deletion ui/pages/accounts/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import (

func (m ViewModel) View() string {
table := style.ApplyBorder(m.Width, m.Height, m.BorderColor).Render(m.table.View())
ctls := m.Controls
if m.Data.Status.LastRound < uint64(m.Data.Metrics.Window) {
ctls = "( Insufficient Data )"
}
return style.WithNavigation(
m.Navigation,
style.WithControls(
m.Controls,
ctls,
style.WithTitle(
m.Title,
table,
Expand Down

0 comments on commit b8e3149

Please sign in to comment.