diff --git a/services/wallet/api.go b/services/wallet/api.go index 32e6b809f..61edd5f5a 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -873,3 +873,7 @@ func (api *API) SignTypedDataV4(typedJson string, address string, password strin } return types.HexBytes(sig), err } + +func (api *API) RestartWalletReloadTimer(ctx context.Context) error { + return api.s.reader.Restart() +} diff --git a/services/wallet/reader.go b/services/wallet/reader.go index a0215cf55..bbc5c29c0 100644 --- a/services/wallet/reader.go +++ b/services/wallet/reader.go @@ -143,6 +143,11 @@ func (r *Reader) Stop() { r.lastWalletTokenUpdateTimestamp = sync.Map{} } +func (r *Reader) Restart() error { + r.Stop() + return r.Start() +} + func (r *Reader) triggerWalletReload() { r.cancelDelayedWalletReload() diff --git a/services/wallet/reader_test.go b/services/wallet/reader_test.go index b55955dad..5f8f8c442 100644 --- a/services/wallet/reader_test.go +++ b/services/wallet/reader_test.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/event" "github.com/status-im/status-go/rpc/chain" mock_client "github.com/status-im/status-go/rpc/chain/mock/client" "github.com/status-im/status-go/services/wallet/testutils" @@ -165,8 +166,9 @@ func setupReader(t *testing.T) (*Reader, *mock_token.MockManagerInterface, *mock mockCtrl := gomock.NewController(t) mockTokenManager := mock_token.NewMockManagerInterface(mockCtrl) tokenBalanceStorage := mock_balance_persistence.NewMockTokenBalancesStorage(mockCtrl) + eventsFeed := &event.Feed{} - return NewReader(mockTokenManager, nil, tokenBalanceStorage, nil), mockTokenManager, tokenBalanceStorage, mockCtrl + return NewReader(mockTokenManager, nil, tokenBalanceStorage, eventsFeed), mockTokenManager, tokenBalanceStorage, mockCtrl } func TestGetCachedWalletTokensWithoutMarketData(t *testing.T) { @@ -1023,3 +1025,18 @@ func TestFetchBalances(t *testing.T) { require.True(t, reader.isBalanceCacheValid(addresses)) } + +func TestReaderRestart(t *testing.T) { + reader, _, _, mockCtrl := setupReader(t) + defer mockCtrl.Finish() + + err := reader.Start() + require.NoError(t, err) + require.NotNil(t, reader.walletEventsWatcher) + previousWalletEventsWatcher := reader.walletEventsWatcher + + err = reader.Restart() + require.NoError(t, err) + require.NotNil(t, reader.walletEventsWatcher) + require.NotEqual(t, previousWalletEventsWatcher, reader.walletEventsWatcher) +}