Browse Source

Qt: fix async JMQtMessageBox usage part1

add_frost_channel_encryption
zebra-lucky 2 months ago
parent
commit
d318d3402b
  1. 82
      scripts/joinmarket-qt.py

82
scripts/joinmarket-qt.py

@ -380,10 +380,10 @@ class SpendTab(QWidget):
def checkAddress(self, addr): def checkAddress(self, addr):
valid, errmsg = validate_address(str(addr)) valid, errmsg = validate_address(str(addr))
if not valid and len(addr) > 0: if not valid and len(addr) > 0:
JMQtMessageBox(self, asyncio.ensure_future(
"Bitcoin address not valid.\n" + errmsg, JMQtMessageBox(
mbtype='warn', self, "Bitcoin address not valid.\n" + errmsg,
title="Error") mbtype='warn', title="Error"))
def parseURIAndValidateAddress(self, addr): def parseURIAndValidateAddress(self, addr):
addr = addr.strip() addr = addr.strip()
@ -391,10 +391,10 @@ class SpendTab(QWidget):
try: try:
parsed = btc.decode_bip21_uri(addr) parsed = btc.decode_bip21_uri(addr)
except ValueError as e: except ValueError as e:
JMQtMessageBox(self, asyncio.ensure_future(
"Bitcoin URI not valid.\n" + str(e), JMQtMessageBox(
mbtype='warn', self, "Bitcoin URI not valid.\n" + str(e),
title="Error") mbtype='warn', title="Error"))
return return
self.bip21_uri = addr self.bip21_uri = addr
addr = parsed['address'] addr = parsed['address']
@ -416,22 +416,25 @@ class SpendTab(QWidget):
try: try:
amount_sat = btc.amount_to_sat(amount_str) amount_sat = btc.amount_to_sat(amount_str)
except ValueError as e: except ValueError as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") asyncio.ensure_future(
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn"))
return False return False
if amount_sat < jm_single().DUST_THRESHOLD: if amount_sat < jm_single().DUST_THRESHOLD:
JMQtMessageBox(self, asyncio.ensure_future(
"Amount " + btc.amount_to_str(amount_sat) + JMQtMessageBox(self,
" is below dust threshold " + "Amount " + btc.amount_to_str(amount_sat) +
btc.amount_to_str(jm_single().DUST_THRESHOLD) + ".", " is below dust threshold " +
mbtype='warn', btc.amount_to_str(jm_single().DUST_THRESHOLD) + ".",
title="Error") mbtype='warn',
title="Error"))
return False return False
return True return True
def generateTumbleSchedule(self): def generateTumbleSchedule(self):
if not mainWindow.wallet_service: if not mainWindow.wallet_service:
JMQtMessageBox(self, "Cannot start without a loaded wallet.", asyncio.ensure_future(
mbtype="crit", title="Error") JMQtMessageBox(self, "Cannot start without a loaded wallet.",
mbtype="crit", title="Error"))
return return
#needs a set of tumbler options and destination addresses, so needs #needs a set of tumbler options and destination addresses, so needs
#a wizard #a wizard
@ -444,9 +447,10 @@ class SpendTab(QWidget):
mainWindow.wallet_service.get_balance_by_mixdepth(), mainWindow.wallet_service.get_balance_by_mixdepth(),
mainWindow.wallet_service.mixdepth) mainWindow.wallet_service.mixdepth)
except ScheduleGenerationErrorNoFunds: except ScheduleGenerationErrorNoFunds:
JMQtMessageBox(self, asyncio.ensure_future(
"Failed to start tumbler; no funds available.", JMQtMessageBox(self,
title="Tumbler start failed.") "Failed to start tumbler; no funds available.",
title="Tumbler start failed."))
return return
self.spendstate.schedule_name = wizard.get_name() self.spendstate.schedule_name = wizard.get_name()
self.updateSchedView() self.updateSchedView()
@ -457,10 +461,14 @@ class SpendTab(QWidget):
if required_mixdepths > jm_single().config.getint("GUI", "max_mix_depth"): if required_mixdepths > jm_single().config.getint("GUI", "max_mix_depth"):
jm_single().config.set("GUI", "max_mix_depth", str(required_mixdepths)) jm_single().config.set("GUI", "max_mix_depth", str(required_mixdepths))
#recreate wallet and sync again; needed due to cache. #recreate wallet and sync again; needed due to cache.
JMQtMessageBox(self, asyncio.ensure_future(
"Max mixdepth has been reset to: " + str(required_mixdepths) + ".\n" + JMQtMessageBox(
"Please choose 'Load' from the Wallet menu and resync before running.", self,
title='Wallet resync required') f"Max mixdepth has been reset to: "
f"{str(required_mixdepths)}.\n"
f"Please choose 'Load' from the Wallet menu and resync"
f" before running.",
title='Wallet resync required'))
return return
self.sch_startButton.setEnabled(True) self.sch_startButton.setEnabled(True)
@ -480,21 +488,29 @@ class SpendTab(QWidget):
res, schedule = get_schedule(firstarg[0]) res, schedule = get_schedule(firstarg[0])
if not res: if not res:
JMQtMessageBox(self, "Not a valid JM schedule file", mbtype='crit', asyncio.ensure_future(
title='Error') JMQtMessageBox(
self, "Not a valid JM schedule file",
mbtype='crit', title='Error'))
else: else:
mainWindow.statusBar().showMessage("Schedule loaded OK.") mainWindow.statusBar().showMessage("Schedule loaded OK.")
self.spendstate.loaded_schedule = schedule self.spendstate.loaded_schedule = schedule
self.spendstate.schedule_name = os.path.basename(str(firstarg[0])) self.spendstate.schedule_name = os.path.basename(str(firstarg[0]))
self.updateSchedView() self.updateSchedView()
if self.spendstate.schedule_name == "TUMBLE.schedule": if self.spendstate.schedule_name == "TUMBLE.schedule":
reply = JMQtMessageBox(self, "An incomplete tumble run detected. "
"\nDo you want to restart?", def finished_cb(result):
title="Restart detected", mbtype='question') if result != QMessageBox.Yes:
if reply != QMessageBox.Yes: self.giveUp()
self.giveUp() return
return self.tumbler_options = True
self.tumbler_options = True
asyncio.ensure_future(
JMQtMessageBox(
self, "An incomplete tumble run detected. "
"\nDo you want to restart?",
title="Restart detected",
mbtype='question', finished_cb=finished_cb))
def updateSchedView(self): def updateSchedView(self):
self.sch_label2.setText(self.spendstate.schedule_name) self.sch_label2.setText(self.spendstate.schedule_name)

Loading…
Cancel
Save