Skip to content

Commit

Permalink
Delete sigs option (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Apr 5, 2021
1 parent 6edd75f commit 69b37fe
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion project/Deps.scala
Expand Up @@ -16,7 +16,7 @@ object Deps {

val scalaFxV = "15.0.1-R21"
val javaFxV = "17-ea+5"
val bitcoinsV = "0.5.0-116-2745fdf8-SNAPSHOT"
val bitcoinsV = "0.5.0-122-656e0928-SNAPSHOT"
}

object Compile {
Expand Down
Binary file added src/main/resources/icons/trash-black.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/icons/trash-white.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/main/resources/themes/base.css
Expand Up @@ -7,4 +7,12 @@
-fx-background-repeat: no-repeat;
-fx-padding: 5 10 5 10;
-fx-background-position: center;
-fx-background-size: 16px;
}
.delete-button {
-fx-background-image: url("../icons/trash-black.png");
-fx-background-repeat: no-repeat;
-fx-padding: 5 10 5 10;
-fx-background-position: center;
-fx-background-size: 16px;
}
4 changes: 4 additions & 0 deletions src/main/resources/themes/dark-theme.css
Expand Up @@ -49,3 +49,7 @@
.copy-button {
-fx-background-image: url("../icons/copy-white.png");
}

.delete-button {
-fx-background-image: url("../icons/trash-white.png");
}
52 changes: 51 additions & 1 deletion src/main/scala/com/krystal/bull/gui/dialog/ViewEventDialog.scala
Expand Up @@ -21,7 +21,8 @@ import scalafx.stage.Window

import java.awt.Toolkit.getDefaultToolkit
import java.awt.datatransfer.StringSelection
import scala.concurrent.Future
import scala.concurrent.duration.DurationInt
import scala.concurrent.{Await, Future}
import scala.util.Try

object ViewEventDialog {
Expand All @@ -37,6 +38,52 @@ object ViewEventDialog {
}
}

private def deleteSigsButton(event: CompletedOracleEvent): Button = {
new Button() {
styleClass += "delete-button"
onAction = _ => {
val f = oracleExplorerClient
.getEvent(event.announcementTLV.sha256)
.map(_.attestations)

val res = Try(Await.result(f, 5.seconds)).getOrElse(None)

res match {
case None => showDeleteSigsAlert(event)
case Some(_) => showCannotDeleteSigsAlert(event)
}
}
}
}

private def showDeleteSigsAlert(event: CompletedOracleEvent): Unit = {
new Alert(AlertType.Confirmation) {
initOwner(owner)
title = "Warning!"
contentText =
s"Deleting signatures for event ${event.eventName} can result in leaking your private key!\n\n" +
"Only delete signatures if you have not published the previous signatures publicly " +
"and are absolutely sure you know what you are doing!"
dialogPane().stylesheets = GlobalData.currentStyleSheets
}.showAndWait() match {
case Some(ButtonType.OK) =>
GlobalData.oracle.deleteAttestations(event.eventTLV)
case None | Some(_) => ()
}
}

private def showCannotDeleteSigsAlert(event: CompletedOracleEvent): Unit = {
new Alert(AlertType.Error) {
initOwner(owner)
title = "Error!"
contentText =
s"Cannot delete signatures for ${event.eventName}. " +
s"Signatures have already been publicly published and would result in revealing your private key!"
dialogPane().stylesheets = GlobalData.currentStyleSheets
}.showAndWait()
()
}

private def showNoOutcomeAlert(): Unit = {
new Alert(AlertType.Error) {
initOwner(owner)
Expand Down Expand Up @@ -226,6 +273,9 @@ object ViewEventDialog {
add(copyButton(completed.oracleAttestmentV0TLV.hex),
columnIndex = 2,
rowIndex = row)
if (GlobalData.advancedMode) {
add(deleteSigsButton(completed), columnIndex = 3, rowIndex = row)
}
case pendingEnum: PendingEnumV0OracleEvent =>
var outcomeOpt: Option[String] = None

Expand Down

0 comments on commit 69b37fe

Please sign in to comment.