diff --git a/cryptolive/cryptolive.go b/cryptolive/cryptolive.go index adc99660..462c144e 100644 --- a/cryptolive/cryptolive.go +++ b/cryptolive/cryptolive.go @@ -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, + }) +} diff --git a/cryptolive/widget.go b/cryptolive/widget.go index 09e01985..0766e63a 100644 --- a/cryptolive/widget.go +++ b/cryptolive/widget.go @@ -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 +}