mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-18 21:22:04 +01:00
Small DLC GUI touchups (#2390)
This commit is contained in:
parent
a66aa8f146
commit
f06dcbb160
6 changed files with 48 additions and 33 deletions
|
@ -1,17 +1,10 @@
|
|||
package org.bitcoins.gui.dlc
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
import javafx.event.{ActionEvent, EventHandler}
|
||||
import org.bitcoins.gui.{GlobalData, TaskRunner}
|
||||
import scalafx.geometry.{Insets, Pos}
|
||||
import scalafx.scene.control._
|
||||
import scalafx.scene.layout._
|
||||
import scalafx.stage.FileChooser
|
||||
import scalafx.stage.FileChooser.ExtensionFilter
|
||||
|
||||
import scala.util.Properties
|
||||
|
||||
class DLCPane(glassPane: VBox) {
|
||||
|
||||
|
@ -28,25 +21,8 @@ class DLCPane(glassPane: VBox) {
|
|||
}
|
||||
|
||||
private val exportButton = new Button("Export Result") {
|
||||
alignmentInParent = Pos.BottomRight
|
||||
onAction = _ => {
|
||||
val txtFilter = new ExtensionFilter("Text Files", "*.txt")
|
||||
val allExtensionFilter = new ExtensionFilter("All Files", "*")
|
||||
val fileChooser = new FileChooser() {
|
||||
extensionFilters.addAll(txtFilter, allExtensionFilter)
|
||||
selectedExtensionFilter = txtFilter
|
||||
initialDirectory = new File(Properties.userHome)
|
||||
}
|
||||
|
||||
val selectedFile = fileChooser.showSaveDialog(null)
|
||||
|
||||
if (selectedFile != null) {
|
||||
val bytes = resultTextArea.text.value.getBytes
|
||||
|
||||
Files.write(selectedFile.toPath, bytes)
|
||||
()
|
||||
}
|
||||
}
|
||||
alignmentInParent = Pos.BottomLeft
|
||||
onAction = _ => model.exportResult(resultTextArea.text.value)
|
||||
}
|
||||
|
||||
private val resultArea = new BorderPane() {
|
||||
|
|
|
@ -3,9 +3,9 @@ package org.bitcoins.gui.dlc
|
|||
import org.bitcoins.cli.CliCommand._
|
||||
import org.bitcoins.cli.{CliCommand, Config, ConsoleCli}
|
||||
import org.bitcoins.commons.serializers.Picklers._
|
||||
import org.bitcoins.core.protocol.dlc.DLCMessage._
|
||||
import org.bitcoins.core.config.MainNet
|
||||
import org.bitcoins.core.number.{Int32, UInt16, UInt32}
|
||||
import org.bitcoins.core.protocol.dlc.DLCMessage._
|
||||
import org.bitcoins.core.protocol.dlc.DLCStatus
|
||||
import org.bitcoins.core.protocol.tlv._
|
||||
import org.bitcoins.core.protocol.transaction.Transaction
|
||||
|
@ -15,10 +15,13 @@ import org.bitcoins.gui.{GlobalData, TaskRunner}
|
|||
import scalafx.beans.property.ObjectProperty
|
||||
import scalafx.collections.ObservableBuffer
|
||||
import scalafx.scene.control.TextArea
|
||||
import scalafx.stage.Window
|
||||
import scalafx.stage.FileChooser.ExtensionFilter
|
||||
import scalafx.stage.{FileChooser, Window}
|
||||
import upickle.default._
|
||||
|
||||
import scala.util.{Failure, Success, Try}
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import scala.util.{Failure, Properties, Success, Try}
|
||||
|
||||
class DLCPaneModel(resultArea: TextArea, oracleInfoArea: TextArea) {
|
||||
var taskRunner: TaskRunner = _
|
||||
|
@ -275,4 +278,28 @@ class DLCPaneModel(resultArea: TextArea, oracleInfoArea: TextArea) {
|
|||
updatedStatus.getOrElse(status),
|
||||
this)
|
||||
}
|
||||
|
||||
def exportResult(result: String): Unit = {
|
||||
val txtFilter = new ExtensionFilter("Text Files", "*.txt")
|
||||
val allExtensionFilter = new ExtensionFilter("All Files", "*")
|
||||
val fileChooser = new FileChooser() {
|
||||
extensionFilters.addAll(txtFilter, allExtensionFilter)
|
||||
selectedExtensionFilter = txtFilter
|
||||
initialDirectory = new File(Properties.userHome)
|
||||
}
|
||||
|
||||
val selectedFile = fileChooser.showSaveDialog(null)
|
||||
|
||||
taskRunner.run(
|
||||
"Export Result",
|
||||
op = {
|
||||
if (selectedFile != null) {
|
||||
val bytes = result.getBytes
|
||||
|
||||
Files.write(selectedFile.toPath, bytes)
|
||||
()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,10 +58,12 @@ class AcceptDLCDialog
|
|||
}
|
||||
} else {
|
||||
new Alert(AlertType.Confirmation) {
|
||||
resizable = true
|
||||
initOwner(owner)
|
||||
title = "Confirm no Oracle Announcement"
|
||||
contentText =
|
||||
s"Are you sure you would like sign to accept this DLC Offer without verifying it has the correct oracle?"
|
||||
dialogPane().getScene.getWindow.sizeToScene()
|
||||
}.showAndWait() match {
|
||||
case Some(ButtonType.OK) => ()
|
||||
case None | Some(_) => throw new RuntimeException("Did not accept")
|
||||
|
|
|
@ -17,7 +17,8 @@ class AddSigsDLCDialog
|
|||
Some(file)
|
||||
DLCDialog.signFileChosenLabel.text =
|
||||
file.toString
|
||||
}
|
||||
},
|
||||
DLCDialog.fileChosenStr -> DLCDialog.signFileChosenLabel
|
||||
),
|
||||
Vector(DLCDialog.dlcSigStr,
|
||||
DLCDialog.dlcSignFileStr)) {
|
||||
|
|
|
@ -16,7 +16,8 @@ class SignDLCDialog
|
|||
Some(file)
|
||||
DLCDialog.acceptFileChosenLabel.text =
|
||||
file.toString
|
||||
}
|
||||
},
|
||||
DLCDialog.fileChosenStr -> DLCDialog.acceptFileChosenLabel
|
||||
),
|
||||
Vector(DLCDialog.dlcAcceptStr,
|
||||
DLCDialog.dlcAcceptFileStr)) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import org.bitcoins.core.protocol.dlc.DLCMessage.{
|
|||
MultiNonceContractInfo,
|
||||
SingleNonceContractInfo
|
||||
}
|
||||
import org.bitcoins.core.protocol.dlc.DLCStatus
|
||||
import org.bitcoins.core.protocol.dlc.{DLCPayoutCurve, DLCStatus}
|
||||
import org.bitcoins.gui.GlobalData
|
||||
import org.bitcoins.gui.dlc.{DLCPaneModel, DLCPlotUtil, GlobalDLCData}
|
||||
import scalafx.Includes._
|
||||
|
@ -193,9 +193,17 @@ object ViewDLCDialog {
|
|||
roundingIntervals) =>
|
||||
val previewGraphButton: Button = new Button("Preview Graph") {
|
||||
onAction = _ => {
|
||||
|
||||
val payoutCurve = if (status.isInitiator) {
|
||||
outcomeValueFunc
|
||||
} else {
|
||||
DLCPayoutCurve(outcomeValueFunc.points.map { point =>
|
||||
point.copy(payout = totalCollateral.toLong - point.payout)
|
||||
})
|
||||
}
|
||||
DLCPlotUtil.plotCETsWithOriginalCurve(base,
|
||||
numDigits,
|
||||
outcomeValueFunc,
|
||||
payoutCurve,
|
||||
totalCollateral,
|
||||
roundingIntervals)
|
||||
()
|
||||
|
|
Loading…
Add table
Reference in a new issue