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":
|
case "bargraph":
|
||||||
widget = bargraph.NewWidget(app)
|
widget = bargraph.NewWidget(app)
|
||||||
case "bittrex":
|
case "bittrex":
|
||||||
widget = bittrex.NewWidget(app)
|
cfg := bittrex.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = bittrex.NewWidget(app, cfg)
|
||||||
case "blockfolio":
|
case "blockfolio":
|
||||||
widget = blockfolio.NewWidget(app)
|
widget = blockfolio.NewWidget(app)
|
||||||
case "circleci":
|
case "circleci":
|
||||||
|
@ -12,14 +12,21 @@ func (widget *Widget) display() {
|
|||||||
return
|
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 := ""
|
str := ""
|
||||||
|
|
||||||
for _, baseCurrency := range list.items {
|
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")
|
resultTemplate := template.New("bittrex")
|
||||||
|
|
||||||
@ -38,9 +45,9 @@ func summaryText(list *summaryList, colors *TextColors) string {
|
|||||||
)
|
)
|
||||||
|
|
||||||
strTemplate.Execute(writer, map[string]string{
|
strTemplate.Execute(writer, map[string]string{
|
||||||
"nameColor": colors.market.name,
|
"nameColor": widget.settings.colors.market.name,
|
||||||
"fieldColor": colors.market.field,
|
"fieldColor": widget.settings.colors.market.field,
|
||||||
"valueColor": colors.market.value,
|
"valueColor": widget.settings.colors.market.value,
|
||||||
"mName": marketCurrency.name,
|
"mName": marketCurrency.name,
|
||||||
"High": marketCurrency.High,
|
"High": marketCurrency.High,
|
||||||
"Low": marketCurrency.Low,
|
"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"
|
"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 ok = true
|
||||||
var errorText = ""
|
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
|
// Widget define wtf widget to register widget later
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
settings *Settings
|
||||||
summaryList
|
summaryList
|
||||||
TextColors
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget(app *tview.Application) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(app, "Bittrex", "bittrex", false),
|
TextWidget: wtf.NewTextWidget(app, "Bittrex", "bittrex", false),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
summaryList: summaryList{},
|
summaryList: summaryList{},
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
errorText = ""
|
errorText = ""
|
||||||
|
|
||||||
widget.config()
|
|
||||||
widget.setSummaryList()
|
widget.setSummaryList()
|
||||||
|
|
||||||
return &widget
|
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() {
|
func (widget *Widget) setSummaryList() {
|
||||||
sCurrencies, _ := wtf.Config.Map("wtf.mods.bittrex.summary")
|
sCurrencies := widget.settings.summary
|
||||||
for baseCurrencyName := range sCurrencies {
|
for baseCurrencyName := range sCurrencies {
|
||||||
displayName, _ := wtf.Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName")
|
displayName, _ := wtf.Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName")
|
||||||
mCurrencyList := makeSummaryMarketList(baseCurrencyName)
|
mCurrencyList := makeSummaryMarketList(baseCurrencyName)
|
||||||
|
@ -6,17 +6,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
Common *cfg.Common
|
common *cfg.Common
|
||||||
|
|
||||||
FilePath string
|
filePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||||
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
|
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
|
||||||
|
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||||
FilePath: localConfig.UString("filename"),
|
filePath: localConfig.UString("filename"),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &settings
|
return &settings
|
||||||
|
@ -53,7 +53,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
filePath: settings.FilePath,
|
filePath: settings.filePath,
|
||||||
list: checklist.NewChecklist(),
|
list: checklist.NewChecklist(),
|
||||||
pages: pages,
|
pages: pages,
|
||||||
}
|
}
|
||||||
@ -257,8 +257,8 @@ func (widget *Widget) modalFocus(form *tview.Form) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
func (widget *Widget) modalForm(lbl, text string) *tview.Form {
|
||||||
form := tview.NewForm().SetFieldBackgroundColor(wtf.ColorFor(widget.settings.Common.Colors.Background))
|
form := tview.NewForm().SetFieldBackgroundColor(wtf.ColorFor(widget.settings.common.Colors.Background))
|
||||||
form.SetButtonsAlign(tview.AlignCenter).SetButtonTextColor(wtf.ColorFor(widget.settings.Common.Colors.Text))
|
form.SetButtonsAlign(tview.AlignCenter).SetButtonTextColor(wtf.ColorFor(widget.settings.common.Colors.Text))
|
||||||
|
|
||||||
form.AddInputField(lbl, text, 60, nil, nil)
|
form.AddInputField(lbl, text, 60, nil, nil)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user