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