diff --git a/services/wallet/reader.go b/services/wallet/reader.go index 0c0486722..1cd1c17bb 100644 --- a/services/wallet/reader.go +++ b/services/wallet/reader.go @@ -222,7 +222,10 @@ func (r *Reader) startWalletEventsWatcher() { for _, address := range event.Accounts { timestamp, ok := r.lastWalletTokenUpdateTimestamp.Load(address) - timecheck := timestamp.(int64) - activityReloadMarginSeconds + timecheck := int64(0) + if ok { + timecheck = timestamp.(int64) - activityReloadMarginSeconds + } if !ok || event.At > timecheck { r.triggerDelayedWalletReload() diff --git a/services/wallet/thirdparty/coingecko/client.go b/services/wallet/thirdparty/coingecko/client.go index 0d7aa6f01..b5339906a 100644 --- a/services/wallet/thirdparty/coingecko/client.go +++ b/services/wallet/thirdparty/coingecko/client.go @@ -14,45 +14,52 @@ import ( ) var coinGeckoMapping = map[string]string{ - "STT": "status", - "SNT": "status", - "ETH": "ethereum", - "AST": "airswap", - "AMB": "", - "ABT": "arcblock", - "ATM": "", - "BNB": "binancecoin", - "BLT": "bloom", - "CDT": "", - "COMP": "compound-coin", - "EDG": "edgeless", - "ELF": "", - "ENG": "enigma", - "EOS": "eos", - "GEN": "daostack", - "MANA": "decentraland-wormhole", - "LEND": "ethlend", - "LRC": "loopring", - "MET": "metronome", - "POLY": "polymath", - "PPT": "populous", - "SAN": "santiment-network-token", - "DNT": "district0x", - "SPN": "sapien", - "USDS": "stableusd", - "STX": "stox", - "SUB": "substratum", - "PAY": "tenx", - "GRT": "the-graph", - "TNT": "tierion", - "TRX": "tron", - "TGT": "", - "RARE": "superrare", - "UNI": "uniswap", - "USDC": "usd-coin", - "USDP": "paxos-standard", - "VRS": "", - "TIME": "", + "STT": "status", + "SNT": "status", + "ETH": "ethereum", + "AST": "airswap", + "AMB": "", + "ABT": "arcblock", + "ATM": "", + "BNB": "binancecoin", + "BLT": "bloom", + "CDT": "", + "COMP": "compound-coin", + "EDG": "edgeless", + "ELF": "", + "ENG": "enigma", + "EOS": "eos", + "GEN": "daostack", + "MANA": "decentraland-wormhole", + "LEND": "ethlend", + "LRC": "loopring", + "MET": "metronome", + "POLY": "polymath", + "PPT": "populous", + "SAN": "santiment-network-token", + "DNT": "district0x", + "SPN": "sapien", + "USDS": "stableusd", + "STX": "stox", + "SUB": "substratum", + "PAY": "tenx", + "GRT": "the-graph", + "TNT": "tierion", + "TRX": "tron", + "TGT": "", + "RARE": "superrare", + "UNI": "uniswap", + "USDC": "usd-coin", + "USDP": "paxos-standard", + "VRS": "", + "TIME": "", + "USDT": "tether", + "SHIB": "shiba-inu", + "LINK": "chainlink", + "MATIC": "matic-network", + "DAI": "dai", + "ARB": "arbitrum", + "OP": "optimism", } const baseURL = "https://api.coingecko.com/api/v3/" @@ -150,6 +157,7 @@ func (c *Client) mapSymbolsToIds(symbols []string) ([]string, error) { ids = append(ids, token.ID) } } + ids = utils.RemoveDuplicates(ids) return ids, nil } @@ -182,7 +190,7 @@ func (c *Client) FetchPrices(symbols []string, currencies []string) (map[string] prices := make(map[string]map[string]float64) err = json.Unmarshal(body, &prices) if err != nil { - return nil, err + return nil, fmt.Errorf("%s - %s", err, string(body)) } result := make(map[string]map[string]float64) @@ -240,7 +248,7 @@ func (c *Client) FetchTokenMarketValues(symbols []string, currency string) (map[ var marketValues []GeckoMarketValues err = json.Unmarshal(body, &marketValues) if err != nil { - return nil, err + return nil, fmt.Errorf("%s - %s", err, string(body)) } result := make(map[string]thirdparty.TokenMarketValues) diff --git a/services/wallet/thirdparty/cryptocompare/client.go b/services/wallet/thirdparty/cryptocompare/client.go index aeaa74595..15bb0b85d 100644 --- a/services/wallet/thirdparty/cryptocompare/client.go +++ b/services/wallet/thirdparty/cryptocompare/client.go @@ -71,7 +71,7 @@ func (c *Client) FetchPrices(symbols []string, currencies []string) (map[string] prices := make(map[string]map[string]float64) err = json.Unmarshal(body, &prices) if err != nil { - return nil, err + return nil, fmt.Errorf("%s - %s", err, string(body)) } for _, symbol := range smbls { @@ -132,8 +132,12 @@ func (c *Client) FetchTokenMarketValues(symbols []string, currency string) (map[ container := MarketValuesContainer{} err = json.Unmarshal(body, &container) + + if len(container.Raw) == 0 { + return nil, fmt.Errorf("no data found - %s", string(body)) + } if err != nil { - return item, err + return nil, fmt.Errorf("%s - %s", err, string(body)) } for _, symbol := range smbls { diff --git a/services/wallet/thirdparty/utils/symbols.go b/services/wallet/thirdparty/utils/symbols.go index fbec17466..d97fd1482 100644 --- a/services/wallet/thirdparty/utils/symbols.go +++ b/services/wallet/thirdparty/utils/symbols.go @@ -13,6 +13,18 @@ func RenameSymbols(symbols []string) (renames []string) { return } +func RemoveDuplicates(strings []string) []string { + uniqueStrings := make(map[string]bool) + var uniqueSlice []string + for _, str := range strings { + if !uniqueStrings[str] { + uniqueStrings[str] = true + uniqueSlice = append(uniqueSlice, str) + } + } + return uniqueSlice +} + func GetRealSymbol(symbol string) string { if val, ok := renameMapping[strings.ToUpper(symbol)]; ok { return val