2017-06-29 23:03:11 +00:00
|
|
|
import WalletDecrypt from 'components/WalletDecrypt';
|
2017-09-25 02:06:28 +00:00
|
|
|
import { IWallet } from 'libs/wallet/IWallet';
|
|
|
|
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-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
interface Props {
|
2017-10-11 05:04:49 +00:00
|
|
|
title: React.ReactElement<any>;
|
2017-09-25 02:06:28 +00:00
|
|
|
wallet: IWallet;
|
2017-11-29 23:14:57 +00:00
|
|
|
allowReadOnly?: boolean;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
|
|
|
interface State {
|
|
|
|
expanded: boolean;
|
|
|
|
}
|
|
|
|
export class UnlockHeader extends React.Component<Props, State> {
|
|
|
|
public state = {
|
2017-07-13 21:02:39 +00:00
|
|
|
expanded: !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) {
|
2017-07-04 03:21:19 +00:00
|
|
|
if (this.props.wallet && this.props.wallet !== prevProps.wallet) {
|
|
|
|
this.setState({ expanded: false });
|
|
|
|
}
|
2017-06-29 23:03:11 +00:00
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
// not sure if could happen
|
|
|
|
if (!this.props.wallet && this.props.wallet !== prevProps.wallet) {
|
|
|
|
this.setState({ expanded: true });
|
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() {
|
2017-11-29 23:14:57 +00:00
|
|
|
const { title, allowReadOnly } = this.props;
|
2017-07-02 05:49:06 +00:00
|
|
|
return (
|
|
|
|
<article className="collapse-container">
|
2017-10-11 05:04:49 +00:00
|
|
|
<div>
|
|
|
|
<a className="collapse-button" onClick={this.toggleExpanded}>
|
|
|
|
<span>{this.state.expanded ? '-' : '+'}</span>
|
2017-07-02 05:49:06 +00:00
|
|
|
</a>
|
2017-10-11 05:04:49 +00:00
|
|
|
<h1>{title}</h1>
|
2017-07-02 05:49:06 +00:00
|
|
|
</div>
|
2017-11-29 23:14:57 +00:00
|
|
|
{this.state.expanded && <WalletDecrypt allowReadOnly={allowReadOnly} />}
|
2017-07-02 05:49:06 +00:00
|
|
|
{this.state.expanded && <hr />}
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
2017-06-26 22:27:55 +00:00
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
public toggleExpanded = () => {
|
2017-07-02 05:49:06 +00:00
|
|
|
this.setState(state => {
|
|
|
|
return { expanded: !state.expanded };
|
|
|
|
});
|
|
|
|
};
|
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);
|