@@ -36,25 +36,45 @@ import { useAccountsList, useAccountsClaimBurn } from "../../../api/hooks/useAcc
36
36
import { useTheme } from "@mui/material/styles" ;
37
37
import { accountsClaimBurn } from "../../../utils/json_rpc" ;
38
38
import useAccountStore from "../../../store/accountStore" ;
39
+ import { useKeysList } from "../../../api/hooks/useKeys" ;
39
40
40
41
export default function ClaimBurn ( ) {
41
42
const [ open , setOpen ] = useState ( false ) ;
42
43
const [ claimBurnFormState , setClaimBurnFormState ] = useState ( {
43
44
account : "" ,
45
+ key : "" ,
44
46
claimProof : "" ,
45
47
fee : "" ,
46
48
is_valid_json : false ,
49
+ newAccount : false ,
47
50
filled : false ,
48
51
disabled : false ,
49
52
} ) ;
50
53
51
54
const { data : dataAccountsList } = useAccountsList ( 0 , 10 ) ;
55
+ const { data : dataKeysList } = useKeysList ( ) ;
52
56
const { setPopup } = useAccountStore ( ) ;
53
57
54
- const onClaimBurnAccountChange = ( e : SelectChangeEvent < string > ) => {
58
+ const onClaimBurnKeyChange = ( e : SelectChangeEvent < string > ) => {
59
+ let key = e . target . value ;
60
+ let key_index = dataKeysList . keys . indexOf ( key ) ;
61
+ let account = claimBurnFormState . account ;
62
+ let selected_account = dataAccountsList . accounts . find ( ( account : any ) => account . account . key_index === key_index ) ;
63
+ let new_account_name ;
64
+ if ( selected_account !== undefined ) {
65
+ account = selected_account . account . name ;
66
+ new_account_name = false ;
67
+ } else {
68
+ if ( claimBurnFormState . newAccount === false ) {
69
+ account = "" ;
70
+ }
71
+ new_account_name = true ;
72
+ }
55
73
setClaimBurnFormState ( {
56
74
...claimBurnFormState ,
57
- [ e . target . name ] : e . target . value ,
75
+ "key" : key ,
76
+ "account" : account ,
77
+ "newAccount" : new_account_name ,
58
78
filled : claimBurnFormState . is_valid_json && claimBurnFormState . fee !== "" && e . target . value !== "" ,
59
79
} ) ;
60
80
} ;
@@ -69,7 +89,7 @@ export default function ClaimBurn() {
69
89
...claimBurnFormState ,
70
90
[ e . target . name ] : e . target . value ,
71
91
is_valid_json : true ,
72
- filled : claimBurnFormState . account !== "" && claimBurnFormState . fee !== "" && e . target . value !== "" ,
92
+ filled : claimBurnFormState . key !== "" && claimBurnFormState . fee !== "" && e . target . value !== "" ,
73
93
} ) ;
74
94
} catch {
75
95
setClaimBurnFormState ( {
@@ -81,21 +101,32 @@ export default function ClaimBurn() {
81
101
}
82
102
} ;
83
103
104
+ const onClaimBurnAccountNameChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
105
+ setClaimBurnFormState ( {
106
+ ...claimBurnFormState ,
107
+ [ e . target . name ] : e . target . value ,
108
+ filled : claimBurnFormState . key !== "" && claimBurnFormState . is_valid_json && e . target . value !== "" ,
109
+ } ) ;
110
+ }
111
+
84
112
const onClaimBurnFeeChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
85
113
setClaimBurnFormState ( {
86
114
...claimBurnFormState ,
87
115
[ e . target . name ] : e . target . value ,
88
- filled : claimBurnFormState . account !== "" && claimBurnFormState . is_valid_json && e . target . value !== "" ,
116
+ filled : claimBurnFormState . key !== "" && claimBurnFormState . is_valid_json && e . target . value !== "" ,
89
117
} ) ;
90
118
}
91
119
92
120
const onClaimBurn = async ( ) => {
93
121
try {
94
122
setClaimBurnFormState ( { ...claimBurnFormState , disabled : true } ) ;
95
- await accountsClaimBurn ( claimBurnFormState . account , JSON . parse ( claimBurnFormState . claimProof ) , + claimBurnFormState . fee ) ;
123
+ await accountsClaimBurn ( claimBurnFormState . account , JSON . parse ( claimBurnFormState . claimProof ) , + claimBurnFormState . fee , + claimBurnFormState . key [ 0 ] ) ;
96
124
setOpen ( false ) ;
97
125
setPopup ( { title : "Claimed" , error : false } ) ;
98
- setClaimBurnFormState ( { account : "" , claimProof : "" , fee : "" , is_valid_json : false , filled : false , disabled : false } ) ;
126
+ setClaimBurnFormState ( {
127
+ key : "" , account : "" , claimProof : "" , fee : "" , is_valid_json : false , filled : false , disabled : false ,
128
+ newAccount : false ,
129
+ } ) ;
99
130
} catch ( e : any ) {
100
131
setClaimBurnFormState ( { ...claimBurnFormState , disabled : false } ) ;
101
132
setPopup ( { title : "Claim burn failed: " + e . message , error : true } ) ;
@@ -111,6 +142,14 @@ export default function ClaimBurn() {
111
142
setOpen ( false ) ;
112
143
} ;
113
144
145
+ const formattedKey = ( key : any [ ] ) => {
146
+ let account = dataAccountsList . accounts . find ( ( account : any ) => account . account . key_index === + key [ 0 ] )
147
+ if ( account === undefined ) {
148
+ return < div > < b > { key [ 0 ] } </ b > { key [ 1 ] } </ div >
149
+ }
150
+ return < div > < b > { key [ 0 ] } </ b > { key [ 1 ] } < br > </ br > Account < i > { account . account . name } </ i > </ div >
151
+ }
152
+
114
153
return (
115
154
< div >
116
155
< Button variant = "outlined" onClick = { handleClickOpen } >
@@ -121,23 +160,30 @@ export default function ClaimBurn() {
121
160
< DialogContent className = "dialog-content" >
122
161
< Form onSubmit = { onClaimBurn } className = "flex-container-vertical" style = { { paddingTop : theme . spacing ( 1 ) } } >
123
162
< FormControl >
124
- < InputLabel id = "account" > Account </ InputLabel >
163
+ < InputLabel id = "key" > Key </ InputLabel >
125
164
< Select
126
- labelId = "account "
127
- name = "account "
128
- label = "Account "
129
- value = { claimBurnFormState . account }
130
- onChange = { onClaimBurnAccountChange }
165
+ labelId = "key "
166
+ name = "key "
167
+ label = "Key "
168
+ value = { claimBurnFormState . key }
169
+ onChange = { onClaimBurnKeyChange }
131
170
style = { { flexGrow : 1 , minWidth : "200px" } }
132
171
disabled = { claimBurnFormState . disabled }
133
172
>
134
- { dataAccountsList ?. accounts . map ( ( account : any ) => (
135
- < MenuItem key = { account . account . address . Component } value = { account . account . address . Component } >
136
- { account . account . name }
173
+ { dataKeysList ?. keys ? .map ( ( key : any ) => (
174
+ < MenuItem key = { key } value = { key } >
175
+ { formattedKey ( key ) }
137
176
</ MenuItem >
138
177
) ) }
139
178
</ Select >
140
179
</ FormControl >
180
+ < TextField name = "account"
181
+ label = "Account Name"
182
+ value = { claimBurnFormState . account }
183
+ onChange = { onClaimBurnAccountNameChange }
184
+ style = { { flexGrow : 1 } }
185
+ disabled = { claimBurnFormState . disabled || ! claimBurnFormState . newAccount } >
186
+ </ TextField >
141
187
< TextField
142
188
name = "claimProof"
143
189
label = "Claim Proof"
0 commit comments