1
1
var UI = ( function ( UI , $ , undefined ) {
2
+ var isProcessing = false ;
3
+
2
4
UI . showPasteTrytes = function ( callback ) {
3
5
console . log ( "UI.showPasteTrytes" ) ;
4
6
@@ -23,60 +25,121 @@ var UI = (function(UI, $, undefined) {
23
25
modal . open ( ) ;
24
26
}
25
27
26
- //999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999A9RGRKVGWMWMKOLVMDFWJUHNUNYWZTJADGGPZGXNLERLXYWJE9WQHWWBMCPZMVVMJUMWWBLZLNMLDCGDJ999999999999999999999999999999999999999999999999999999YGYQIVD99999999999999999999TXEFLKNPJRBYZPORHZU9CEMFIFVVQBUSTDGSJCZMBTZCDTTJVUFPTCCVHHORPMGCURKTH9VGJIXUQJVHK999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
27
- UI . handlePastingTrytes = function ( ) {
28
- $ ( "#verify-pasted-trytes-btn" ) . on ( "click" , function ( e ) {
29
- var trytes = $ ( "#pasted-trytes" ) . val ( ) ;
28
+ function parseTrytesToBundle ( trytes ) {
29
+ var bundleTxs = [ ] ;
30
30
31
- if ( iota . validate . isTrytes ( trytes ) ) {
32
- var transaction = iota . utils . transactionObject ( trytes ) ;
33
- } else {
34
- // We conver to trytes, then back to transaction so that no extra json key/value pairs are added..
35
- try {
36
- var transaction = JSON . parse ( $ ( "#pasted-trytes" ) . val ( ) ) ;
37
- } catch ( err ) {
38
- transaction = null ;
39
- }
40
- if ( transaction ) {
41
- trytes = iota . utils . transactionTrytes ( transaction ) ;
42
- transaction = iota . utils . transactionObject ( trytes ) ;
31
+ if ( iota . valid . isTrytes ( trytes ) ) {
32
+ var bundle = [ trytes ] ;
33
+ } else {
34
+ try {
35
+ var bundle = JSON . parse ( trytes ) ;
36
+ } catch ( err ) {
37
+ bundle = null ;
38
+ }
39
+ }
40
+
41
+ var trytesError = false ;
42
+
43
+ if ( $ . isArray ( bundle ) ) {
44
+ $ . each ( bundle , function ( index , trytes ) {
45
+ if ( ! iota . valid . isTrytes ( trytes ) ) {
46
+ trytesError = true ;
47
+ return false ;
48
+ } else {
49
+ var transaction = iota . utils . transactionObject ( trytes ) ;
50
+ if ( transaction ) {
51
+ bundleTxs . push ( transaction ) ;
52
+ } else {
53
+ trytesError = true ;
54
+ return false ;
55
+ }
43
56
}
57
+ } ) ;
58
+ }
59
+
60
+ if ( trytesError || ! bundleTxs || bundleTxs . length == 0 ) {
61
+ return false ;
62
+ }
63
+
64
+ return bundleTxs ;
65
+ }
66
+
67
+ UI . handlePastingTrytes = function ( ) {
68
+ $ ( document ) . on ( "closed" , "#paste-trytes-modal" , function ( e ) {
69
+ if ( isProcessing ) {
70
+ isProcessing = false ;
71
+ $ ( "#process-pasted-trytes-btn" ) . loadingReset ( "Process Trytes" ) ;
72
+ iota . api . interruptAttachingToTangle ( ) ;
44
73
}
74
+ } ) ;
45
75
46
- $ ( "#process-trytes" ) . val ( trytes ) ;
76
+ $ ( "#verify-pasted-trytes-btn" ) . on ( "click" , function ( e ) {
77
+ var trytes = $ ( "#pasted-trytes" ) . val ( ) ;
47
78
48
- if ( ! transaction ) {
49
- $ ( "#verify-pasted-trytes-btn" ) . loadingError ( "Invalid trytes" , { "initial" : "Verify Trytes" } ) ;
79
+ var bundleTxs = parseTrytesToBundle ( $ ( "#pasted-trytes" ) . val ( ) ) ;
80
+
81
+ if ( ! bundleTxs ) {
82
+ $ ( "#verify-pasted-trytes-btn" ) . loadingError ( "Invalid trytes or input" , { "initial" : "Verify Trytes" } ) ;
83
+ return ;
84
+ } else if ( ! iota . utils . isBundle ( bundleTxs ) ) {
85
+ $ ( "#verify-pasted-trytes-btn" ) . loadingError ( "Invalid signature" , { "initial" : "Process Trytes" } ) ;
50
86
return ;
51
87
}
52
-
88
+
53
89
var html = "<div class='list'><ul>" ;
54
- $ . each ( transaction , function ( key , value ) {
55
- html += "<li><div class='details details-" + String ( key ) . escapeHTML ( ) + "' title='" + String ( key ) . escapeHTML ( ) + "'><div class='address'>" + String ( key ) . escapeHTML ( ) + "</div></div><div class='value value-" + String ( key ) . escapeHTML ( ) + "' title='" + String ( value ) . escapeHTML ( ) + "'>" + String ( value ) . escapeHTML ( ) + "</div></li>" ;
56
- } ) ;
57
90
58
- html += "</ul></div>" ;
91
+ for ( var i = 0 ; i < bundleTxs . length ; i ++ ) {
92
+ html += "<li><div class='details'><div class='address'>" + UI . formatForClipboard ( iota . utils . addChecksum ( bundleTxs [ i ] . address ) ) + "</div></div><div class='value'>" + UI . formatAmount ( bundleTxs [ i ] . value ) + "</div></li>" ;
93
+ }
59
94
95
+ html += "</ul></div>" ;
96
+
97
+ $ ( "#process-trytes" ) . html ( html ) ;
60
98
$ ( "#paste-trytes-modal h1" ) . html ( "Verify Trytes" ) ;
61
- $ ( "#verify-trytes" ) . html ( html ) ;
62
99
$ ( "#process-trytes-group" ) . show ( ) ;
63
100
$ ( "#paste-trytes-group" ) . hide ( ) ;
101
+ $ ( "#process-pasted-trytes-completed" ) . val ( 0 ) ;
102
+
64
103
$ ( "#verify-pasted-trytes-btn" ) . loadingReset ( "Verify Trytes" ) ;
65
104
} ) ;
66
105
67
106
$ ( "#process-pasted-trytes-btn" ) . on ( "click" , function ( e ) {
68
- iota . api . sendTrytes ( $ ( "#process-trytes" ) . val ( ) , connection . depth , connection . minWeightMagnitude , function ( error , transfers ) {
107
+ var bundleTxs = parseTrytesToBundle ( $ ( "#pasted-trytes" ) . val ( ) ) ;
108
+
109
+ if ( $ ( "#process-pasted-trytes-completed" ) . val ( ) == 1 ) {
110
+ $ ( "#process-pasted-trytes-btn" ) . loadingError ( "Already Processed" , { "initial" : "Process Trytes" } ) ;
111
+ return ;
112
+ } else if ( ! bundleTxs ) {
113
+ $ ( "#process-pasted-trytes-btn" ) . loadingError ( "Invalid trytes or input" , { "initial" : "Process Trytes" } ) ;
114
+ return ;
115
+ } else if ( ! iota . utils . isBundle ( bundleTxs ) ) {
116
+ $ ( "#process-pasted-trytes-btn" ) . loadingError ( "Invalid signature" , { "initial" : "Process Trytes" } ) ;
117
+ return ;
118
+ }
119
+
120
+ var trytes = [ ] ;
121
+
122
+ $ . each ( bundleTxs , function ( index , transaction ) {
123
+ trytes . push ( iota . utils . transactionTrytes ( transaction ) ) ;
124
+ } ) ;
125
+
126
+ trytes = trytes . reverse ( ) ;
127
+
128
+ console . log ( trytes ) ;
129
+
130
+ isProcessing = true ;
131
+
132
+ iota . api . sendTrytes ( trytes , connection . depth , connection . minWeightMagnitude , function ( error , transfers ) {
69
133
if ( error ) {
70
134
console . log ( "Process Pasted Trytes: Error" ) ;
71
135
console . log ( error ) ;
72
-
73
-
136
+ $ ( "#process-pasted-trytes-btn" ) . loadingError ( error ) ;
74
137
} else {
75
138
console . log ( "Process Pasted Trytes: Success" ) ;
76
139
$ ( "#process-pasted-trytes-btn" ) . loadingSuccess ( "Transaction Completed" ) ;
140
+ $ ( "#process-pasted-trytes-completed" ) . val ( 1 ) ;
77
141
UI . updateState ( 1000 ) ;
78
142
}
79
- $stack . removeClass ( "loading" ) ;
80
143
} ) ;
81
144
} ) ;
82
145
}
0 commit comments