forked from wildone/btcgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overview.go
209 lines (177 loc) · 4.74 KB
/
overview.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
/*
* Copyright (c) 2013, 2014 Conformal Systems LLC <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package main
import (
"fmt"
"github.com/conformal/gotk3/gtk"
"log"
)
const NOverviewTxs = 5
var (
// Overview holds pointers to widgets shown in the overview tab.
Overview = struct {
Balance *gtk.Label
Unconfirmed *gtk.Label
NTransactions *gtk.Label // TODO(jrick): update with value from btcwallet, requires extension.
Txs *gtk.Grid
TxList []*gtk.Widget
}{
TxList: make([]*gtk.Widget, 0, NOverviewTxs),
}
// Holds pointers to the latest tx label widgets.
)
func createWalletInfo() *gtk.Widget {
grid, err := gtk.GridNew()
if err != nil {
log.Fatal(err)
}
header, err := gtk.LabelNew("")
if err != nil {
log.Fatal(err)
}
header.SetMarkup("<b>Wallet</b>")
header.OverrideFont("sans-serif 16")
header.SetHAlign(gtk.ALIGN_START)
grid.Attach(header, 0, 0, 1, 1)
balance, err := gtk.LabelNew("Balance:")
if err != nil {
log.Fatal(err)
}
balance.SetHAlign(gtk.ALIGN_START)
grid.Attach(balance, 0, 1, 1, 1)
unconfirmed, err := gtk.LabelNew("Unconfirmed:")
if err != nil {
log.Fatal(err)
}
unconfirmed.SetHAlign(gtk.ALIGN_START)
grid.Attach(unconfirmed, 0, 2, 1, 1)
balance, err = gtk.LabelNew("")
if err != nil {
log.Fatal(err)
}
balance.SetHAlign(gtk.ALIGN_START)
grid.Attach(balance, 1, 1, 1, 1)
Overview.Balance = balance
unconfirmed, err = gtk.LabelNew("")
if err != nil {
log.Fatal(err)
}
grid.Attach(unconfirmed, 1, 2, 1, 1)
Overview.Unconfirmed = unconfirmed
/*
transactions, err := gtk.LabelNew("Number of transactions:")
if err != nil {
log.Fatal(err)
}
transactions.SetHAlign(gtk.ALIGN_START)
grid.Attach(transactions, 0, 3, 1, 1)
transactions, err = gtk.LabelNew("a lot")
if err != nil {
log.Fatal(err)
}
transactions.SetHAlign(gtk.ALIGN_START)
grid.Attach(transactions, 1, 3, 1, 1)
Overview.NTransactions = transactions
*/
return &grid.Container.Widget
}
func createTxInfo() *gtk.Widget {
grid, err := gtk.GridNew()
if err != nil {
log.Fatal(err)
}
grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
l, err := gtk.LabelNew("")
if err != nil {
log.Fatal(err)
}
l.SetMarkup("<b>Recent Transactions</b>")
l.OverrideFont("sans-serif 10")
l.SetHAlign(gtk.ALIGN_START)
grid.Add(l)
txGrid, err := gtk.GridNew()
if err != nil {
log.Fatal(err)
}
txGrid.SetOrientation(gtk.ORIENTATION_VERTICAL)
grid.Add(txGrid)
Overview.Txs = txGrid
return &grid.Container.Widget
}
func createTxLabel(attr *TxAttributes) (*gtk.Widget, error) {
grid, err := gtk.GridNew()
if err != nil {
return nil, err
}
grid.SetHExpand(true)
var amtLabel *gtk.Label
var description *gtk.Label
var icon *gtk.Image
switch attr.Direction {
case Send:
amtLabel, err = gtk.LabelNew(attr.Amount.String())
if err != nil {
return nil, err
}
description, err = gtk.LabelNew(fmt.Sprintf("Send (%s)", attr.Address))
if err != nil {
return nil, err
}
icon, err = gtk.ImageNewFromIconName("go-next",
gtk.ICON_SIZE_SMALL_TOOLBAR)
if err != nil {
return nil, err
}
case Recv:
amtLabel, err = gtk.LabelNew(attr.Amount.String())
if err != nil {
return nil, err
}
description, err = gtk.LabelNew(fmt.Sprintf("Receive (%s)", attr.Address))
if err != nil {
return nil, err
}
icon, err = gtk.ImageNewFromIconName("go-previous",
gtk.ICON_SIZE_SMALL_TOOLBAR)
if err != nil {
return nil, err
}
}
grid.Attach(icon, 0, 0, 2, 2)
grid.Attach(description, 2, 1, 2, 1)
description.SetHAlign(gtk.ALIGN_START)
grid.Attach(amtLabel, 3, 0, 1, 1)
amtLabel.SetHAlign(gtk.ALIGN_END)
amtLabel.SetHExpand(true)
date, err := gtk.LabelNew(attr.Date.Format("Jan 2, 2006 at 3:04 PM"))
if err != nil {
return nil, err
}
grid.Attach(date, 2, 0, 1, 1)
date.SetHAlign(gtk.ALIGN_START)
grid.SetHAlign(gtk.ALIGN_FILL)
return &grid.Container.Widget, nil
}
func createOverview() *gtk.Widget {
grid, err := gtk.GridNew()
if err != nil {
log.Fatal(err)
}
grid.SetColumnHomogeneous(true)
grid.Add(createWalletInfo())
grid.Add(createTxInfo())
return &grid.Container.Widget
}