@@ -18,7 +18,9 @@ type Account struct {
18
18
accountInfo * AccountInfo
19
19
transactionList * TransactionList
20
20
methodCall * MethodCallDialog
21
+ importABI * ImportABIDialog
21
22
account * serv.Account
23
+ contract * serv.Contract
22
24
}
23
25
24
26
type AccountInfo struct {
@@ -50,6 +52,7 @@ func (a *Account) SetAccount(account *serv.Account) {
50
52
if account .IsContract () {
51
53
contract , err := account .AsContract ()
52
54
if err == nil {
55
+ a .contract = contract
53
56
a .methodCall .SetContract (contract )
54
57
} else {
55
58
log .Error ("Cannot upgrade account to contract" , "account" , account .GetAddress (), "error" , err )
@@ -80,6 +83,10 @@ func (a *Account) initLayout() {
80
83
methodCall := NewMethodCallDialog (a .app )
81
84
a .methodCall = methodCall
82
85
86
+ // ImportABIDialog
87
+ importABI := NewImportABIDialog (a .app )
88
+ a .importABI = importABI
89
+
83
90
// Transactions
84
91
transactions := NewTransactionList (a .app , true )
85
92
transactions .SetTitleColor (s .SecondaryTitleColor )
@@ -99,16 +106,7 @@ func (a *Account) initLayout() {
99
106
}
100
107
101
108
func (a * Account ) initKeymap () {
102
- keymaps := a .KeyMaps ()
103
- a .SetInputCapture (func (event * tcell.EventKey ) * tcell.EventKey {
104
- handler , ok := keymaps .FindHandler (util .AsKey (event ))
105
- if ok {
106
- handler (event )
107
- return nil
108
- } else {
109
- return event
110
- }
111
- })
109
+ InitKeymap (a , a .app )
112
110
}
113
111
114
112
func (a * Account ) KeyMaps () util.KeyMaps {
@@ -120,7 +118,14 @@ func (a *Account) KeyMaps() util.KeyMaps {
120
118
Shortcut : "C" ,
121
119
Description : "Call Contract" ,
122
120
Handler : func (* tcell.EventKey ) {
123
- a .ShowMethodCallDialog ()
121
+ // FIXME: don't show "Call Contract" for wallet account
122
+ if a .account .IsContract () {
123
+ if a .methodCall .contract .HasABI () {
124
+ a .ShowMethodCallDialog ()
125
+ } else {
126
+ a .ShowImportABIDialog ()
127
+ }
128
+ }
124
129
},
125
130
})
126
131
@@ -152,6 +157,27 @@ func (a *Account) HideMethodCallDialog() {
152
157
a .app .SetFocus (a )
153
158
}
154
159
160
+ func (a * Account ) ShowImportABIDialog () {
161
+ log .Debug ("Show importABI dialog" )
162
+
163
+ if ! a .importABI .IsDisplay () {
164
+ a .importABI .Clear ()
165
+ a .importABI .Display (true )
166
+ }
167
+
168
+ a .app .SetFocus (a .importABI )
169
+ }
170
+
171
+ func (a * Account ) HideImportABIDialog () {
172
+ log .Debug ("Hide importABI dialog" )
173
+
174
+ if a .importABI .IsDisplay () {
175
+ a .importABI .Display (false )
176
+ }
177
+
178
+ a .app .SetFocus (a )
179
+ }
180
+
155
181
func (a * Account ) refresh () {
156
182
addr := a .account .GetAddress ()
157
183
a .accountInfo .address .SetText (addr .Hex ())
@@ -180,20 +206,29 @@ func (a *Account) HasFocus() bool {
180
206
if a .methodCall .HasFocus () {
181
207
return true
182
208
}
209
+ if a .importABI .HasFocus () {
210
+ return true
211
+ }
183
212
return a .Flex .HasFocus ()
184
213
}
185
214
186
215
// InputHandler implements tview.Primitive
187
216
func (a * Account ) InputHandler () func (event * tcell.EventKey , setFocus func (p tview.Primitive )) {
188
217
return func (event * tcell.EventKey , setFocus func (p tview.Primitive )) {
189
- if a .Flex .HasFocus () {
190
- if handler := a .Flex .InputHandler (); handler != nil {
218
+ if a .methodCall .HasFocus () {
219
+ if handler := a .methodCall .InputHandler (); handler != nil {
191
220
handler (event , setFocus )
192
221
return
193
222
}
194
223
}
195
- if a .methodCall .HasFocus () {
196
- if handler := a .methodCall .InputHandler (); handler != nil {
224
+ if a .importABI .HasFocus () {
225
+ if handler := a .importABI .InputHandler (); handler != nil {
226
+ handler (event , setFocus )
227
+ return
228
+ }
229
+ }
230
+ if a .Flex .HasFocus () {
231
+ if handler := a .Flex .InputHandler (); handler != nil {
197
232
handler (event , setFocus )
198
233
return
199
234
}
@@ -205,10 +240,12 @@ func (a *Account) InputHandler() func(event *tcell.EventKey, setFocus func(p tvi
205
240
func (a * Account ) SetRect (x int , y int , width int , height int ) {
206
241
a .Flex .SetRect (x , y , width , height )
207
242
a .methodCall .SetRect (a .GetInnerRect ())
243
+ a .importABI .SetRect (a .GetInnerRect ())
208
244
}
209
245
210
246
// Draw implements tview.Primitive
211
247
func (a * Account ) Draw (screen tcell.Screen ) {
212
248
a .Flex .Draw (screen )
213
249
a .methodCall .Draw (screen )
250
+ a .importABI .Draw (screen )
214
251
}
0 commit comments