pull/20/head
Miguel Mota 6 years ago
parent 1a81f7edfc
commit b0e44a999f

@ -55,6 +55,10 @@ In action
## Installing ## Installing
There are multiple ways you can install cointop depending on the platform you're on.
## From source (always latest)
Make sure to have [go](https://golang.org/) (1.9+) installed, then do: Make sure to have [go](https://golang.org/) (1.9+) installed, then do:
```bash ```bash
@ -94,7 +98,7 @@ sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub
Install cointop flatpak Install cointop flatpak
```bash ```bash
sudo flatpak install cointop com.github.miguelmota.Cointop sudo flatpak install flathub com.github.miguelmota.Cointop
``` ```
Run cointop flatpak Run cointop flatpak

@ -42,7 +42,8 @@ type Cointop struct {
api api.Interface api api.Interface
allcoins []*coin allcoins []*coin
coins []*coin coins []*coin
allcoinsmap map[string]*coin allcoinssymbolmap map[string]*coin
allcoinsslugmap map[string]*coin
page int page int
perpage int perpage int
refreshmux sync.Mutex refreshmux sync.Mutex
@ -144,10 +145,10 @@ func New() *Cointop {
log.Fatal(err) log.Fatal(err)
} }
allcoinsmap := map[string]apitypes.Coin{} allcoinsslugmap := map[string]apitypes.Coin{}
coinscachekey := "allcoinsmap" coinscachekey := "allcoinsslugmap"
fcache.Get(coinscachekey, &allcoinsmap) fcache.Get(coinscachekey, &allcoinsslugmap)
ct.cache.Set(coinscachekey, allcoinsmap, 10*time.Second) ct.cache.Set(coinscachekey, allcoinsslugmap, 10*time.Second)
var globaldata []float64 var globaldata []float64
chartcachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.selectedchartrange, " ", "", -1))) chartcachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.selectedchartrange, " ", "", -1)))

@ -20,11 +20,12 @@ var supportedfiatconversions = map[string]string{
"KRW": "South Korean Won", "KRW": "South Korean Won",
"NZD": "New Zealand Dollar", "NZD": "New Zealand Dollar",
"CFH": "Swiss Franc", "CFH": "Swiss Franc",
"NOK": "Norwegian Krone",
"MXN": "Mexican Peso", "MXN": "Mexican Peso",
"AUD": "Australian Dollar", "AUD": "Australian Dollar",
"IDR": "Indonesian Rupiah", "IDR": "Indonesian Rupiah",
"RUB": "Russian Ruble", "RUB": "Russian Ruble",
"CAD": "Canadian dollar", "CAD": "Canadian Dollar",
"MYR": "Malaysian Ringgit", "MYR": "Malaysian Ringgit",
} }

@ -17,6 +17,7 @@ var currencysymbols = map[string]string{
"KRW": "₩", "KRW": "₩",
"NZD": "$", "NZD": "$",
"CFH": "₣", "CFH": "₣",
"NOK": "kr",
"MXN": "$", "MXN": "$",
"AUD": "$", "AUD": "$",
"IDR": "Rp.", "IDR": "Rp.",

@ -74,9 +74,9 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
go func() { go func() {
ct.updateCoins() ct.updateCoins()
ct.updateTable() ct.updateTable()
_, found := ct.cache.Get("allcoinsmap") _, found := ct.cache.Get("allcoinsslugmap")
if found { if found {
ct.cache.Delete("allcoinsmap") ct.cache.Delete("allcoinsslugmap")
ct.updateCoins() ct.updateCoins()
ct.updateTable() ct.updateTable()
} }

@ -14,36 +14,36 @@ func (ct *Cointop) updateCoins() error {
coinslock.Lock() coinslock.Lock()
defer coinslock.Unlock() defer coinslock.Unlock()
list := []*coin{} list := []*coin{}
cachekey := "allcoinsmap" cachekey := "allcoinsslugmap"
var err error var err error
var allcoinsmap map[string]types.Coin var allcoinsslugmap map[string]types.Coin
cached, found := ct.cache.Get(cachekey) cached, found := ct.cache.Get(cachekey)
if found { if found {
// cache hit // cache hit
allcoinsmap, _ = cached.(map[string]types.Coin) allcoinsslugmap, _ = cached.(map[string]types.Coin)
ct.debuglog("soft cache hit") ct.debuglog("soft cache hit")
} }
// cache miss // cache miss
if allcoinsmap == nil { if allcoinsslugmap == nil {
ct.debuglog("cache miss") ct.debuglog("cache miss")
allcoinsmap, err = ct.api.GetAllCoinData(ct.currencyconversion) allcoinsslugmap, err = ct.api.GetAllCoinData(ct.currencyconversion)
if err != nil { if err != nil {
return err return err
} }
ct.cache.Set(cachekey, allcoinsmap, 10*time.Second) ct.cache.Set(cachekey, allcoinsslugmap, 10*time.Second)
go func() { go func() {
_ = fcache.Set(cachekey, allcoinsmap, 24*time.Hour) _ = fcache.Set(cachekey, allcoinsslugmap, 24*time.Hour)
}() }()
} }
if len(ct.allcoinsmap) == 0 { if len(ct.allcoinsslugmap) == 0 {
ct.allcoinsmap = map[string]*coin{} ct.allcoinsslugmap = map[string]*coin{}
} }
for k, v := range allcoinsmap { for k, v := range allcoinsslugmap {
last := ct.allcoinsmap[k] last := ct.allcoinsslugmap[k]
ct.allcoinsmap[k] = &coin{ ct.allcoinsslugmap[k] = &coin{
ID: v.ID, ID: v.ID,
Name: v.Name, Name: v.Name,
Symbol: v.Symbol, Symbol: v.Symbol,
@ -59,20 +59,20 @@ func (ct *Cointop) updateCoins() error {
LastUpdated: v.LastUpdated, LastUpdated: v.LastUpdated,
} }
if last != nil { if last != nil {
ct.allcoinsmap[k].Favorite = last.Favorite ct.allcoinsslugmap[k].Favorite = last.Favorite
} }
} }
if len(ct.allcoins) == 0 { if len(ct.allcoins) == 0 {
for i := range ct.allcoinsmap { for i := range ct.allcoinsslugmap {
coin := ct.allcoinsmap[i] coin := ct.allcoinsslugmap[i]
list = append(list, coin) list = append(list, coin)
} }
ct.allcoins = list ct.allcoins = list
ct.sort(ct.sortby, ct.sortdesc, ct.allcoins) ct.sort(ct.sortby, ct.sortdesc, ct.allcoins)
} else { } else {
// update list in place without changing order // update list in place without changing order
for i := range ct.allcoinsmap { for i := range ct.allcoinsslugmap {
cm := ct.allcoinsmap[i] cm := ct.allcoinsslugmap[i]
for k := range ct.allcoins { for k := range ct.allcoins {
c := ct.allcoins[k] c := ct.allcoins[k]
if c.ID == cm.ID { if c.ID == cm.ID {

@ -14,7 +14,8 @@ func (ct *Cointop) refreshAll() error {
ct.refreshmux.Lock() ct.refreshmux.Lock()
defer ct.refreshmux.Unlock() defer ct.refreshmux.Unlock()
ct.setRefreshStatus() ct.setRefreshStatus()
ct.cache.Delete("allcoinsmap") ct.cache.Delete("allcoinsslugmap")
ct.cache.Delete("allcoinssymbolmap")
ct.cache.Delete("market") ct.cache.Delete("market")
ct.updateCoins() ct.updateCoins()
ct.updateTable() ct.updateTable()

@ -103,8 +103,8 @@ func (ct *Cointop) refreshTable() error {
func (ct *Cointop) updateTable() error { func (ct *Cointop) updateTable() error {
sliced := []*coin{} sliced := []*coin{}
for i := range ct.allcoinsmap { for i := range ct.allcoinsslugmap {
v := ct.allcoinsmap[i] v := ct.allcoinsslugmap[i]
if ct.favorites[v.Symbol] { if ct.favorites[v.Symbol] {
v.Favorite = true v.Favorite = true
} }

@ -3,6 +3,7 @@ package cointop
type coin struct { type coin struct {
ID string ID string
Name string Name string
Slug string
Symbol string Symbol string
Rank int Rank int
Price float64 Price float64

@ -5,6 +5,7 @@ import (
"encoding/gob" "encoding/gob"
"os" "os"
"runtime" "runtime"
"strings"
"github.com/miguelmota/cointop/pkg/open" "github.com/miguelmota/cointop/pkg/open"
) )
@ -39,3 +40,8 @@ func userHomeDir() string {
} }
return os.Getenv("HOME") return os.Getenv("HOME")
} }
func (ct *Cointop) slugify(s string) string {
s = strings.ToLower(s)
return s
}

Loading…
Cancel
Save