mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Bittrex extracted to new config format
This commit is contained in:
parent
fbf89448af
commit
3db2848169
3
main.go
3
main.go
@ -187,7 +187,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
case "bargraph":
|
||||
widget = bargraph.NewWidget(app)
|
||||
case "bittrex":
|
||||
widget = bittrex.NewWidget(app)
|
||||
cfg := bittrex.NewSettingsFromYAML(wtf.Config)
|
||||
widget = bittrex.NewWidget(app, cfg)
|
||||
case "blockfolio":
|
||||
widget = blockfolio.NewWidget(app)
|
||||
case "circleci":
|
||||
|
@ -12,14 +12,21 @@ func (widget *Widget) display() {
|
||||
return
|
||||
}
|
||||
|
||||
widget.View.SetText(summaryText(&widget.summaryList, &widget.TextColors))
|
||||
summaryText := widget.summaryText(&widget.summaryList)
|
||||
widget.View.SetText(summaryText)
|
||||
}
|
||||
|
||||
func summaryText(list *summaryList, colors *TextColors) string {
|
||||
func (widget *Widget) summaryText(list *summaryList) string {
|
||||
str := ""
|
||||
|
||||
for _, baseCurrency := range list.items {
|
||||
str += fmt.Sprintf(" [%s]%s[%s] (%s)\n\n", colors.base.displayName, baseCurrency.displayName, colors.base.name, baseCurrency.name)
|
||||
str += fmt.Sprintf(
|
||||
" [%s]%s[%s] (%s)\n\n",
|
||||
widget.settings.colors.base.displayName,
|
||||
baseCurrency.displayName,
|
||||
widget.settings.colors.base.name,
|
||||
baseCurrency.name,
|
||||
)
|
||||
|
||||
resultTemplate := template.New("bittrex")
|
||||
|
||||
@ -38,9 +45,9 @@ func summaryText(list *summaryList, colors *TextColors) string {
|
||||
)
|
||||
|
||||
strTemplate.Execute(writer, map[string]string{
|
||||
"nameColor": colors.market.name,
|
||||
"fieldColor": colors.market.field,
|
||||
"valueColor": colors.market.value,
|
||||
"nameColor": widget.settings.colors.market.name,
|
||||
"fieldColor": widget.settings.colors.market.field,
|
||||
"valueColor": widget.settings.colors.market.value,
|
||||
"mName": marketCurrency.name,
|
||||
"High": marketCurrency.High,
|
||||
"Low": marketCurrency.Low,
|
||||
|
45
modules/cryptoexchanges/bittrex/settings.go
Normal file
45
modules/cryptoexchanges/bittrex/settings.go
Normal file
@ -0,0 +1,45 @@
|
||||
package bittrex
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
base struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
market struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
|
||||
summary map[string]interface{}
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.bittrex")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
}
|
||||
|
||||
settings.colors.base.name = localConfig.UString("colors.base.name")
|
||||
settings.colors.base.displayName = localConfig.UString("colors.base.displayName")
|
||||
|
||||
settings.colors.market.name = localConfig.UString("colors.market.name")
|
||||
settings.colors.market.field = localConfig.UString("colors.market.field")
|
||||
settings.colors.market.value = localConfig.UString("colors.market.value")
|
||||
|
||||
summaryMap, _ := ymlConfig.Map("summary")
|
||||
settings.summary = summaryMap
|
||||
|
||||
return &settings
|
||||
}
|
@ -11,56 +11,38 @@ import (
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
type TextColors struct {
|
||||
base struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
market struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
|
||||
var ok = true
|
||||
var errorText = ""
|
||||
|
||||
var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary"
|
||||
const baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary"
|
||||
|
||||
// Widget define wtf widget to register widget later
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
settings *Settings
|
||||
summaryList
|
||||
TextColors
|
||||
}
|
||||
|
||||
// NewWidget Make new instance of widget
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, "Bittrex", "bittrex", false),
|
||||
TextWidget: wtf.NewTextWidget(app, "Bittrex", "bittrex", false),
|
||||
|
||||
settings: settings,
|
||||
summaryList: summaryList{},
|
||||
}
|
||||
|
||||
ok = true
|
||||
errorText = ""
|
||||
|
||||
widget.config()
|
||||
widget.setSummaryList()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
func (widget *Widget) config() {
|
||||
widget.TextColors.base.name = wtf.Config.UString("wtf.mods.bittrex.colors.base.name", "red")
|
||||
widget.TextColors.base.displayName = wtf.Config.UString("wtf.mods.bittrex.colors.base.displayName", "grey")
|
||||
widget.TextColors.market.name = wtf.Config.UString("wtf.mods.bittrex.colors.market.name", "red")
|
||||
widget.TextColors.market.field = wtf.Config.UString("wtf.mods.bittrex.colors.market.field", "coral")
|
||||
widget.TextColors.market.value = wtf.Config.UString("wtf.mods.bittrex.colors.market.value", "white")
|
||||
}
|
||||
|
||||
func (widget *Widget) setSummaryList() {
|
||||
sCurrencies, _ := wtf.Config.Map("wtf.mods.bittrex.summary")
|
||||
sCurrencies := widget.settings.summary
|
||||
for baseCurrencyName := range sCurrencies {
|
||||
displayName, _ := wtf.Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName")
|
||||
mCurrencyList := makeSummaryMarketList(baseCurrencyName)
|
||||
|
@ -6,17 +6,17 @@ import (
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
Common *cfg.Common
|
||||
common *cfg.Common
|
||||
|
||||
FilePath string
|
||||
filePath string
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
|
||||
|
||||
settings := Settings{
|
||||
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
FilePath: localConfig.UString("filename"),
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
filePath: localConfig.UString("filename"),
|
||||
}
|
||||
|
||||
return &settings
|
||||
|
@ -53,7 +53,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
filePath: settings.FilePath,
|
||||
filePath: settings.filePath,
|
||||
list: checklist.NewChecklist(),
|
||||
pages: pages,
|
||||
}
|
||||
@ -257,8 +257,8 @@ func (widget *Widget) modalFocus(form *tview.Form) {
|
||||
}
|
||||
|
||||
func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
||||
form := tview.NewForm().SetFieldBackgroundColor(wtf.ColorFor(widget.settings.Common.Colors.Background))
|
||||
form.SetButtonsAlign(tview.AlignCenter).SetButtonTextColor(wtf.ColorFor(widget.settings.Common.Colors.Text))
|
||||
form := tview.NewForm().SetFieldBackgroundColor(wtf.ColorFor(widget.settings.common.Colors.Background))
|
||||
form.SetButtonsAlign(tview.AlignCenter).SetButtonTextColor(wtf.ColorFor(widget.settings.common.Colors.Text))
|
||||
|
||||
form.AddInputField(lbl, text, 60, nil, nil)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user