-
Notifications
You must be signed in to change notification settings - Fork 3
/
account-form.go
358 lines (329 loc) · 9.88 KB
/
account-form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
package cryptonym
import (
"context"
"errors"
"fmt"
"fyne.io/fyne"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
errs "github.com/blockpane/cryptonym/errLog"
"github.com/fioprotocol/fio-go"
"strings"
"time"
)
func NewAccountSearchTab(box chan fyne.Container, account *fio.Account) {
accountOuput := &widget.Box{}
accountInput := NewClickEntry(&widget.Button{})
accountSelect := widget.NewSelect(accountSearchType, func(s string) {
accountInput.Refresh()
})
accountSelect.SetSelected(accountSearchType[0])
accountInput.SetText(account.PubKey)
accountInput.OnChanged = func(s string) {
selected := accountSelect.Selected
switch {
case len(s) == 53 && strings.HasPrefix(s, "FIO"):
accountSelect.SetSelected("Public Key")
case len(s) == 51 && strings.HasPrefix(s, "5"):
accountSelect.SetSelected("Private Key")
case strings.Contains(s, "@"):
accountSelect.SetSelected("Fio Address")
case len(s) == 12:
accountSelect.SetSelected("Actor/Account")
case selected != "Fio Domain":
accountSelect.SetSelected("Fio Domain")
}
accountInput.SetText(s)
go func() {
time.Sleep(100 * time.Millisecond)
accountInput.Refresh()
}()
}
accountSubmit := &widget.Button{}
emptyBox := func() *widget.Box {
return widget.NewVBox(
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(RWidth(), 40)),
widget.NewHBox(
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(accountSelect.MinSize()), accountSelect),
accountInput,
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(accountSubmit.MinSize()), accountSubmit),
),
),
layout.NewSpacer(),
)
}
mkBox := func(accountOutput *widget.Box) *widget.Box {
accountBox := widget.NewVBox(
accountOuput,
)
accountOuput.Refresh()
return widget.NewVBox(
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.NewSize(RWidth(), 40)),
widget.NewHBox(
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(accountSelect.MinSize()), accountSelect),
accountInput,
fyne.NewContainerWithLayout(layout.NewFixedGridLayout(accountSubmit.MinSize()), accountSubmit),
),
),
fyne.NewContainerWithLayout(layout.NewVBoxLayout(),
accountBox,
),
)
}
accountSubmit = widget.NewButtonWithIcon("Search", theme.SearchIcon(), func() {
go func() {
accountSubmit.Disable()
defer accountSubmit.Enable()
d := time.Now().Add(5 * time.Second)
ctx, cancel := context.WithDeadline(context.Background(), d)
defer cancel()
finished := make(chan bool)
go func() {
box <- *fyne.NewContainerWithLayout(layout.NewVBoxLayout(),
emptyBox(),
layout.NewSpacer(),
)
info, err := AccountSearch(accountSelect.Selected, accountInput.Text)
if err != nil {
errs.ErrChan <- err.Error()
return
}
ao, err := info.report()
if err != nil {
errs.ErrChan <- err.Error()
return
}
deRef := *ao
accountOuput = &deRef
accountOuput.Refresh()
accountOuput.Show()
box <- *fyne.NewContainerWithLayout(
layout.NewMaxLayout(),
widget.NewScrollContainer(mkBox(&deRef)),
)
finished <- true
}()
for {
select {
case <-finished:
return
case <-ctx.Done():
errs.ErrChan <- "hit time limit while getting account information"
return
}
}
}()
})
accountInput.Button = accountSubmit
box <- *fyne.NewContainerWithLayout(layout.NewVBoxLayout(),
emptyBox(),
layout.NewSpacer(),
)
}
func (as *AccountInformation) report() (*widget.Box, error) {
if as.Actor == "" || as.PubKey == "" {
return nil, errors.New("nothing to report, account or key name empty")
}
vSpace := widget.NewHBox(widget.NewLabel(" "))
names := func() *widget.Box {
b := widget.NewVBox()
if len(as.FioNames) > 0 {
for _, r := range as.FioNames {
b.Append(vSpace)
fioName := widget.NewEntry()
func(n string) {
fioName.SetText(n)
fioName.OnChanged = func(string) {
fioName.SetText(n)
}
}(r.Name) // deref
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Fio Name:", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
fioName,
layout.NewSpacer(),
))
expires := widget.NewEntry()
func(s string) {
expires.SetText(s)
expires.OnChanged = func(string) {
expires.SetText(s)
}
}(time.Unix(r.Expiration, 0).String()) // deref
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Expiration:", fyne.TextAlignTrailing, fyne.TextStyle{}),
expires,
layout.NewSpacer(),
))
bundle := widget.NewEntry()
func(s string) {
bundle.SetText(s)
bundle.OnChanged = func(string) {
bundle.SetText(s)
}
}(fmt.Sprintf("%d", r.BundleCount)) // deref
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Free Bundled TX remaining:", fyne.TextAlignTrailing, fyne.TextStyle{}),
bundle,
layout.NewSpacer(),
))
addressBox := make([]*fyne.Container, 0)
for _, public := range r.Addresses {
if public.PublicAddress == as.PubKey {
continue
}
pubAddr := widget.NewEntry()
var symbol string
switch {
case public.TokenCode != "" && public.ChainCode != "":
symbol = fmt.Sprintf("%s • %s", public.TokenCode, public.ChainCode)
case public.TokenCode != "":
symbol = public.TokenCode
default:
symbol = public.ChainCode
}
func(s string) {
pubAddr.SetText(s)
pubAddr.OnChanged = func(string) {
pubAddr.SetText(s)
}
}(public.PublicAddress) // deref
addressBox = append(addressBox,
fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle(symbol, fyne.TextAlignTrailing, fyne.TextStyle{Italic: true}),
pubAddr,
layout.NewSpacer(),
))
}
for _, app := range addressBox {
b.Append(app)
}
}
}
b.Append(fyne.NewContainerWithLayout(layout.NewFixedGridLayout(fyne.Size{
Width: 20,
Height: 50,
})))
return b
}()
domains := func() *widget.Box {
b := widget.NewVBox()
if len(as.FioDomains) > 0 {
for _, r := range as.FioDomains {
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(1), widget.NewLabel(" ")))
fioDomain := widget.NewEntry()
func(s string) {
fioDomain.SetText(s)
fioDomain.OnChanged = func(string) {
fioDomain.SetText(s)
}
}(r.Name) // deref
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Fio Domain:", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
fioDomain,
layout.NewSpacer(),
))
public := widget.NewEntry()
toBool := func() string {
if r.IsPublic > 0 {
return "True"
}
return "False"
}
func(s string) {
public.SetText(s)
public.OnChanged = func(string) {
public.SetText(s)
}
}(toBool())
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Allows Public Registration:", fyne.TextAlignTrailing, fyne.TextStyle{}),
public,
layout.NewSpacer(),
))
expires := widget.NewEntry()
func(s string) {
expires.SetText(s)
expires.OnChanged = func(string) {
expires.SetText(s)
}
}(time.Unix(r.Expiration, 0).String()) // deref
b.Append(fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Expiration:", fyne.TextAlignTrailing, fyne.TextStyle{}),
expires,
layout.NewSpacer(),
))
}
}
return b
}()
report := &widget.Box{}
entryActor := widget.NewEntry()
entryActor.SetText(as.Actor)
entryActor.OnChanged = func(string) {
entryActor.SetText(as.Actor)
}
entryPub := widget.NewEntry()
entryPub.SetText(as.PubKey)
entryPub.OnChanged = func(string) {
entryPub.SetText(as.PubKey)
}
entryBal := widget.NewEntry()
entryBal.SetText(p.Sprintf("ᵮ %.9g", float64(as.Balance)/1000000000.0))
entryBal.OnChanged = func(string) {
entryBal.SetText(p.Sprintf("ᵮ %.9g", float64(as.Balance)/1000000000.0))
}
ramUsed := widget.NewEntry()
ramContainer := fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Ram Used: ", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
ramUsed,
layout.NewSpacer(),
)
ramContainer.Hide()
if as.RamUsed != 0 {
ramContainer.Show()
ramUsed.SetText(p.Sprintf("%d", as.RamUsed))
ramUsed.OnChanged = func(string) {
ramUsed.SetText(p.Sprintf("%d", as.RamUsed))
}
ramUsed.Refresh()
}
msig := widget.NewMultiLineEntry()
msigContainer := fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("MultiSig Account Info: ", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
msig,
layout.NewSpacer(),
)
msigContainer.Hide()
if len(as.MsigOwners) != 0 {
msigContainer.Show()
msig.SetText(fmt.Sprintf("Required Threshold: %d\nOwners:\n - %s", as.MsigThresh, strings.Join(as.MsigOwners, "\n - ")))
msig.OnChanged = func(string) {
msig.SetText(fmt.Sprintf("Required Threshold: %d\nOwners:\n - %s", as.MsigThresh, strings.Join(as.MsigOwners, "\n - ")))
}
msig.Refresh()
}
report = widget.NewVBox(
fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Actor: ", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
entryActor,
layout.NewSpacer(),
),
fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Public Key: ", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
entryPub,
layout.NewSpacer(),
),
fyne.NewContainerWithLayout(layout.NewGridLayoutWithColumns(3),
widget.NewLabelWithStyle("Balance: ", fyne.TextAlignTrailing, fyne.TextStyle{Bold: true}),
entryBal,
layout.NewSpacer(),
),
ramContainer,
msigContainer,
domains,
names,
)
report.Refresh()
return report, nil
}