From 26956fcaca1198d1b0aabfaae1bf3d8273d864df Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Mon, 24 Aug 2020 21:35:49 -0700 Subject: [PATCH] Move coins without rank to end of list. Fixes #59 --- cointop/cointop.go | 11 +++++++++++ cointop/list.go | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cointop/cointop.go b/cointop/cointop.go index 411df7f..2d1b9ad 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -321,6 +321,17 @@ func NewCointop(config *Config) (*Cointop, error) { ct.filecache.Get(coinscachekey, &allCoinsSlugMap) } + // fix for https://github.com/miguelmota/cointop/issues/59 + // can remove this after everyone has cleared their cache + for _, v := range allCoinsSlugMap { + // Some APIs returns rank 0 for new coins + // or coins with low activity so we need to put them + // at the end of the list. + if v.Rank == 0 { + v.Rank = 10000 + } + } + for k, v := range allCoinsSlugMap { ct.State.allCoinsSlugMap.Store(k, v) } diff --git a/cointop/list.go b/cointop/list.go index 58dff77..a01c1f6 100644 --- a/cointop/list.go +++ b/cointop/list.go @@ -20,7 +20,6 @@ func (ct *Cointop) UpdateCoins() error { var err error var allCoinsSlugMap map[string]types.Coin cached, found := ct.cache.Get(cachekey) - _ = cached if found { // cache hit allCoinsSlugMap, _ = cached.(map[string]types.Coin) @@ -49,6 +48,7 @@ func (ct *Cointop) UpdateCoins() error { // ProcessCoinsMap processes coins map func (ct *Cointop) processCoinsMap(coinsMap map[string]types.Coin) { ct.debuglog("processCoinsMap()") + var coins []types.Coin for _, v := range coinsMap { coins = append(coins, v) @@ -67,6 +67,15 @@ func (ct *Cointop) processCoins(coins []types.Coin) { for _, v := range coins { k := v.Name + + // Fix for https://github.com/miguelmota/cointop/issues/59 + // some APIs returns rank 0 for new coins + // or coins with low activity so we need to put them + // at the end of the list + if v.Rank == 0 { + v.Rank = 10000 + } + ilast, _ := ct.State.allCoinsSlugMap.Load(k) ct.State.allCoinsSlugMap.Store(k, &Coin{ ID: v.ID,