-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsctoken.go
104 lines (91 loc) · 2.76 KB
/
bsctoken.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
package settingss
import (
"errors"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"github.com/ocoderr/bsc-tool/config"
"github.com/spf13/viper"
"strings"
)
// SyrupScreen account info
var BscTokenListSelectIndex int = -1
func BscTokenTab(w fyne.Window) *fyne.Container {
KeyBingData, KeyInput := NewStrEntryWithData()
ValueBingData, ValueInput := NewStrEntryWithData()
list := widget.NewList(
func() int { return len(config.CF.BscToken) },
func() fyne.CanvasObject {
symbol := widget.NewLabel("List item x")
address := widget.NewLabel("List item x")
return container.NewHBox(symbol, address)
},
func(index widget.ListItemID, template fyne.CanvasObject) {
cont := template.(*fyne.Container)
label := cont.Objects[0].(*widget.Label)
label.SetText(config.BscTokenKeyIndex(index))
label = cont.Objects[1].(*widget.Label)
label.SetText(config.BscTokenValueIndex(index))
})
list.OnSelected = func(index widget.ListItemID) {
BscTokenListSelectIndex = index
}
list.OnUnselected = func(index widget.ListItemID) {
BscTokenListSelectIndex = -1
}
AddBtn := widget.NewButton("Add", func() {
keyBing, _ := KeyBingData.Get()
valueBing, _ := ValueBingData.Get()
keyBing = strings.ToLower(keyBing)
valueBing = strings.ToLower(valueBing)
if keyBing != "" && valueBing != "" {
config.CF.BscToken[keyBing] = valueBing
config.SaveValue(fmt.Sprintf("bsctoken.%s", keyBing), valueBing)
list.Refresh()
list.UnselectAll()
BscTokenListSelectIndex = -1
KeyBingData.Set("")
ValueBingData.Set("")
}
})
DeleteBtn := widget.NewButton("Delete", func() {
if BscTokenListSelectIndex >= 0 {
key := config.BscTokenKeyIndex(BscTokenListSelectIndex)
if key != "" {
key = strings.ToLower(key)
if key == "busd" || key == "wbnb" || key == "usdt" || key == "cake" {
list.Refresh()
list.UnselectAll()
BscTokenListSelectIndex = -1
dialog.ShowError(errors.New(fmt.Sprintf("can not delete %s", key)), w)
return
}
delete(config.CF.BscToken, key)
delete(viper.Get("bsctoken").(map[string]interface{}), key)
viper.WriteConfig()
list.Refresh()
list.UnselectAll()
BscTokenListSelectIndex = -1
}
}
})
content := container.NewBorder(container.NewVBox(
widget.NewForm(
&widget.FormItem{Text: "Symbol:", Widget: KeyInput},
&widget.FormItem{Text: "Address:", Widget: ValueInput},
),
container.NewGridWithColumns(2, AddBtn, DeleteBtn),
), nil, nil, nil, list,
)
return content
}
func NewStrEntryWithData() (binding.String, *widget.Entry) {
dataAddress := binding.NewString()
addEntry := widget.NewEntryWithData(dataAddress)
//widget.NewEntry()
//addEntry.Disable()
return dataAddress, addEntry
}