mirror of https://github.com/miguelmota/cointop
Clean up
parent
bedbda8e00
commit
4ef4f7aa54
@ -0,0 +1,61 @@
|
|||||||
|
package cointop
|
||||||
|
|
||||||
|
// Coin is the row structure
|
||||||
|
type Coin struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
Slug string
|
||||||
|
Symbol string
|
||||||
|
Rank int
|
||||||
|
Price float64
|
||||||
|
Volume24H float64
|
||||||
|
MarketCap float64
|
||||||
|
AvailableSupply float64
|
||||||
|
TotalSupply float64
|
||||||
|
PercentChange1H float64
|
||||||
|
PercentChange24H float64
|
||||||
|
PercentChange7D float64
|
||||||
|
LastUpdated string
|
||||||
|
// for favorites
|
||||||
|
Favorite bool
|
||||||
|
// for portfolio
|
||||||
|
Holdings float64
|
||||||
|
Balance float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Cointop) allCoins() []*Coin {
|
||||||
|
if ct.State.filterByFavorites {
|
||||||
|
var list []*Coin
|
||||||
|
for i := range ct.State.allCoins {
|
||||||
|
coin := ct.State.allCoins[i]
|
||||||
|
if coin.Favorite {
|
||||||
|
list = append(list, coin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
if ct.State.portfolioVisible {
|
||||||
|
var list []*Coin
|
||||||
|
for i := range ct.State.allCoins {
|
||||||
|
coin := ct.State.allCoins[i]
|
||||||
|
if ct.PortfolioEntryExists(coin) {
|
||||||
|
list = append(list, coin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
return ct.State.allCoins
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Cointop) coinBySymbol(symbol string) *Coin {
|
||||||
|
for i := range ct.State.allCoins {
|
||||||
|
coin := ct.State.allCoins[i]
|
||||||
|
if coin.Symbol == symbol {
|
||||||
|
return coin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package cointop
|
||||||
|
|
||||||
|
func (ct *Cointop) selectedCoinName() string {
|
||||||
|
coin := ct.State.selectedCoin
|
||||||
|
if coin != nil {
|
||||||
|
return coin.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Cointop) selectedCoinSymbol() string {
|
||||||
|
coin := ct.State.selectedCoin
|
||||||
|
if coin != nil {
|
||||||
|
return coin.Symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
@ -1,24 +0,0 @@
|
|||||||
package cointop
|
|
||||||
|
|
||||||
// Coin is the row structure
|
|
||||||
type Coin struct {
|
|
||||||
ID string
|
|
||||||
Name string
|
|
||||||
Slug string
|
|
||||||
Symbol string
|
|
||||||
Rank int
|
|
||||||
Price float64
|
|
||||||
Volume24H float64
|
|
||||||
MarketCap float64
|
|
||||||
AvailableSupply float64
|
|
||||||
TotalSupply float64
|
|
||||||
PercentChange1H float64
|
|
||||||
PercentChange24H float64
|
|
||||||
PercentChange7D float64
|
|
||||||
LastUpdated string
|
|
||||||
// for favorites
|
|
||||||
Favorite bool
|
|
||||||
// for portfolio
|
|
||||||
Holdings float64
|
|
||||||
Balance float64
|
|
||||||
}
|
|
@ -0,0 +1,39 @@
|
|||||||
|
package cointop
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jroimartin/gocui"
|
||||||
|
)
|
||||||
|
|
||||||
|
// View is a cointop view
|
||||||
|
type View struct {
|
||||||
|
Backing *gocui.View
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Cointop) setActiveView(v string) error {
|
||||||
|
ct.g.SetViewOnTop(v)
|
||||||
|
ct.g.SetCurrentView(v)
|
||||||
|
if v == ct.Views.SearchField.Name {
|
||||||
|
ct.Views.SearchField.Backing.Clear()
|
||||||
|
ct.Views.SearchField.Backing.SetCursor(1, 0)
|
||||||
|
fmt.Fprintf(ct.Views.SearchField.Backing, "%s", "/")
|
||||||
|
} else if v == ct.Views.Table.Name {
|
||||||
|
ct.g.SetViewOnTop(ct.Views.Statusbar.Name)
|
||||||
|
}
|
||||||
|
if v == ct.Views.PortfolioUpdateMenu.Name {
|
||||||
|
ct.g.SetViewOnTop(ct.Views.Input.Name)
|
||||||
|
ct.g.SetCurrentView(ct.Views.Input.Name)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Cointop) activeViewName() string {
|
||||||
|
return ct.g.CurrentView().Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ct *Cointop) setViewOnBottom(v string) error {
|
||||||
|
_, err := ct.g.SetViewOnBottom(v)
|
||||||
|
return err
|
||||||
|
}
|
Loading…
Reference in New Issue