Skip to content

Commit

Permalink
[wallet] Show PNs right after enabling
Browse files Browse the repository at this point in the history
  • Loading branch information
rasom committed Jan 13, 2021
1 parent 46157dc commit 7971622
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 35 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.68.3
0.68.4
23 changes: 0 additions & 23 deletions api/geth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
6 changes: 1 addition & 5 deletions services/local-notifications/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 6 additions & 5 deletions services/local-notifications/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion services/local-notifications/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -80,6 +80,7 @@ func TestTransactionNotification(t *testing.T) {

feed := &event.Feed{}
require.NoError(t, s.SubscribeWallet(feed))
s.WatchingEnabled = true

s.StartWalletWatcher()

Expand Down

0 comments on commit 7971622

Please sign in to comment.