[wallet] Show PNs right after enabling
This commit is contained in:
parent
46157dc4dc
commit
79716227db
|
@ -886,29 +886,6 @@ func (b *GethStatusBackend) AppStateChange(state string) {
|
||||||
b.log.Info("App State changed", "new-state", s)
|
b.log.Info("App State changed", "new-state", s)
|
||||||
b.appState = 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)
|
// TODO: put node in low-power mode if the app is in background (or inactive)
|
||||||
// and normal mode if the app is in foreground.
|
// and normal mode if the app is in foreground.
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,7 @@ func (api *API) SwitchWalletNotifications(ctx context.Context, preference bool)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if preference {
|
api.s.WatchingEnabled = preference
|
||||||
api.s.StartWalletWatcher()
|
|
||||||
} else {
|
|
||||||
api.s.StopWalletWatcher()
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,6 +107,7 @@ type transmitter struct {
|
||||||
// Service keeps the state of message bus
|
// Service keeps the state of message bus
|
||||||
type Service struct {
|
type Service struct {
|
||||||
started bool
|
started bool
|
||||||
|
WatchingEnabled bool
|
||||||
transmitter *transmitter
|
transmitter *transmitter
|
||||||
walletTransmitter *transmitter
|
walletTransmitter *transmitter
|
||||||
db *Database
|
db *Database
|
||||||
|
@ -308,12 +309,12 @@ func (s *Service) SubscribeWallet(publisher *event.Feed) error {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to get wallet preference", "error", err)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -363,7 +364,7 @@ func (s *Service) StartWalletWatcher() {
|
||||||
newBlocks = true
|
newBlocks = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if newBlocks {
|
if newBlocks && s.WatchingEnabled {
|
||||||
s.transmitter.publisher.Send(TransactionEvent{
|
s.transmitter.publisher.Send(TransactionEvent{
|
||||||
Type: string(event.Type),
|
Type: string(event.Type),
|
||||||
BlockNumber: event.BlockNumber,
|
BlockNumber: event.BlockNumber,
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestWalletSubscription(t *testing.T) {
|
||||||
require.Equal(t, true, s.IsStarted())
|
require.Equal(t, true, s.IsStarted())
|
||||||
|
|
||||||
require.NoError(t, s.SubscribeWallet(feed))
|
require.NoError(t, s.SubscribeWallet(feed))
|
||||||
require.Equal(t, false, s.IsWatchingWallet())
|
require.Equal(t, true, s.IsWatchingWallet())
|
||||||
|
|
||||||
s.StartWalletWatcher()
|
s.StartWalletWatcher()
|
||||||
require.Equal(t, true, s.IsWatchingWallet())
|
require.Equal(t, true, s.IsWatchingWallet())
|
||||||
|
@ -80,6 +80,7 @@ func TestTransactionNotification(t *testing.T) {
|
||||||
|
|
||||||
feed := &event.Feed{}
|
feed := &event.Feed{}
|
||||||
require.NoError(t, s.SubscribeWallet(feed))
|
require.NoError(t, s.SubscribeWallet(feed))
|
||||||
|
s.WatchingEnabled = true
|
||||||
|
|
||||||
s.StartWalletWatcher()
|
s.StartWalletWatcher()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue