Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max_pages parameter to config file #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions cointop/cointop.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type State struct {
keepRowFocusOnSort bool
lastSelectedRowIndex int
marketBarHeight int
maxPages int
maxPages uint
page int
perPage int
portfolio *Portfolio
Expand Down Expand Up @@ -282,7 +282,7 @@ func NewCointop(config *Config) (*Cointop, error) {
hidePortfolioBalances: config.HidePortfolioBalances,
keepRowFocusOnSort: false,
marketBarHeight: 1,
maxPages: int(maxPages),
maxPages: maxPages,
onlyTable: config.OnlyTable,
onlyChart: config.OnlyChart,
refreshRate: 60 * time.Second,
Expand Down Expand Up @@ -423,7 +423,7 @@ func NewCointop(config *Config) (*Cointop, error) {
if ct.apiChoice == CoinMarketCap {
ct.api = api.NewCMC(ct.apiKeys.cmc)
} else if ct.apiChoice == CoinGecko {
ct.api = api.NewCG(perPage, maxPages)
ct.api = api.NewCG(perPage, ct.State.maxPages)
} else {
return nil, ErrInvalidAPIChoice
}
Expand Down
12 changes: 12 additions & 0 deletions cointop/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ConfigFileConfig struct {
CompactNotation interface{} `toml:"compact_notation"`
EnableMouse interface{} `toml:"enable_mouse"`
AltCoinLink interface{} `toml:"alt_coin_link"` // TODO: should really be in API-specific section
MaxPages interface{} `toml:"max_pages"`
Table map[string]interface{} `toml:"table"`
Chart map[string]interface{} `toml:"chart"`
}
Expand Down Expand Up @@ -79,6 +80,7 @@ func (ct *Cointop) SetupConfig() error {
ct.loadAltCoinLinkFromConfig,
ct.loadPriceAlertsFromConfig,
ct.loadPortfolioFromConfig,
ct.loadMaxPagesFromConfig,
}

for _, f := range loaders {
Expand Down Expand Up @@ -302,6 +304,7 @@ func (ct *Cointop) ConfigToToml() ([]byte, error) {
CompactNotation: ct.State.compactNotation,
EnableMouse: ct.State.enableMouse,
AltCoinLink: ct.State.altCoinLink,
MaxPages: ct.State.maxPages,
}

var b bytes.Buffer
Expand Down Expand Up @@ -746,6 +749,15 @@ func (ct *Cointop) loadPriceAlertsFromConfig() error {
return nil
}

func (ct *Cointop) loadMaxPagesFromConfig() error {
log.Debug("loadMaxPagesFromConfig()")
if MaxPages, ok := ct.config.MaxPages.(int64); ok {
ct.State.maxPages = uint(MaxPages)
}

return nil
}

// GetColorschemeColors loads colors from colorscheme file to struct
func (ct *Cointop) GetColorschemeColors() (map[string]interface{}, error) {
log.Debug("GetColorschemeColors()")
Expand Down