forked from planetdecred/godcr
/
modal_templates.go
741 lines (679 loc) · 22.4 KB
/
modal_templates.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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
package ui
import (
"gioui.org/font/gofont"
"gioui.org/layout"
"gioui.org/text"
"gioui.org/unit"
"gioui.org/widget"
"gioui.org/widget/material"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/values"
"golang.org/x/exp/shiny/materialdesign/icons"
)
const CreateWalletTemplate = "CreateWallet"
const RenameWalletTemplate = "RenameWallet"
const CreateAccountTemplate = "CreateNewAccount"
const RenameAccountTemplate = "RenameAccount"
const PasswordTemplate = "Password"
const ChangePasswordTemplate = "ChangePassword"
const ConfirmRemoveTemplate = "ConfirmRemove"
const VerifyMessageInfoTemplate = "VerifyMessageInfo"
const SignMessageInfoTemplate = "SignMessageInfo"
const PrivacyInfoTemplate = "PrivacyInfo"
const RescanWalletTemplate = "RescanWallet"
const ChangeStartupPasswordTemplate = "ChangeStartupPassword"
const SetStartupPasswordTemplate = "SetStartupPassword"
const RemoveStartupPasswordTemplate = "RemoveStartupPassword"
const UnlockWalletTemplate = "UnlockWallet"
const ConnectToSpecificPeerTemplate = "ConnectToSpecificPeer"
const ChangeSpecificPeerTemplate = "ChangeSpecificPeer"
const UserAgentTemplate = "UserAgent"
const SetupMixerInfoTemplate = "ConfirmSetupMixer"
const ConfirmMixerAcctExistTemplate = "MixerAcctExistTemplate"
const SecurityToolsInfoTemplate = "SecurityToolsInfo"
const ImportWatchOnlyWalletTemplate = "ImportWatchOnlyWallet"
const UnlockWalletRestoreTemplate = "UnlockWalletRestoreTemplate"
const SendInfoTemplate = "SendInfo"
const ReceiveInfoTemplate = "ReceiveInfo"
const TransactionDetailsInfoTemplate = "TransactionDetailsInfoInfo"
type ModalTemplate struct {
th *decredmaterial.Theme
walletName decredmaterial.Editor
oldSpendingPassword decredmaterial.Editor
spendingPassword decredmaterial.Editor
matchSpendingPassword decredmaterial.Editor
extendedPublicKey decredmaterial.Editor
confirm decredmaterial.Button
cancel decredmaterial.Button
alert *widget.Icon
passwordStrength decredmaterial.ProgressBarStyle
}
type modalLoad struct {
template string
title string
confirm interface{}
loading bool
confirmText string
cancel interface{}
cancelText string
isReset bool
}
func (win *Window) LoadModalTemplates() *ModalTemplate {
cancel := win.theme.Button(new(widget.Clickable), "Cancel")
cancel.TextSize = values.TextSize16
return &ModalTemplate{
th: win.theme,
confirm: win.theme.Button(new(widget.Clickable), "Confirm"),
cancel: cancel,
walletName: win.theme.Editor(new(widget.Editor), ""),
oldSpendingPassword: win.theme.EditorPassword(new(widget.Editor), "Old spending password"),
spendingPassword: win.theme.EditorPassword(new(widget.Editor), "Spending password"),
matchSpendingPassword: win.theme.EditorPassword(new(widget.Editor), "Confirm spending password"),
extendedPublicKey: win.theme.Editor(new(widget.Editor), "Extended public key"),
alert: mustIcon(widget.NewIcon(icons.AlertError)),
passwordStrength: win.theme.ProgressBar(0),
}
}
func (m *ModalTemplate) importWatchOnlyWallet() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return m.walletName.Layout(gtx)
},
func(gtx C) D {
return m.extendedPublicKey.Layout(gtx)
},
}
}
func (load *modalLoad) setLoading(isLoading bool) {
load.loading = isLoading
}
func (m *ModalTemplate) createNewWallet() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return m.walletName.Layout(gtx)
},
func(gtx C) D {
m.spendingPassword.Editor.SingleLine = true
return m.spendingPassword.Layout(gtx)
},
func(gtx C) D {
return m.passwordStrength.Layout(gtx)
},
func(gtx C) D {
m.matchSpendingPassword.Editor.SingleLine = true
return m.matchSpendingPassword.Layout(gtx)
},
}
}
func (m *ModalTemplate) renameWallet() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return m.walletName.Layout(gtx)
},
}
}
func (m *ModalTemplate) createNewAccount() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
m.alert.Color = m.th.Color.Gray
return layout.Inset{Top: values.MarginPadding7, Right: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return m.alert.Layout(gtx, unit.Dp(15))
})
}),
layout.Rigid(func(gtx C) D {
info := m.th.Body1("Accounts")
info.Color = m.th.Color.Gray
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return info.Layout(gtx)
})
}),
layout.Rigid(func(gtx C) D {
info := m.th.Body1(" cannot ")
info.Color = m.th.Color.DeepBlue
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return info.Layout(gtx)
})
}),
layout.Rigid(func(gtx C) D {
info := m.th.Body1("be deleted when created")
info.Color = m.th.Color.Gray
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return info.Layout(gtx)
})
}),
)
},
func(gtx C) D {
return m.walletName.Layout(gtx)
},
func(gtx C) D {
m.spendingPassword.Editor.SingleLine = true
return m.spendingPassword.Layout(gtx)
},
}
}
func (m *ModalTemplate) removeWallet() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
info := m.th.Body1("Make sure to have the seed phrase backed up before removing the wallet")
info.Color = m.th.Color.Gray
return info.Layout(gtx)
},
}
}
func (m *ModalTemplate) Password() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
m.spendingPassword.Editor.SingleLine = true
return m.spendingPassword.Layout(gtx)
},
}
}
func (m *ModalTemplate) changePassword() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
m.oldSpendingPassword.Editor.SingleLine = true
return m.oldSpendingPassword.Layout(gtx)
},
func(gtx C) D {
m.spendingPassword.Editor.SingleLine = true
return m.spendingPassword.Layout(gtx)
},
func(gtx C) D {
return m.passwordStrength.Layout(gtx)
},
func(gtx C) D {
m.matchSpendingPassword.Editor.SingleLine = true
return m.matchSpendingPassword.Layout(gtx)
},
}
}
func (m *ModalTemplate) setStartupPassword() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
m.spendingPassword.Editor.SingleLine = true
return m.spendingPassword.Layout(gtx)
},
func(gtx C) D {
return m.passwordStrength.Layout(gtx)
},
func(gtx C) D {
m.matchSpendingPassword.Editor.SingleLine = true
return m.matchSpendingPassword.Layout(gtx)
},
}
}
func (m *ModalTemplate) verifyMessageInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
text := m.th.Body1("After you or your counterparty has genrated a signature, you can use this form to verify the" +
" validity of the signature. \n \nOnce you have entered the address, the message and the corresponding " +
"signature, you will see VALID if the signature appropriately matches the address and message, otherwise INVALID.")
text.Color = m.th.Color.Gray
return text.Layout(gtx)
},
}
}
func (m *ModalTemplate) signMessageInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
text := m.th.Body1("Signing a message with an address' private key allows you to prove that you are the owner of a given address" +
" to a possible counterparty.")
text.Color = m.th.Color.Gray
return text.Layout(gtx)
},
}
}
func (m *ModalTemplate) rescanWallet() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
text := m.th.Body1("Rescanning may help resolve some balance errors. This will take some time, as it scans the entire" +
" blockchain for transactions")
text.Color = m.th.Color.Gray
return text.Layout(gtx)
},
}
}
func (m *ModalTemplate) securityToolsInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
text := m.th.Body1("Various tools that help in different aspects of crypto currency security will be located here.")
text.Color = m.th.Color.Gray
return text.Layout(gtx)
},
}
}
func (m *ModalTemplate) sendInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
text := m.th.Body1("Input or scan the destination wallet address and input the amount to send funds.")
text.Color = m.th.Color.Gray
return text.Layout(gtx)
},
}
}
func (m *ModalTemplate) receiveInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
text := m.th.Label(values.TextSize20, "Each time you receive a payment, a new address is generated to protect your privacy.")
text.Color = m.th.Color.Gray
return text.Layout(gtx)
},
}
}
func (m *ModalTemplate) privacyInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Rigid(func(gtx C) D {
ic := mustIcon(widget.NewIcon(icons.ImageLens))
ic.Color = m.th.Color.Gray
return ic.Layout(gtx, values.MarginPadding8)
}),
layout.Rigid(func(gtx C) D {
text := m.th.Body1("When you turn on the mixer, your unmixed DCRs in this wallet (unmixed balance) will be gradually mixed.")
text.Color = m.th.Color.Gray
return layout.Inset{Left: values.MarginPadding10}.Layout(gtx, text.Layout)
}),
)
},
func(gtx C) D {
txt := m.th.Body1("Important: keep this app opened while mixer is running.")
txt.Font.Weight = text.Bold
return txt.Layout(gtx)
},
func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Rigid(func(gtx C) D {
ic := mustIcon(widget.NewIcon(icons.ImageLens))
ic.Color = m.th.Color.Gray
return ic.Layout(gtx, values.MarginPadding8)
}),
layout.Rigid(func(gtx C) D {
text := m.th.Body1("Mixer will automatically stop when unmixed balance are fully mixed.")
text.Color = m.th.Color.Gray
return layout.Inset{Left: values.MarginPadding10}.Layout(gtx, text.Layout)
}),
)
},
}
}
func (m *ModalTemplate) setupMixerInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
txt := m.th.Body1("Two dedicated accounts (“mixed” & “unmixed”) will be created in order to use the mixer.")
txt.Color = m.th.Color.Gray
return layout.Inset{Left: values.MarginPadding10}.Layout(gtx, txt.Layout)
},
func(gtx C) D {
txt := m.th.Label(values.TextSize18, "This action cannot be undone.")
return txt.Layout(gtx)
},
}
}
func (m *ModalTemplate) warnExistMixerAcct() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Inset{Top: values.MarginPadding10, Bottom: values.MarginPadding20}.Layout(gtx, func(gtx C) D {
return layout.Center.Layout(gtx, func(gtx C) D {
m.alert.Color = m.th.Color.DeepBlue
return m.alert.Layout(gtx, values.MarginPadding50)
})
})
}),
layout.Rigid(func(gtx C) D {
label := m.th.H6("Account name is taken")
label.Font.Weight = text.Bold
return label.Layout(gtx)
}),
)
},
func(gtx C) D {
txt := m.th.Body1("There are existing accounts named mixed or unmixed. Please change the name to something else for now. You can change them back after the setup.")
txt.Color = m.th.Color.Gray
return txt.Layout(gtx)
},
}
}
func (m *ModalTemplate) unlockWalletRestore() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
info := m.th.Body1("The restoration process to discover your accounts was interrupted in the last sync.")
info.Color = m.th.Color.Gray
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return info.Layout(gtx)
})
},
func(gtx C) D {
info := m.th.Body1("Unlock to resume the process.")
info.Color = m.th.Color.Gray
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
return info.Layout(gtx)
})
},
func(gtx C) D {
m.spendingPassword.Editor.SingleLine = true
return m.spendingPassword.Layout(gtx)
},
}
}
func (m *ModalTemplate) transactionDetailsInfo() []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
t := m.th.Body1("Tap on")
t.Color = m.th.Color.Gray
return t.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
t := m.th.Body1("blue text")
t.Color = m.th.Color.Primary
m := values.MarginPadding2
return layout.Inset{
Left: m,
Right: m,
}.Layout(gtx, func(gtx C) D {
return t.Layout(gtx)
})
}),
layout.Rigid(func(gtx C) D {
t := m.th.Body1("to copy the item.")
t.Color = m.th.Color.Gray
return t.Layout(gtx)
}),
)
},
}
}
func (m *ModalTemplate) Layout(th *decredmaterial.Theme, load *modalLoad) []layout.Widget {
if !load.isReset {
m.resetFields()
load.isReset = true
load.setLoading(false)
}
title := []layout.Widget{
func(gtx C) D {
txt := load.title
if load.template == TransactionDetailsInfoTemplate {
txt = "How to copy"
}
if load.template == PrivacyInfoTemplate {
txt = "How to use the mixer?"
}
t := th.H6(txt)
t.Font.Weight = text.Bold
return t.Layout(gtx)
},
}
w := m.handle(th, load)
w = append(title, w...)
w = append(w, m.actions(th, load)...)
return w
}
func (m *ModalTemplate) actions(th *decredmaterial.Theme, load *modalLoad) []layout.Widget {
return []layout.Widget{
func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if load.cancelText == "" {
return layout.Dimensions{}
}
m.cancel.Text = load.cancelText
m.cancel.Font.Weight = text.Bold
m.cancel.Background = th.Color.Surface
m.cancel.Color = th.Color.Primary
return m.cancel.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
if load.confirmText == "" {
return layout.Dimensions{}
}
m.confirm.Text = load.confirmText
if load.template == ConfirmRemoveTemplate {
m.confirm.Background, m.confirm.Color = th.Color.Surface, th.Color.Danger
}
if load.template == RescanWalletTemplate {
m.confirm.Background, m.confirm.Color = th.Color.Surface, th.Color.Primary
}
if load.loading {
th := material.NewTheme(gofont.Collection())
return layout.Inset{Top: unit.Dp(7)}.Layout(gtx, func(gtx C) D {
return material.Loader(th).Layout(gtx)
})
}
m.confirm.Font.Weight = text.Bold
return m.confirm.Layout(gtx)
}),
)
})
},
}
}
func (m *ModalTemplate) handle(th *decredmaterial.Theme, load *modalLoad) (template []layout.Widget) {
m.walletName.Editor.SingleLine = true
switch load.template {
case CreateWalletTemplate:
if m.spendingPassword.Editor.Text() == m.matchSpendingPassword.Editor.Text() {
// reset error label when password and matching password fields match
m.matchSpendingPassword.SetError("")
}
if m.editorsNotEmpty(th, m.walletName.Editor, m.spendingPassword.Editor, m.matchSpendingPassword.Editor) &&
m.confirm.Button.Clicked() {
load.setLoading(true)
if m.passwordsMatch(m.spendingPassword.Editor, m.matchSpendingPassword.Editor) {
load.confirm.(func(string, string))(m.walletName.Editor.Text(), m.spendingPassword.Editor.Text())
}
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
computePasswordStrength(&m.passwordStrength, th, m.spendingPassword.Editor)
template = m.createNewWallet()
m.walletName.Hint = "Wallet name"
return
case RenameWalletTemplate, RenameAccountTemplate, ConnectToSpecificPeerTemplate, ChangeSpecificPeerTemplate, UserAgentTemplate:
if m.editorsNotEmpty(th, m.walletName.Editor) && m.confirm.Button.Clicked() {
load.confirm.(func(string))(m.walletName.Editor.Text())
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
template = m.renameWallet()
m.walletName.Hint = "Wallet name"
if load.template == RenameAccountTemplate {
m.walletName.Hint = "Account name"
}
if load.template == ConnectToSpecificPeerTemplate || load.template == ChangeSpecificPeerTemplate {
m.walletName.Hint = "IP address"
}
if load.template == UserAgentTemplate {
m.walletName.Hint = "User agent"
}
return
case CreateAccountTemplate:
if m.editorsNotEmpty(th, m.walletName.Editor, m.spendingPassword.Editor) && m.confirm.Button.Clicked() {
load.setLoading(true)
load.confirm.(func(string, string))(m.walletName.Editor.Text(), m.spendingPassword.Editor.Text())
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
template = m.createNewAccount()
m.walletName.Hint = "Account name"
return
case PasswordTemplate, UnlockWalletTemplate, RemoveStartupPasswordTemplate:
if m.editorsNotEmpty(th, m.spendingPassword.Editor) && m.confirm.Button.Clicked() {
load.confirm.(func(string))(m.spendingPassword.Editor.Text())
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
m.spendingPassword.Hint = "Spending password"
if load.template == RemoveStartupPasswordTemplate || load.template == UnlockWalletTemplate {
m.spendingPassword.Hint = "Startup password"
}
template = m.Password()
return
case ChangePasswordTemplate, ChangeStartupPasswordTemplate:
if m.spendingPassword.Editor.Text() == m.matchSpendingPassword.Editor.Text() {
// reset error label when password and matching password fields match
m.matchSpendingPassword.SetError("")
}
if m.editorsNotEmpty(th, m.oldSpendingPassword.Editor, m.spendingPassword.Editor, m.matchSpendingPassword.Editor) &&
m.confirm.Button.Clicked() {
load.setLoading(true)
if m.passwordsMatch(m.spendingPassword.Editor, m.matchSpendingPassword.Editor) {
load.confirm.(func(string, string))(m.oldSpendingPassword.Editor.Text(), m.spendingPassword.Editor.Text())
}
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
computePasswordStrength(&m.passwordStrength, th, m.spendingPassword.Editor)
m.spendingPassword.Hint = "New spending password"
m.matchSpendingPassword.Hint = "Confirm new spending password"
if load.template == ChangeStartupPasswordTemplate {
m.oldSpendingPassword.Hint = "Old startup password"
m.spendingPassword.Hint = "New startup password"
m.matchSpendingPassword.Hint = "Confirm new startup password"
}
template = m.changePassword()
return
case ImportWatchOnlyWalletTemplate:
if m.confirm.Button.Clicked() {
load.setLoading(true)
load.confirm.(func(string, string))(m.walletName.Editor.Text(), m.extendedPublicKey.Editor.Text())
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
m.walletName.Hint = "Wallet name"
template = m.importWatchOnlyWallet()
return
case ConfirmRemoveTemplate:
m.handleButtonEvents(load)
template = m.removeWallet()
return
case VerifyMessageInfoTemplate:
m.handleButtonEvents(load)
template = m.verifyMessageInfo()
return
case SignMessageInfoTemplate:
m.handleButtonEvents(load)
template = m.signMessageInfo()
return
case RescanWalletTemplate:
m.handleButtonEvents(load)
template = m.rescanWallet()
return
case PrivacyInfoTemplate:
m.handleButtonEvents(load)
template = m.privacyInfo()
return
case SetStartupPasswordTemplate:
if m.spendingPassword.Editor.Text() == m.matchSpendingPassword.Editor.Text() {
// reset error label when password and matching password fields match
m.matchSpendingPassword.SetError("")
}
if m.editorsNotEmpty(th, m.spendingPassword.Editor, m.matchSpendingPassword.Editor) &&
m.confirm.Button.Clicked() {
if m.passwordsMatch(m.spendingPassword.Editor, m.matchSpendingPassword.Editor) {
load.confirm.(func(string))(m.spendingPassword.Editor.Text())
}
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
computePasswordStrength(&m.passwordStrength, th, m.spendingPassword.Editor)
m.spendingPassword.Hint = "Startup password"
m.matchSpendingPassword.Hint = "Confirm startup password"
template = m.setStartupPassword()
return
case SetupMixerInfoTemplate:
m.handleButtonEvents(load)
template = m.setupMixerInfo()
return
case ConfirmMixerAcctExistTemplate:
m.handleButtonEvents(load)
template = m.warnExistMixerAcct()
return
case UnlockWalletRestoreTemplate:
if m.editorsNotEmpty(th, m.spendingPassword.Editor) && m.confirm.Button.Clicked() {
load.confirm.(func(string))(m.spendingPassword.Editor.Text())
}
m.spendingPassword.Hint = "Spending password"
template = m.unlockWalletRestore()
return
case SendInfoTemplate:
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
template = m.sendInfo()
return
case ReceiveInfoTemplate:
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
template = m.receiveInfo()
return
case TransactionDetailsInfoTemplate:
m.handleButtonEvents(load)
template = m.transactionDetailsInfo()
return
default:
return
}
}
func (m *ModalTemplate) handleButtonEvents(load *modalLoad) {
if m.confirm.Button.Clicked() {
load.confirm.(func())()
}
if m.cancel.Button.Clicked() {
load.cancel.(func())()
}
}
// editorsNotEmpty checks that the editor fields are not empty. It returns false if they are empty and true if they are
// not and false if it doesn't. It sets the background of the confirm button to decredmaterial Hint color if fields
// are empty. It sets it to decredmaterial Primary color if they are not empty.
func (m *ModalTemplate) editorsNotEmpty(th *decredmaterial.Theme, editors ...*widget.Editor) bool {
m.confirm.Color = th.Color.Surface
for _, e := range editors {
if e.Text() == "" {
m.confirm.Background = th.Color.Hint
return false
}
}
m.confirm.Background = th.Color.Primary
return true
}
// passwordMatches checks that the password and matching password field matches. It returns true if it matches
// and false if it doesn't. It sets the background of the confirm button to decredmaterial Hint color if the passwords
// don't match. It sets it to decredmaterial Primary color if the passwords match.
func (m *ModalTemplate) passwordsMatch(editors ...*widget.Editor) bool {
if len(editors) < 2 {
return false
}
password := editors[0]
matching := editors[1]
if password.Text() != matching.Text() {
m.matchSpendingPassword.SetError("passwords do not match")
return false
}
m.matchSpendingPassword.SetError("")
return true
}
// resetFields clears all modal fields when the modal is closed
func (m *ModalTemplate) resetFields() {
m.matchSpendingPassword.Editor.SetText("")
m.spendingPassword.Editor.SetText("")
m.walletName.Editor.SetText("")
m.matchSpendingPassword.SetError("")
m.oldSpendingPassword.Editor.SetText("")
m.extendedPublicKey.Editor.SetText("")
}