diff --git a/electrum/gui/qml/components/AddressDetails.qml b/electrum/gui/qml/components/AddressDetails.qml index eb5d815fa..b72fff689 100644 --- a/electrum/gui/qml/components/AddressDetails.qml +++ b/electrum/gui/qml/components/AddressDetails.qml @@ -172,13 +172,67 @@ Pane { } Label { + Layout.columnSpan: 2 + Layout.topMargin: constants.paddingSmall + visible: !Daemon.currentWallet.isWatchOnly + text: qsTr('Private key') + color: Material.accentColor + } + + TextHighlightPane { + Layout.columnSpan: 2 + Layout.fillWidth: true + visible: !Daemon.currentWallet.isWatchOnly + RowLayout { + width: parent.width + Label { + id: privateKeyText + Layout.fillWidth: true + visible: addressdetails.privkey + text: addressdetails.privkey + wrapMode: Text.Wrap + font.pixelSize: constants.fontSizeLarge + font.family: FixedFont + } + Label { + id: showPrivateKeyText + Layout.fillWidth: true + visible: !addressdetails.privkey + horizontalAlignment: Text.AlignHCenter + text: qsTr('Tap to show private key') + wrapMode: Text.Wrap + font.pixelSize: constants.fontSizeLarge + } + ToolButton { + icon.source: '../../icons/share.png' + visible: addressdetails.privkey + onClicked: { + var dialog = app.genericShareDialog.createObject(root, { + title: qsTr('Private key'), + text: addressdetails.privkey + }) + dialog.open() + } + } + + MouseArea { + anchors.fill: parent + enabled: !addressdetails.privkey + onClicked: addressdetails.requestShowPrivateKey() + } + } + } + + Label { + Layout.topMargin: constants.paddingSmall text: qsTr('Script type') color: Material.accentColor } Label { - text: addressdetails.scriptType + Layout.topMargin: constants.paddingSmall Layout.fillWidth: true + text: addressdetails.scriptType } Label { @@ -235,5 +289,8 @@ Pane { address: root.address onFrozenChanged: addressDetailsChanged() onLabelChanged: addressDetailsChanged() + onAuthRequired: { + app.handleAuthRequired(addressdetails, method, authMessage) + } } } diff --git a/electrum/gui/qml/qeaddressdetails.py b/electrum/gui/qml/qeaddressdetails.py index 096ba506f..f09cbb630 100644 --- a/electrum/gui/qml/qeaddressdetails.py +++ b/electrum/gui/qml/qeaddressdetails.py @@ -2,12 +2,13 @@ from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject from electrum.logging import get_logger +from .auth import auth_protect, AuthMixin from .qetransactionlistmodel import QETransactionListModel from .qetypes import QEAmount from .qewallet import QEWallet -class QEAddressDetails(QObject): +class QEAddressDetails(AuthMixin, QObject): _logger = get_logger(__name__) detailsChanged = pyqtSignal() @@ -66,6 +67,10 @@ class QEAddressDetails(QObject): def pubkeys(self): return self._pubkeys + @pyqtProperty(str, notify=detailsChanged) + def privkey(self): + return self._privkey + @pyqtProperty(str, notify=detailsChanged) def derivationPath(self): return self._derivationPath @@ -108,6 +113,19 @@ class QEAddressDetails(QObject): onchain_domain=[self._address], include_lightning=False) return self._historyModel + @pyqtSlot() + def requestShowPrivateKey(self): + self.retrieve_private_key() + + @auth_protect(method='wallet') + def retrieve_private_key(self): + try: + self._privkey = self._wallet.wallet.export_private_key(self._address, self._wallet.password) + except Exception: + self._privkey = '' + + self.detailsChanged.emit() + def update(self): if self._wallet is None: self._logger.error('wallet undefined')