1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 Remove last of wtf.Config from CryptoLive

This commit is contained in:
Chris Cummer
2019-04-19 11:37:55 -07:00
parent bc967be9e2
commit 6227b2bcdb
5 changed files with 73 additions and 41 deletions

View File

@@ -5,7 +5,7 @@ import (
"github.com/wtfutil/wtf/cfg"
)
const configKey = "toplist"
const configKey = "cryptolive"
type colors struct {
from struct {
@@ -29,23 +29,24 @@ type colors struct {
}
}
type currency struct {
displayName string
limit int
to []interface{}
}
type Settings struct {
colors
common *cfg.Common
currencies map[string]interface{}
top map[string]interface{}
currencies map[string]*currency
top map[string]*currency
}
func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods." + configKey)
currencies, _ := localConfig.Map("currencies")
top, _ := localConfig.Map("top")
settings := Settings{
common: cfg.NewCommonSettingsFromYAML(name, configKey, ymlConfig),
currencies: currencies,
top: top,
common: cfg.NewCommonSettingsFromYAML(name, configKey, ymlConfig),
}
settings.colors.from.name = localConfig.UString("colors.from.name")
@@ -61,5 +62,35 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
settings.colors.top.to.field = localConfig.UString("colors.top.to.field")
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
settings.currencies = make(map[string]*currency)
for key, val := range localConfig.UMap("currencies") {
coercedVal := val.(map[string]interface{})
limit, _ := coercedVal["limit"].(int)
currency := &currency{
displayName: coercedVal["displayName"].(string),
limit: limit,
to: coercedVal["to"].([]interface{}),
}
settings.currencies[key] = currency
}
for key, val := range localConfig.UMap("top") {
coercedVal := val.(map[string]interface{})
limit, _ := coercedVal["limit"].(int)
currency := &currency{
displayName: coercedVal["displayName"].(string),
limit: limit,
to: coercedVal["to"].([]interface{}),
}
settings.currencies[key] = currency
}
return &settings
}

View File

@@ -7,8 +7,6 @@ import (
"os"
"sync"
"time"
"github.com/wtfutil/wtf/wtf"
)
var baseURL = "https://min-api.cryptocompare.com/data/top/exchanges"
@@ -36,19 +34,16 @@ func NewWidget(settings *Settings) *Widget {
}
func (widget *Widget) setList() {
for fromCurrency := range widget.settings.top {
displayName := wtf.Config.UString("wtf.mods.cryptolive.top."+fromCurrency+".displayName", "")
limit := wtf.Config.UInt("wtf.mods.cryptolive.top."+fromCurrency+".limit", 1)
widget.list.addItem(fromCurrency, displayName, limit, makeToList(fromCurrency, limit))
for symbol, currency := range widget.settings.top {
toList := widget.makeToList(symbol, currency.limit)
widget.list.addItem(symbol, currency.displayName, currency.limit, toList)
}
}
func makeToList(fCurrencyName string, limit int) (list []*tCurrency) {
toList, _ := wtf.Config.List("wtf.mods.cryptolive.top." + fCurrencyName + ".to")
for _, toCurrency := range toList {
func (widget *Widget) makeToList(symbol string, limit int) (list []*tCurrency) {
for _, to := range widget.settings.top[symbol].to {
list = append(list, &tCurrency{
name: toCurrency.(string),
name: to.(string),
info: make([]tInfo, limit),
})
}