Bug Fixes [CORDA-282] - TX id is not rendering properly in new transaction screen (#336)

* Fixed bug [CORDA-282] - TX id is not rendering properly in the New Cash Transaction screen
This commit is contained in:
Patrick Kuo 2017-03-09 15:55:00 +00:00 committed by GitHub
parent 6362e2ff7c
commit 570b871524

View File

@ -1,10 +1,16 @@
package net.corda.explorer.views.cordapps.cash package net.corda.explorer.views.cordapps.cash
import com.google.common.base.Splitter
import javafx.beans.binding.Bindings import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding import javafx.beans.binding.BooleanBinding
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
import javafx.collections.FXCollections import javafx.collections.FXCollections
import javafx.geometry.Insets
import javafx.geometry.VPos
import javafx.scene.control.* import javafx.scene.control.*
import javafx.scene.layout.GridPane
import javafx.scene.text.Font
import javafx.scene.text.FontWeight
import javafx.stage.Window import javafx.stage.Window
import net.corda.client.fxutils.ChosenList import net.corda.client.fxutils.ChosenList
import net.corda.client.fxutils.isNotNull import net.corda.client.fxutils.isNotNull
@ -22,7 +28,7 @@ import net.corda.core.getOrThrow
import net.corda.core.messaging.startFlow import net.corda.core.messaging.startFlow
import net.corda.core.node.NodeInfo import net.corda.core.node.NodeInfo
import net.corda.core.serialization.OpaqueBytes import net.corda.core.serialization.OpaqueBytes
import net.corda.core.transactions.SignedTransaction import net.corda.core.then
import net.corda.explorer.model.CashTransaction import net.corda.explorer.model.CashTransaction
import net.corda.explorer.model.IssuerModel import net.corda.explorer.model.IssuerModel
import net.corda.explorer.model.ReportingCurrencyModel import net.corda.explorer.model.ReportingCurrencyModel
@ -32,8 +38,7 @@ import net.corda.explorer.views.stringConverter
import net.corda.flows.CashFlowCommand import net.corda.flows.CashFlowCommand
import net.corda.flows.IssuerFlow.IssuanceRequester import net.corda.flows.IssuerFlow.IssuanceRequester
import org.controlsfx.dialog.ExceptionDialog import org.controlsfx.dialog.ExceptionDialog
import tornadofx.Fragment import tornadofx.*
import tornadofx.booleanBinding
import java.math.BigDecimal import java.math.BigDecimal
import java.util.* import java.util.*
@ -79,56 +84,60 @@ class NewTransaction : Fragment() {
}) })
fun show(window: Window): Unit { fun show(window: Window): Unit {
dialog(window).showAndWait().ifPresent { newTransactionDialog(window).showAndWait().ifPresent { command ->
val dialog = Alert(Alert.AlertType.INFORMATION).apply { val dialog = Alert(Alert.AlertType.INFORMATION).apply {
headerText = null headerText = null
contentText = "Transaction Started." contentText = "Transaction Started."
dialogPane.isDisable = true dialogPane.isDisable = true
initOwner(window) initOwner(window)
show()
} }
dialog.show() val handle = if (command is CashFlowCommand.IssueCash) {
runAsync {
val handle = if (it is CashFlowCommand.IssueCash) {
myIdentity.value?.let { myIdentity ->
rpcProxy.value!!.startFlow(::IssuanceRequester, rpcProxy.value!!.startFlow(::IssuanceRequester,
it.amount, command.amount,
it.recipient, command.recipient,
it.issueRef, command.issueRef,
myIdentity.legalIdentity) myIdentity.value!!.legalIdentity)
}
} else { } else {
it.startFlow(rpcProxy.value!!) command.startFlow(rpcProxy.value!!)
} }
val response = try { runAsync {
handle?.returnValue?.getOrThrow() handle.returnValue.then { dialog.dialogPane.isDisable = false }.getOrThrow()
} catch (e: FlowException) {
e
}
it to response
}.ui { }.ui {
val (command, response) = it
val (alertType, contentText) = if (response is FlowException) {
Alert.AlertType.ERROR to response.message
} else {
val type = when (command) { val type = when (command) {
is CashFlowCommand.IssueCash -> "Cash Issued" is CashFlowCommand.IssueCash -> "Cash Issued"
is CashFlowCommand.ExitCash -> "Cash Exited" is CashFlowCommand.ExitCash -> "Cash Exited"
is CashFlowCommand.PayCash -> "Cash Paid" is CashFlowCommand.PayCash -> "Cash Paid"
} }
Alert.AlertType.INFORMATION to "$type \nTransaction ID : ${(response as SignedTransaction).id}" dialog.alertType = Alert.AlertType.INFORMATION
dialog.dialogPane.content = gridpane {
padding = Insets(10.0, 40.0, 10.0, 20.0)
vgap = 10.0
hgap = 10.0
row { label(type) { font = Font.font(font.family, FontWeight.EXTRA_BOLD, font.size + 2) } }
row {
label("Transaction ID :") { GridPane.setValignment(this, VPos.TOP) }
label { text = Splitter.fixedLength(16).split("${it.id}").joinToString("\n") }
}
} }
dialog.alertType = alertType
dialog.contentText = contentText
dialog.dialogPane.isDisable = false
dialog.dialogPane.scene.window.sizeToScene() dialog.dialogPane.scene.window.sizeToScene()
}.setOnFailed { }.setOnFailed {
val ex = it.source.exception
when (ex) {
is FlowException -> {
dialog.alertType = Alert.AlertType.ERROR
dialog.contentText = ex.message
}
else -> {
dialog.close() dialog.close()
ExceptionDialog(it.source.exception).apply { initOwner(window) }.showAndWait() ExceptionDialog(ex).apply { initOwner(window) }.showAndWait()
}
}
} }
} }
} }
private fun dialog(window: Window) = Dialog<CashFlowCommand>().apply { private fun newTransactionDialog(window: Window) = Dialog<CashFlowCommand>().apply {
dialogPane = root dialogPane = root
initOwner(window) initOwner(window)
setResultConverter { setResultConverter {