@@ -21,6 +21,7 @@ import { getAccounts, IAccount } from './api/account';
21
21
import { syncAccountsList } from './api/accountsync' ;
22
22
import { getDeviceList , TDevices } from './api/devices' ;
23
23
import { syncDeviceList } from './api/devicessync' ;
24
+ import { syncNewTxs } from './api/transactions' ;
24
25
import { notifyUser } from './api/system' ;
25
26
import { unsubscribe , UnsubscribeList } from './utils/subscriptions' ;
26
27
import { ConnectedApp } from './connected' ;
@@ -33,70 +34,55 @@ import { MobileDataWarning } from './components/mobiledatawarning';
33
34
import { Sidebar , toggleSidebar } from './components/sidebar/sidebar' ;
34
35
import { Update } from './components/update/update' ;
35
36
import { translate , TranslateProps } from './decorators/translate' ;
36
- import { apiWebsocket } from './utils/websocket' ;
37
37
import { route , RouterWatcher } from './utils/route' ;
38
38
import { Darkmode } from './components/darkmode/darkmode' ;
39
39
import { DarkModeProvider } from './contexts/DarkmodeProvider' ;
40
40
import { AppProvider } from './contexts/AppProvider' ;
41
41
42
- interface State {
43
- accounts : IAccount [ ] ;
44
- devices : TDevices ;
45
- }
42
+ type State = {
43
+ accounts : IAccount [ ] ;
44
+ devices : TDevices ;
45
+ }
46
46
47
- type Props = TranslateProps ;
47
+ type Props = TranslateProps ;
48
48
49
49
class App extends Component < Props , State > {
50
50
public readonly state : State = {
51
51
accounts : [ ] ,
52
52
devices : { } ,
53
53
} ;
54
54
55
- private unsubscribe ! : ( ) => void ;
56
55
private unsubscribeList : UnsubscribeList = [ ] ;
57
56
58
57
/**
59
- * Gets fired when the route changes.
60
- */
58
+ * Gets fired when the route changes.
59
+ */
61
60
private handleRoute = ( ) => {
62
61
if ( panelStore . state . activeSidebar ) {
63
62
toggleSidebar ( ) ;
64
63
}
65
64
} ;
66
65
67
66
public componentDidMount ( ) {
68
- this . unsubscribe = apiWebsocket ( ( payload ) => {
69
- if ( 'type' in payload ) {
70
- const { data, meta, type } = payload ;
71
- switch ( type ) {
72
- case 'backend' :
73
- switch ( data ) {
74
- case 'newTxs' :
75
- notifyUser ( this . props . t ( 'notification.newTxs' , {
76
- count : meta . count ,
77
- accountName : meta . accountName ,
78
- } ) ) ;
79
- break ;
80
- }
81
- break ;
82
- }
83
- }
84
- } ) ;
85
-
86
67
Promise . all ( [ getDeviceList ( ) , getAccounts ( ) ] )
87
68
. then ( ( [ devices , accounts ] ) => {
88
69
this . setStateWithDeviceList ( { accounts, devices } ) ;
89
70
} )
90
71
. catch ( console . error ) ;
91
72
92
73
this . unsubscribeList . push (
74
+ syncNewTxs ( ( meta ) => {
75
+ notifyUser ( this . props . t ( 'notification.newTxs' , {
76
+ count : meta . count ,
77
+ accountName : meta . accountName ,
78
+ } ) ) ;
79
+ } ) ,
93
80
syncAccountsList ( accounts => {
94
81
this . setState ( { accounts } , this . maybeRoute ) ;
95
82
} ) ,
96
83
syncDeviceList ( ( devices ) => {
97
84
this . setStateWithDeviceList ( { devices } ) ;
98
85
} ) ,
99
- // TODO: add syncBackendNewTX
100
86
) ;
101
87
}
102
88
@@ -107,7 +93,7 @@ class App extends Component<Props, State> {
107
93
// if the first device is new
108
94
if (
109
95
newDeviceIDList . length > 0
110
- && newDeviceIDList [ 0 ] !== oldDeviceIDList [ 0 ]
96
+ && newDeviceIDList [ 0 ] !== oldDeviceIDList [ 0 ]
111
97
) {
112
98
// route new unlocked device with accounts
113
99
if ( this . state . accounts . length ) {
@@ -124,7 +110,6 @@ class App extends Component<Props, State> {
124
110
}
125
111
126
112
public componentWillUnmount ( ) {
127
- this . unsubscribe ( ) ;
128
113
unsubscribe ( this . unsubscribeList ) ;
129
114
}
130
115
@@ -143,9 +128,9 @@ class App extends Component<Props, State> {
143
128
// if no accounts are registered on specified views route to /
144
129
if ( accounts . length === 0 && (
145
130
currentURL . startsWith ( '/account-summary' )
146
- || currentURL . startsWith ( '/add-account' )
147
- || currentURL . startsWith ( '/settings/manage-accounts' )
148
- || currentURL . startsWith ( '/passphrase' )
131
+ || currentURL . startsWith ( '/add-account' )
132
+ || currentURL . startsWith ( '/settings/manage-accounts' )
133
+ || currentURL . startsWith ( '/passphrase' )
149
134
) ) {
150
135
route ( '/' , true ) ;
151
136
return ;
0 commit comments