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:
parent
bc967be9e2
commit
6227b2bcdb
@ -57,7 +57,7 @@ func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
|
|||||||
market: coercedVal["market"].([]interface{}),
|
market: coercedVal["market"].([]interface{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.currencies[key] = currency
|
settings.summary.currencies[key] = currency
|
||||||
}
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/wtfutil/wtf/cfg"
|
"github.com/wtfutil/wtf/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configKey = "price"
|
const configKey = "cryptolive"
|
||||||
|
|
||||||
type colors struct {
|
type colors struct {
|
||||||
from struct {
|
from struct {
|
||||||
@ -29,23 +29,22 @@ type colors struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type currency struct {
|
||||||
|
displayName string
|
||||||
|
to []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
colors
|
colors
|
||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
currencies map[string]interface{}
|
currencies map[string]*currency
|
||||||
top map[string]interface{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
|
||||||
localConfig, _ := ymlConfig.Get("wtf.mods." + configKey)
|
localConfig, _ := ymlConfig.Get("wtf.mods." + configKey)
|
||||||
|
|
||||||
currencies, _ := localConfig.Map("currencies")
|
|
||||||
top, _ := localConfig.Map("top")
|
|
||||||
|
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
common: cfg.NewCommonSettingsFromYAML(name, configKey, ymlConfig),
|
common: cfg.NewCommonSettingsFromYAML(name, configKey, ymlConfig),
|
||||||
currencies: currencies,
|
|
||||||
top: top,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.colors.from.name = localConfig.UString("colors.from.name")
|
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.field = localConfig.UString("colors.top.to.field")
|
||||||
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
|
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 := ¤cy{
|
||||||
|
displayName: coercedVal["displayName"].(string),
|
||||||
|
to: coercedVal["to"].([]interface{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.currencies[key] = currency
|
||||||
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var baseURL = "https://min-api.cryptocompare.com/data/price"
|
var baseURL = "https://min-api.cryptocompare.com/data/price"
|
||||||
@ -37,12 +35,10 @@ func NewWidget(settings *Settings) *Widget {
|
|||||||
func (widget *Widget) setList() {
|
func (widget *Widget) setList() {
|
||||||
widget.list = &list{}
|
widget.list = &list{}
|
||||||
|
|
||||||
for currency := range widget.settings.currencies {
|
for symbol, currency := range widget.settings.currencies {
|
||||||
displayName, _ := wtf.Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
|
toList := widget.getToList(symbol)
|
||||||
toList := getToList(currency)
|
widget.list.addItem(symbol, currency.displayName, toList)
|
||||||
widget.list.addItem(currency, displayName, toList)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
@ -91,12 +87,10 @@ func (widget *Widget) display() {
|
|||||||
widget.Result = fmt.Sprintf("\n%s", str)
|
widget.Result = fmt.Sprintf("\n%s", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getToList(fromName string) []*toCurrency {
|
func (widget *Widget) getToList(symbol string) []*toCurrency {
|
||||||
toNames, _ := wtf.Config.List("wtf.mods.cryptolive.currencies." + fromName + ".to")
|
|
||||||
|
|
||||||
var toList []*toCurrency
|
var toList []*toCurrency
|
||||||
|
|
||||||
for _, to := range toNames {
|
for _, to := range widget.settings.currencies[symbol].to {
|
||||||
toList = append(toList, &toCurrency{
|
toList = append(toList, &toCurrency{
|
||||||
name: to.(string),
|
name: to.(string),
|
||||||
price: 0,
|
price: 0,
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/wtfutil/wtf/cfg"
|
"github.com/wtfutil/wtf/cfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configKey = "toplist"
|
const configKey = "cryptolive"
|
||||||
|
|
||||||
type colors struct {
|
type colors struct {
|
||||||
from struct {
|
from struct {
|
||||||
@ -29,23 +29,24 @@ type colors struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type currency struct {
|
||||||
|
displayName string
|
||||||
|
limit int
|
||||||
|
to []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
colors
|
colors
|
||||||
common *cfg.Common
|
common *cfg.Common
|
||||||
currencies map[string]interface{}
|
currencies map[string]*currency
|
||||||
top map[string]interface{}
|
top map[string]*currency
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(name string, ymlConfig *config.Config) *Settings {
|
||||||
localConfig, _ := ymlConfig.Get("wtf.mods." + configKey)
|
localConfig, _ := ymlConfig.Get("wtf.mods." + configKey)
|
||||||
|
|
||||||
currencies, _ := localConfig.Map("currencies")
|
|
||||||
top, _ := localConfig.Map("top")
|
|
||||||
|
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
common: cfg.NewCommonSettingsFromYAML(name, configKey, ymlConfig),
|
common: cfg.NewCommonSettingsFromYAML(name, configKey, ymlConfig),
|
||||||
currencies: currencies,
|
|
||||||
top: top,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
settings.colors.from.name = localConfig.UString("colors.from.name")
|
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.field = localConfig.UString("colors.top.to.field")
|
||||||
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
|
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 := ¤cy{
|
||||||
|
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 := ¤cy{
|
||||||
|
displayName: coercedVal["displayName"].(string),
|
||||||
|
limit: limit,
|
||||||
|
to: coercedVal["to"].([]interface{}),
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.currencies[key] = currency
|
||||||
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var baseURL = "https://min-api.cryptocompare.com/data/top/exchanges"
|
var baseURL = "https://min-api.cryptocompare.com/data/top/exchanges"
|
||||||
@ -36,19 +34,16 @@ func NewWidget(settings *Settings) *Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) setList() {
|
func (widget *Widget) setList() {
|
||||||
for fromCurrency := range widget.settings.top {
|
for symbol, currency := range widget.settings.top {
|
||||||
displayName := wtf.Config.UString("wtf.mods.cryptolive.top."+fromCurrency+".displayName", "")
|
toList := widget.makeToList(symbol, currency.limit)
|
||||||
limit := wtf.Config.UInt("wtf.mods.cryptolive.top."+fromCurrency+".limit", 1)
|
widget.list.addItem(symbol, currency.displayName, currency.limit, toList)
|
||||||
widget.list.addItem(fromCurrency, displayName, limit, makeToList(fromCurrency, limit))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeToList(fCurrencyName string, limit int) (list []*tCurrency) {
|
func (widget *Widget) makeToList(symbol string, limit int) (list []*tCurrency) {
|
||||||
toList, _ := wtf.Config.List("wtf.mods.cryptolive.top." + fCurrencyName + ".to")
|
for _, to := range widget.settings.top[symbol].to {
|
||||||
|
|
||||||
for _, toCurrency := range toList {
|
|
||||||
list = append(list, &tCurrency{
|
list = append(list, &tCurrency{
|
||||||
name: toCurrency.(string),
|
name: to.(string),
|
||||||
info: make([]tInfo, limit),
|
info: make([]tInfo, limit),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user