1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 Blockfolio extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-13 17:58:32 -07:00
parent 3db2848169
commit 1630fb96b7
3 changed files with 74 additions and 18 deletions

View File

@ -190,7 +190,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
cfg := bittrex.NewSettingsFromYAML(wtf.Config)
widget = bittrex.NewWidget(app, cfg)
case "blockfolio":
widget = blockfolio.NewWidget(app)
cfg := blockfolio.NewSettingsFromYAML(wtf.Config)
widget = blockfolio.NewWidget(app, cfg)
case "circleci":
cfg := circleci.NewSettingsFromYAML(wtf.Config)
widget = circleci.NewWidget(app, cfg)

View File

@ -0,0 +1,33 @@
package blockfolio
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
type colors struct {
name string
grows string
drop string
}
type Settings struct {
colors
common *cfg.Common
deviceToken string
displayHoldings bool
}
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.todo")
settings := Settings{
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
deviceToken: localConfig.UString("device_token"),
displayHoldings: localConfig.UBool("displayHoldings", true),
}
return &settings
}

View File

@ -15,12 +15,15 @@ type Widget struct {
wtf.TextWidget
device_token string
settings *Settings
}
func NewWidget(app *tview.Application) *Widget {
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, "Blockfolio", "blockfolio", false),
device_token: wtf.Config.UString("wtf.mods.blockfolio.device_token"),
TextWidget: wtf.NewTextWidget(app, "Blockfolio", "blockfolio", false),
device_token: settings.deviceToken,
settings: settings,
}
return &widget
@ -36,31 +39,50 @@ func (widget *Widget) Refresh() {
return
}
widget.View.SetText(contentFrom(positions))
content := widget.contentFrom(positions)
widget.View.SetText(content)
}
/* -------------------- Unexported Functions -------------------- */
func contentFrom(positions *AllPositionsResponse) string {
func (widget *Widget) contentFrom(positions *AllPositionsResponse) string {
res := ""
colorName := wtf.Config.UString("wtf.mods.blockfolio.colors.name")
colorGrows := wtf.Config.UString("wtf.mods.blockfolio.colors.grows")
colorDrop := wtf.Config.UString("wtf.mods.blockfolio.colors.drop")
displayHoldings := wtf.Config.UBool("wtf.mods.blockfolio.displayHoldings")
var totalFiat float32
totalFiat = 0.0
totalFiat := float32(0.0)
for i := 0; i < len(positions.PositionList); i++ {
colorForChange := colorGrows
colorForChange := widget.settings.colors.grows
if positions.PositionList[i].TwentyFourHourPercentChangeFiat <= 0 {
colorForChange = colorDrop
colorForChange = widget.settings.colors.drop
}
totalFiat += positions.PositionList[i].HoldingValueFiat
if displayHoldings {
res = res + fmt.Sprintf("[%s]%-6s - %5.2f ([%s]%.3fk [%s]%.2f%s)\n", colorName, positions.PositionList[i].Coin, positions.PositionList[i].Quantity, colorForChange, positions.PositionList[i].HoldingValueFiat/1000, colorForChange, positions.PositionList[i].TwentyFourHourPercentChangeFiat, "%")
if widget.settings.displayHoldings {
res = res + fmt.Sprintf(
"[%s]%-6s - %5.2f ([%s]%.3fk [%s]%.2f%s)\n",
widget.settings.colors.name,
positions.PositionList[i].Coin,
positions.PositionList[i].Quantity,
colorForChange,
positions.PositionList[i].HoldingValueFiat/1000,
colorForChange,
positions.PositionList[i].TwentyFourHourPercentChangeFiat,
"%",
)
} else {
res = res + fmt.Sprintf("[%s]%-6s - %5.2f ([%s]%.2f%s)\n", colorName, positions.PositionList[i].Coin, positions.PositionList[i].Quantity, colorForChange, positions.PositionList[i].TwentyFourHourPercentChangeFiat, "%")
res = res + fmt.Sprintf(
"[%s]%-6s - %5.2f ([%s]%.2f%s)\n",
widget.settings.colors.name,
positions.PositionList[i].Coin,
positions.PositionList[i].Quantity,
colorForChange,
positions.PositionList[i].TwentyFourHourPercentChangeFiat,
"%",
)
}
}
if displayHoldings {
if widget.settings.displayHoldings {
res = res + fmt.Sprintf("\n[%s]Total value: $%.3fk", "green", totalFiat/1000)
}