Skip to content

Commit

Permalink
fix(ui): input focus and return to accounts on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
PhearZero committed Nov 21, 2024
1 parent e395e99 commit a9851e2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
15 changes: 13 additions & 2 deletions internal/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ func waitForNewKey(
if err != nil {
return nil, err
}
if keys == nil && currentKeys != nil {
return currentKeys, nil
}
// Check the length against known keys
if len(*currentKeys) == len(*keys) {
if currentKeys == nil || len(*currentKeys) == 0 || len(*currentKeys) == len(*keys) {
// Sleep then try again
time.Sleep(interval)
return waitForNewKey(ctx, client, keys, interval, timeout)
Expand All @@ -81,6 +84,14 @@ func findKeyPair(
}
}
}
// If keys are empty, return the found keys
if originalKeys == nil || len(*originalKeys) == 0 {
keys := *currentKeys
participationKey = keys[0]
}
if participationKey.Id == "" {
return nil, errors.New("key not found")
}
return &participationKey, nil
}

Expand All @@ -102,7 +113,7 @@ func GenerateKeyPair(
return nil, err
}
if key.StatusCode() != 200 {
return nil, errors.New(key.Status())
return nil, errors.New("something went wrong")
}

// Wait for the api to have a new key
Expand Down
2 changes: 1 addition & 1 deletion internal/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *StateModel) Watch(cb func(model *StateModel, err error), ctx context.Co
continue
}
// Run Round Averages and RX/TX every 5 rounds
if s.Status.LastRound%5 == 0 {
if s.Status.LastRound%5 == 0 || (s.Status.LastRound > 100 && s.Metrics.RoundTime.Seconds() == 0) {
bm, err := GetBlockMetrics(ctx, client, s.Status.LastRound, s.Metrics.Window)
s.waitAfterError(err, cb)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions ui/modal/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
// On closing events
if msg.Type == app.CloseModal {
m.Open = false
m.generateModal.Input.Focus()
} else {
m.Open = true
}
Expand All @@ -46,6 +47,7 @@ func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
m.Open = false
m.SetType(app.InfoModal)
m.generateModal.SetStep(generate.AddressStep)
m.generateModal.Input.Focus()
case app.TransactionModal:
m.SetType(app.InfoModal)
case app.ExceptionModal:
Expand Down
3 changes: 3 additions & 0 deletions ui/pages/keys/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func New(address string, keys *[]api.ParticipationKey) ViewModel {

return m
}
func (m *ViewModel) Rows() []table.Row {
return m.table.Rows()
}

// SelectedKey returns the currently selected participation key from the ViewModel's data set, or nil if no key is selected.
func (m ViewModel) SelectedKey() (*api.ParticipationKey, bool) {
Expand Down
5 changes: 5 additions & 0 deletions ui/viewport.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (m ViewportViewModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.keysPage, cmd = m.keysPage.HandleMessage(msg)
cmds = append(cmds, cmd)
return m, tea.Batch(cmds...)
case app.DeleteFinished:
if len(m.keysPage.Rows()) <= 1 {
cmd = app.EmitShowPage(app.AccountsPage)
cmds = append(cmds, cmd)
}
case tea.KeyMsg:
switch msg.String() {
case "g":
Expand Down

0 comments on commit a9851e2

Please sign in to comment.