Skip to content

Commit

Permalink
feat: skip account loading on syncing
Browse files Browse the repository at this point in the history
feat: remove offline account expires date
  • Loading branch information
PhearZero committed Nov 4, 2024
1 parent c16080f commit 5615e87
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
25 changes: 15 additions & 10 deletions internal/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,23 @@ func AccountsFromState(state *StateModel, t Time, client *api.ClientWithResponse
for _, key := range *state.ParticipationKeys {
val, ok := values[key.Address]
if !ok {

account, err := GetAccount(client, key.Address)

// TODO: handle error
if err != nil {
// TODO: Logging
panic(err)
var account = api.Account{
Address: key.Address,
Status: "Unknown",
Amount: 0,
}

var expires = t.Now()
if state.Status.State != "SYNCING" {
var err error
account, err = GetAccount(client, key.Address)
// TODO: handle error
if err != nil {
// TODO: Logging
panic(err)
}
}
now := t.Now()
var expires = now.Add(-(time.Hour * 24 * 365 * 100))
if key.EffectiveLastValid != nil {
now := t.Now()
roundDiff := max(0, *key.EffectiveLastValid-int(state.Status.LastRound))
distance := int(state.Metrics.RoundTime) * roundDiff
expires = now.Add(time.Duration(distance))
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/accounts/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (ViewModel, tea.Cmd) {

switch msg := msg.(type) {
case internal.StateModel:
m.Data = msg.Accounts
m.Data = &msg
m.table.SetRows(*m.makeRows())
case tea.KeyMsg:
switch msg.String() {
Expand Down
26 changes: 17 additions & 9 deletions ui/pages/accounts/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/algorandfoundation/hack-tui/ui/style"
"sort"
"strconv"
"time"

"github.com/algorandfoundation/hack-tui/internal"
"github.com/charmbracelet/bubbles/table"
Expand All @@ -13,7 +14,7 @@ import (
type ViewModel struct {
Width int
Height int
Data map[string]internal.Account
Data *internal.StateModel

table table.Model
navigation string
Expand All @@ -24,7 +25,7 @@ func New(state *internal.StateModel) ViewModel {
m := ViewModel{
Width: 0,
Height: 0,
Data: state.Accounts,
Data: state,
controls: "( (g)enerate )",
navigation: "| " + style.Green.Render("(a)ccounts") + " | (k)eys | (t)xn |",
}
Expand Down Expand Up @@ -52,7 +53,7 @@ func (m ViewModel) SelectedAccount() internal.Account {
var account internal.Account
var selectedRow = m.table.SelectedRow()
if selectedRow != nil {
account = m.Data[selectedRow[0]]
account = m.Data.Accounts[selectedRow[0]]
}
return account
}
Expand All @@ -70,13 +71,20 @@ func (m ViewModel) makeColumns(width int) []table.Column {
func (m ViewModel) makeRows() *[]table.Row {
rows := make([]table.Row, 0)

for key := range m.Data {
for key := range m.Data.Accounts {
expires := m.Data.Accounts[key].Expires.String()
if m.Data.Status.State == "SYNCING" {
expires = "SYNCING"
}
if !m.Data.Accounts[key].Expires.After(time.Now().Add(-(time.Hour * 24 * 365 * 50))) {
expires = "NA"
}
rows = append(rows, table.Row{
m.Data[key].Address,
strconv.Itoa(m.Data[key].Keys),
m.Data[key].Status,
m.Data[key].Expires.String(),
strconv.Itoa(m.Data[key].Balance),
m.Data.Accounts[key].Address,
strconv.Itoa(m.Data.Accounts[key].Keys),
m.Data.Accounts[key].Status,
expires,
strconv.Itoa(m.Data.Accounts[key].Balance),
})
}
sort.SliceStable(rows, func(i, j int) bool {
Expand Down

0 comments on commit 5615e87

Please sign in to comment.