@@ -36,25 +36,45 @@ import { useAccountsList, useAccountsClaimBurn } from "../../../api/hooks/useAcc
3636import { useTheme } from "@mui/material/styles" ;
3737import { accountsClaimBurn } from "../../../utils/json_rpc" ;
3838import useAccountStore from "../../../store/accountStore" ;
39+ import { useKeysList } from "../../../api/hooks/useKeys" ;
3940
4041export default function ClaimBurn ( ) {
4142 const [ open , setOpen ] = useState ( false ) ;
4243 const [ claimBurnFormState , setClaimBurnFormState ] = useState ( {
4344 account : "" ,
45+ key : "" ,
4446 claimProof : "" ,
4547 fee : "" ,
4648 is_valid_json : false ,
49+ newAccount : false ,
4750 filled : false ,
4851 disabled : false ,
4952 } ) ;
5053
5154 const { data : dataAccountsList } = useAccountsList ( 0 , 10 ) ;
55+ const { data : dataKeysList } = useKeysList ( ) ;
5256 const { setPopup } = useAccountStore ( ) ;
5357
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+ }
5573 setClaimBurnFormState ( {
5674 ...claimBurnFormState ,
57- [ e . target . name ] : e . target . value ,
75+ "key" : key ,
76+ "account" : account ,
77+ "newAccount" : new_account_name ,
5878 filled : claimBurnFormState . is_valid_json && claimBurnFormState . fee !== "" && e . target . value !== "" ,
5979 } ) ;
6080 } ;
@@ -69,7 +89,7 @@ export default function ClaimBurn() {
6989 ...claimBurnFormState ,
7090 [ e . target . name ] : e . target . value ,
7191 is_valid_json : true ,
72- filled : claimBurnFormState . account !== "" && claimBurnFormState . fee !== "" && e . target . value !== "" ,
92+ filled : claimBurnFormState . key !== "" && claimBurnFormState . fee !== "" && e . target . value !== "" ,
7393 } ) ;
7494 } catch {
7595 setClaimBurnFormState ( {
@@ -81,21 +101,32 @@ export default function ClaimBurn() {
81101 }
82102 } ;
83103
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+
84112 const onClaimBurnFeeChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
85113 setClaimBurnFormState ( {
86114 ...claimBurnFormState ,
87115 [ 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 !== "" ,
89117 } ) ;
90118 }
91119
92120 const onClaimBurn = async ( ) => {
93121 try {
94122 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 ] ) ;
96124 setOpen ( false ) ;
97125 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+ } ) ;
99130 } catch ( e : any ) {
100131 setClaimBurnFormState ( { ...claimBurnFormState , disabled : false } ) ;
101132 setPopup ( { title : "Claim burn failed: " + e . message , error : true } ) ;
@@ -111,6 +142,14 @@ export default function ClaimBurn() {
111142 setOpen ( false ) ;
112143 } ;
113144
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+
114153 return (
115154 < div >
116155 < Button variant = "outlined" onClick = { handleClickOpen } >
@@ -121,23 +160,30 @@ export default function ClaimBurn() {
121160 < DialogContent className = "dialog-content" >
122161 < Form onSubmit = { onClaimBurn } className = "flex-container-vertical" style = { { paddingTop : theme . spacing ( 1 ) } } >
123162 < FormControl >
124- < InputLabel id = "account" > Account </ InputLabel >
163+ < InputLabel id = "key" > Key </ InputLabel >
125164 < 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 }
131170 style = { { flexGrow : 1 , minWidth : "200px" } }
132171 disabled = { claimBurnFormState . disabled }
133172 >
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 ) }
137176 </ MenuItem >
138177 ) ) }
139178 </ Select >
140179 </ 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 >
141187 < TextField
142188 name = "claimProof"
143189 label = "Claim Proof"
0 commit comments