You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cointop/cointop/favorites.go

46 lines
836 B
Go

package cointop
func (ct *Cointop) toggleFavorite() error {
5 years ago
ct.State.portfolioVisible = false
coin := ct.HighlightedRowCoin()
if coin == nil {
return nil
}
5 years ago
_, ok := ct.State.favorites[coin.Name]
if ok {
5 years ago
delete(ct.State.favorites, coin.Name)
coin.Favorite = false
} else {
5 years ago
ct.State.favorites[coin.Name] = true
coin.Favorite = true
}
5 years ago
go ct.updateTable()
if err := ct.save(); err != nil {
return err
}
return nil
}
func (ct *Cointop) toggleShowFavorites() error {
5 years ago
ct.State.portfolioVisible = false
ct.State.filterByFavorites = !ct.State.filterByFavorites
5 years ago
go ct.updateTable()
return nil
}
func (ct *Cointop) getFavoritesSlice() []*Coin {
sliced := []*Coin{}
for i := range ct.State.allCoins {
coin := ct.State.allCoins[i]
if coin.Favorite {
sliced = append(sliced, coin)
}
}
return sliced
}