From 645cd5d03b4c9bfb22aab14deea5f88b6084d005 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 22 May 2023 10:55:33 +0200 Subject: [PATCH] feat: return only enabled networks from the reader --- services/wallet/reader.go | 21 +++++++++++++++++---- services/wallet/token/token.go | 12 ++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/services/wallet/reader.go b/services/wallet/reader.go index 79b4c38db..499266443 100644 --- a/services/wallet/reader.go +++ b/services/wallet/reader.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "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/services/wallet/async" "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) { - networks, err := r.rpcClient.NetworkManager.Get(false) + areTestNetworksEnabled, err := r.accountsDB.GetTestNetworksEnabled() if err != nil { 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 { + if network.IsTest != areTestNetworksEnabled { + continue + } + availableNetworks = append(availableNetworks, network) + } + + chainIDs := make([]uint64, 0) + for _, network := range availableNetworks { 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, getFixedCurrencies()...) - allTokens, err := r.tokenManager.GetAllTokens() + allTokens, err := r.tokenManager.GetTokensByChainIDs(chainIDs) if err != nil { return nil, err } - for _, network := range networks { + for _, network := range availableNetworks { allTokens = append(allTokens, r.tokenManager.ToToken(network)) } diff --git a/services/wallet/token/token.go b/services/wallet/token/token.go index 4b814d46b..9ba4804a5 100644 --- a/services/wallet/token/token.go +++ b/services/wallet/token/token.go @@ -230,6 +230,18 @@ func (tm *Manager) GetAllTokens() ([]*Token, error) { 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) { if !tm.areTokensFetched() { tm.fetchTokens()