forked from carver/mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transaction.qml
694 lines (639 loc) · 14.3 KB
/
Transaction.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Transaction.qml
* @author Yann [email protected]
* @author Arkadiy Paronyan [email protected]
* @date 2015
* Ethereum IDE client.
*/
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.1
import Qt.labs.settings 1.0
import "js/Debugger.js" as Debugger
import "js/ErrorLocationFormater.js" as ErrorLocationFormater
import "js/ScientificNumber.js" as ScientificNumber
import "."
ColumnLayout
{
id: rowTransaction
Layout.minimumHeight: trHeight
Layout.preferredWidth: blockWidth
spacing: 1
property bool isCall
property variant tx
property int txIndex
property int callIndex
property bool detailVisible: txDetail.visible
property string trDetailColor: "#adadad"
Keys.onDeletePressed:
{
if (!isCall && blockChain)
{
deleteConfirmation.open();
}
}
function highlight()
{
rowContentTr.select()
}
function unHightlight()
{
rowContentTr.deselect()
}
Connections
{
target: blockChainPanel
onTxExecuted:
{
if (_blockIndex == blockIndex && _txIndex == txIndex && _callIndex == callIndex)
txDetail.updateView()
}
}
ColumnLayout
{
id: rowContentTr
anchors.top: parent.top
Layout.preferredWidth: parent.width
Layout.preferredHeight: rowTr.height
spacing: 0
property bool selected: false
Connections
{
target: blockChainPanel
onTxSelected: {
if (root.blockIndex !== blockIndex || rowTransaction.txIndex !== txIndex || rowTransaction.callIndex !== callIndex)
rowContentTr.deselect()
}
}
function select()
{
rowContentTr.selected = true
hash.color = selectedBlockForeground
func.color = selectedBlockForeground
if (isCall)
txSelected(txIndex, callIndex)
else
txSelected(txIndex, -1)
rowTransaction.forceActiveFocus()
}
function deselect()
{
rowContentTr.selected = false
hash.color = labelColor
func.color = labelColor
}
Menu
{
id: contextMenu
visible: false
MenuItem {
text: qsTr("Delete")
onTriggered: {
deleteConfirmation.open();
}
}
}
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked:
{
contextMenu.popup()
}
}
MessageDialog
{
id: deleteConfirmation
text: qsTr("Are you sure you want to delete this transaction?\n\nTo mark multiple transactions to delete on reload, click on 'Mark to delete' icon at the left")
standardButtons: StandardIcon.Ok | StandardIcon.Cancel
onAccepted:
{
deleteTransaction(blockIndex, txIndex)
contextMenu.visible = false
}
}
MouseArea
{
anchors.fill: parent
onClicked: {
if (!rowContentTr.selected)
rowContentTr.select()
}
onDoubleClicked:
{
if (!isCall)
root.editTx(index)
}
}
Rectangle
{
color: rowContentTr.selected ? selectedTxColor : (status === "mined" ? (isCall ? callColor : txColor) : halfOpacity)
Layout.preferredWidth: blockWidth
Layout.minimumHeight: trHeight
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: statusWidth
id: rowTr
Rectangle
{
id: trSaveStatus
anchors.right: parent.left
anchors.top: parent.top
width: statusWidth
height: rowTransactionItem.height < trHeight ? trHeight : rowTransactionItem.height
color: "transparent"
TooltipArea {
text: qsTr("Mark to delete")
anchors.fill: parent
}
property bool saveStatus
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: -4
id: saveStatusImage
source: "qrc:/qml/img/[email protected]"
width: statusWidth + 10
fillMode: Image.PreserveAspectFit
visible: !isCall
}
Image {
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 3
source: "qrc:/qml/img/javascript_logo.png"
height: 15
width: 15
fillMode: Image.PreserveAspectFit
visible: isCall
}
Component.onCompleted:
{
if (tx && tx.saveStatus)
saveStatus = tx.saveStatus
}
onSaveStatusChanged:
{
if (saveStatus)
saveStatusImage.source = "qrc:/qml/img/[email protected]"
else
saveStatusImage.source = "qrc:/qml/img/[email protected]"
if (index >= 0)
tx.saveStatus = saveStatus
}
MouseArea {
id: statusMouseArea
anchors.fill: parent
onClicked:
{
if (!isCall)
parent.saveStatus = !parent.saveStatus
}
}
}
RowLayout
{
id: rowTransactionItem
anchors.verticalCenter: parent.verticalCenter
onHeightChanged: {
parent.Layout.minimumHeight = height < trHeight ? trHeight : height
}
Component.onCompleted: {
parent.Layout.minimumHeight = trHeight
}
width: parent.width
DefaultText
{
id: hash
Layout.preferredWidth: (parent.width / 2) - 80
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: horizontalMargin
elide: Text.ElideRight
width: parent.width - 80
maximumLineCount: 1
clip: true
color: labelColor
font.bold: true
text: {
if (tx)
return bc.addAccountNickname(clientModel.resolveAddress(tx.sender), true)
else
return ""
}
}
Rectangle
{
Layout.preferredWidth: 30
DefaultLabel
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
color: labelColor
text: {
if (!tx || tx.exception === "None" || tx.exception === undefined)
{
color = labelColor
return "→"
}
else
{
color = "red"
font.italic = true
return tx.exception
}
}
}
}
DefaultText
{
anchors.verticalCenter: parent.verticalCenter
Layout.preferredWidth: (parent.width / 2) - 85
id: func
text: {
if (tx)
return bc.formatRecipientLabel(tx)
else
return ""
}
elide: Text.ElideRight
color: labelColor
font.bold: true
clip: true
maximumLineCount: 1
}
function userFrienldyToken(value)
{
if (value && value.indexOf("<") === 0)
{
if (value.split("> ")[1] === " - ")
return value.split(" - ")[0].replace("<", "")
else
return value.split(" - ")[0].replace("<", "") + "." + value.split("> ")[1] + "()";
}
else
return value
}
}
RowLayout
{
anchors.right: parent.right
DefaultButton
{
width: 15
height: 15
id: debugTxButton
anchors.verticalCenter: parent.verticalCenter
Layout.preferredWidth: 30
Layout.preferredHeight: 30
style: ButtonStyle
{
id: name
label: Image { source: "qrc:/qml/img/bugiconactive.png" }
}
TooltipArea {
text: qsTr("Debug transaction")
anchors.fill: parent
onClicked:
{
if (tx.recordIndex !== undefined)
clientModel.debugRecord(tx.recordIndex, tx.label);
}
}
}
Rectangle
{
width: 15
height: 15
color: "transparent"
TooltipArea {
text: qsTr("Expand transaction")
anchors.fill: parent
}
Image {
id: expandImg
source: txDetail.visible ? "qrc:/qml/img/[email protected]" : "qrc:/qml/img/[email protected]"
width: parent.width
fillMode: Image.PreserveAspectFit
anchors.horizontalCenter: parent.horizontalCenter
visible: tx !== null && tx !== undefined && tx.recordIndex !== undefined
MouseArea
{
anchors.fill: parent
onClicked:
{
txDetail.visible = !txDetail.visible
if (txDetail.visible)
colDetail.updateContainerHeight()
else
txDetail.Layout.preferredHeight = 0
}
}
}
}
}
}
}
Rectangle
{
Layout.preferredWidth: blockWidth
color: status === "mined" ? (isCall ? callColor : txColor) : halfOpacity
visible: false
id: txDetail
anchors.left: parent.left
anchors.leftMargin: statusWidth
function ensureScientificNumber(value)
{
return ScientificNumber.shouldConvertToScientific(value) ? ScientificNumber.toScientificNumber(value) + " (" + value + ")" : value
}
function updateView()
{
inputList.clear()
outputList.clear()
eventList.clear()
if (tx && tx.parameters)
{
var keys = Object.keys(tx.parameters)
for (var k in keys)
inputList.append({ "key": keys[k] === "" ? "undefined" : keys[k], "value": ensureScientificNumber(tx.parameters[keys[k]]) })
}
if (tx && tx.returnParameters)
{
var keys = Object.keys(tx.returnParameters)
for (var k in keys)
outputList.append({ "key": keys[k] === "" ? "undefined" : keys[k], "value": ensureScientificNumber(tx.returnParameters[keys[k]]) })
}
if (tx && tx.logs)
{
for (var k = 0; k < tx.logs.count; k++)
{
var param = ""
for (var p = 0; p < tx.logs.get(k).param.count; p++)
param += " " + tx.logs.get(k).param.get(p).value
param = "(" + param + ")"
eventList.append({ "key": tx.logs.get(k).name, "value": param })
}
}
}
ColumnLayout
{
anchors.top: parent.top
id: colDetail
onHeightChanged: {
updateContainerHeight()
}
Component.onCompleted: {
updateContainerHeight()
}
function updateContainerHeight()
{
if (txDetail.visible)
parent.Layout.preferredHeight = height + 5
else
parent.Layout.preferredHeight = 0
}
spacing: 5
RowLayout
{
anchors.left: parent.left
anchors.leftMargin: 5
DefaultLabel
{
id: labelFrom
text: qsTr("From: ")
color: trDetailColor
}
DefaultLabel
{
text: {
if (!tx)
return ""
else
{
var addr = clientModel.resolveAddress(tx.sender)
return blockChain.addAccountNickname(addr, true)
}
}
width: rowTransactionItem.width - 75
elide: Text.ElideRight
color: trDetailColor
font.bold: true
}
}
RowLayout
{
id: toDetail
anchors.left: parent.left
anchors.leftMargin: 5
DefaultLabel
{
text: qsTr("To: ")
color: trDetailColor
}
DefaultLabel
{
text: blockChain.formatRecipientLabel(tx)
width: rowTransactionItem.width - 75
elide: Text.ElideRight
color: trDetailColor
font.bold: true
}
}
RowLayout
{
id: valueDetail
anchors.left: parent.left
anchors.leftMargin: 5
DefaultLabel
{
text: qsTr("Value: ")
color: trDetailColor
}
DefaultLabel
{
text: tx ? tx.value.format() : ""
width: rowTransactionItem.width - 30
elide: Text.ElideRight
color: trDetailColor
font.bold: true
}
}
RowLayout
{
id: gasUsedDetail
anchors.left: parent.left
anchors.leftMargin: 5
DefaultLabel
{
text: qsTr("Gas Used: ")
color: trDetailColor
}
DefaultLabel
{
text: tx ? tx.gas.value() : ""
width: rowTransactionItem.width - 30
elide: Text.ElideRight
color: trDetailColor
font.bold: true
}
}
RowLayout
{
id: inputDetail
anchors.left: parent.left
anchors.leftMargin: 5
Column
{
DefaultLabel
{
id: labelInput
text: qsTr("Input:")
color: trDetailColor
}
ListModel
{
id: inputList
}
Repeater
{
model: inputList
DefaultLabel
{
color: trDetailColor
text: key + "\t" + value
width: rowTransactionItem.width - 40
elide: Text.ElideRight
font.bold: true
}
}
}
}
RowLayout
{
id: outputDetail
anchors.left: parent.left
anchors.leftMargin: 5
ColumnLayout
{
DefaultLabel
{
color: trDetailColor
id: labelOutput
text: qsTr("Output:")
}
ListModel
{
id: outputList
}
Repeater
{
model: outputList
DefaultLabel
{
color: trDetailColor
text: key + "\t" + value
width: rowTransactionItem.width - 40
elide: Text.ElideRight
font.bold: true
}
}
}
}
RowLayout
{
id: eventDetail
anchors.left: parent.left
anchors.leftMargin: 5
ColumnLayout
{
DefaultLabel
{
color: trDetailColor
id: labelEvent
text: qsTr("Events:")
}
ListModel
{
id: eventList
}
Repeater
{
model: eventList
RowLayout
{
DefaultLabel
{
color: trDetailColor
text: index >= 0 ? eventList.get(index).key : ""
font.bold: true
}
DefaultLabel
{
color: trDetailColor
text: index >= 0 ? eventList.get(index).value : ""
width: rowTransactionItem.width - 70
elide: Text.ElideRight
font.bold: true
}
}
}
}
}
RowLayout
{
id: debugDetail
spacing: 5
width: parent.width
layoutDirection: Qt.RightToLeft
anchors.left: parent.left
anchors.leftMargin: 5
CopyButton
{
anchors.verticalCenter: parent.verticalCenter
getContent: function() {
return JSON.stringify(tx)
}
width: 25
}
DefaultButton
{
id: editTx
anchors.verticalCenter: parent.verticalCenter
visible: !isCall
onClicked:
{
if (!isCall)
root.editTx(index)
}
text: qsTr("Edit transaction...")
}
DefaultButton
{
id: debugTx
anchors.verticalCenter: parent.verticalCenter
onClicked:
{
if (tx.recordIndex !== undefined)
clientModel.debugRecord(tx.recordIndex, tx.label);
}
text: isCall ? qsTr("Debug call...") : qsTr("Debug transaction...")
}
}
}
}
}