Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions modules/cryptocurrency/mempool/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@ package mempool
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/utils"
)

const (
defaultFocusable = false
defaultTitle = "mempool"
defaultAPIURL = "https://mempool.space/api/v1/fees/recommended"
)

// Settings defines the configuration properties for this module
type Settings struct {
common *cfg.Common

// Define your settings attributes here
apiURL string `help:"Fee recommendation endpoint URL." optional:"true"`
}

// NewSettingsFromYAML creates a new settings instance from a YAML config block
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),

// Configure your settings attributes here. See http://github.com/olebedev/config for type details
apiURL: ymlConfig.UString("apiURL", defaultAPIURL),
}

return &settings
}

func (widget *Widget) ConfigText() string {
return utils.HelpFromInterface(Settings{})
}
15 changes: 7 additions & 8 deletions modules/cryptocurrency/mempool/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,22 @@ func (widget *Widget) Refresh() {
/* -------------------- Unexported Functions -------------------- */

func (widget *Widget) content() string {
return getBTCTxFees()
return getBTCTxFees(widget.settings.apiURL)
}

func getBTCTxFees() string {
url := "https://mempool.space/api/v1/fees/recommended"
resp, err := http.Get(url)
func getBTCTxFees(apiURL string) string {
resp, err := http.Get(apiURL)
if err != nil {
logger.Log(fmt.Sprintf("[mempool] Error: Failed to make request to mempool. Reason: %s", err))
return "[mempool] error callng mempool API"
logger.Log(fmt.Sprintf("[mempool] Error: Failed to make request to fee API. Reason: %s", err))
return "[mempool] error calling fee API"
}
defer resp.Body.Close()

parsed := feeStruct{}
err = utils.ParseJSON(&parsed, resp.Body)
if err != nil {
logger.Log(fmt.Sprintf("[mempool] Error: Failed to decode JSON data from mempool. Reason: %s", err))
return "[mempool] error parsing JSON from mempool API"
logger.Log(fmt.Sprintf("[mempool] Error: Failed to decode JSON data from fee API. Reason: %s", err))
return "[mempool] error parsing JSON from fee API"
}

finalStr := ""
Expand Down
Loading