feat: remove consecutive

This commit is contained in:
Anthony Laibe 2023-03-31 11:20:02 +02:00 committed by Anthony Laibe
parent cd6d22d1c1
commit c84d6fcc35
5 changed files with 17 additions and 18 deletions

View File

@ -34,10 +34,9 @@ type ClientWithFallback struct {
WalletNotifier func(chainId uint64, message string) WalletNotifier func(chainId uint64, message string)
IsConnected bool IsConnected bool
consecutiveFailureCount int IsConnectedLock sync.RWMutex
IsConnectedLock sync.RWMutex LastCheckedAt int64
LastCheckedAt int64
} }
var vmErrors = []error{ var vmErrors = []error{
@ -71,14 +70,13 @@ func NewSimpleClient(main *rpc.Client, chainID uint64) *ClientWithFallback {
}) })
return &ClientWithFallback{ return &ClientWithFallback{
ChainID: chainID, ChainID: chainID,
main: ethclient.NewClient(main), main: ethclient.NewClient(main),
fallback: nil, fallback: nil,
mainRPC: main, mainRPC: main,
fallbackRPC: nil, fallbackRPC: nil,
IsConnected: true, IsConnected: true,
consecutiveFailureCount: 0, LastCheckedAt: time.Now().Unix(),
LastCheckedAt: time.Now().Unix(),
} }
} }
@ -129,7 +127,6 @@ func (c *ClientWithFallback) SetIsConnected(value bool) {
defer c.IsConnectedLock.Unlock() defer c.IsConnectedLock.Unlock()
c.LastCheckedAt = time.Now().Unix() c.LastCheckedAt = time.Now().Unix()
if !value { if !value {
c.consecutiveFailureCount += 1
if c.IsConnected { if c.IsConnected {
if c.WalletNotifier != nil { if c.WalletNotifier != nil {
c.WalletNotifier(c.ChainID, "down") c.WalletNotifier(c.ChainID, "down")
@ -138,8 +135,6 @@ func (c *ClientWithFallback) SetIsConnected(value bool) {
} }
} else { } else {
c.consecutiveFailureCount = 0
if !c.IsConnected { if !c.IsConnected {
c.IsConnected = true c.IsConnected = true
if c.WalletNotifier != nil { if c.WalletNotifier != nil {

View File

@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/event"
gethrpc "github.com/ethereum/go-ethereum/rpc" gethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
@ -41,7 +42,7 @@ func setupDummyServiceNoDependencies(t *testing.T) (service *Service, closeFn fu
rpcClient, err := statusRPC.NewClient(client, 1, upstreamConfig, nil, db) rpcClient, err := statusRPC.NewClient(client, 1, upstreamConfig, nil, db)
require.NoError(t, err) require.NoError(t, err)
return NewService(db, nil, rpcClient, nil, market.NewManager(cryptoCompare, cryptoCompare)), func() { return NewService(db, nil, rpcClient, nil, market.NewManager(cryptoCompare, cryptoCompare, &event.Feed{})), func() {
require.NoError(t, db.Close()) require.NoError(t, db.Close())
} }
} }

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/afex/hystrix-go/hystrix" "github.com/afex/hystrix-go/hystrix"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"

View File

@ -4,6 +4,8 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/ethereum/go-ethereum/event"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/status-im/status-go/services/wallet/thirdparty" "github.com/status-im/status-go/services/wallet/thirdparty"
@ -46,7 +48,7 @@ func (mpp *MockPriceProvider) FetchPrices(symbols []string, currencies []string)
} }
func setupTestPrice(t *testing.T, provider thirdparty.MarketDataProvider) *Manager { func setupTestPrice(t *testing.T, provider thirdparty.MarketDataProvider) *Manager {
return NewManager(provider, provider) return NewManager(provider, provider, &event.Feed{})
} }
func TestPrice(t *testing.T) { func TestPrice(t *testing.T) {

View File

@ -224,7 +224,7 @@ func (c *Client) FetchTokenMarketValues(symbols []string, currency string) (map[
if err != nil { if err != nil {
return nil, err return nil, err
} }
url := fmt.Sprintf("%scoins/markets?ids=%s&vs_currency=%s&order=market_cap_desc&per_page=250&page=1&sparkline=false&price_change_percentage=1h%2C24h", baseURL, strings.Join(ids, ","), currency) url := fmt.Sprintf("%scoins/markets?ids=%s&vs_currency=%s&order=market_cap_desc&per_page=250&page=1&sparkline=false&price_change_percentage=%s", baseURL, strings.Join(ids, ","), currency, "1h%2C24h")
resp, err := c.DoQuery(url) resp, err := c.DoQuery(url)
if err != nil { if err != nil {