Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: view transitions #24

Merged
merged 60 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
25a6a8e
fix: responsiveness with qr code, remove controls
PhearZero Oct 30, 2024
10b0354
Merge remote-tracking branch 'origin/fix/responsive-qr-code' into ref…
PhearZero Nov 5, 2024
da64fee
refactor: use arrow keys and remove hotkeys
PhearZero Nov 5, 2024
236d8ca
Merge branch 'main' into refactor/view-transitions
PhearZero Nov 6, 2024
34a6dde
refactor: move transaction and generate page
PhearZero Nov 6, 2024
d78a619
refactor: overlays with modal
PhearZero Nov 6, 2024
b5cb153
refactor: generate modal
PhearZero Nov 8, 2024
159688b
test: add last voted to test
PhearZero Nov 12, 2024
76974dd
fix: title loading
PhearZero Nov 12, 2024
7b2ff73
refactor: create app module, refactors cmds
PhearZero Nov 13, 2024
e3f2e8f
chore: move account address in confirm modal
PhearZero Nov 13, 2024
723007d
fix: online/offline transactions
PhearZero Nov 14, 2024
603e9cf
fix: block delete key
PhearZero Nov 14, 2024
cd20d0e
refactor: generate command
PhearZero Nov 14, 2024
6458d01
Merge branch 'main' into refactor/view-transitions
PhearZero Nov 18, 2024
e71253c
Merge branch 'main' into refactor/view-transitions
PhearZero Nov 19, 2024
23779eb
test(ui): keys page 100% coverage
PhearZero Nov 19, 2024
f6053bf
test(ui): refactor test fixtures, increase accounts coverage
PhearZero Nov 19, 2024
a0dd193
test(ui): accounts page 100% coverage
PhearZero Nov 19, 2024
233968d
test(ui): confirm modal 100% coverage
PhearZero Nov 19, 2024
4e4e9d9
test(ui): exception modal 100% coverage
PhearZero Nov 19, 2024
79628d2
test(ui): info modal 100% coverage
PhearZero Nov 19, 2024
53ca01c
test(ui): transaction modal increase coverage
PhearZero Nov 19, 2024
7e1a067
test(ui): generate modal 100% coverage
PhearZero Nov 19, 2024
8031447
test(ui): overlay 100% coverage
PhearZero Nov 19, 2024
7abda83
test(ui): increase style coverage
PhearZero Nov 19, 2024
acfbb10
test(ui): utils 100% coverage
PhearZero Nov 20, 2024
4fc1270
test: refactor to interface for client, increase coverage
PhearZero Nov 20, 2024
a39d905
test: allow mock api in internal
PhearZero Nov 20, 2024
e2a3af5
test(internal): status test
PhearZero Nov 20, 2024
af577a7
test(internal): github tests 100%, adds HttpPkg interface
PhearZero Nov 21, 2024
ab6e066
test(internal): metrics tests 100% coverage
PhearZero Nov 21, 2024
dff0cc7
test(internal): status coverage
PhearZero Nov 21, 2024
9a91f8f
feat(ui): lora transaction wizard
PhearZero Nov 21, 2024
ceb0e76
test(ui): update snapshots
PhearZero Nov 21, 2024
e395e99
fix(ui): empty account generate key
PhearZero Nov 21, 2024
a9851e2
fix(ui): input focus and return to accounts on delete
PhearZero Nov 21, 2024
a2f484c
feat(ui): display network and hide qrcode
PhearZero Nov 21, 2024
8b61cf0
chore(ui): remove extra parameters
PhearZero Nov 21, 2024
db34376
refactor(internal): participation watcher
PhearZero Nov 21, 2024
c66b330
fix(ui): state updates for online/offline
PhearZero Nov 21, 2024
194c3af
chore(build): fund TUI account
PhearZero Nov 21, 2024
b8e3149
fix(ui): catch invalid states
PhearZero Nov 21, 2024
c172119
build(docker): change order of clerk call
PhearZero Nov 22, 2024
297d4f1
build(docker): remove funding for now
PhearZero Nov 22, 2024
b89bb06
chore(internal): update generate status and rename idx
PhearZero Nov 26, 2024
d6b8708
chore(internal): remove offset
PhearZero Nov 26, 2024
f9352b9
refactor(internal): move GetAddressFromGenesis to test package
PhearZero Nov 26, 2024
844f286
chore(ui): update verbiage
PhearZero Nov 27, 2024
1069d6e
change build: no CGO dependency
Nov 27, 2024
f90ea9f
Dockerfile lint/warnings
Nov 27, 2024
00c47ca
Merge pull request #29 from algorandfoundation/chore/build-with-no-cho
PhearZero Nov 27, 2024
d77d9b4
test(ui): update modal snapshot
PhearZero Nov 27, 2024
92002bb
text fixes for modals, mostly keyreg
Nov 27, 2024
53c297c
test(ui): update snapshots
PhearZero Nov 27, 2024
f88b5c4
test(ui): fix lint error
PhearZero Nov 27, 2024
4d9c36c
chore(ui): add message while syncing for generate
PhearZero Nov 27, 2024
0b57899
chore(ui): consistent NA values
PhearZero Nov 27, 2024
fc8b3f3
feat(ui): handle fast catchup
PhearZero Nov 27, 2024
58d3e8d
chore(ui): format date value
PhearZero Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: overlays with modal
  • Loading branch information
PhearZero committed Nov 6, 2024
commit d78a619533df12183a4ea7e349f435c415067668
13 changes: 7 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -52,7 +52,8 @@ var (
client, err := getClient()
cobra.CheckErr(err)

partkeys, err := internal.GetPartKeys(context.Background(), client)
ctx := context.Background()
partkeys, err := internal.GetPartKeys(ctx, client)
if err != nil {
return fmt.Errorf(
style.Red.Render("failed to get participation keys: %s"),
@@ -75,11 +76,14 @@ var (
TX: 0,
},
ParticipationKeys: partkeys,

Client: client,
Context: ctx,
}
state.Accounts = internal.AccountsFromState(&state, new(internal.Clock), client)

// Fetch current state
err = state.Status.Fetch(context.Background(), client)
err = state.Status.Fetch(ctx, client)
cobra.CheckErr(err)

m, err := ui.MakeViewportViewModel(&state, client)
@@ -99,12 +103,9 @@ var (
p.Send(state)
p.Send(err)
}
}, context.Background(), client)
}, ctx, client)
}()
_, err = p.Run()
//for {
// time.Sleep(10 * time.Second)
//}
return err
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/charmbracelet/x/ansi v0.3.2
github.com/charmbracelet/x/exp/golden v0.0.0-20241022174419-46d9bb99a691 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
15 changes: 9 additions & 6 deletions internal/state.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@ type StateModel struct {
// TODO: handle contexts instead of adding it to state
Admin bool
Watching bool

Client *api.ClientWithResponses
Context context.Context
}

func (s *StateModel) waitAfterError(err error, cb func(model *StateModel, err error)) {
@@ -60,7 +63,7 @@ func (s *StateModel) Watch(cb func(model *StateModel, err error), ctx context.Co
s.Status.Update(status.JSON200.LastRound, status.JSON200.CatchupTime, status.JSON200.UpgradeNodeVote)

// Fetch Keys
s.UpdateKeys(ctx, client)
s.UpdateKeys()

if s.Status.State == "SYNCING" {
lastRound = s.Status.LastRound
@@ -107,18 +110,18 @@ func (s *StateModel) UpdateMetricsFromRPC(ctx context.Context, client *api.Clien
s.Metrics.LastRX = res["algod_network_received_bytes_total"]
}
}
func (s *StateModel) UpdateAccounts(client *api.ClientWithResponses) {
s.Accounts = AccountsFromState(s, new(Clock), client)
func (s *StateModel) UpdateAccounts() {
s.Accounts = AccountsFromState(s, new(Clock), s.Client)
}

func (s *StateModel) UpdateKeys(ctx context.Context, client *api.ClientWithResponses) {
func (s *StateModel) UpdateKeys() {
var err error
s.ParticipationKeys, err = GetPartKeys(ctx, client)
s.ParticipationKeys, err = GetPartKeys(s.Context, s.Client)
if err != nil {
s.Admin = false
}
if err == nil {
s.Admin = true
s.UpdateAccounts(client)
s.UpdateAccounts()
}
}
2 changes: 2 additions & 0 deletions internal/state_test.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@ func Test_StateModel(t *testing.T) {
RX: 0,
TPS: 0,
},
Client: client,
Context: context.Background(),
}
count := 0
go state.Watch(func(model *StateModel, err error) {
81 changes: 81 additions & 0 deletions ui/modals/confirm/confirm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package confirm

import (
"fmt"
"github.com/algorandfoundation/hack-tui/api"
"github.com/algorandfoundation/hack-tui/internal"
"github.com/algorandfoundation/hack-tui/ui/style"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)

type Msg *api.ParticipationKey

func EmitMsg(key *api.ParticipationKey) tea.Cmd {
return func() tea.Msg {
return Msg(key)
}
}

type ViewModel struct {
Width int
Height int
Title string
Controls string
BorderColor string
ActiveKey *api.ParticipationKey
Data *internal.StateModel
}

func New(state *internal.StateModel) *ViewModel {
return &ViewModel{
Width: 0,
Height: 0,
Title: "Delete Key",
BorderColor: "9",
Controls: "( " + style.Green.Render("(y)es") + " | " + style.Red.Render("(n)o") + " )",
Data: state,
}
}

func (m ViewModel) Init() tea.Cmd {
return nil
}

func (m ViewModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.HandleMessage(msg)
}
func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "y":
return &m, EmitMsg(m.ActiveKey)
case "n":
return &m, EmitMsg(nil)
}
case tea.WindowSizeMsg:
m.Width = msg.Width
m.Height = msg.Height
}
return &m, nil
}
func (m ViewModel) View() string {
if m.ActiveKey == nil {
return "No key selected"
}
return renderDeleteConfirmationModal(m.ActiveKey)

}

func renderDeleteConfirmationModal(partKey *api.ParticipationKey) string {
modalStyle := lipgloss.NewStyle().
Width(60).
Height(7).
Align(lipgloss.Center).
Padding(1, 2)

modalContent := fmt.Sprintf("Participation Key: %v\nAccount Address: %v", partKey.Id, partKey.Address)

return modalStyle.Render("Are you sure you want to delete this key from your node?\n" + modalContent)
}
86 changes: 86 additions & 0 deletions ui/modals/info/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package info

import (
"github.com/algorandfoundation/hack-tui/api"
"github.com/algorandfoundation/hack-tui/internal"
"github.com/algorandfoundation/hack-tui/ui/style"
"github.com/algorandfoundation/hack-tui/ui/utils"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
)

type ViewModel struct {
Width int
Height int
Title string
Controls string
BorderColor string
ActiveKey *api.ParticipationKey
Data *internal.StateModel
}

func New(state *internal.StateModel) *ViewModel {
return &ViewModel{
Width: 0,
Height: 0,
Title: "Key Information",
BorderColor: "3",
Controls: "( " + style.Red.Render("(d)elete") + " | " + style.Green.Render("(o)nline") + " )",
Data: state,
}
}

func (m ViewModel) Init() tea.Cmd {
return nil
}

func (m ViewModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m.HandleMessage(msg)
}
func (m ViewModel) HandleMessage(msg tea.Msg) (*ViewModel, tea.Cmd) {

switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.Width = msg.Width
m.Height = msg.Height
}
m.UpdateState()
return &m, nil
}
func (m *ViewModel) UpdateState() {
if m.ActiveKey == nil {
return
}
accountStatus := m.Data.Accounts[m.ActiveKey.Address].Status

if accountStatus == "Online" {
m.Controls = "( " + style.Red.Render("(d)elete") + " | " + style.Yellow.Render("(o)ffline") + " )"
} else {
m.Controls = "( " + style.Red.Render("(d)elete") + " | " + style.Green.Render("(o)nline") + " )"
}
}
func (m ViewModel) View() string {
if m.ActiveKey == nil {
return "No key selected"
}

id := style.Cyan.Render("Participation ID: ") + m.ActiveKey.Id
selection := style.Yellow.Render("Selection Key: ") + *utils.UrlEncodeBytesPtrOrNil(m.ActiveKey.Key.SelectionParticipationKey[:])
vote := style.Yellow.Render("Vote Key: ") + *utils.UrlEncodeBytesPtrOrNil(m.ActiveKey.Key.VoteParticipationKey[:])
stateProof := style.Yellow.Render("State Proof Key: ") + *utils.UrlEncodeBytesPtrOrNil(*m.ActiveKey.Key.StateProofKey)
voteFirstValid := style.Purple("Vote First Valid: ") + utils.IntToStr(m.ActiveKey.Key.VoteFirstValid)
voteLastValid := style.Purple("Vote Last Valid: ") + utils.IntToStr(m.ActiveKey.Key.VoteLastValid)
voteKeyDilution := style.Purple("Vote Key Dilution: ") + utils.IntToStr(m.ActiveKey.Key.VoteKeyDilution)

return ansi.Hardwrap(lipgloss.JoinVertical(lipgloss.Left,
id,
selection,
vote,
stateProof,
voteFirstValid,
voteLastValid,
voteKeyDilution,
), m.Width, true)

}
Loading
Loading