Skip to content

Commit

Permalink
fix: transaction modal support non-resident keys & warn. chore: change
Browse files Browse the repository at this point in the history
accounts page columns & Status values
  • Loading branch information
Tasos Bitsios committed Jan 22, 2025
1 parent 6ab2f93 commit f9665a2
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 10 deletions.
55 changes: 48 additions & 7 deletions ui/modal/controller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package modal

import (
"bytes"
"fmt"
"github.com/algorandfoundation/nodekit/internal/algod"
"github.com/algorandfoundation/nodekit/internal/algod/participation"
Expand All @@ -23,6 +24,13 @@ func (m ViewModel) Init() tea.Cmd {
)
}

func boolToInt(input bool) int {
if input {
return 1
}
return 0
}

// HandleMessage processes the given message, updates the ViewModel state, and returns any commands to execute.
func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
var (
Expand Down Expand Up @@ -75,13 +83,46 @@ 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 &&
acct.Participation.VoteFirstValid == m.transactionModal.Participation.Key.VoteFirstValid {
m.SetActive(true)
m.infoModal.Active = true
m.infoModal.Prefix = "Successfully registered online!\n"
m.HasPrefix = true
m.SetType(app.InfoModal)
if acct.Participation != nil {
// 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)
kdMatch := boolToInt(acct.Participation.VoteKeyDilution == m.transactionModal.Participation.Key.VoteKeyDilution)
selMatch := boolToInt(bytes.Equal(acct.Participation.SelectionParticipationKey, m.transactionModal.Participation.Key.SelectionParticipationKey))
votMatch := boolToInt(bytes.Equal(acct.Participation.VoteParticipationKey, m.transactionModal.Participation.Key.VoteParticipationKey))
spkMatch := boolToInt(bytes.Equal(*acct.Participation.StateProofKey, *m.transactionModal.Participation.Key.StateProofKey))
matchCount := fvMatch + lvMatch + kdMatch + selMatch + votMatch + spkMatch
if matchCount == 6 {
m.SetActive(true)
m.infoModal.Active = true
m.infoModal.Prefix = "Successfully registered online!\n"
m.HasPrefix = true
m.SetType(app.InfoModal)
} else if matchCount >= 4 {
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"
if fvMatch == 0 {
m.infoModal.Prefix = m.infoModal.Prefix + "Mismatched: Vote First Valid\n"
}
if lvMatch == 0 {
m.infoModal.Prefix = m.infoModal.Prefix + "Mismatched: Vote Last Valid\n"
}
if kdMatch == 0 {
m.infoModal.Prefix = m.infoModal.Prefix + "Mismatched: Vote Key Dilution\n"
}
if votMatch == 0 {
m.infoModal.Prefix = m.infoModal.Prefix + "Mismatched: Vote Key\n"
}
if selMatch == 0 {
m.infoModal.Prefix = m.infoModal.Prefix + "Mismatched: Selection Key\n"
}
if spkMatch == 0 {
m.infoModal.Prefix = m.infoModal.Prefix + "Mismatched: State Proof Key\n"
}
m.HasPrefix = true
m.SetType(app.InfoModal)
}
}
} else {
if acct.Participation == nil {
Expand Down
34 changes: 31 additions & 3 deletions ui/pages/accounts/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/charmbracelet/lipgloss"
)

var minEligibleBalance = 30_000
var maxEligibleBalance = 70_000_000

type ViewModel struct {
Data *algod.StateModel

Expand Down Expand Up @@ -67,8 +70,8 @@ func (m ViewModel) makeColumns(width int) []table.Column {
avgWidth := (width - lipgloss.Width(style.Border.Render("")) - 9) / 5
return []table.Column{
{Title: "Account", Width: avgWidth},
{Title: "Keys", Width: avgWidth},
{Title: "Status", Width: avgWidth},
{Title: "Rewards", Width: avgWidth},
{Title: "Expires", Width: avgWidth},
{Title: "Balance", Width: avgWidth},
}
Expand All @@ -78,11 +81,13 @@ func (m ViewModel) makeRows() *[]table.Row {
rows := make([]table.Row, 0)

for addr := range m.Data.Accounts {
expired := false
var expires = "N/A"
if m.Data.Accounts[addr].Expires != nil {
// This condition will only exist for a split second
// until algod deletes the key
if m.Data.Accounts[addr].Expires.Before(time.Now()) {
expired = true
expires = "EXPIRED"
} else {
expires = m.Data.Accounts[addr].Expires.Format(time.RFC822)
Expand All @@ -105,10 +110,33 @@ func (m ViewModel) makeRows() *[]table.Row {
}
}

status := m.Data.Accounts[addr].Status
if status == "Online" && !expired {
status = "PARTICIPATING"
} else {
status = "IDLE"
}

incentiveLevel := ""
balance := m.Data.Accounts[addr].Balance
if m.Data.Accounts[addr].IncentiveEligible && status == "PARTICIPATING" {
if balance >= minEligibleBalance && balance <= maxEligibleBalance {
incentiveLevel = "ELIGIBLE"
} else {
incentiveLevel = "PAUSED"
}
} else {
if status == "PARTICIPATING" {
incentiveLevel = "INELIGIBLE"
} else {
incentiveLevel = ""
}
}

rows = append(rows, table.Row{
m.Data.Accounts[addr].Address,
strconv.Itoa(m.Data.Accounts[addr].Keys),
m.Data.Accounts[addr].Status,
status,
incentiveLevel,
expires,
strconv.Itoa(m.Data.Accounts[addr].Balance),
})
Expand Down

0 comments on commit f9665a2

Please sign in to comment.