diff --git a/app/assets/locales/locale-cn.json b/app/assets/locales/locale-cn.json index eb900fba8b..778b0f679e 100644 --- a/app/assets/locales/locale-cn.json +++ b/app/assets/locales/locale-cn.json @@ -1155,6 +1155,11 @@ "approval_remove": "同意移除", "key_approval_add": "同意添加密钥", "key_approval_remove": "同意移除密钥" + }, + "qrcode":{ + "label":"二维码", + "title":"私钥二维码", + "input_messate":"请输入用于加密二维码的密码,密码为空表示不加密" } }, "init_error": { diff --git a/app/assets/locales/locale-en.json b/app/assets/locales/locale-en.json index d0f389ba64..20a3e5631c 100644 --- a/app/assets/locales/locale-en.json +++ b/app/assets/locales/locale-en.json @@ -1187,7 +1187,12 @@ "key_approval_add": "Key approval to add", "key_approval_remove": "Key approval to remove" }, - "ok": "OK" + "ok": "OK", + "qrcode":{ + "label":"qrcode", + "title":"Private key QR code", + "input_messate":"Please enter the password used to encrypt the QR code, the password is empty that does not encrypt." + } }, "init_error": { "title": "Application initialization issues", diff --git a/app/components/Modal/QrcodeModal.jsx b/app/components/Modal/QrcodeModal.jsx new file mode 100644 index 0000000000..e028347e43 --- /dev/null +++ b/app/components/Modal/QrcodeModal.jsx @@ -0,0 +1,119 @@ +import React, {PropTypes} from "react"; +import ZfApi from "react-foundation-apps/src/utils/foundation-api"; +import BaseModal from "./BaseModal"; +import Translate from "react-translate-component"; +import QRCode from "qrcode.react"; +import {Aes} from "bitsharesjs/es"; + + +class QrcodeModal extends React.Component { + constructor(props) { + super(props); + this.state = this._getInitialState(); + this.onPasswordEnter = this.onPasswordEnter.bind(this); + this.onKeyDown = this.onKeyDown.bind(this); + this.onCancel = this.onCancel.bind(this); + this.onClose = this.onClose.bind(this); + } + + _getInitialState() { + return { + isShowQrcode: false, + keyString: null + }; + } + + show() { + ZfApi.publish(this.props.modalId, "open"); + } + + onCancel() { + ZfApi.publish(this.props.modalId, "close"); + this.onClose(); + } + + onClose() { + if (this.refs.password_input) this.refs.password_input.value = ""; + this.setState(this._getInitialState()); + } + + onPasswordEnter(e) { + e.preventDefault(); + let pwd = this.refs.password_input.value; + let key = this.props.keyValue; + if (pwd != null && pwd != "") { + if (key !== undefined && key != null && key != "") { + let pwd_aes = Aes.fromSeed(pwd); + let qrkey = pwd_aes.encryptToHex(key); + this.setState({isShowQrcode: true, keyString: qrkey}); + } + } else { + //notify.error("You'd better enter a password to encrypt the qr code"); + this.setState({isShowQrcode: true, keyString: key}); + } + } + + onKeyDown(e) { + if (e.keyCode === 13) this.onPasswordEnter(e); + } + + + render() { + let pos = null; + if(this.state.isShowQrcode)pos = {textAlign: "center"}; + return ( + +

+ +

+
+
+ {this.state.isShowQrcode ? +
+ +
+ : +
+ + { + this.refs.password_input.setAttribute("type", "password"); + }} + ref="password_input" + autoComplete="off" + onKeyDown={this.onKeyDown} + /> +
+ } +
+
+
+ {this.state.isShowQrcode == false ? + + : + null + } + +
+
+
+
+ ); + } +} + +QrcodeModal.propTypes = { + modalId: PropTypes.string.isRequired, + keyValue: PropTypes.string +}; +QrcodeModal.defaultProps = { + modalId: "qr_code_password_modal" +}; +export default QrcodeModal; + \ No newline at end of file diff --git a/app/components/PrivateKeyView.jsx b/app/components/PrivateKeyView.jsx index c580e7d770..498c02e90f 100644 --- a/app/components/PrivateKeyView.jsx +++ b/app/components/PrivateKeyView.jsx @@ -5,6 +5,7 @@ import WalletUnlockActions from "actions/WalletUnlockActions"; import WalletDb from "stores/WalletDb"; import Translate from "react-translate-component"; import PrivateKeyStore from "stores/PrivateKeyStore"; +import QrcodeModal from "./Modal/QrcodeModal"; export default class PrivateKeyView extends Component { @@ -58,7 +59,7 @@ export default class PrivateKeyView extends Component {
{this.state.wif ? {this.state.wif} -  (hide) +  (hide,) : () } @@ -86,6 +87,7 @@ export default class PrivateKeyView extends Component {
+ } @@ -111,4 +113,8 @@ export default class PrivateKeyView extends Component { this.setState({ wif: null }) } + showQrCode(){ + this.refs.qrmodal.show(); + } + } diff --git a/package.json b/package.json index f739b01ae3..7819bf059c 100644 --- a/package.json +++ b/package.json @@ -145,6 +145,7 @@ "numeral": "2.0.4", "object-assign": "^4.0.1", "perfect-scrollbar": "git+https://github.com/bitshares/perfect-scrollbar.git", + "qrcode.react": "^0.7.1", "react": "^15.6.1", "react-clipboard.js": "^1.0.1", "react-dom": "^15.6.1",