/
account_details_page.go
281 lines (262 loc) · 8.71 KB
/
account_details_page.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
package ui
import (
"fmt"
"strings"
"gioui.org/layout"
"gioui.org/widget"
"github.com/decred/dcrd/dcrutil"
"github.com/planetdecred/godcr/ui/decredmaterial"
"github.com/planetdecred/godcr/ui/values"
"github.com/planetdecred/godcr/wallet"
)
const PageAccountDetails = "AccountDetails"
type acctDetailsPage struct {
wallet *wallet.Wallet
current wallet.InfoShort
theme *decredmaterial.Theme
acctDetailsPageContainer layout.List
backButton decredmaterial.IconButton
acctInfo **wallet.Account
editAccount *widget.Clickable
errorReceiver chan error
}
func (win *Window) AcctDetailsPage(common pageCommon) layout.Widget {
pg := &acctDetailsPage{
acctDetailsPageContainer: layout.List{
Axis: layout.Vertical,
},
wallet: common.wallet,
acctInfo: &win.walletAccount,
theme: common.theme,
backButton: common.theme.PlainIconButton(new(widget.Clickable), common.icons.navigationArrowBack),
editAccount: new(widget.Clickable),
errorReceiver: make(chan error),
}
pg.backButton.Color = common.theme.Color.Text
pg.backButton.Inset = layout.UniformInset(values.MarginPadding0)
return func(gtx C) D {
pg.Handler(gtx, common)
return pg.Layout(gtx, common)
}
}
func (pg *acctDetailsPage) Layout(gtx layout.Context, common pageCommon) layout.Dimensions {
widgets := []func(gtx C) D{
func(gtx C) D {
return pg.accountBalanceLayout(gtx, &common)
},
func(gtx C) D {
m := values.MarginPadding10
return layout.Inset{Top: m, Bottom: m}.Layout(gtx, func(gtx C) D {
return pg.theme.Separator().Layout(gtx)
})
},
func(gtx C) D {
return pg.accountInfoLayout(gtx)
},
}
title := "Not found"
if *pg.acctInfo != nil {
title = (*pg.acctInfo).Name
}
acctName := strings.Title(strings.ToLower(title))
body := func(gtx C) D {
page := SubPage{
title: acctName,
walletName: common.info.Wallets[*common.selectedWallet].Name,
back: func() {
common.changePage(PageWallet)
},
body: func(gtx C) D {
return layout.Inset{Bottom: values.MarginPadding7}.Layout(gtx, func(gtx C) D {
return pg.theme.Card().Layout(gtx, func(gtx C) D {
return layout.Inset{Top: values.MarginPadding5}.Layout(gtx, func(gtx C) D {
if *pg.acctInfo == nil {
return layout.Dimensions{}
}
return pg.acctDetailsPageContainer.Layout(gtx, len(widgets), func(gtx C, i int) D {
return layout.Inset{}.Layout(gtx, widgets[i])
})
})
})
})
},
extraItem: pg.editAccount,
extra: func(gtx C) D {
return layout.Inset{}.Layout(gtx, func(gtx C) D {
edit := common.icons.editIcon
edit.Scale = 1
return layout.E.Layout(gtx, func(gtx C) D {
return edit.Layout(gtx)
})
})
},
}
return common.SubPageLayout(gtx, page)
}
return common.Layout(gtx, func(gtx C) D {
return common.UniformPadding(gtx, body)
})
}
func (pg *acctDetailsPage) accountBalanceLayout(gtx layout.Context, common *pageCommon) layout.Dimensions {
totalBalanceMain, totalBalanceSub := breakBalance(common.printer, (*pg.acctInfo).TotalBalance)
spendable := dcrutil.Amount((*pg.acctInfo).SpendableBalance).String()
spendableMain, spendableSub := breakBalance(common.printer, spendable)
immatureRewards := dcrutil.Amount((*pg.acctInfo).Balance.ImmatureReward).String()
rewardBalanceMain, rewardBalanceSub := breakBalance(common.printer, immatureRewards)
lockedByTickets := dcrutil.Amount((*pg.acctInfo).Balance.LockedByTickets).String()
lockBalanceMain, lockBalanceSub := breakBalance(common.printer, lockedByTickets)
votingAuthority := dcrutil.Amount((*pg.acctInfo).Balance.VotingAuthority).String()
voteBalanceMain, voteBalanceSub := breakBalance(common.printer, votingAuthority)
immatureStakeGen := dcrutil.Amount((*pg.acctInfo).Balance.ImmatureStakeGeneration).String()
stakeBalanceMain, stakeBalanceSub := breakBalance(common.printer, immatureStakeGen)
return pg.pageSections(gtx, func(gtx C) D {
accountIcon := common.icons.accountIcon
if (*pg.acctInfo).Name == "imported" {
accountIcon = common.icons.importedAccountIcon
}
accountIcon.Scale = 1
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
m := values.MarginPadding10
return layout.Inset{
Right: m,
Top: m,
}.Layout(gtx, func(gtx C) D {
return accountIcon.Layout(gtx)
})
}),
layout.Rigid(func(gtx C) D {
return pg.acctBalLayout(gtx, "Total Balance", totalBalanceMain, totalBalanceSub, true)
}),
)
}),
layout.Rigid(func(gtx C) D {
return pg.acctBalLayout(gtx, "Spendable", spendableMain, spendableSub, false)
}),
layout.Rigid(func(gtx C) D {
return pg.acctBalLayout(gtx, "Immature Rewards", rewardBalanceMain, rewardBalanceSub, false)
}),
layout.Rigid(func(gtx C) D {
return pg.acctBalLayout(gtx, "Locked By Tickets", lockBalanceMain, lockBalanceSub, false)
}),
layout.Rigid(func(gtx C) D {
return pg.acctBalLayout(gtx, "Voting Authority", voteBalanceMain, voteBalanceSub, false)
}),
layout.Rigid(func(gtx C) D {
return pg.acctBalLayout(gtx, "Immature Stake Gen", stakeBalanceMain, stakeBalanceSub, false)
}),
)
})
}
func (pg *acctDetailsPage) acctBalLayout(gtx layout.Context, balType string, mainBalance, subBalance string, isFirst bool) layout.Dimensions {
mainLabel := pg.theme.Body1(mainBalance)
subLabel := pg.theme.Caption(subBalance)
subLabel.Color = pg.theme.Color.DeepBlue
marginTop := values.MarginPadding16
marginLeft := values.MarginPadding35
if isFirst {
mainLabel = pg.theme.H4(mainBalance)
subLabel = pg.theme.Body1(subBalance)
marginTop = values.MarginPadding0
marginLeft = values.MarginPadding0
}
return layout.Inset{
Right: values.MarginPadding10,
Top: marginTop,
Left: marginLeft,
}.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Flex{Alignment: layout.Baseline}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return mainLabel.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
return subLabel.Layout(gtx)
}),
)
}),
layout.Rigid(func(gtx C) D {
txt := pg.theme.Body2(balType)
txt.Color = pg.theme.Color.Gray
return txt.Layout(gtx)
}),
)
})
}
func (pg *acctDetailsPage) accountInfoLayout(gtx layout.Context) layout.Dimensions {
return pg.pageSections(gtx, func(gtx C) D {
m := values.MarginPadding10
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return pg.acctInfoLayout(gtx, "Account Number", fmt.Sprint((*pg.acctInfo).Number))
}),
layout.Rigid(func(gtx C) D {
inset := layout.Inset{
Top: m,
Bottom: m,
}
return inset.Layout(gtx, func(gtx C) D {
return pg.acctInfoLayout(gtx, "HD Path", (*pg.acctInfo).HDPath)
})
}),
layout.Rigid(func(gtx C) D {
inset := layout.Inset{
Bottom: m,
}
return inset.Layout(gtx, func(gtx C) D {
ext := (*pg.acctInfo).Keys.External
int := (*pg.acctInfo).Keys.Internal
imp := (*pg.acctInfo).Keys.Imported
return pg.acctInfoLayout(gtx, "Key", ext+" external, "+int+" internal, "+imp+" imported")
})
}),
)
})
}
func (pg *acctDetailsPage) acctInfoLayout(gtx layout.Context, leftText, rightText string) layout.Dimensions {
return layout.Flex{}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
layout.Rigid(func(gtx C) D {
leftTextLabel := pg.theme.Label(values.TextSize14, leftText)
leftTextLabel.Color = pg.theme.Color.Gray
return leftTextLabel.Layout(gtx)
}),
)
}),
layout.Flexed(1, func(gtx C) D {
return layout.E.Layout(gtx, func(gtx C) D {
return pg.theme.Body1(rightText).Layout(gtx)
})
}),
)
}
func (pg *acctDetailsPage) pageSections(gtx layout.Context, body layout.Widget) layout.Dimensions {
m := values.MarginPadding20
mtb := values.MarginPadding5
return layout.Inset{Left: m, Right: m, Top: mtb, Bottom: mtb}.Layout(gtx, body)
}
func (pg *acctDetailsPage) Handler(gtx layout.Context, common pageCommon) {
if pg.backButton.Button.Clicked() {
common.changePage(PageWallet)
}
if pg.editAccount.Clicked() {
pg.current = common.info.Wallets[*common.selectedWallet]
go func() {
common.modalReceiver <- &modalLoad{
template: RenameAccountTemplate,
title: "Rename account",
confirm: func(name string) {
pg.wallet.RenameAccount(pg.current.ID, (*pg.acctInfo).Number, name, pg.errorReceiver)
(*pg.acctInfo).Name = name
},
confirmText: "Rename",
cancel: common.closeModal,
cancelText: "Cancel",
}
}()
}
}