[wallet] Show PNs right after enabling

This commit is contained in:
Roman Volosovskyi 2020-12-28 17:09:25 +02:00
parent 46157dc4dc
commit 79716227db
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
5 changed files with 10 additions and 35 deletions

View File

@ -1 +1 @@
0.68.3
0.68.4

View File

@ -886,29 +886,6 @@ func (b *GethStatusBackend) AppStateChange(state string) {
b.log.Info("App State changed", "new-state", s)
b.appState = s
if s == appStateBackground {
localNotifications, err := b.statusNode.LocalNotificationsService()
if err != nil {
b.log.Error("Retrieving of local notifications service failed on app state change", "error", err)
}
wallet, err := b.statusNode.WalletService()
if err != nil {
b.log.Error("Retrieving of wallet service failed on app state change to background", "error", err)
return
}
// If we have no local notifications, force wallet stop, otherwise check if it's watching the wallet
if localNotifications == nil || (localNotifications != nil && !localNotifications.IsWatchingWallet()) {
err = wallet.Stop()
if err != nil {
b.log.Error("Wallet service stop failed on app state change to background", "error", err)
return
}
}
}
// TODO: put node in low-power mode if the app is in background (or inactive)
// and normal mode if the app is in foreground.
}

View File

@ -25,11 +25,7 @@ func (api *API) SwitchWalletNotifications(ctx context.Context, preference bool)
return err
}
if preference {
api.s.StartWalletWatcher()
} else {
api.s.StopWalletWatcher()
}
api.s.WatchingEnabled = preference
return nil
}

View File

@ -107,6 +107,7 @@ type transmitter struct {
// Service keeps the state of message bus
type Service struct {
started bool
WatchingEnabled bool
transmitter *transmitter
walletTransmitter *transmitter
db *Database
@ -308,12 +309,12 @@ func (s *Service) SubscribeWallet(publisher *event.Feed) error {
if err != nil {
log.Error("Failed to get wallet preference", "error", err)
return nil
s.WatchingEnabled = false
} else {
s.WatchingEnabled = preference.Enabled
}
if preference.Enabled {
s.StartWalletWatcher()
}
return nil
}
@ -363,7 +364,7 @@ func (s *Service) StartWalletWatcher() {
newBlocks = true
}
}
if newBlocks {
if newBlocks && s.WatchingEnabled {
s.transmitter.publisher.Send(TransactionEvent{
Type: string(event.Type),
BlockNumber: event.BlockNumber,

View File

@ -47,7 +47,7 @@ func TestWalletSubscription(t *testing.T) {
require.Equal(t, true, s.IsStarted())
require.NoError(t, s.SubscribeWallet(feed))
require.Equal(t, false, s.IsWatchingWallet())
require.Equal(t, true, s.IsWatchingWallet())
s.StartWalletWatcher()
require.Equal(t, true, s.IsWatchingWallet())
@ -80,6 +80,7 @@ func TestTransactionNotification(t *testing.T) {
feed := &event.Feed{}
require.NoError(t, s.SubscribeWallet(feed))
s.WatchingEnabled = true
s.StartWalletWatcher()