Browse Source

qml: make txdetails less reliant on txid

master
Sander van Grieken 3 years ago
parent
commit
b9ec04f13a
  1. 1
      electrum/gui/qml/components/CpfpBumpFeeDialog.qml
  2. 1
      electrum/gui/qml/components/RbfBumpFeeDialog.qml
  3. 1
      electrum/gui/qml/components/RbfCancelDialog.qml
  4. 25
      electrum/gui/qml/components/TxDetails.qml
  5. 17
      electrum/gui/qml/qetxdetails.py
  6. 8
      electrum/gui/qml/qewallet.py

1
electrum/gui/qml/components/CpfpBumpFeeDialog.qml

@ -10,7 +10,6 @@ import "controls"
ElDialog {
id: dialog
required property string txid
required property QtObject cpfpfeebumper
title: qsTr('Bump Fee')

1
electrum/gui/qml/components/RbfBumpFeeDialog.qml

@ -10,7 +10,6 @@ import "controls"
ElDialog {
id: dialog
required property string txid
required property QtObject rbffeebumper
title: qsTr('Bump Fee')

1
electrum/gui/qml/components/RbfCancelDialog.qml

@ -10,7 +10,6 @@ import "controls"
ElDialog {
id: dialog
required property string txid
required property QtObject txcanceller
title: qsTr('Cancel Transaction')

25
electrum/gui/qml/components/TxDetails.qml

@ -15,7 +15,6 @@ Pane {
property string txid
property string rawtx
property alias label: txdetails.label
signal detailsChanged
@ -311,9 +310,9 @@ Pane {
visible: txdetails.canBump || txdetails.canCpfp
onClicked: {
if (txdetails.canBump) {
var dialog = rbfBumpFeeDialog.createObject(root, { txid: root.txid })
var dialog = rbfBumpFeeDialog.createObject(root, { txid: txdetails.txid })
} else {
var dialog = cpfpBumpFeeDialog.createObject(root, { txid: root.txid })
var dialog = cpfpBumpFeeDialog.createObject(root, { txid: txdetails.txid })
}
dialog.open()
}
@ -326,7 +325,7 @@ Pane {
text: qsTr('Cancel Tx')
visible: txdetails.canCancel
onClicked: {
var dialog = rbfCancelDialog.createObject(root, { txid: root.txid })
var dialog = rbfCancelDialog.createObject(root, { txid: txdetails.txid })
dialog.open()
}
}
@ -400,8 +399,6 @@ Pane {
TxDetails {
id: txdetails
wallet: Daemon.currentWallet
txid: root.txid
rawtx: root.rawtx
onLabelChanged: root.detailsChanged()
onConfirmRemoveLocalTx: {
var dialog = app.messageDialog.createObject(app, { text: message, yesno: true })
@ -411,6 +408,13 @@ Pane {
})
dialog.open()
}
Component.onCompleted: {
if (root.txid) {
txdetails.txid = root.txid
} else if (root.rawtx) {
txdetails.rawtx = root.rawtx
}
}
}
Connections {
@ -440,13 +444,14 @@ Pane {
id: rbfBumpFeeDialog
RbfBumpFeeDialog {
id: dialog
required property string txid
rbffeebumper: TxRbfFeeBumper {
id: rbffeebumper
wallet: Daemon.currentWallet
txid: dialog.txid
}
onAccepted: {
root.rawtx = rbffeebumper.getNewTx()
txdetails.rawtx = rbffeebumper.getNewTx()
if (txdetails.wallet.canSignWithoutCosigner) {
txdetails.signAndBroadcast()
} else {
@ -465,6 +470,7 @@ Pane {
id: cpfpBumpFeeDialog
CpfpBumpFeeDialog {
id: dialog
required property string txid
cpfpfeebumper: TxCpfpFeeBumper {
id: cpfpfeebumper
wallet: Daemon.currentWallet
@ -473,7 +479,7 @@ Pane {
onAccepted: {
// replaces parent tx with cpfp tx
root.rawtx = cpfpfeebumper.getNewTx()
txdetails.rawtx = cpfpfeebumper.getNewTx()
if (txdetails.wallet.canSignWithoutCosigner) {
txdetails.signAndBroadcast()
} else {
@ -492,6 +498,7 @@ Pane {
id: rbfCancelDialog
RbfCancelDialog {
id: dialog
required property string txid
txcanceller: TxCanceller {
id: txcanceller
wallet: Daemon.currentWallet
@ -499,7 +506,7 @@ Pane {
}
onAccepted: {
root.rawtx = txcanceller.getNewTx()
txdetails.rawtx = txcanceller.getNewTx()
if (txdetails.wallet.canSignWithoutCosigner) {
txdetails.signAndBroadcast()
} else {

17
electrum/gui/qml/qetxdetails.py

@ -95,10 +95,10 @@ class QETxDetails(QObject, QtEventListener):
@txid.setter
def txid(self, txid: str):
if self._txid != txid:
self._logger.debug('txid set -> %s' % txid)
self._logger.debug(f'txid set -> {txid}')
self._txid = txid
self.txidChanged.emit()
self.update()
self.update(from_txid=True)
@pyqtProperty(str, notify=detailsChanged)
def rawtx(self):
@ -107,13 +107,14 @@ class QETxDetails(QObject, QtEventListener):
@rawtx.setter
def rawtx(self, rawtx: str):
if self._rawtx != rawtx:
self._logger.debug('rawtx set -> %s' % rawtx)
self._logger.debug(f'rawtx set -> {rawtx}')
self._rawtx = rawtx
if not rawtx:
return
try:
self._tx = tx_from_any(rawtx, deserialize=True)
self.txid = self._tx.txid() # triggers update()
self._txid = self._tx.txid()
self.update()
except Exception as e:
self._tx = None
self._logger.error(repr(e))
@ -226,12 +227,10 @@ class QETxDetails(QObject, QtEventListener):
def isFinal(self):
return self._is_final
def update(self):
if self._wallet is None:
self._logger.error('wallet undefined')
return
def update(self, from_txid: bool = False):
assert self._wallet
if not self._rawtx:
if from_txid:
self._tx = self._wallet.wallet.db.get_transaction(self._txid)
assert self._tx is not None

8
electrum/gui/qml/qewallet.py

@ -490,15 +490,15 @@ class QEWallet(AuthMixin, QObject, QtEventListener):
def sign(self, tx, *, broadcast: bool = False, on_success: Callable[[Transaction], None] = None, on_failure: Callable[[], None] = None):
sign_hook = run_hook('tc_sign_wrapper', self.wallet, tx, partial(self.on_sign_complete, on_success, broadcast), partial(self.on_sign_failed, on_failure))
if sign_hook:
signSuccess = self.do_sign(tx, False)
if signSuccess:
success = self.do_sign(tx, False)
if success:
self._logger.debug('plugin needs to sign tx too')
sign_hook(tx)
return
else:
signSuccess = self.do_sign(tx, broadcast)
success = self.do_sign(tx, broadcast)
if signSuccess:
if success:
if on_success: on_success(tx)
else:
if on_failure: on_failure()

Loading…
Cancel
Save