mirror of
https://github.com/status-im/status-go.git
synced 2025-02-18 01:37:22 +00:00
feat: return only enabled networks from the reader
This commit is contained in:
parent
aded83fc6e
commit
645cd5d03b
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/status-im/status-go/multiaccounts/accounts"
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
||||||
|
"github.com/status-im/status-go/params"
|
||||||
"github.com/status-im/status-go/rpc"
|
"github.com/status-im/status-go/rpc"
|
||||||
"github.com/status-im/status-go/services/wallet/async"
|
"github.com/status-im/status-go/services/wallet/async"
|
||||||
"github.com/status-im/status-go/services/wallet/market"
|
"github.com/status-im/status-go/services/wallet/market"
|
||||||
@ -154,13 +155,25 @@ func (r *Reader) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address) (map[common.Address][]Token, error) {
|
func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address) (map[common.Address][]Token, error) {
|
||||||
networks, err := r.rpcClient.NetworkManager.Get(false)
|
areTestNetworksEnabled, err := r.accountsDB.GetTestNetworksEnabled()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
chainIDs := make([]uint64, 0)
|
networks, err := r.rpcClient.NetworkManager.Get(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
availableNetworks := make([]*params.Network, 0)
|
||||||
for _, network := range networks {
|
for _, network := range networks {
|
||||||
|
if network.IsTest != areTestNetworksEnabled {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
availableNetworks = append(availableNetworks, network)
|
||||||
|
}
|
||||||
|
|
||||||
|
chainIDs := make([]uint64, 0)
|
||||||
|
for _, network := range availableNetworks {
|
||||||
chainIDs = append(chainIDs, network.ChainID)
|
chainIDs = append(chainIDs, network.ChainID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,11 +185,11 @@ func (r *Reader) GetWalletToken(ctx context.Context, addresses []common.Address)
|
|||||||
currencies = append(currencies, currency)
|
currencies = append(currencies, currency)
|
||||||
currencies = append(currencies, getFixedCurrencies()...)
|
currencies = append(currencies, getFixedCurrencies()...)
|
||||||
|
|
||||||
allTokens, err := r.tokenManager.GetAllTokens()
|
allTokens, err := r.tokenManager.GetTokensByChainIDs(chainIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, network := range networks {
|
for _, network := range availableNetworks {
|
||||||
allTokens = append(allTokens, r.tokenManager.ToToken(network))
|
allTokens = append(allTokens, r.tokenManager.ToToken(network))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +230,18 @@ func (tm *Manager) GetAllTokens() ([]*Token, error) {
|
|||||||
return tokens, nil
|
return tokens, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tm *Manager) GetTokensByChainIDs(chainIDs []uint64) ([]*Token, error) {
|
||||||
|
tokens := make([]*Token, 0)
|
||||||
|
for _, chainID := range chainIDs {
|
||||||
|
t, err := tm.GetTokens(chainID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tokens = append(tokens, t...)
|
||||||
|
}
|
||||||
|
return tokens, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (tm *Manager) GetTokens(chainID uint64) ([]*Token, error) {
|
func (tm *Manager) GetTokens(chainID uint64) ([]*Token, error) {
|
||||||
if !tm.areTokensFetched() {
|
if !tm.areTokensFetched() {
|
||||||
tm.fetchTokens()
|
tm.fetchTokens()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user