fix: wallet token return on no network

This commit is contained in:
Anthony Laibe 2023-03-30 09:06:47 +02:00 committed by Anthony Laibe
parent d86446ad53
commit e92049b9ca
2 changed files with 57 additions and 81 deletions

View File

@ -198,10 +198,10 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
})
clients, err := r.rpcClient.EthClients(chainIDs)
group.Add(func(parent context.Context) error {
if err != nil {
return err
return nil, err
}
group.Add(func(parent context.Context) error {
balances, err = r.tokenManager.GetBalancesByChain(ctx, clients, addresses, tokenAddresses)
if err != nil {
return err
@ -218,6 +218,7 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
if err != nil {
return nil, err
}
result := make(map[common.Address][]Token)
for _, address := range addresses {
for symbol, tokens := range getTokenBySymbols(allTokens) {

View File

@ -4,7 +4,6 @@ import (
"context"
"database/sql"
"errors"
"fmt"
"math/big"
"strconv"
"sync"
@ -648,9 +647,11 @@ func (tm *Manager) GetBalancesByChain(parent context.Context, clients map[uint64
contractMaker := contracts.ContractMaker{RPCClient: tm.RPCClient}
for clientIdx := range clients {
client := clients[clientIdx]
ethScanContract, err := contractMaker.NewEthScan(client.ChainID)
if err == nil {
if err != nil {
return nil, err
}
fetchChainBalance := false
var tokenChunks [][]common.Address
chunkSize := 500
@ -676,7 +677,7 @@ func (tm *Manager) GetBalancesByChain(parent context.Context, clients map[uint64
Context: ctx,
}, accounts)
if err != nil {
fmt.Println(err)
log.Error("can't fetch chain balance", err)
return nil
}
@ -701,7 +702,7 @@ func (tm *Manager) GetBalancesByChain(parent context.Context, clients map[uint64
Context: ctx,
}, account, chunk)
if err != nil {
fmt.Println(err)
log.Error("can't fetch erc20 token balance", "account", account, "error", err)
return nil
}
@ -718,32 +719,6 @@ func (tm *Manager) GetBalancesByChain(parent context.Context, clients map[uint64
})
}
}
} else {
for tokenIdx := range tokens {
for accountIdx := range accounts {
// Below, we set account, token and client from idx on purpose to avoid override
account := accounts[accountIdx]
token := tokens[tokenIdx]
if !tm.inStore(token, client.ChainID) {
continue
}
client := clients[clientIdx]
group.Add(func(parent context.Context) error {
ctx, cancel := context.WithTimeout(parent, requestTimeout)
defer cancel()
balance, err := tm.GetBalance(ctx, client, account, token)
if err != nil {
log.Error("can't fetch erc20 token balance", "account", account, "token", token, "error", err)
return nil
}
updateBalance(client.ChainID, account, token, balance)
return nil
})
}
}
}
}
select {