mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
clean up cryptolive
This commit is contained in:
parent
6a35f122a3
commit
adbb8eab52
@ -42,3 +42,13 @@ type cResponse struct {
|
||||
USD float32 `json:"USD"`
|
||||
EUR float32 `json:"EUR"`
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (l *list) addItem(name string, displayName string, to []*toCurrency) {
|
||||
l.items = append(l.items, &fromCurrency{
|
||||
name: name,
|
||||
displayName: displayName,
|
||||
to: to,
|
||||
})
|
||||
}
|
||||
|
@ -33,32 +33,22 @@ func NewWidget() *Widget {
|
||||
updateInterval: Config.UInt("wtf.mods.cryptolive.updateInterval", 10),
|
||||
}
|
||||
|
||||
widget.setList()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
func (widget *Widget) setList() {
|
||||
currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies")
|
||||
|
||||
var currencies []*fromCurrency
|
||||
widget.list = &list{}
|
||||
|
||||
for currency := range currenciesMap {
|
||||
displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
|
||||
toCList, _ := Config.List("wtf.mods.cryptolive.currencies." + currency + ".to")
|
||||
var toList []*toCurrency
|
||||
for _, v := range toCList {
|
||||
toList = append(toList, &toCurrency{
|
||||
name: v.(string),
|
||||
price: -1,
|
||||
})
|
||||
}
|
||||
currencies = append(currencies, &fromCurrency{
|
||||
name: currency,
|
||||
displayName: displayName,
|
||||
to: toList,
|
||||
})
|
||||
toList := getToList(currency)
|
||||
widget.list.addItem(currency, displayName, toList)
|
||||
}
|
||||
|
||||
widget.list = &list{
|
||||
items: currencies,
|
||||
}
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
@ -130,3 +120,18 @@ func (widget *Widget) updateCurrencies() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func getToList(fromName string) []*toCurrency {
|
||||
toNames, _ := Config.List("wtf.mods.cryptolive.currencies." + fromName + ".to")
|
||||
|
||||
var toList []*toCurrency
|
||||
|
||||
for _, to := range toNames {
|
||||
toList = append(toList, &toCurrency{
|
||||
name: to.(string),
|
||||
price: -1,
|
||||
})
|
||||
}
|
||||
|
||||
return toList
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user