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 { ElDialog {
id: dialog id: dialog
required property string txid
required property QtObject cpfpfeebumper required property QtObject cpfpfeebumper
title: qsTr('Bump Fee') title: qsTr('Bump Fee')

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

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

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

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

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

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

17
electrum/gui/qml/qetxdetails.py

@ -95,10 +95,10 @@ class QETxDetails(QObject, QtEventListener):
@txid.setter @txid.setter
def txid(self, txid: str): def txid(self, txid: str):
if self._txid != txid: if self._txid != txid:
self._logger.debug('txid set -> %s' % txid) self._logger.debug(f'txid set -> {txid}')
self._txid = txid self._txid = txid
self.txidChanged.emit() self.txidChanged.emit()
self.update() self.update(from_txid=True)
@pyqtProperty(str, notify=detailsChanged) @pyqtProperty(str, notify=detailsChanged)
def rawtx(self): def rawtx(self):
@ -107,13 +107,14 @@ class QETxDetails(QObject, QtEventListener):
@rawtx.setter @rawtx.setter
def rawtx(self, rawtx: str): def rawtx(self, rawtx: str):
if self._rawtx != rawtx: if self._rawtx != rawtx:
self._logger.debug('rawtx set -> %s' % rawtx) self._logger.debug(f'rawtx set -> {rawtx}')
self._rawtx = rawtx self._rawtx = rawtx
if not rawtx: if not rawtx:
return return
try: try:
self._tx = tx_from_any(rawtx, deserialize=True) 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: except Exception as e:
self._tx = None self._tx = None
self._logger.error(repr(e)) self._logger.error(repr(e))
@ -226,12 +227,10 @@ class QETxDetails(QObject, QtEventListener):
def isFinal(self): def isFinal(self):
return self._is_final return self._is_final
def update(self): def update(self, from_txid: bool = False):
if self._wallet is None: assert self._wallet
self._logger.error('wallet undefined')
return
if not self._rawtx: if from_txid:
self._tx = self._wallet.wallet.db.get_transaction(self._txid) self._tx = self._wallet.wallet.db.get_transaction(self._txid)
assert self._tx is not None 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): 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)) 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: if sign_hook:
signSuccess = self.do_sign(tx, False) success = self.do_sign(tx, False)
if signSuccess: if success:
self._logger.debug('plugin needs to sign tx too') self._logger.debug('plugin needs to sign tx too')
sign_hook(tx) sign_hook(tx)
return return
else: else:
signSuccess = self.do_sign(tx, broadcast) success = self.do_sign(tx, broadcast)
if signSuccess: if success:
if on_success: on_success(tx) if on_success: on_success(tx)
else: else:
if on_failure: on_failure() if on_failure: on_failure()

Loading…
Cancel
Save