1
1
package localbackup
2
2
3
3
import (
4
+ "encoding/json"
4
5
"errors"
5
6
7
+ "github.com/ethereum/go-ethereum/event"
6
8
"github.com/golang/protobuf/proto"
7
9
"github.com/status-im/status-go/eth-node/types"
8
10
"github.com/status-im/status-go/multiaccounts/accounts"
9
11
multiaccountscommon "github.com/status-im/status-go/multiaccounts/common"
10
12
"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"
11
15
)
12
16
13
17
// TODO this is duplicated
@@ -16,14 +20,20 @@ var (
16
20
ErrTryingToStoreOldWalletAccount = errors .New ("trying to store an old wallet account" )
17
21
)
18
22
23
+ const (
24
+ EventWatchOnlyAccountRetrieved walletevent.EventType = "wallet-watch-only-account-retrieved"
25
+ )
26
+
19
27
// Service is a wallet local backup service.
20
28
type Service struct {
21
29
accountsDB * accounts.Database
30
+ feed * event.Feed
22
31
}
23
32
24
- func NewService (accountsDB * accounts.Database ) * Service {
33
+ func NewService (accountsDB * accounts.Database , feed * event. Feed ) * Service {
25
34
return & Service {
26
35
accountsDB : accountsDB ,
36
+ feed : feed ,
27
37
}
28
38
}
29
39
@@ -138,19 +148,6 @@ func (s *Service) handleSyncWatchOnlyAccount(message *protobuf.SyncAccount) (*ac
138
148
return nil , err
139
149
}
140
150
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
- // }
154
151
return acc , nil
155
152
}
156
153
@@ -159,18 +156,22 @@ func (s *Service) handleWatchOnlyAccount(message *protobuf.SyncAccount) error {
159
156
return nil
160
157
}
161
158
162
- _ , err := s .handleSyncWatchOnlyAccount (message )
159
+ acc , err := s .handleSyncWatchOnlyAccount (message )
163
160
if err != nil {
164
161
return err
165
162
}
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 )
174
175
175
176
return nil
176
177
}
0 commit comments