diff --git a/services/wallet/token/token-lists/token_collision_solving_test.go b/services/wallet/token/token-lists/token_collision_solving_test.go index 841bd5bcd17..068486aeaad 100644 --- a/services/wallet/token/token-lists/token_collision_solving_test.go +++ b/services/wallet/token/token-lists/token_collision_solving_test.go @@ -226,8 +226,9 @@ func TestSolvingCollision(t *testing.T) { // start the auto-refresh process with a 5 second interval, and 1 second check interval const autoRefreshInterval = 3 * time.Second const autoRefreshCheckInterval = 1 * time.Second + const thirdpartyServicesEnabled = true - tokensLists.Start(context.Background(), server.URL, autoRefreshInterval, autoRefreshCheckInterval) + tokensLists.Start(context.Background(), server.URL, autoRefreshInterval, autoRefreshCheckInterval, thirdpartyServicesEnabled) // the token lists should not be updated allTokens = tokensLists.GetUniqueTokens() diff --git a/services/wallet/token/token-lists/token_lists.go b/services/wallet/token/token-lists/token_lists.go index 0d7b802f312..4121d2b4ab3 100644 --- a/services/wallet/token/token-lists/token_lists.go +++ b/services/wallet/token/token-lists/token_lists.go @@ -73,12 +73,16 @@ func NewTokenLists(appDb *sql.DB, walletDb *sql.DB) (*TokenLists, error) { // The auto-refresh interval is used to fetch the list of token lists from the remote source and update the local cache. // The auto-refresh check interval is used to check if the auto-refresh should be triggered. func (t *TokenLists) Start(ctx context.Context, remoteListUrl string, autoRefreshInterval time.Duration, - autoRefreshCheckInterval time.Duration) { + autoRefreshCheckInterval time.Duration, thirdpartyServicesEnabled bool) { err := t.initializeTokensLists() if err != nil { logutils.ZapLogger().Error("Failed to initialize token lists", zap.Error(err)) } + if !thirdpartyServicesEnabled { + return + } + t.tokenListsFetcher.SetURLOfRemoteListOfTokenLists(remoteListUrl) go func() { diff --git a/services/wallet/token/token-lists/token_lists_test.go b/services/wallet/token/token-lists/token_lists_test.go index d5141f7b183..960d2ddd856 100644 --- a/services/wallet/token/token-lists/token_lists_test.go +++ b/services/wallet/token/token-lists/token_lists_test.go @@ -112,8 +112,9 @@ func TestTokensLists(t *testing.T) { // start the auto-refresh process with a 5 second interval, and 1 second check interval const autoRefreshInterval = 3 * time.Second const autoRefreshCheckInterval = 1 * time.Second + const thirdpartyServicesEnabled = true - tokensLists.Start(context.Background(), server.URL, autoRefreshInterval, autoRefreshCheckInterval) + tokensLists.Start(context.Background(), server.URL, autoRefreshInterval, autoRefreshCheckInterval, thirdpartyServicesEnabled) // immediately after starting the server check if the initial token lists are loaded allTokensLists := tokensLists.GetTokensLists() diff --git a/services/wallet/token/token.go b/services/wallet/token/token.go index 0ed785b0fba..c4367730a0e 100644 --- a/services/wallet/token/token.go +++ b/services/wallet/token/token.go @@ -24,6 +24,7 @@ import ( cryptotypes "github.com/status-im/status-go/crypto/types" "github.com/status-im/status-go/logutils" "github.com/status-im/status-go/multiaccounts/accounts" + "github.com/status-im/status-go/multiaccounts/settings" "github.com/status-im/status-go/params" "github.com/status-im/status-go/pkg/pubsub" "github.com/status-im/status-go/protocol/communities/token" @@ -83,6 +84,7 @@ type ManagerInterface interface { type Manager struct { balancefetcher.BalanceFetcher db *sql.DB + settings *settings.Database RPCClient rpc.ClientInterface ContractMaker *contracts.ContractMaker networkManager network.ManagerInterface @@ -113,6 +115,11 @@ func NewTokenManager( ) *Manager { maker, _ := contracts.NewContractMaker(RPCClient) + settings, err := settings.MakeNewDB(appDB) + if err != nil { + return nil + } + tokensLists, err := tokenlists.NewTokenLists(appDB, db) if err != nil { logutils.ZapLogger().Error("Failed to create token lists", zap.Error(err)) @@ -122,6 +129,7 @@ func NewTokenManager( return &Manager{ BalanceFetcher: balancefetcher.NewDefaultBalanceFetcher(maker), db: db, + settings: settings, RPCClient: RPCClient, ContractMaker: maker, networkManager: networkManager, @@ -140,9 +148,15 @@ func (tm *Manager) Start(ctx context.Context, autoRefreshInterval time.Duration, tm.stopCh = make(chan struct{}) tm.startAccountsWatcher() + thirdpartyServicesEnabled, err := tm.settings.ThirdpartyServicesEnabled() + if err != nil { + logutils.ZapLogger().Error("failed to get if thirdparty services are enabled", zap.Error(err)) + return + } + // For now we don't have the list of tokens lists remotely set so we're uisng the harcoded default lists. Once we have it //we will just need to update the empty string with the correct URL. - tm.tokenLists.Start(ctx, fetcher.RemoteListOfTokenLists, autoRefreshInterval, autoRefreshCheckInterval) + tm.tokenLists.Start(ctx, fetcher.RemoteListOfTokenLists, autoRefreshInterval, autoRefreshCheckInterval, thirdpartyServicesEnabled) } func (tm *Manager) startAccountsWatcher() {