import React from 'react'; import { connect } from 'react-redux'; import { AppState } from 'reducers'; import translate from 'translations'; import WalletDecrypt from 'components/WalletDecrypt'; import { IWallet } from 'libs/wallet/IWallet'; import './UnlockHeader.scss'; interface Props { title: React.ReactElement; wallet: IWallet; disabledWallets?: string[]; } interface State { isExpanded: boolean; } export class UnlockHeader extends React.Component { public state = { isExpanded: !this.props.wallet }; public componentDidUpdate(prevProps: Props) { if (this.props.wallet && this.props.wallet !== prevProps.wallet) { this.setState({ isExpanded: !this.state.isExpanded }); } } public render() { const { title, wallet, disabledWallets } = this.props; const { isExpanded } = this.state; return (

{title}

{wallet && !isExpanded && ( )} {wallet && isExpanded && ( )}
); } public toggleisExpanded = () => { this.setState(state => { return { isExpanded: !state.isExpanded }; }); }; } function mapStateToProps(state: AppState) { return { wallet: state.wallet.inst }; } export default connect(mapStateToProps)(UnlockHeader);