Skip to content

Commit a86c42c

Browse files
committed
send wallet events for watch only accounts
1 parent a457699 commit a86c42c

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

services/wallet/localbackup/service.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package localbackup
22

33
import (
4+
"encoding/json"
45
"errors"
56

7+
"github.com/ethereum/go-ethereum/event"
68
"github.com/golang/protobuf/proto"
79
"github.com/status-im/status-go/eth-node/types"
810
"github.com/status-im/status-go/multiaccounts/accounts"
911
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
1012
"github.com/status-im/status-go/protocol/protobuf"
13+
"github.com/status-im/status-go/protocol/wakusync"
14+
"github.com/status-im/status-go/services/wallet/walletevent"
1115
)
1216

1317
// TODO this is duplicated
@@ -16,14 +20,20 @@ var (
1620
ErrTryingToStoreOldWalletAccount = errors.New("trying to store an old wallet account")
1721
)
1822

23+
const (
24+
EventWatchOnlyAccountRetrieved walletevent.EventType = "wallet-watch-only-account-retrieved"
25+
)
26+
1927
// Service is a wallet local backup service.
2028
type Service struct {
2129
accountsDB *accounts.Database
30+
feed *event.Feed
2231
}
2332

24-
func NewService(accountsDB *accounts.Database) *Service {
33+
func NewService(accountsDB *accounts.Database, feed *event.Feed) *Service {
2534
return &Service{
2635
accountsDB: accountsDB,
36+
feed: feed,
2737
}
2838
}
2939

@@ -138,19 +148,6 @@ func (s *Service) handleSyncWatchOnlyAccount(message *protobuf.SyncAccount) (*ac
138148
return nil, err
139149
}
140150

141-
// TODO is this useful?
142-
// if m.config.accountsFeed != nil {
143-
// var eventType accountsevent.EventType
144-
// if acc.Removed {
145-
// eventType = accountsevent.EventTypeRemoved
146-
// } else {
147-
// eventType = accountsevent.EventTypeAdded
148-
// }
149-
// m.config.accountsFeed.Send(accountsevent.Event{
150-
// Type: eventType,
151-
// Accounts: []gethcommon.Address{gethcommon.Address(acc.Address)},
152-
// })
153-
// }
154151
return acc, nil
155152
}
156153

@@ -159,18 +156,22 @@ func (s *Service) handleWatchOnlyAccount(message *protobuf.SyncAccount) error {
159156
return nil
160157
}
161158

162-
_, err := s.handleSyncWatchOnlyAccount(message)
159+
acc, err := s.handleSyncWatchOnlyAccount(message)
163160
if err != nil {
164161
return err
165162
}
166-
// TODO send the account trhough a signal?
167-
// if m.config.messengerSignalsHandler != nil {
168-
// response := wakusync.WakuBackedUpDataResponse{
169-
// WatchOnlyAccount: acc,
170-
// }
171-
172-
// m.config.messengerSignalsHandler.SendWakuBackedUpWatchOnlyAccount(&response)
173-
// }
163+
response := wakusync.WakuBackedUpDataResponse{
164+
WatchOnlyAccount: acc,
165+
}
166+
encodedmessage, err := json.Marshal(response)
167+
if err != nil {
168+
return err
169+
}
170+
event := walletevent.Event{
171+
Type: EventWatchOnlyAccountRetrieved,
172+
Message: string(encodedmessage),
173+
}
174+
s.feed.Send(event)
174175

175176
return nil
176177
}

services/wallet/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func NewService(
199199

200200
activity := activity.NewService(db, accountsDB, tokenManager, collectiblesManager, feed)
201201

202-
localBackup := localbackup.NewService(accountsDB)
202+
localBackup := localbackup.NewService(accountsDB, feed)
203203

204204
router := router.NewRouter(rpcClient, transactor, tokenManager, marketManager, collectibles,
205205
collectiblesManager)

0 commit comments

Comments
 (0)