1717
1818import React , { Component } from 'react' ;
1919import { Link , NavLink } from 'react-router-dom' ;
20+ import { TKeystores , subscribeKeystores , TUnsubscribe , getKeystores } from '../../api/keystores' ;
2021import { IAccount } from '../../api/account' ;
2122import coins from '../../assets/icons/coins.svg' ;
2223import ejectIcon from '../../assets/icons/eject.svg' ;
2324import info from '../../assets/icons/info.svg' ;
2425import settings from '../../assets/icons/settings-alt.svg' ;
2526import settingsGrey from '../../assets/icons/settings-alt_disabled.svg' ;
2627import { share } from '../../decorators/share' ;
27- import { subscribe } from '../../decorators/subscribe' ;
2828import { translate , TranslateProps } from '../../decorators/translate' ;
2929import { debug } from '../../utils/env' ;
3030import { apiPost } from '../../utils/request' ;
@@ -40,18 +40,14 @@ interface SidebarProps {
4040 accounts : IAccount [ ] ;
4141}
4242
43- interface SubscribedProps {
44- keystores ?: Array < { type : 'hardware' | 'software' } > ;
45- }
46-
4743export type SharedPanelProps = {
4844 // eslint-disable-next-line react/no-unused-prop-types
4945 activeSidebar : boolean ;
5046 // eslint-disable-next-line react/no-unused-prop-types
5147 sidebarStatus : string ;
5248}
5349
54- type Props = SubscribedProps & SharedPanelProps & SidebarProps & TranslateProps ;
50+ type Props = SharedPanelProps & SidebarProps & TranslateProps ;
5551
5652type TGetAccountLinkProps = IAccount & { handleSidebarItemClick : ( ( e : React . SyntheticEvent ) => void ) } ;
5753
@@ -92,16 +88,30 @@ const GetAccountLink = ({ coinCode, code, name, handleSidebarItemClick }: TGetAc
9288 ) ;
9389} ;
9490
91+ type State = {
92+ keystores : TKeystores ;
93+ }
9594
9695class Sidebar extends Component < Props > {
9796 private swipe ! : SwipeAttributes ;
97+ private unsubscribeFn ?: TUnsubscribe ;
98+
99+ public readonly state : State = {
100+ keystores : [ ] ,
101+ } ;
98102
99103 public componentDidMount ( ) {
100104 this . registerTouchEvents ( ) ;
105+ getKeystores ( ) . then ( keystores => this . setState ( { keystores } , ( ) => {
106+ this . unsubscribeFn = subscribeKeystores ( keystores => this . setState ( { keystores } ) ) ;
107+ } ) ) ;
101108 }
102109
103110 public componentWillUnmount ( ) {
104111 this . removeTouchEvents ( ) ;
112+ if ( this . unsubscribeFn ) {
113+ this . unsubscribeFn ( ) ;
114+ }
105115 }
106116
107117 private registerTouchEvents = ( ) => {
@@ -158,11 +168,11 @@ class Sidebar extends Component<Props> {
158168 } ;
159169
160170 public render ( ) {
171+ const { keystores } = this . state ;
161172 const {
162173 t,
163174 deviceIDs,
164175 accounts,
165- keystores,
166176 activeSidebar,
167177 sidebarStatus,
168178 } = this . props ;
@@ -255,12 +265,6 @@ function eject(e: React.SyntheticEvent): void {
255265 e . preventDefault ( ) ;
256266}
257267
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 ) ;
265269const translateHOC = translate ( ) ( guideShareHOC ) ;
266270export { translateHOC as Sidebar } ;
0 commit comments