diff --git a/services/local-notifications/core_test.go b/services/local-notifications/core_test.go index 758b5bb99..ae1a74808 100644 --- a/services/local-notifications/core_test.go +++ b/services/local-notifications/core_test.go @@ -121,9 +121,8 @@ func TestTransactionNotification(t *testing.T) { require.NoError(t, transfer.SaveTransfersMarkBlocksLoaded(walletDb, 1777, header.Address, transfers, []*big.Int{header.Number})) feed.Send(walletevent.Event{ - Type: transfer.EventRecentHistoryReady, - BlockNumber: big.NewInt(0), - Accounts: []common.Address{header.Address}, + Type: transfer.EventRecentHistoryReady, + Accounts: []common.Address{header.Address}, }) feed.Send(walletevent.Event{ diff --git a/services/local-notifications/database.go b/services/local-notifications/database.go index e30f08203..4e06a750a 100644 --- a/services/local-notifications/database.go +++ b/services/local-notifications/database.go @@ -41,6 +41,9 @@ func (db *Database) GetWalletPreference() (rst NotificationPreference, err error pref := db.db.QueryRow("SELECT service, event, identifier, enabled FROM local_notifications_preferences WHERE service = 'wallet' AND event = 'transaction' AND identifier = 'all'") err = pref.Scan(&rst.Service, &rst.Event, &rst.Identifier, &rst.Enabled) + if err == sql.ErrNoRows { + return rst, nil + } return } diff --git a/services/local-notifications/transaction.go b/services/local-notifications/transaction.go index 219318114..2365d948a 100644 --- a/services/local-notifications/transaction.go +++ b/services/local-notifications/transaction.go @@ -143,7 +143,7 @@ func (s *Service) SubscribeWallet(publisher *event.Feed) error { s.StartWalletWatcher() - return nil + return err } // StartWalletWatcher - Forward wallet events to notifications @@ -167,6 +167,7 @@ func (s *Service) StartWalletWatcher() { maxKnownBlocks := map[common.Address]*big.Int{} go func() { defer s.walletTransmitter.wg.Done() + historyReady := false for { select { case <-s.walletTransmitter.quit: @@ -180,7 +181,7 @@ func (s *Service) StartWalletWatcher() { } return case event := <-events: - if event.Type == transfer.EventNewTransfers && len(maxKnownBlocks) > 0 && event.BlockNumber != nil { + if event.Type == transfer.EventNewTransfers && historyReady && event.BlockNumber != nil { newBlocks := false for _, address := range event.Accounts { if _, ok := maxKnownBlocks[address]; !ok { @@ -200,9 +201,12 @@ func (s *Service) StartWalletWatcher() { }) } } else if event.Type == transfer.EventRecentHistoryReady { - for _, address := range event.Accounts { - if _, ok := maxKnownBlocks[address]; !ok { - maxKnownBlocks[address] = event.BlockNumber + historyReady = true + if event.BlockNumber != nil { + for _, address := range event.Accounts { + if _, ok := maxKnownBlocks[address]; !ok { + maxKnownBlocks[address] = event.BlockNumber + } } } } diff --git a/services/wallet/transfer/commands_sequential.go b/services/wallet/transfer/commands_sequential.go index 95d01b7ee..1b95c7cfd 100644 --- a/services/wallet/transfer/commands_sequential.go +++ b/services/wallet/transfer/commands_sequential.go @@ -817,7 +817,7 @@ func (c *loadBlocksAndTransfersCommand) fetchHistoryBlocks(ctx context.Context, // If we blockRange is nil, we need to load all blocks from `fromNum` to `toNum` // As current implementation checks ETH first then tokens, tokens ranges maybe behind ETH ranges in // cases when block searching was interrupted, so we use tokens ranges - if blockRange != nil { + if blockRange != nil && blockRange.tokens != nil { if blockRange.tokens.LastKnown != nil && toNum.Cmp(blockRange.tokens.LastKnown) > 0 { ranges = append(ranges, []*big.Int{blockRange.tokens.LastKnown, toNum}) }