Refactored simple send to use states

This commit is contained in:
Maran 2014-04-11 15:18:38 -04:00
parent 4d18798468
commit 5768b18a3b
1 changed files with 208 additions and 177 deletions

View File

@ -187,52 +187,89 @@ ApplicationWindow {
anchors.bottomMargin: 5
id: newTransactionTab
Component.onCompleted:{
addTab("Send ether", newTransaction)
addTab("Simple send", newTransaction)
addTab("Create contract", newContract)
}
}
Component {
id: newTransaction
Column {
id: simpleSendColumn
states: [
State{
name: "ERROR"
},
State {
name: "DONE"
PropertyChanges { target: txSimpleValue; visible:false}
PropertyChanges { target: txSimpleRecipient; visible:false}
PropertyChanges { target:newSimpleTxButton; visible:false}
PropertyChanges { target: txSimpleResult; visible:true}
PropertyChanges { target: txSimpleOutput; visible:true}
PropertyChanges { target:newSimpleTxButton; visible:true}
},
State {
name: "SETUP"
PropertyChanges { target: txSimpleValue; visible:true; text: ""}
PropertyChanges { target: txSimpleRecipient; visible:true; text: ""}
PropertyChanges { target: txSimpleButton; visible:true}
PropertyChanges { target:newSimpleTxButton; visible:false}
}
]
spacing: 5
anchors.leftMargin: 5
anchors.topMargin: 5
anchors.top: parent.top
anchors.left: parent.left
function checkFormState(){
if(txSimpleRecipient.text.length == 40 && txSimpleValue.text.length > 0) {
txSimpleButton.state = "READY"
}else{
txSimpleButton.state = "NOTREADY"
}
}
TextField {
id: txSimpleRecipient
placeholderText: "Recipient address"
Layout.fillWidth: true
validator: RegExpValidator { regExp: /[a-f0-9]{40}/ }
width: 530
onTextChanged: { checkFormState() }
}
TextField {
id: txSimpleValue
placeholderText: "Amount"
anchors.rightMargin: 5
validator: IntValidator { }
onTextChanged: { checkFormState() }
}
Button {
id: txSimpleButton
states: [
State {
name: "READY"
PropertyChanges { target: txSimpleButton; enabled: true}
},
State {
name: "NOTREADY"
PropertyChanges { target: txSimpleButton; enabled: false}
}
]
text: "Send"
enabled: false
onClicked: {
//this.enabled = false
var res = eth.createTx(txSimpleRecipient.text, txSimpleValue.text,"","","")
if(res[1]) {
txSimpleResult.text = "There has been an error broadcasting your transaction:" + res[1].error()
txSimpleResult.visible = true
} else {
txSimpleResult.text = "Your transaction has been broadcasted over the network.\nYour transaction id is:"
txSimpleOutput.text = res[0]
txSimpleOutput.visible = true
txSimpleResult.visible = true
txSimpleValue.visible = false
txSimpleRecipient.visible = false
txSimpleValue.text = ""
txSimpleRecipient.text = ""
txSimpleRecipient.focus = true
newSimpleTxButton.visible = true
this.visible = false
simpleSendColumn.state = "DONE"
}
}
}
@ -252,13 +289,7 @@ ApplicationWindow {
text: "Create an other transaction"
onClicked: {
this.visible = false
txSimpleResult.text = ""
txSimpleOutput.text = ""
txSimpleResult.visible = false
txSimpleOutput.visible = false
txSimpleValue.visible = true
txSimpleRecipient.visible = true
txSimpleButton.visible = true
simpleSendColumn.state = "SETUP"
}
}
}
@ -713,4 +744,4 @@ ApplicationWindow {
function setPeers(text) {
peerLabel.text = text
}
}
}