From 79716227db0f4b2a2ddcd8763ce48bab5d487d04 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 28 Dec 2020 17:09:25 +0200 Subject: [PATCH] [wallet] Show PNs right after enabling --- VERSION | 2 +- api/geth_backend.go | 23 ----------------------- services/local-notifications/api.go | 6 +----- services/local-notifications/core.go | 11 ++++++----- services/local-notifications/core_test.go | 3 ++- 5 files changed, 10 insertions(+), 35 deletions(-) diff --git a/VERSION b/VERSION index cb45b67bf..5f7bb02a9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.68.3 +0.68.4 diff --git a/api/geth_backend.go b/api/geth_backend.go index db353a788..b1278f445 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -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. } diff --git a/services/local-notifications/api.go b/services/local-notifications/api.go index 3c5e226e3..1ba5ecd60 100644 --- a/services/local-notifications/api.go +++ b/services/local-notifications/api.go @@ -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 } diff --git a/services/local-notifications/core.go b/services/local-notifications/core.go index 5fe5686d9..5390a3218 100644 --- a/services/local-notifications/core.go +++ b/services/local-notifications/core.go @@ -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() - } + 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, diff --git a/services/local-notifications/core_test.go b/services/local-notifications/core_test.go index 03b76c344..0eb158644 100644 --- a/services/local-notifications/core_test.go +++ b/services/local-notifications/core_test.go @@ -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()