fix: collectible status event
This commit is contained in:
parent
b2ea01c32e
commit
ec5449c2bd
|
@ -144,14 +144,14 @@ func (c *Client) EthClient(chainID uint64) (*chain.ClientWithFallback, error) {
|
|||
return client, nil
|
||||
}
|
||||
|
||||
func (c *Client) EthClients(chainIDs []uint64) ([]*chain.ClientWithFallback, error) {
|
||||
clients := make([]*chain.ClientWithFallback, 0)
|
||||
func (c *Client) EthClients(chainIDs []uint64) (map[uint64]*chain.ClientWithFallback, error) {
|
||||
clients := make(map[uint64]*chain.ClientWithFallback, 0)
|
||||
for _, chainID := range chainIDs {
|
||||
client, err := c.getClientUsingCache(chainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
clients = append(clients, client)
|
||||
clients[chainID] = client
|
||||
}
|
||||
|
||||
return clients, nil
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/rpc/chain"
|
||||
"github.com/status-im/status-go/services/wallet/bridge"
|
||||
"github.com/status-im/status-go/services/wallet/currency"
|
||||
"github.com/status-im/status-go/services/wallet/history"
|
||||
|
@ -108,11 +107,11 @@ func (api *API) GetCachedBalancesbyChainID(ctx context.Context, chainID uint64,
|
|||
|
||||
// GetTokensBalances return mapping of token balances for every account.
|
||||
func (api *API) GetTokensBalances(ctx context.Context, accounts, addresses []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error) {
|
||||
chainClient, err := api.s.rpcClient.EthClient(api.s.rpcClient.UpstreamChainID)
|
||||
chainClients, err := api.s.rpcClient.EthClients([]uint64{api.s.rpcClient.UpstreamChainID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return api.s.tokenManager.GetBalances(ctx, []*chain.ClientWithFallback{chainClient}, accounts, addresses)
|
||||
return api.s.tokenManager.GetBalances(ctx, chainClients, accounts, addresses)
|
||||
}
|
||||
|
||||
func (api *API) GetTokensBalancesForChainIDs(ctx context.Context, chainIDs []uint64, accounts, addresses []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error) {
|
||||
|
|
|
@ -50,12 +50,14 @@ type TokenMarketValues struct {
|
|||
ChangePct24hour float64 `json:"changePct24hour"`
|
||||
Change24hour float64 `json:"change24hour"`
|
||||
Price float64 `json:"price"`
|
||||
HasError bool `json:"hasError"`
|
||||
}
|
||||
|
||||
type ChainBalance struct {
|
||||
Balance *big.Float `json:"balance"`
|
||||
Address common.Address `json:"address"`
|
||||
ChainID uint64 `json:"chainId"`
|
||||
Balance *big.Float `json:"balance"`
|
||||
Address common.Address `json:"address"`
|
||||
ChainID uint64 `json:"chainId"`
|
||||
HasError bool `json:"hasError"`
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
|
@ -195,8 +197,8 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
|
|||
return nil
|
||||
})
|
||||
|
||||
clients, err := r.rpcClient.EthClients(chainIDs)
|
||||
group.Add(func(parent context.Context) error {
|
||||
clients, err := r.rpcClient.EthClients(chainIDs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -230,10 +232,15 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
|
|||
big.NewFloat(math.Pow(10, float64(decimals))),
|
||||
)
|
||||
}
|
||||
hasError := false
|
||||
if client, ok := clients[token.ChainID]; ok {
|
||||
hasError = !client.IsConnected
|
||||
}
|
||||
balancesPerChain[token.ChainID] = ChainBalance{
|
||||
Balance: balance,
|
||||
Address: token.Address,
|
||||
ChainID: token.ChainID,
|
||||
Balance: balance,
|
||||
Address: token.Address,
|
||||
ChainID: token.ChainID,
|
||||
HasError: hasError,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,6 +255,7 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
|
|||
ChangePct24hour: tokenMarketValues[symbol].CHANGEPCT24HOUR,
|
||||
Change24hour: tokenMarketValues[symbol].CHANGE24HOUR,
|
||||
Price: prices[symbol][currency],
|
||||
HasError: !r.marketManager.IsConnected,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ func NewService(
|
|||
transactor: transactor,
|
||||
ens: ens,
|
||||
stickers: stickers,
|
||||
feed: accountFeed,
|
||||
feed: walletFeed,
|
||||
signals: signals,
|
||||
reader: reader,
|
||||
history: history,
|
||||
|
|
|
@ -27,9 +27,22 @@ const (
|
|||
const AssetLimit = 200
|
||||
const CollectionLimit = 300
|
||||
|
||||
<<<<<<< HEAD
|
||||
const RequestTimeout = 5 * time.Second
|
||||
const GetRequestRetryMaxCount = 15
|
||||
const GetRequestWaitTime = 300 * time.Millisecond
|
||||
=======
|
||||
const RequestRetryMaxCount = 1
|
||||
const RequestWaitTime = 300 * time.Millisecond
|
||||
|
||||
var OpenseaClientInstances = make(map[uint64]*Client)
|
||||
|
||||
var BaseURLs = map[uint64]string{
|
||||
1: "https://api.opensea.io/api/v1",
|
||||
4: "https://rinkeby-api.opensea.io/api/v1",
|
||||
5: "https://testnets-api.opensea.io/api/v1",
|
||||
}
|
||||
>>>>>>> 6173eabe7 (feat: add error on get wallet token)
|
||||
|
||||
const ChainIDRequiringAPIKey = 1
|
||||
|
||||
|
@ -235,6 +248,11 @@ func NewOpenseaClient(chainID uint64, apiKey string, feed *event.Feed) (*Client,
|
|||
if chainID == ChainIDRequiringAPIKey {
|
||||
tmpAPIKey = apiKey
|
||||
}
|
||||
if client, ok := OpenseaClientInstances[chainID]; ok {
|
||||
if client.apiKey == tmpAPIKey {
|
||||
return client, nil
|
||||
}
|
||||
}
|
||||
|
||||
baseURL, err := getbaseURL(chainID)
|
||||
if err != nil {
|
||||
|
|
|
@ -474,7 +474,7 @@ func (tm *Manager) GetBalance(ctx context.Context, client *chain.ClientWithFallb
|
|||
return tm.GetTokenBalance(ctx, client, account, token)
|
||||
}
|
||||
|
||||
func (tm *Manager) GetBalances(parent context.Context, clients []*chain.ClientWithFallback, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error) {
|
||||
func (tm *Manager) GetBalances(parent context.Context, clients map[uint64]*chain.ClientWithFallback, accounts, tokens []common.Address) (map[common.Address]map[common.Address]*hexutil.Big, error) {
|
||||
var (
|
||||
group = async.NewAtomicGroup(parent)
|
||||
mu sync.Mutex
|
||||
|
@ -604,7 +604,7 @@ func (tm *Manager) GetBalances(parent context.Context, clients []*chain.ClientWi
|
|||
return response, group.Error()
|
||||
}
|
||||
|
||||
func (tm *Manager) GetBalancesByChain(parent context.Context, clients []*chain.ClientWithFallback, accounts, tokens []common.Address) (map[uint64]map[common.Address]map[common.Address]*hexutil.Big, error) {
|
||||
func (tm *Manager) GetBalancesByChain(parent context.Context, clients map[uint64]*chain.ClientWithFallback, accounts, tokens []common.Address) (map[uint64]map[common.Address]map[common.Address]*hexutil.Big, error) {
|
||||
var (
|
||||
group = async.NewAtomicGroup(parent)
|
||||
mu sync.Mutex
|
||||
|
|
|
@ -119,7 +119,7 @@ func (c *Controller) CheckRecentHistory(chainIDs []uint64, accounts []common.Add
|
|||
|
||||
// watchAccountsChanges subscribes to a feed and watches for changes in accounts list. If there are new or removed accounts
|
||||
// reactor will be restarted.
|
||||
func watchAccountsChanges(ctx context.Context, accountFeed *event.Feed, reactor *Reactor, chainClients []*chain.ClientWithFallback, initial []common.Address) error {
|
||||
func watchAccountsChanges(ctx context.Context, accountFeed *event.Feed, reactor *Reactor, chainClients map[uint64]*chain.ClientWithFallback, initial []common.Address) error {
|
||||
accounts := make(chan []*accounts.Account, 1) // it may block if the rate of updates will be significantly higher
|
||||
sub := accountFeed.Subscribe(accounts)
|
||||
defer sub.Unsubscribe()
|
||||
|
|
|
@ -61,7 +61,7 @@ func (r *Reactor) newControlCommand(chainClient *chain.ClientWithFallback, accou
|
|||
}
|
||||
|
||||
// Start runs reactor loop in background.
|
||||
func (r *Reactor) start(chainClients []*chain.ClientWithFallback, accounts []common.Address) error {
|
||||
func (r *Reactor) start(chainClients map[uint64]*chain.ClientWithFallback, accounts []common.Address) error {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
|
@ -88,7 +88,7 @@ func (r *Reactor) stop() {
|
|||
r.group = nil
|
||||
}
|
||||
|
||||
func (r *Reactor) restart(chainClients []*chain.ClientWithFallback, accounts []common.Address) error {
|
||||
func (r *Reactor) restart(chainClients map[uint64]*chain.ClientWithFallback, accounts []common.Address) error {
|
||||
r.stop()
|
||||
return r.start(chainClients, accounts)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue