From 3c58075e9fffd8455ba59754b524e305ad896779 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Thu, 16 Nov 2017 20:18:29 +0300 Subject: [PATCH] add back copy wif key; refactor receive coin buttons into context menu --- react/src/actions/actions/settings.js | 38 ++++++++++++++++ .../components/dashboard/qrModal/qrModal.js | 12 ++--- .../dashboard/qrModal/qrModal.render.js | 7 +-- .../dashboard/receiveCoin/receiveCoin.js | 34 +++++++++++++- .../receiveCoin/receiveCoin.render.js | 29 +++++++++--- react/src/components/overrides.scss | 45 +++++++++++++++++++ 6 files changed, 149 insertions(+), 16 deletions(-) diff --git a/react/src/actions/actions/settings.js b/react/src/actions/actions/settings.js index 4532c12..5db5ebf 100644 --- a/react/src/actions/actions/settings.js +++ b/react/src/actions/actions/settings.js @@ -440,4 +440,42 @@ export function getWalletDatKeys(chain, keyMatchPattern) { resolve(json); }); }); +} + +export function dumpPrivKey(coin, address) { + return new Promise((resolve, reject) => { + const payload = { + mode: null, + chain: coin, + cmd: 'dumpprivkey', + params: [ address ] + }; + + const _fetchConfig = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ 'payload': payload }), + }; + + fetch( + `http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, + _fetchConfig + ) + .catch(function(error) { + console.log(error); + dispatch( + triggerToaster( + 'dumpPrivKey', + 'Error', + 'error' + ) + ); + }) + .then(response => response.json()) + .then(json => { + resolve(json.result ? json.result : json); + }) + }); } \ No newline at end of file diff --git a/react/src/components/dashboard/qrModal/qrModal.js b/react/src/components/dashboard/qrModal/qrModal.js index b5e366f..85002ac 100755 --- a/react/src/components/dashboard/qrModal/qrModal.js +++ b/react/src/components/dashboard/qrModal/qrModal.js @@ -70,12 +70,12 @@ class QRModal extends React.Component { } saveAsImage(e) { - const qrCanvas = document.getElementById('qrModalCanvas' + this.props.content); - const canvas = qrCanvas.getElementsByTagName('canvas'); - const dataURL = canvas[0].toDataURL(); - const a = document.getElementById('saveModalImage' + this.props.content); - a.href = dataURL; - a.download = this.props.content; + const qrCanvas = document.getElementById('qrModalCanvas' + this.props.content); + const canvas = qrCanvas.getElementsByTagName('canvas'); + const dataURL = canvas[0].toDataURL(); + const a = document.getElementById('saveModalImage' + this.props.content); + a.href = dataURL; + a.download = this.props.content; } render() { diff --git a/react/src/components/dashboard/qrModal/qrModal.render.js b/react/src/components/dashboard/qrModal/qrModal.render.js index a96f886..7aa8650 100644 --- a/react/src/components/dashboard/qrModal/qrModal.render.js +++ b/react/src/components/dashboard/qrModal/qrModal.render.js @@ -5,10 +5,11 @@ import QRCode from 'qrcode.react'; export const QRModalRender = function() { return ( - - + generate QR-code
-
{ + if (json.length && + json.length > 10) { + Store.dispatch(copyString(json, 'WIF address copied to clipboard')); + } + }); + } + handleClickOutside(e) { - if (e.srcElement.className.indexOf('dropdown') === -1 && + if (e && + e.srcElement && + e.srcElement.offsetParent && + e.srcElement.offsetParent.className.indexOf('dropdown') === -1 && (e.srcElement.offsetParent && e.srcElement.offsetParent.className.indexOf('dropdown') === -1)) { this.setState({ openDropMenu: false, + toggledAddressMenu: + e.srcElement.className.indexOf('receive-address-context-menu-trigger') === -1 && + e.srcElement.className.indexOf('fa-qrcode') === -1 && + e.srcElement.className.indexOf('receive-address-context-menu-get-qr') === -1 && + e.srcElement.className.indexOf('qrcode-modal') === -1 ? null : this.state.toggledAddressMenu, }); } } @@ -64,6 +93,7 @@ class ReceiveCoin extends React.Component { } _copyCoinAddress(address) { + this.toggleAddressMenu(address); Store.dispatch(copyCoinAddress(address)); } diff --git a/react/src/components/dashboard/receiveCoin/receiveCoin.render.js b/react/src/components/dashboard/receiveCoin/receiveCoin.render.js index 657de38..c8915b9 100644 --- a/react/src/components/dashboard/receiveCoin/receiveCoin.render.js +++ b/react/src/components/dashboard/receiveCoin/receiveCoin.render.js @@ -7,15 +7,34 @@ export const AddressActionsNonBasiliskModeRender = function(address, type) { return ( - +   { type === 'public' ? translate('IAPI.PUBLIC_SM') : translate('KMD_NATIVE.PRIVATE') } - + { this.state.toggledAddressMenu && + this.state.toggledAddressMenu === address && +
+
    +
  • this._copyCoinAddress(address) }> + { translate('INDEX.COPY') + ' pub key' } +
  • + { address[0] !== 'b' && +
  • this.dumpPrivKey(address) }> + { translate('INDEX.COPY') + ' priv key (WIF)' } +
  • + } +
  • + +
  • +
+
+ } ); }; diff --git a/react/src/components/overrides.scss b/react/src/components/overrides.scss index d885da6..62ea340 100644 --- a/react/src/components/overrides.scss +++ b/react/src/components/overrides.scss @@ -546,4 +546,49 @@ select{ .settings-coind-stdout-textarea { border: none; background-image: none !important; +} + +.receive-address-context-menu { + box-shadow: 0 1px 2px 1px rgba(0, 0, 0, 0.4); + background: #fff; + position: absolute; + z-index: 100; + margin-left: 65px; + margin-top: 5px; + + ul { + margin: 0; + list-style: none; + -webkit-margin-before: 0; + -webkit-margin-after: 0; + -webkit-margin-start: 0; + -webkit-margin-end: 0; + -webkit-padding-start: 0; + + li { + padding: 5px 15px; + + &:first-child { + margin-top: 5px; + } + &:last-child { + margin-bottom: 5px; + } + &:hover { + background: #f9f9f9; + cursor: pointer; + } + } + } + &.closed { + z-index: 1700; + position: absolute; + top: -100%; + left: -100%; + } + .receive-address-context-menu-get-qr { + .modal { + cursor: default; + } + } } \ No newline at end of file