2017-09-25 02:06:28 +00:00
|
|
|
import React from 'react';
|
2017-06-29 23:03:11 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-09-25 02:06:28 +00:00
|
|
|
import { AppState } from 'reducers';
|
2017-12-15 04:52:59 +00:00
|
|
|
import translate from 'translations';
|
|
|
|
import WalletDecrypt from 'components/WalletDecrypt';
|
|
|
|
import { IWallet } from 'libs/wallet/IWallet';
|
|
|
|
import './UnlockHeader.scss';
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
2018-01-11 18:04:11 +00:00
|
|
|
title: React.ReactElement<string> | string;
|
2017-09-25 02:06:28 +00:00
|
|
|
wallet: IWallet;
|
2018-01-01 19:46:28 +00:00
|
|
|
disabledWallets?: string[];
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
|
|
|
interface State {
|
2017-12-15 04:52:59 +00:00
|
|
|
isExpanded: boolean;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
|
|
|
export class UnlockHeader extends React.Component<Props, State> {
|
|
|
|
public state = {
|
2017-12-15 04:52:59 +00:00
|
|
|
isExpanded: !this.props.wallet
|
2017-07-02 05:49:06 +00:00
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public componentDidUpdate(prevProps: Props) {
|
2018-01-15 06:27:26 +00:00
|
|
|
if (this.props.wallet !== prevProps.wallet) {
|
2017-12-15 04:52:59 +00:00
|
|
|
this.setState({ isExpanded: !this.state.isExpanded });
|
2017-06-29 23:03:11 +00:00
|
|
|
}
|
2017-07-04 03:21:19 +00:00
|
|
|
}
|
2017-06-29 23:03:11 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
2018-01-01 19:46:28 +00:00
|
|
|
const { title, wallet, disabledWallets } = this.props;
|
2017-12-15 04:52:59 +00:00
|
|
|
const { isExpanded } = this.state;
|
|
|
|
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
2017-12-15 04:52:59 +00:00
|
|
|
<article className="UnlockHeader">
|
|
|
|
<h1 className="UnlockHeader-title">{title}</h1>
|
|
|
|
{wallet &&
|
|
|
|
!isExpanded && (
|
|
|
|
<button
|
|
|
|
className="UnlockHeader-open btn btn-default btn-smr"
|
|
|
|
onClick={this.toggleisExpanded}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
<span className="hidden-xs UnlockHeader-open-text">
|
|
|
|
{translate('Change Wallet')}
|
|
|
|
</span>
|
|
|
|
<i className="fa fa-refresh" />
|
|
|
|
</span>
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{wallet &&
|
|
|
|
isExpanded && (
|
|
|
|
<button className="UnlockHeader-close" onClick={this.toggleisExpanded}>
|
|
|
|
<i className="fa fa-times" />
|
|
|
|
</button>
|
|
|
|
)}
|
2018-01-01 19:46:28 +00:00
|
|
|
<WalletDecrypt hidden={!this.state.isExpanded} disabledWallets={disabledWallets} />
|
2017-07-02 05:49:06 +00:00
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-12-15 04:52:59 +00:00
|
|
|
public toggleisExpanded = () => {
|
2017-07-02 05:49:06 +00:00
|
|
|
this.setState(state => {
|
2017-12-15 04:52:59 +00:00
|
|
|
return { isExpanded: !state.isExpanded };
|
2017-07-02 05:49:06 +00:00
|
|
|
});
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
2017-06-29 23:03:11 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
function mapStateToProps(state: AppState) {
|
2017-07-04 03:21:19 +00:00
|
|
|
return {
|
2017-07-13 21:02:39 +00:00
|
|
|
wallet: state.wallet.inst
|
2017-07-04 03:21:19 +00:00
|
|
|
};
|
2017-06-29 23:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(UnlockHeader);
|