17
17
18
18
import React , { Component } from 'react' ;
19
19
import { Link , NavLink } from 'react-router-dom' ;
20
+ import { TKeystores , subscribeKeystores , TUnsubscribe , getKeystores } from '../../api/keystores' ;
20
21
import { IAccount } from '../../api/account' ;
21
22
import coins from '../../assets/icons/coins.svg' ;
22
23
import ejectIcon from '../../assets/icons/eject.svg' ;
23
24
import info from '../../assets/icons/info.svg' ;
24
25
import settings from '../../assets/icons/settings-alt.svg' ;
25
26
import settingsGrey from '../../assets/icons/settings-alt_disabled.svg' ;
26
27
import { share } from '../../decorators/share' ;
27
- import { subscribe } from '../../decorators/subscribe' ;
28
28
import { translate , TranslateProps } from '../../decorators/translate' ;
29
29
import { debug } from '../../utils/env' ;
30
30
import { apiPost } from '../../utils/request' ;
@@ -40,18 +40,14 @@ interface SidebarProps {
40
40
accounts : IAccount [ ] ;
41
41
}
42
42
43
- interface SubscribedProps {
44
- keystores ?: Array < { type : 'hardware' | 'software' } > ;
45
- }
46
-
47
43
export type SharedPanelProps = {
48
44
// eslint-disable-next-line react/no-unused-prop-types
49
45
activeSidebar : boolean ;
50
46
// eslint-disable-next-line react/no-unused-prop-types
51
47
sidebarStatus : string ;
52
48
}
53
49
54
- type Props = SubscribedProps & SharedPanelProps & SidebarProps & TranslateProps ;
50
+ type Props = SharedPanelProps & SidebarProps & TranslateProps ;
55
51
56
52
type TGetAccountLinkProps = IAccount & { handleSidebarItemClick : ( ( e : React . SyntheticEvent ) => void ) } ;
57
53
@@ -92,16 +88,30 @@ const GetAccountLink = ({ coinCode, code, name, handleSidebarItemClick }: TGetAc
92
88
) ;
93
89
} ;
94
90
91
+ type State = {
92
+ keystores : TKeystores ;
93
+ }
95
94
96
95
class Sidebar extends Component < Props > {
97
96
private swipe ! : SwipeAttributes ;
97
+ private unsubscribeFn ?: TUnsubscribe ;
98
+
99
+ public readonly state : State = {
100
+ keystores : [ ] ,
101
+ } ;
98
102
99
103
public componentDidMount ( ) {
100
104
this . registerTouchEvents ( ) ;
105
+ getKeystores ( ) . then ( keystores => this . setState ( { keystores } , ( ) => {
106
+ this . unsubscribeFn = subscribeKeystores ( keystores => this . setState ( { keystores } ) ) ;
107
+ } ) ) ;
101
108
}
102
109
103
110
public componentWillUnmount ( ) {
104
111
this . removeTouchEvents ( ) ;
112
+ if ( this . unsubscribeFn ) {
113
+ this . unsubscribeFn ( ) ;
114
+ }
105
115
}
106
116
107
117
private registerTouchEvents = ( ) => {
@@ -158,11 +168,11 @@ class Sidebar extends Component<Props> {
158
168
} ;
159
169
160
170
public render ( ) {
171
+ const { keystores } = this . state ;
161
172
const {
162
173
t,
163
174
deviceIDs,
164
175
accounts,
165
- keystores,
166
176
activeSidebar,
167
177
sidebarStatus,
168
178
} = this . props ;
@@ -255,12 +265,6 @@ function eject(e: React.SyntheticEvent): void {
255
265
e . preventDefault ( ) ;
256
266
}
257
267
258
- const subscribeHOC = subscribe < SubscribedProps , SharedPanelProps & SidebarProps & TranslateProps > (
259
- { keystores : 'keystores' } ,
260
- false ,
261
- false ,
262
- ) ( Sidebar ) ;
263
-
264
- const guideShareHOC = share < SharedPanelProps , SidebarProps & TranslateProps > ( panelStore ) ( subscribeHOC ) ;
268
+ const guideShareHOC = share < SharedPanelProps , SidebarProps & TranslateProps > ( panelStore ) ( Sidebar ) ;
265
269
const translateHOC = translate ( ) ( guideShareHOC ) ;
266
270
export { translateHOC as Sidebar } ;
0 commit comments