Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion services/wallet/token/token-lists/token_lists.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion services/wallet/token/token-lists/token_lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 15 additions & 1 deletion services/wallet/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -122,6 +129,7 @@ func NewTokenManager(
return &Manager{
BalanceFetcher: balancefetcher.NewDefaultBalanceFetcher(maker),
db: db,
settings: settings,
RPCClient: RPCClient,
ContractMaker: maker,
networkManager: networkManager,
Expand All @@ -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() {
Expand Down
Loading