-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
95 lines (86 loc) · 1.87 KB
/
main.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
package main
import (
"math"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/container"
"fyne.io/fyne/dialog"
"fyne.io/fyne/theme"
"github.com/hectorchu/gonano/rpc"
"github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
func main() {
f := app.New()
f.SetIcon(resourceNanoPng)
win := f.NewWindow("Gonano v0.1.13")
if err := initConfig(); err != nil {
dialog.ShowError(err, win)
}
go loadTokens(win)
al := newAccountList(win)
wl := newWalletList(win, al)
al.wl = wl
split := container.NewHSplit(wl.widget, al.widget)
split.SetOffset(0)
win.SetContent(split)
win.Resize(fyne.NewSize(1000, 600))
win.CenterOnScreen()
win.ShowAndRun()
}
var lightTheme bool
var rpcURL string
func initConfig() (err error) {
home, err := homedir.Dir()
if err != nil {
return
}
viper.AddConfigPath(home)
viper.SetConfigName(".gonano-gui")
viper.SetConfigType("yaml")
if err = viper.ReadInConfig(); err != nil {
err = viper.SafeWriteConfig()
}
lightTheme = viper.GetBool("lightTheme")
setTheme()
chooseRPC()
return
}
func setTheme() {
t := theme.DarkTheme()
if lightTheme {
t = theme.LightTheme()
}
fyne.CurrentApp().Settings().SetTheme(t)
}
func toggleTheme() {
lightTheme = !lightTheme
setTheme()
viper.Set("lightTheme", lightTheme)
viper.WriteConfig()
}
func chooseRPC() {
var n uint64 = math.MaxUint64
for _, url := range []string{
"https://gonano.dev/rpc",
"https://mynano.ninja/api/node",
"https://proxy.nanos.cc/proxy",
"https://proxy.powernode.cc/proxy",
"https://rainstorm.city/api",
} {
rpcClient := rpc.Client{URL: url}
if _, _, unchecked, err := rpcClient.BlockCount(); err == nil && unchecked < n {
rpcURL = url
n = unchecked
}
}
}
func loadTokens(win fyne.Window) {
prog := dialog.NewProgressInfinite("Gonano", "Loading tokens...", win)
prog.Show()
err := tcm.load()
prog.Hide()
if err != nil {
dialog.ShowError(err, win)
}
}