Skip to content

Commit 708dc41

Browse files
committed
qml: add busy property on QETxFinalizer for guarding re-entry while background job
is running
1 parent cdfcf88 commit 708dc41

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

electrum/gui/qml/components/ConfirmTxDialog.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ ElDialog {
324324
? qsTr('Finalize...')
325325
: qsTr('Pay...')
326326
icon.source: '../../icons/confirmed.png'
327-
enabled: finalizer.valid
327+
enabled: finalizer.valid && !finalizer.busy
328328
onClicked: confirmed()
329329
}
330330
}

electrum/gui/qml/qetxfinalizer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def __init__(
451451
self._extraFee = QEAmount()
452452
self._canRbf = False
453453
self._swapStatusMsg = ''
454+
self._busy = False
454455
self.swap_task: Future = None
455456

456457
self.swapAvailabilityChanged.connect(self.on_swap_availability_changed, Qt.ConnectionType.QueuedConnection)
@@ -492,6 +493,17 @@ def amount(self, amount: QEAmount):
492493
self._amount.copyFrom(amount)
493494
self.amountChanged.emit()
494495

496+
busyChanged = pyqtSignal()
497+
@pyqtProperty(bool, notify=busyChanged)
498+
def busy(self) -> bool:
499+
return self._busy
500+
501+
@busy.setter
502+
def busy(self, busy: bool):
503+
if self._busy != busy:
504+
self._busy = busy
505+
self.busyChanged.emit()
506+
495507
effectiveAmountChanged = pyqtSignal()
496508
@pyqtProperty(QEAmount, notify=effectiveAmountChanged)
497509
def effectiveAmount(self):
@@ -645,6 +657,10 @@ def signAndSend(self):
645657
self._logger.debug('no valid tx')
646658
return
647659

660+
if self.busy:
661+
self._logger.debug('busy')
662+
return
663+
648664
tx = self._tx
649665

650666
if self.f_accept:
@@ -662,6 +678,8 @@ def _send_with_swap_change(self, tx):
662678
assert self._wallet.wallet.lnworker
663679
assert tx.get_dummy_output(DummyAddress.SWAP)
664680

681+
self.busy = True
682+
665683
async def handle_swap_task():
666684
try:
667685
swap_dummy_output = tx.get_dummy_output(DummyAddress.SWAP)
@@ -720,6 +738,7 @@ async def handle_swap_task():
720738
finally:
721739
# ensures that swap_task is always set None if transport closes
722740
self.swap_task = None
741+
self.busy = False
723742

724743
self.swap_task = asyncio.run_coroutine_threadsafe(handle_swap_task(), get_asyncio_loop())
725744

0 commit comments

Comments
 (0)