github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/assets/qml/views/jeffcoin/jeffcoin.qml (about)

     1  import QtQuick 2.0
     2  import QtQuick.Controls 1.0;
     3  import QtQuick.Layouts 1.0;
     4  import QtQuick.Dialogs 1.0;
     5  import QtQuick.Window 2.1;
     6  import QtQuick.Controls.Styles 1.1
     7  
     8  Rectangle {
     9  	id: root
    10  	property var title: "JeffCoin"
    11  	property var iconSource: "./views/jeffcoin/jeff.png"
    12  	property var menuItem
    13  	property var filter
    14  	property var address: "fc0a9436890478bb9b1c6ed7455c2535366f4a99"
    15  
    16  	function insertTx(message, blockNumber) {
    17  		if(!message) return;
    18  
    19  		var from = message.from
    20  		var to = message.input.substr(24, 40)
    21  		var value = eth.fromNumber(message.input.substr(64, 64))
    22  
    23  		var me = eth.key().address;
    24  		if((to == me|| from == me) && message.input.length == 128) {
    25  			var to = eth.lookupName(to)
    26  			var from = eth.lookupName(from)
    27  			txModel.insert(0, {confirmations: blockNumber - message.number, from: from, to: to, value: value})
    28  		}
    29  	}
    30  
    31  	function setBalance() {
    32  		var jeffCoinAmount = eth.fromNumber(eth.storageAt(address, eth.key().address)) + " JΞF"
    33  		menuItem.secondaryTitle = jeffCoinAmount
    34  
    35  		balance.text = "<b>Balance</b>: " + jeffCoinAmount;
    36  	}
    37  
    38  	function onReady() {
    39  		setBalance()
    40  
    41  		filter = new ethx.watch({latest: -1, to: address})
    42  		filter.changed(function(messages) {
    43  			setBalance()
    44  
    45  			var blockNumber = eth.block(-1).number;
    46  			for(var i = 0; i < messages.length; i++) {
    47  				insertTx(messages.get(i), blockNumber);
    48  			}
    49  		});
    50  
    51  		var blockNumber = eth.block(-1).number;
    52  		var msgs = filter.messages()
    53  		for(var i = msgs.length-1; i >= 0; i--) {
    54  			var message = JSON.parse(msgs.getAsJson(i))
    55  
    56  			insertTx(message, blockNumber)
    57  		}
    58  
    59  		var chainChanged = ethx.watch("chain")
    60  		chainChanged.changed(function() {
    61  			for(var i = 0; i < txModel.count; i++) {
    62  				var entry = txModel.get(i);
    63  				entry.confirmations++;
    64  			}
    65  		});
    66  	}
    67  
    68  	function onDestroy() {
    69  		filter.uninstall()
    70  	}
    71  
    72  	ColumnLayout {
    73  		spacing: 10
    74  		y: 40
    75  		anchors.fill: parent
    76  
    77  		Text {
    78  			id: balance
    79  			text: "<b>Balance</b>: " + eth.fromNumber(eth.storageAt(address, eth.key().address)) + " JΞF"
    80  			font.pixelSize: 24
    81  			anchors {
    82  				horizontalCenter: parent.horizontalCenter
    83  				top: parent.top
    84  				topMargin: 20
    85  			}
    86  		}
    87  
    88  		Rectangle {
    89  			id: newTxPane
    90  			color: "#ececec"
    91  			border.color: "#cccccc"
    92  			border.width: 1
    93  			anchors {
    94  				top: balance.bottom
    95  				topMargin: 10
    96  				left: parent.left
    97  				leftMargin: 5
    98  				right: parent.right
    99  				rightMargin: 5
   100  			}
   101  			height: 100
   102  
   103  			RowLayout {
   104  				id: amountFields
   105  				spacing: 10
   106  				anchors {
   107  					top: parent.top
   108  					topMargin: 20
   109  					left: parent.left
   110  					leftMargin: 20
   111  				}
   112  
   113  				Text {
   114  					text: "JΞF  "
   115  				}
   116  
   117  				// There's something off with the row layout where textfields won't listen to the width setting
   118  				Rectangle {
   119  					width: 50
   120  					height: 20
   121  					TextField {
   122  						id: txValue
   123  						width: parent.width
   124  						placeholderText: "0.00"
   125  					}
   126  				}
   127  			}
   128  
   129  			RowLayout {
   130  				id: toFields
   131  				spacing: 10
   132  				anchors {
   133  					top: amountFields.bottom
   134  					topMargin: 5
   135  					left: parent.left
   136  					leftMargin: 20
   137  				}
   138  
   139  				Text {
   140  					text: "To"
   141  				}
   142  
   143  				Rectangle {
   144  					width: 200
   145  					height: 20
   146  					TextField {
   147  						id: txTo
   148  						width: parent.width
   149  						placeholderText: "Address or name"
   150  					}
   151  				}
   152  
   153  				Button {
   154  					text: "Send"
   155  					onClicked: {
   156  						var lookup = eth.lookupAddress(address)
   157  						if(lookup.length == 0)
   158  							lookup = address
   159  
   160  						eth.transact({from: eth.key().privateKey, to:lookup, gas: "9000", gasPrice: "10000000000000", data: ["0x"+txTo.text, txValue.text]})
   161  					}
   162  				}
   163  			}
   164  		}
   165  
   166  		Rectangle {
   167  			anchors {
   168  				left: parent.left
   169  				right: parent.right
   170  				top: newTxPane.bottom
   171  				topMargin: 10
   172  				bottom: parent.bottom
   173  			}
   174  			TableView {
   175  				id: txTableView
   176  				anchors.fill : parent
   177  				TableViewColumn{ role: "value" ; title: "Amount" ; width: 100 }
   178  				TableViewColumn{ role: "from" ; title: "From" ; width: 280 }
   179  				TableViewColumn{ role: "to" ; title: "To" ; width: 280 }
   180  				TableViewColumn{ role: "confirmations" ; title: "Confirmations" ; width: 100 }
   181  
   182  				model: ListModel {
   183  					id: txModel
   184  					Component.onCompleted: {
   185  					}
   186  				}
   187  			}
   188  		}
   189  	}
   190  }