@@ -110,17 +110,44 @@ const ComputedValue = ({
110
110
) ;
111
111
} ;
112
112
113
+ const EditableField = ( {
114
+ onChange,
115
+ value,
116
+ } : {
117
+ onChange : ( e : React . ChangeEvent < HTMLInputElement > ) => void ;
118
+ value ?: number | bigint ;
119
+ } ) => {
120
+ const { numeralSystem } = useContext ( NumeralSystemContext ) ;
121
+
122
+ return (
123
+ < div className = "flex-[3]" >
124
+ < Input
125
+ className = "w-20 h-6 m-0 py-0 px-[4px] text-md border-white hover:border-input"
126
+ onChange = { onChange }
127
+ onKeyUp = { ( e ) => {
128
+ if ( e . key === "Enter" ) {
129
+ e . currentTarget . blur ( ) ;
130
+ }
131
+ } }
132
+ value = { valueToNumeralSystem ( value ?? 0 , numeralSystem ) }
133
+ />
134
+ </ div >
135
+ ) ;
136
+ } ;
137
+
113
138
export const Registers = ( {
114
139
currentState,
115
140
previousState,
116
141
onCurrentStateChange,
117
142
allowEditingPc,
143
+ allowEditingGas,
118
144
allowEditingRegisters,
119
145
} : {
120
146
currentState : ExpectedState ;
121
147
previousState : ExpectedState ;
122
148
onCurrentStateChange : ( changedState : ExpectedState ) => void ;
123
149
allowEditingPc : boolean ;
150
+ allowEditingGas : boolean ;
124
151
allowEditingRegisters : boolean ;
125
152
} ) => {
126
153
const { numeralSystem } = useContext ( NumeralSystemContext ) ;
@@ -134,25 +161,17 @@ export const Registers = ({
134
161
< div className = "flex flex-row items-center justify-between w-full mb-2" >
135
162
< p className = "flex-[2]" > PC</ p >
136
163
{ allowEditingPc ? (
137
- < div className = "flex-[3]" >
138
- < Input
139
- className = "w-20 h-6 m-0 py-0 px-[4px] text-md border-white hover:border-input"
140
- onChange = { ( e ) => {
141
- const value = e . target ?. value ;
142
- const newValue = stringToNumber ( value , Number ) ;
143
- onCurrentStateChange ( {
144
- ...currentState ,
145
- pc : newValue ,
146
- } ) ;
147
- } }
148
- onKeyUp = { ( e ) => {
149
- if ( e . key === "Enter" ) {
150
- e . currentTarget . blur ( ) ;
151
- }
152
- } }
153
- value = { valueToNumeralSystem ( currentState . pc ?? 0 , numeralSystem ) }
154
- />
155
- </ div >
164
+ < EditableField
165
+ onChange = { ( e ) => {
166
+ const value = e . target ?. value ;
167
+ const newValue = stringToNumber ( value , Number ) ;
168
+ onCurrentStateChange ( {
169
+ ...currentState ,
170
+ pc : newValue ,
171
+ } ) ;
172
+ } }
173
+ value = { currentState . pc }
174
+ />
156
175
) : (
157
176
< ComputedValue
158
177
value = { currentState . pc }
@@ -164,12 +183,26 @@ export const Registers = ({
164
183
</ div >
165
184
< div className = "flex flex-row items-center justify-between w-full mb-2" >
166
185
< p className = "flex-[2]" > Gas</ p >
167
- < ComputedValue
168
- value = { currentState . gas }
169
- previousValue = { previousState . gas }
170
- propName = "gas"
171
- workers = { workers }
172
- />
186
+ { allowEditingGas ? (
187
+ < EditableField
188
+ onChange = { ( e ) => {
189
+ const value = e . target ?. value ;
190
+ const newValue = BigInt ( stringToNumber ( value , Number ) ) ;
191
+ onCurrentStateChange ( {
192
+ ...currentState ,
193
+ gas : newValue ,
194
+ } ) ;
195
+ } }
196
+ value = { currentState . gas }
197
+ />
198
+ ) : (
199
+ < ComputedValue
200
+ value = { currentState . gas }
201
+ previousValue = { previousState . gas }
202
+ propName = "gas"
203
+ workers = { workers }
204
+ />
205
+ ) }
173
206
</ div >
174
207
< div className = "flex flex-row items-center justify-between w-full" >
175
208
< p className = "flex-[2]" > Status</ p >
0 commit comments