fix_: Fix timestamo integer cast (#5092)

This commit is contained in:
Cuteivist 2024-04-25 14:15:07 +02:00 committed by GitHub
parent 90b18d4f88
commit eb1ed696f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 71 additions and 44 deletions

View File

@ -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()

View File

@ -53,6 +53,13 @@ var coinGeckoMapping = map[string]string{
"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)

View File

@ -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 {

View File

@ -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