2018-04-06 21:32:25 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2018-07-06 21:04:31 +00:00
|
|
|
import { addHexPrefix } from 'ethereumjs-util';
|
2018-04-06 21:32:25 +00:00
|
|
|
import translate, { translateRaw } from 'translations';
|
2018-06-18 01:53:00 +00:00
|
|
|
import { AppState } from 'features/reducers';
|
|
|
|
import { paritySignerActions } from 'features/paritySigner';
|
2018-04-06 21:32:25 +00:00
|
|
|
import { ParityQrSigner } from 'components';
|
|
|
|
import Modal, { IButton } from 'components/ui/Modal';
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
scan: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PropsClosed {
|
|
|
|
isOpen: false;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PropsOpen {
|
|
|
|
isOpen: true;
|
2018-04-26 00:36:29 +00:00
|
|
|
isMessage: boolean;
|
2018-04-06 21:32:25 +00:00
|
|
|
from: string;
|
2018-04-26 00:36:29 +00:00
|
|
|
data: string;
|
2018-04-06 21:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ActionProps {
|
2018-06-18 01:53:00 +00:00
|
|
|
finalizeSignature: paritySignerActions.TFinalizeSignature;
|
2018-04-06 21:32:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Props = (PropsClosed | PropsOpen) & ActionProps;
|
|
|
|
|
|
|
|
class QrSignerModal extends React.Component<Props, State> {
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
scan: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
if (!this.props.isOpen) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { scan } = this.state;
|
2018-04-26 00:36:29 +00:00
|
|
|
const { from, data, isMessage } = this.props;
|
2018-04-06 21:32:25 +00:00
|
|
|
|
|
|
|
const buttons: IButton[] = [
|
|
|
|
{
|
|
|
|
disabled: false,
|
|
|
|
text: translate(scan ? 'ACTION_4' : 'ADD_PARITY_3'),
|
|
|
|
type: 'primary',
|
|
|
|
onClick: () => this.setState({ scan: !scan })
|
|
|
|
},
|
|
|
|
{
|
|
|
|
disabled: false,
|
|
|
|
text: translate('ACTION_2'),
|
|
|
|
type: 'default',
|
|
|
|
onClick: this.onClose
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="QrSignerModal">
|
|
|
|
<Modal
|
2018-04-26 00:36:29 +00:00
|
|
|
title={translateRaw(isMessage ? 'NAV_SIGNMSG' : 'DEP_SIGNTX')}
|
2018-04-06 21:32:25 +00:00
|
|
|
isOpen={true}
|
|
|
|
buttons={buttons}
|
|
|
|
handleClose={this.onClose}
|
|
|
|
>
|
|
|
|
<div className="QrSignerModal-qr-bounds">
|
|
|
|
{scan ? (
|
|
|
|
<ParityQrSigner scan={true} onScan={this.onScan} />
|
2018-04-26 00:36:29 +00:00
|
|
|
) : isMessage ? (
|
|
|
|
<ParityQrSigner scan={false} account={from} data={data} />
|
2018-04-06 21:32:25 +00:00
|
|
|
) : (
|
2018-04-26 00:36:29 +00:00
|
|
|
<ParityQrSigner scan={false} account={from} rlp={data} />
|
2018-04-06 21:32:25 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private onClose = () => {
|
|
|
|
if (!this.props.isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.props.finalizeSignature(null);
|
|
|
|
this.setState({ scan: false });
|
|
|
|
};
|
|
|
|
|
|
|
|
private onScan = (signature: string) => {
|
|
|
|
if (!this.props.isOpen) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-06 21:04:31 +00:00
|
|
|
this.props.finalizeSignature(addHexPrefix(signature));
|
2018-04-06 21:32:25 +00:00
|
|
|
this.setState({ scan: false });
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state: AppState): PropsClosed | PropsOpen {
|
|
|
|
const { requested } = state.paritySigner;
|
|
|
|
|
|
|
|
if (!requested) {
|
|
|
|
return { isOpen: false };
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2018-04-26 00:36:29 +00:00
|
|
|
...requested
|
2018-04-06 21:32:25 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-18 01:53:00 +00:00
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
finalizeSignature: paritySignerActions.finalizeSignature
|
|
|
|
})(QrSignerModal);
|