MyCrypto/common/components/ui/UnlockHeader.jsx

77 lines
1.8 KiB
React
Raw Normal View History

2017-06-26 22:27:55 +00:00
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import translate from 'translations';
2017-06-29 23:03:11 +00:00
import WalletDecrypt from 'components/WalletDecrypt';
import BaseWallet from 'libs/wallet/base';
import { connect } from 'react-redux';
import type { State } from 'reducers';
2017-06-26 22:27:55 +00:00
2017-06-29 23:03:11 +00:00
type Props = {
2017-07-04 03:21:19 +00:00
title: string,
wallet: BaseWallet
2017-06-29 23:03:11 +00:00
};
export class UnlockHeader extends React.Component {
2017-07-04 03:21:19 +00:00
props: Props;
2017-07-02 05:49:06 +00:00
static propTypes = {
title: PropTypes.string.isRequired
};
2017-06-26 22:27:55 +00:00
2017-07-02 05:49:06 +00:00
state: {
expanded: boolean
} = {
expanded: !this.props.wallet
2017-07-02 05:49:06 +00:00
};
2017-06-26 22:27:55 +00:00
2017-07-04 03:21:19 +00:00
componentDidUpdate(prevProps: Props) {
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-07-02 05:49:06 +00:00
render() {
return (
<article className="collapse-container">
<div onClick={this.toggleExpanded}>
<a className="collapse-button">
2017-07-04 03:21:19 +00:00
<span>
{this.state.expanded ? '-' : '+'}
</span>
2017-07-02 05:49:06 +00:00
</a>
2017-07-04 03:21:19 +00:00
<h1>
{translate(this.props.title)}
</h1>
2017-07-02 05:49:06 +00:00
</div>
{this.state.expanded &&
<div>
2017-07-04 03:21:19 +00:00
<WalletDecrypt />
2017-07-02 05:49:06 +00:00
{/* @@if (site === 'cx' ) { <cx-wallet-decrypt-drtv></cx-wallet-decrypt-drtv> }
2017-06-26 22:27:55 +00:00
@@if (site === 'mew' ) { <wallet-decrypt-drtv></wallet-decrypt-drtv> } */}
2017-07-02 05:49:06 +00:00
</div>}
2017-06-26 22:27:55 +00:00
2017-07-02 05:49:06 +00:00
{this.state.expanded && <hr />}
</article>
);
}
2017-06-26 22:27:55 +00:00
2017-07-02 05:49:06 +00:00
toggleExpanded = () => {
this.setState(state => {
return { expanded: !state.expanded };
});
};
2017-06-26 22:27:55 +00:00
}
2017-06-29 23:03:11 +00:00
function mapStateToProps(state: State) {
2017-07-04 03:21:19 +00:00
return {
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);