diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go index 3f6f4d92..7bb83b3a 100644 --- a/cryptoexchanges/bittrex/widget.go +++ b/cryptoexchanges/bittrex/widget.go @@ -28,7 +28,7 @@ type TextColors struct { var ok = true var errorText = "" -var started = false + var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary" // Widget define wtf widget to register widget later @@ -40,13 +40,11 @@ type Widget struct { // NewWidget Make new instance of widget func NewWidget() *Widget { - widget := Widget{ TextWidget: wtf.NewTextWidget(" Bittrex ", "bittrex", false), summaryList: summaryList{}, } - started = false ok = true errorText = "" @@ -106,20 +104,9 @@ func (widget *Widget) Refresh() { return } - if started == false { - go func() { - for { - widget.updateSummary() - time.Sleep(time.Second * time.Duration(widget.RefreshInterval())) - } - }() - started = true - } - + widget.updateSummary() widget.UpdateRefreshedAt() - widget.display() - } /* -------------------- Unexported Functions -------------------- */ diff --git a/cryptoexchanges/cryptolive/widget.go b/cryptoexchanges/cryptolive/widget.go index e58b9435..732f6863 100644 --- a/cryptoexchanges/cryptolive/widget.go +++ b/cryptoexchanges/cryptolive/widget.go @@ -13,7 +13,6 @@ import ( // Config is a pointer to the global config object var Config *config.Config -var started = false var baseURL = "https://min-api.cryptocompare.com/data/price" var ok = true @@ -26,7 +25,6 @@ type Widget struct { // NewWidget Make new instance of widget func NewWidget() *Widget { - started = false widget := Widget{ TextWidget: wtf.NewTextWidget(" CryptoLive ", "cryptolive", false), } @@ -36,19 +34,6 @@ func NewWidget() *Widget { return &widget } -func (widget *Widget) setList() { - currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies") - - widget.list = &list{} - - for currency := range currenciesMap { - displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName") - toList := getToList(currency) - widget.list.addItem(currency, displayName, toList) - } - -} - /* -------------------- Exported Functions -------------------- */ // Refresh & update after interval time @@ -57,21 +42,8 @@ func (widget *Widget) Refresh() { return } - if started == false { - // this code should run once - go func() { - for { - widget.updateCurrencies() - time.Sleep(time.Duration(widget.RefreshInterval()) * time.Second) - } - }() - - } - - started = true - + widget.updateCurrencies() widget.UpdateRefreshedAt() - widget.View.Clear() if !ok { widget.View.SetText( @@ -79,12 +51,13 @@ func (widget *Widget) Refresh() { ) return } - display(widget) + + widget.display() } /* -------------------- Unexported Functions -------------------- */ -func display(widget *Widget) { +func (widget *Widget) display() { str := "" var ( fromNameColor = Config.UString("wtf.mods.cryptolive.colors.from.name", "coral") @@ -118,6 +91,18 @@ func getToList(fromName string) []*toCurrency { return toList } +func (widget *Widget) setList() { + currenciesMap, _ := Config.Map("wtf.mods.cryptolive.currencies") + + widget.list = &list{} + + for currency := range currenciesMap { + displayName, _ := Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName") + toList := getToList(currency) + widget.list.addItem(currency, displayName, toList) + } +} + func (widget *Widget) updateCurrencies() { defer func() { recover() @@ -149,7 +134,7 @@ func (widget *Widget) updateCurrencies() { setPrices(&jsonResponse, fromCurrency) } - display(widget) + widget.display() } func makeRequest(currency *fromCurrency) *http.Request {