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' ;
@@ -41,18 +41,14 @@ interface SidebarProps {
41
41
accounts : IAccount [ ] ;
42
42
}
43
43
44
- interface SubscribedProps {
45
- keystores ?: Array < { type : 'hardware' | 'software' } > ;
46
- }
47
-
48
44
export type SharedPanelProps = {
49
45
// eslint-disable-next-line react/no-unused-prop-types
50
46
activeSidebar : boolean ;
51
47
// eslint-disable-next-line react/no-unused-prop-types
52
48
sidebarStatus : string ;
53
49
}
54
50
55
- type Props = SubscribedProps & SharedPanelProps & SidebarProps & TranslateProps ;
51
+ type Props = SharedPanelProps & SidebarProps & TranslateProps ;
56
52
57
53
type TGetAccountLinkProps = IAccount & { handleSidebarItemClick : ( ( e : React . SyntheticEvent ) => void ) } ;
58
54
@@ -93,16 +89,30 @@ const GetAccountLink = ({ coinCode, code, name, handleSidebarItemClick }: TGetAc
93
89
) ;
94
90
} ;
95
91
92
+ type State = {
93
+ keystores : TKeystores ;
94
+ }
96
95
97
96
class Sidebar extends Component < Props > {
98
97
private swipe ! : SwipeAttributes ;
98
+ private unsubscribeFn ?: TUnsubscribe ;
99
+
100
+ public readonly state : State = {
101
+ keystores : [ ] ,
102
+ } ;
99
103
100
104
public componentDidMount ( ) {
101
105
this . registerTouchEvents ( ) ;
106
+ getKeystores ( ) . then ( keystores => this . setState ( { keystores } , ( ) => {
107
+ this . unsubscribeFn = subscribeKeystores ( keystores => this . setState ( { keystores } ) ) ;
108
+ } ) ) ;
102
109
}
103
110
104
111
public componentWillUnmount ( ) {
105
112
this . removeTouchEvents ( ) ;
113
+ if ( this . unsubscribeFn ) {
114
+ this . unsubscribeFn ( ) ;
115
+ }
106
116
}
107
117
108
118
private registerTouchEvents = ( ) => {
@@ -159,11 +169,11 @@ class Sidebar extends Component<Props> {
159
169
} ;
160
170
161
171
public render ( ) {
172
+ const { keystores } = this . state ;
162
173
const {
163
174
t,
164
175
deviceIDs,
165
176
accounts,
166
- keystores,
167
177
activeSidebar,
168
178
sidebarStatus,
169
179
} = this . props ;
@@ -265,12 +275,6 @@ function eject(e: React.SyntheticEvent): void {
265
275
e . preventDefault ( ) ;
266
276
}
267
277
268
- const subscribeHOC = subscribe < SubscribedProps , SharedPanelProps & SidebarProps & TranslateProps > (
269
- { keystores : 'keystores' } ,
270
- false ,
271
- false ,
272
- ) ( Sidebar ) ;
273
-
274
- const guideShareHOC = share < SharedPanelProps , SidebarProps & TranslateProps > ( panelStore ) ( subscribeHOC ) ;
278
+ const guideShareHOC = share < SharedPanelProps , SidebarProps & TranslateProps > ( panelStore ) ( Sidebar ) ;
275
279
const translateHOC = translate ( ) ( guideShareHOC ) ;
276
280
export { translateHOC as Sidebar } ;
0 commit comments