Skip to content

Commit

Permalink
Fix: Support suspended accounts and re-registering
Browse files Browse the repository at this point in the history
  • Loading branch information
Tasos Bitsios committed Jan 22, 2025
1 parent 41c65e2 commit 2d00496
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
14 changes: 10 additions & 4 deletions ui/modal/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
// If the previous state is not active
if ok {
if !m.transactionModal.Active {
if acct.Participation != nil {
if acct.Participation != nil && acct.Status == "Online" {
// comparing values to detect corrupted/non-resident keys
fvMatch := boolToInt(acct.Participation.VoteFirstValid == m.transactionModal.Participation.Key.VoteFirstValid)
lvMatch := boolToInt(acct.Participation.VoteLastValid == m.transactionModal.Participation.Key.VoteLastValid)
Expand All @@ -99,6 +99,10 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
m.HasPrefix = true
m.SetType(app.InfoModal)
} else if matchCount >= 4 {
// We use 4 as the "non resident key" threshold here
// because it would be valid to re-reg with a key that has the same fv / lv / kd
// but it would trigger the non resident condition
// TOOD: refactor this beast to have {previous state} -> compare with next state
m.SetActive(true)
m.infoModal.Active = true
m.infoModal.Prefix = "***WARNING***\nRegistered online but keys do not fully match\nCheck your registered keys carefully against the node keys\n\n"
Expand All @@ -125,15 +129,17 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
}
}
} else {
// TODO: This includes suspended keys, where Status == offline but .Participation is set
// Detect and display this

Check warning on line 133 in ui/modal/controller.go

View check run for this annotation

Codecov / codecov/patch

ui/modal/controller.go#L132-L133

Added lines #L132 - L133 were not covered by tests
if acct.Participation == nil {
m.SetActive(false)
m.infoModal.Active = false
m.transactionModal.Active = false
m.SetType(app.InfoModal)
} else {
m.SetSuspended()

Check warning on line 138 in ui/modal/controller.go

View check run for this annotation

Codecov / codecov/patch

ui/modal/controller.go#L136-L138

Added lines #L136 - L138 were not covered by tests
m.SetType(app.InfoModal)
}
}
}

}

case app.ModalEvent:
Expand Down
10 changes: 10 additions & 0 deletions ui/modal/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ func (m *ViewModel) SetActive(active bool) {
m.transactionModal.UpdateState()
}

// SetSuspended sets the active state to false both infoModal and transactionModal, and sets suspended state to true, also for both modals.
func (m *ViewModel) SetSuspended() {
m.infoModal.Active = false
m.infoModal.Suspended = true
m.infoModal.UpdateState()
m.transactionModal.Active = false
m.transactionModal.Suspended = true
m.transactionModal.UpdateState()

Check warning on line 79 in ui/modal/model.go

View check run for this annotation

Codecov / codecov/patch

ui/modal/model.go#L73-L79

Added lines #L73 - L79 were not covered by tests
}

func (m *ViewModel) SetShortLink(res participation.ShortLinkResponse) {
m.Link = &res
m.transactionModal.Link = &res
Expand Down
7 changes: 5 additions & 2 deletions ui/modals/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ViewModel struct {
Controls string
BorderColor string
Active bool
Suspended bool
Prefix string
Participation *api.ParticipationKey
State *algod.StateModel
Expand Down Expand Up @@ -74,9 +75,8 @@ func (m *ViewModel) UpdateState() {
if m.Participation == nil {
return
}
accountStatus := m.State.Accounts[m.Participation.Address].Status

if accountStatus == "Online" && m.Active {
if m.Active && !m.Suspended {
m.BorderColor = "1"
m.Controls = "( take " + style.Red.Render(style.Red.Render("(o)ffline")) + " )"
}
Expand All @@ -100,6 +100,9 @@ func (m ViewModel) View() string {
voteKeyDilution := style.Purple("Vote Key Dilution: ") + utils.IntToStr(m.Participation.Key.VoteKeyDilution)

prefix := ""
if m.Suspended {
prefix = "**KEY SUSPENDED**: Re-register online"
}

Check warning on line 105 in ui/modals/info/info.go

View check run for this annotation

Codecov / codecov/patch

ui/modals/info/info.go#L104-L105

Added lines #L104 - L105 were not covered by tests
if m.Prefix != "" {
prefix = "\n" + m.Prefix
}
Expand Down
1 change: 1 addition & 0 deletions ui/modals/transaction/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ViewModel struct {
// Active Participation Key
Participation *api.ParticipationKey
Active bool
Suspended bool
Link *participation.ShortLinkResponse

// Pointer to the State
Expand Down

0 comments on commit 2d00496

Please sign in to comment.