4
4
"github.com/algorandfoundation/hack-tui/ui/style"
5
5
"sort"
6
6
"strconv"
7
+ "time"
7
8
8
9
"github.com/algorandfoundation/hack-tui/internal"
9
10
"github.com/charmbracelet/bubbles/table"
@@ -13,7 +14,7 @@ import (
13
14
type ViewModel struct {
14
15
Width int
15
16
Height int
16
- Data map [ string ] internal.Account
17
+ Data * internal.StateModel
17
18
18
19
table table.Model
19
20
navigation string
@@ -24,7 +25,7 @@ func New(state *internal.StateModel) ViewModel {
24
25
m := ViewModel {
25
26
Width : 0 ,
26
27
Height : 0 ,
27
- Data : state . Accounts ,
28
+ Data : state ,
28
29
controls : "( (g)enerate )" ,
29
30
navigation : "| " + style .Green .Render ("(a)ccounts" ) + " | (k)eys | (t)xn |" ,
30
31
}
@@ -52,7 +53,7 @@ func (m ViewModel) SelectedAccount() internal.Account {
52
53
var account internal.Account
53
54
var selectedRow = m .table .SelectedRow ()
54
55
if selectedRow != nil {
55
- account = m .Data [selectedRow [0 ]]
56
+ account = m .Data . Accounts [selectedRow [0 ]]
56
57
}
57
58
return account
58
59
}
@@ -70,13 +71,20 @@ func (m ViewModel) makeColumns(width int) []table.Column {
70
71
func (m ViewModel ) makeRows () * []table.Row {
71
72
rows := make ([]table.Row , 0 )
72
73
73
- for key := range m .Data {
74
+ for key := range m .Data .Accounts {
75
+ expires := m .Data .Accounts [key ].Expires .String ()
76
+ if m .Data .Status .State == "SYNCING" {
77
+ expires = "SYNCING"
78
+ }
79
+ if ! m .Data .Accounts [key ].Expires .After (time .Now ().Add (- (time .Hour * 24 * 365 * 50 ))) {
80
+ expires = "NA"
81
+ }
74
82
rows = append (rows , table.Row {
75
- m .Data [key ].Address ,
76
- strconv .Itoa (m .Data [key ].Keys ),
77
- m .Data [key ].Status ,
78
- m . Data [ key ]. Expires . String () ,
79
- strconv .Itoa (m .Data [key ].Balance ),
83
+ m .Data . Accounts [key ].Address ,
84
+ strconv .Itoa (m .Data . Accounts [key ].Keys ),
85
+ m .Data . Accounts [key ].Status ,
86
+ expires ,
87
+ strconv .Itoa (m .Data . Accounts [key ].Balance ),
80
88
})
81
89
}
82
90
sort .SliceStable (rows , func (i , j int ) bool {
0 commit comments