Rename Stocks to Markets

Also fix bug that would remove markets if a network request failed
and not show them again until Glance was restarted
This commit is contained in:
Svilen Markov
2024-05-28 18:01:26 +01:00
parent d2f5dbbc26
commit 1bebb88d0e
9 changed files with 74 additions and 68 deletions

View File

@@ -85,20 +85,24 @@ var currencyToSymbol = map[string]string{
"PHP": "₱",
}
type Stock struct {
Name string `yaml:"name"`
Symbol string `yaml:"symbol"`
ChartLink string `yaml:"chart-link"`
SymbolLink string `yaml:"symbol-link"`
type MarketRequest struct {
Name string `yaml:"name"`
Symbol string `yaml:"symbol"`
ChartLink string `yaml:"chart-link"`
SymbolLink string `yaml:"symbol-link"`
}
type Market struct {
MarketRequest
Currency string `yaml:"-"`
Price float64 `yaml:"-"`
PercentChange float64 `yaml:"-"`
SvgChartPoints string `yaml:"-"`
}
type Stocks []Stock
type Markets []Market
func (t Stocks) SortByAbsChange() {
func (t Markets) SortByAbsChange() {
sort.Slice(t, func(i, j int) bool {
return math.Abs(t[i].PercentChange) > math.Abs(t[j].PercentChange)
})