diff --git a/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPane.scala b/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPane.scala index d7d185c152..39349549ba 100644 --- a/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPane.scala +++ b/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPane.scala @@ -72,8 +72,9 @@ class DLCPane(glassPane: VBox)(implicit ec: ExecutionContext) { private val refundButton = new Button { text = "Refund" - onAction = new EventHandler[ActionEvent] { - override def handle(event: ActionEvent): Unit = model.onRefund() + onAction = _ => { + model.onRefund() + () } tooltip = Tooltip( "After the refund timeout, broadcasts the refund transaction to the blockchain.") @@ -82,8 +83,9 @@ class DLCPane(glassPane: VBox)(implicit ec: ExecutionContext) { private val executeButton = new Button { text = "Execute" - onAction = new EventHandler[ActionEvent] { - override def handle(event: ActionEvent): Unit = model.onExecute() + onAction = _ => { + model.onExecute() + () } tooltip = Tooltip( "Given an oracle attestation, broadcasts the closing transaction to the blockchain.") diff --git a/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPaneModel.scala b/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPaneModel.scala index 76d66f10f7..d4042118ce 100644 --- a/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPaneModel.scala +++ b/app/gui/src/main/scala/org/bitcoins/gui/dlc/DLCPaneModel.scala @@ -20,7 +20,8 @@ import upickle.default._ import java.io.File import java.nio.file.Files -import scala.concurrent.{ExecutionContext, Future} +import scala.concurrent.duration.DurationInt +import scala.concurrent.{Await, ExecutionContext, Future, Promise} import scala.util.{Failure, Properties, Success} class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext) @@ -91,9 +92,11 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext) def printDLCDialogResult[T <: CliCommand]( caption: String, dialog: DLCDialog[T], - postProcessStr: String => String = str => str): Unit = { + postProcessStr: String => String = str => str): String = { val result = dialog.showAndWait(parentWindow.value) + val promise = Promise[String]() + result match { case Some(command) => taskRunner.run( @@ -102,15 +105,19 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext) ConsoleCli.exec(command, GlobalData.consoleCliConfig) match { case Success(commandReturn) => resultArea.text = postProcessStr(commandReturn) + promise.success(commandReturn) case Failure(err) => err.printStackTrace() resultArea.text = s"Error executing command:\n${err.getMessage}" + promise.success("") } updateDLCs() } ) - case None => () + case None => promise.success("") } + + Await.result(promise.future, 15.seconds) } def onOffer(): Unit = { @@ -211,11 +218,11 @@ class DLCPaneModel(pane: DLCPane)(implicit ec: ExecutionContext) } } - def onExecute(): Unit = { + def onExecute(): String = { printDLCDialogResult("ExecuteDLC", new ExecuteDLCDialog) } - def onRefund(): Unit = { + def onRefund(): String = { printDLCDialogResult("ExecuteDLCRefund", new RefundDLCDialog) } diff --git a/app/gui/src/main/scala/org/bitcoins/gui/dlc/dialog/ViewDLCDialog.scala b/app/gui/src/main/scala/org/bitcoins/gui/dlc/dialog/ViewDLCDialog.scala index fc0ad2abff..d385f94d07 100644 --- a/app/gui/src/main/scala/org/bitcoins/gui/dlc/dialog/ViewDLCDialog.scala +++ b/app/gui/src/main/scala/org/bitcoins/gui/dlc/dialog/ViewDLCDialog.scala @@ -1,16 +1,17 @@ package org.bitcoins.gui.dlc.dialog -import org.bitcoins.core.protocol.dlc.models.DLCStatus.Offered +import org.bitcoins.core.protocol.dlc.models.DLCStatus._ import org.bitcoins.core.protocol.dlc.models._ import org.bitcoins.core.protocol.tlv.{ EnumOutcome, SignedNumericOutcome, UnsignedNumericOutcome } -import org.bitcoins.gui.GlobalData +import org.bitcoins.gui._ import org.bitcoins.gui.dlc.{DLCPaneModel, DLCPlotUtil, GlobalDLCData} import org.bitcoins.gui.util.GUIUtil import scalafx.Includes._ +import scalafx.beans.property.StringProperty import scalafx.geometry.Insets import scalafx.scene.Node import scalafx.scene.control._ @@ -28,6 +29,9 @@ object ViewDLCDialog { title = "View DLC" } + val closingTxId: StringProperty = StringProperty( + DLCStatus.getClosingTxId(status).map(_.hex).getOrElse("")) + dialog.dialogPane().buttonTypes = Seq(ButtonType.Close) dialog.dialogPane().stylesheets = GlobalData.currentStyleSheets dialog.resizable = true @@ -185,7 +189,7 @@ object ViewDLCDialog { row += 1 add(new Label("Closing TxId:"), 0, row) add(new TextField() { - text = DLCStatus.getClosingTxId(status).map(_.hex).getOrElse("") + text <== closingTxId editable = false }, columnIndex = 1, @@ -210,7 +214,10 @@ object ViewDLCDialog { // Set data for this DLC GlobalDLCData.lastContractId = contractId GlobalDLCData.lastOracleSig = "" - model.onExecute() + val res = model.onExecute() + + // Set closing txId in GUI + closingTxId.value = res } } }