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

@ -57,7 +57,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
market: coercedVal["market"].([]interface{}),
}
settings.currencies[key] = currency
settings.summary.currencies[key] = currency
}
return &settings

View File

@ -5,7 +5,7 @@ import (
"github.com/wtfutil/wtf/cfg"
)
const configKey = "price"
const configKey = "cryptolive"
type colors struct {
from struct {
@ -29,23 +29,22 @@ type colors struct {
}
}
type currency struct {
displayName string
to []interface{}
}
type Settings struct {
colors
common *cfg.Common
currencies map[string]interface{}
top map[string]interface{}
currencies 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 +60,18 @@ 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{})
currency := &currency{
displayName: coercedVal["displayName"].(string),
to: coercedVal["to"].([]interface{}),
}
settings.currencies[key] = currency
}
return &settings
}

View File

@ -6,8 +6,6 @@ import (
"net/http"
"sync"
"time"
"github.com/wtfutil/wtf/wtf"
)
var baseURL = "https://min-api.cryptocompare.com/data/price"
@ -37,12 +35,10 @@ func NewWidget(settings *Settings) *Widget {
func (widget *Widget) setList() {
widget.list = &list{}
for currency := range widget.settings.currencies {
displayName, _ := wtf.Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
toList := getToList(currency)
widget.list.addItem(currency, displayName, toList)
for symbol, currency := range widget.settings.currencies {
toList := widget.getToList(symbol)
widget.list.addItem(symbol, currency.displayName, toList)
}
}
/* -------------------- Exported Functions -------------------- */
@ -91,12 +87,10 @@ func (widget *Widget) display() {
widget.Result = fmt.Sprintf("\n%s", str)
}
func getToList(fromName string) []*toCurrency {
toNames, _ := wtf.Config.List("wtf.mods.cryptolive.currencies." + fromName + ".to")
func (widget *Widget) getToList(symbol string) []*toCurrency {
var toList []*toCurrency
for _, to := range toNames {
for _, to := range widget.settings.currencies[symbol].to {
toList = append(toList, &toCurrency{
name: to.(string),
price: 0,

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),
})
}