Skip to content

Commit

Permalink
clean up cryptolive
Browse files Browse the repository at this point in the history
  • Loading branch information
jeangovil authored and senorprogrammer committed Jun 4, 2018
1 parent 6a35f12 commit adbb8ea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
10 changes: 10 additions & 0 deletions cryptolive/cryptolive.go
Expand Up @@ -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,
})
}
43 changes: 24 additions & 19 deletions cryptolive/widget.go
Expand Up @@ -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,
})
}

widget.list = &list{
items: currencies,
toList := getToList(currency)
widget.list.addItem(currency, displayName, toList)
}

return &widget
}

/* -------------------- Exported Functions -------------------- */
Expand Down Expand Up @@ -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
}

0 comments on commit adbb8ea

Please sign in to comment.