fix(wallet)_: Ignore chain down notifications when connection is lost
fixes #21071
This commit is contained in:
parent
dd994587a3
commit
f07e3a83a3
|
@ -584,6 +584,14 @@ func (b *StatusNode) SetWalletCommunityInfoProvider(provider thirdparty.Communit
|
|||
}
|
||||
}
|
||||
|
||||
type PeerOnlineChecker struct {
|
||||
StatusNode *StatusNode
|
||||
}
|
||||
|
||||
func (f *PeerOnlineChecker) Online() bool {
|
||||
return f.StatusNode.PeerCount() > 0
|
||||
}
|
||||
|
||||
func (b *StatusNode) walletService(accountsDB *accounts.Database, appDB *sql.DB, accountsFeed *event.Feed, settingsFeed *event.Feed, walletFeed *event.Feed, statusProxyStageName string) *wallet.Service {
|
||||
if b.walletSrvc == nil {
|
||||
b.walletSrvc = wallet.NewService(
|
||||
|
@ -594,6 +602,7 @@ func (b *StatusNode) walletService(accountsDB *accounts.Database, appDB *sql.DB,
|
|||
walletFeed,
|
||||
b.httpServer,
|
||||
statusProxyStageName,
|
||||
&PeerOnlineChecker{StatusNode: b},
|
||||
)
|
||||
}
|
||||
return b.walletSrvc
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package common
|
||||
|
||||
type OnlineChecker interface {
|
||||
Online() bool
|
||||
}
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/log"
|
||||
|
||||
"github.com/status-im/status-go/circuitbreaker"
|
||||
walletcommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/thirdparty"
|
||||
"github.com/status-im/status-go/services/wallet/walletevent"
|
||||
)
|
||||
|
@ -47,9 +48,10 @@ type Manager struct {
|
|||
IsConnectedLock sync.RWMutex
|
||||
circuitbreaker *circuitbreaker.CircuitBreaker
|
||||
providers []thirdparty.MarketDataProvider
|
||||
onlineChecker walletcommon.OnlineChecker
|
||||
}
|
||||
|
||||
func NewManager(providers []thirdparty.MarketDataProvider, feed *event.Feed) *Manager {
|
||||
func NewManager(providers []thirdparty.MarketDataProvider, feed *event.Feed, onlineChecker walletcommon.OnlineChecker) *Manager {
|
||||
cb := circuitbreaker.NewCircuitBreaker(circuitbreaker.Config{
|
||||
Timeout: 10000,
|
||||
MaxConcurrentRequests: 100,
|
||||
|
@ -65,6 +67,7 @@ func NewManager(providers []thirdparty.MarketDataProvider, feed *event.Feed) *Ma
|
|||
LastCheckedAt: time.Now().Unix(),
|
||||
circuitbreaker: cb,
|
||||
providers: providers,
|
||||
onlineChecker: onlineChecker,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,12 +80,14 @@ func (pm *Manager) setIsConnected(value bool) {
|
|||
if value {
|
||||
message = "up"
|
||||
}
|
||||
pm.feed.Send(walletevent.Event{
|
||||
Type: EventMarketStatusChanged,
|
||||
Accounts: []common.Address{},
|
||||
Message: message,
|
||||
At: time.Now().Unix(),
|
||||
})
|
||||
if pm.onlineChecker.Online() {
|
||||
pm.feed.Send(walletevent.Event{
|
||||
Type: EventMarketStatusChanged,
|
||||
Accounts: []common.Address{},
|
||||
Message: message,
|
||||
At: time.Now().Unix(),
|
||||
})
|
||||
}
|
||||
}
|
||||
pm.IsConnected = value
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/status-im/status-go/services/wallet/balance"
|
||||
"github.com/status-im/status-go/services/wallet/blockchainstate"
|
||||
"github.com/status-im/status-go/services/wallet/collectibles"
|
||||
walletcommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/community"
|
||||
"github.com/status-im/status-go/services/wallet/currency"
|
||||
"github.com/status-im/status-go/services/wallet/history"
|
||||
|
@ -63,6 +64,7 @@ func NewService(
|
|||
feed *event.Feed,
|
||||
mediaServer *server.MediaServer,
|
||||
statusProxyStageName string,
|
||||
onlineChecker walletcommon.OnlineChecker,
|
||||
) *Service {
|
||||
signals := &walletevent.SignalsTransmitter{
|
||||
Publisher: feed,
|
||||
|
@ -90,6 +92,9 @@ func NewService(
|
|||
return
|
||||
}
|
||||
|
||||
if !onlineChecker.Online() {
|
||||
return
|
||||
}
|
||||
feed.Send(walletevent.Event{
|
||||
Type: EventBlockchainStatusChanged,
|
||||
Accounts: []common.Address{},
|
||||
|
@ -125,7 +130,7 @@ func NewService(
|
|||
User: config.WalletConfig.StatusProxyMarketUser,
|
||||
Password: config.WalletConfig.StatusProxyMarketPassword,
|
||||
})
|
||||
marketManager := market.NewManager([]thirdparty.MarketDataProvider{cryptoCompare, coingecko, cryptoCompareProxy}, feed)
|
||||
marketManager := market.NewManager([]thirdparty.MarketDataProvider{cryptoCompare, coingecko, cryptoCompareProxy}, feed, onlineChecker)
|
||||
reader := NewReader(tokenManager, marketManager, token.NewPersistence(db), feed)
|
||||
history := history.NewService(db, accountsDB, accountFeed, feed, rpcClient, tokenManager, marketManager, balanceCacher.Cache())
|
||||
currency := currency.NewService(db, feed, tokenManager, marketManager)
|
||||
|
|
Loading…
Reference in New Issue