diff options
author | Miguel Mota <hello@miguelmota.com> | 2021-10-13 00:36:43 -0700 |
---|---|---|
committer | Miguel Mota <hello@miguelmota.com> | 2021-10-13 00:36:43 -0700 |
commit | 27ad1a782d367aa0304153ed6fe6317f6b7afdd8 (patch) | |
tree | a1581a7ea18afc9e60738bccd146b8eb113fc34d | |
parent | 15c7707883fc43642e6ea8f0570ecd711f4875a9 (diff) | |
parent | b19864014e8ccb2df318e9716d02f06f6e264c48 (diff) |
Merge branch 'master' of github.com:cointop-sh/cointop
-rw-r--r-- | cointop/navigation.go | 11 | ||||
-rw-r--r-- | cointop/portfolio.go | 29 |
2 files changed, 14 insertions, 26 deletions
diff --git a/cointop/navigation.go b/cointop/navigation.go index abbd2be..6c8fe65 100644 --- a/cointop/navigation.go +++ b/cointop/navigation.go @@ -409,13 +409,18 @@ func (ct *Cointop) GoToPageRowIndex(idx int) error { // GoToGlobalIndex navigates to the selected row index of all page rows func (ct *Cointop) GoToGlobalIndex(idx int) error { - log.Debug("GoToGlobalIndex()") + log.Debugf("GoToGlobalIndex(%d)", idx) + target := ct.State.allCoins[idx] l := ct.TableRowsLen() atpage := idx / l ct.SetPage(atpage) - rowIndex := idx % l - ct.HighlightRow(rowIndex) ct.UpdateTable() + // Look for the coin in the current page + for i, coin := range ct.State.coins { + if coin == target { + ct.HighlightRow(i) + } + } return nil } diff --git a/cointop/portfolio.go b/cointop/portfolio.go index d27f32f..52860c1 100644 --- a/cointop/portfolio.go +++ b/cointop/portfolio.go @@ -556,25 +556,13 @@ func (ct *Cointop) GetPortfolioSlice() []*Coin { return sliced } -OUTER: - for i := range ct.State.allCoins { - coin := ct.State.allCoins[i] - p, isNew := ct.PortfolioEntry(coin) - if isNew { + for _, p := range ct.State.portfolio.Entries { + coinIfc, _ := ct.State.allCoinsSlugMap.Load(p.Coin) + coin, ok := coinIfc.(*Coin) + if !ok { + log.Errorf("Could not find coin %s", p.Coin) continue } - // check not already found - updateSlice := -1 - for j := range sliced { - if coin.Symbol == sliced[j].Symbol { - if coin.Rank >= sliced[j].Rank { - continue OUTER // skip updates from lower-ranked coins - } - updateSlice = j // update this later - break - } - } - coin.Holdings = p.Holdings balance := coin.Price * p.Holdings balancestr := fmt.Sprintf("%.2f", balance) @@ -583,12 +571,7 @@ OUTER: } balance, _ = strconv.ParseFloat(balancestr, 64) coin.Balance = balance - if updateSlice == -1 { - sliced = append(sliced, coin) - } else { - sliced[updateSlice] = coin - } - + sliced = append(sliced, coin) } sort.Slice(sliced, func(i, j int) bool { |