@@ -22,6 +22,7 @@ import { PhantomTransactionModel } from '../../../Data/Transaction';
22
22
import { UTXOModel } from '../../../Data/UTXO' ;
23
23
import {
24
24
get_wtxid_backwards ,
25
+ hasOwn ,
25
26
is_mock_outpoint ,
26
27
PrettyAmountField ,
27
28
} from '../../../util' ;
@@ -43,13 +44,23 @@ import {
43
44
recreate_contract ,
44
45
selectHasEffect ,
45
46
} from '../../../AppSlice' ;
47
+ import { RootState } from '../../../Store/store' ;
46
48
47
49
interface UTXODetailProps {
48
50
entity : UTXOModel ;
49
51
contract : ContractModel ;
50
52
}
51
53
54
+ const C = React . memo ( UTXODetailInner , ( prev , next ) => {
55
+ const b = prev . entity == next . entity && prev . contract == next . contract ;
56
+ console . log ( 'NEWCHECK?' , b ) ;
57
+ return b ;
58
+ } ) ;
52
59
export function UTXODetail ( props : UTXODetailProps ) {
60
+ return < C { ...props } > </ C > ;
61
+ }
62
+
63
+ export function UTXODetailInner ( props : UTXODetailProps ) {
53
64
const theme = useTheme ( ) ;
54
65
const dispatch = useDispatch ( ) ;
55
66
const select_continuations = useSelector ( selectContinuation ) ;
@@ -136,9 +147,7 @@ export function UTXODetail(props: UTXODetailProps) {
136
147
const obj = select_continuations ( `${ txid } :${ idx } ` ) ;
137
148
const continuations = obj
138
149
? Object . entries ( obj ) . map ( ( [ k , v ] ) => {
139
- return (
140
- < ContinuationOption key = { k } k = { k } v = { v } > </ ContinuationOption >
141
- ) ;
150
+ return < ContinuationOption key = { k } v = { v } /> ;
142
151
} )
143
152
: null ;
144
153
const cont = continuations ? (
@@ -171,33 +180,11 @@ export function UTXODetail(props: UTXODetailProps) {
171
180
) ;
172
181
}
173
182
174
- function ContinuationOption ( props : { k : string ; v : Continuation } ) {
183
+ function ContinuationOption ( props : { v : Continuation } ) {
175
184
const [ is_open , setOpen ] = React . useState ( false ) ;
176
- const select_effect = useSelector ( selectHasEffect ) ;
177
- const name = props . k . substr ( props . k . lastIndexOf ( '/' ) + 1 ) ;
185
+ const name = props . v . path . substr ( props . v . path . lastIndexOf ( '/' ) + 1 ) ;
178
186
const dispatch = useDispatch ( ) ;
179
- const form = React . useRef < any | null > ( null ) ;
180
- const name_form = React . useRef < any | null > ( null ) ;
181
- const name_schema : JSONSchema7 = {
182
- title : 'Name for this Update' ,
183
- type : 'string' ,
184
- } ;
185
- const this_effect_name = React . useRef ( '' ) ;
186
- const submit = ( e : ISubmitEvent < any > ) => {
187
- const name = this_effect_name . current ;
188
- const data = e . formData ;
189
- dispatch ( add_effect_to_contract ( [ props . k , name , data ] ) ) ;
190
- } ;
191
187
192
- const validate_name_unique = (
193
- data : string ,
194
- errors : FormValidation
195
- ) : FormValidation => {
196
- if ( data === '' ) errors . addError ( 'Name Required' ) ;
197
- if ( select_effect ( props . k , data ) ) errors . addError ( 'Name Already Used' ) ;
198
- this_effect_name . current = data ;
199
- return errors ;
200
- } ;
201
188
return (
202
189
< div >
203
190
< Button onClick = { ( ) => setOpen ( true ) } variant = "contained" >
@@ -206,32 +193,14 @@ function ContinuationOption(props: { k: string; v: Continuation }) {
206
193
< Dialog open = { is_open } onClose = { ( ) => setOpen ( false ) } >
207
194
< DialogTitle >
208
195
< Typography variant = "h5" > { name } </ Typography >
209
- < ASM className = "txhex" value = { props . k } label = "Full Path" />
196
+ < ASM
197
+ className = "txhex"
198
+ value = { props . v . path }
199
+ label = "Full Path"
200
+ />
210
201
</ DialogTitle >
211
202
< DialogContent >
212
- < Form
213
- schema = { name_schema }
214
- validate = { validate_name_unique }
215
- liveValidate
216
- // NOTE: This is a bug documented here
217
- // https://github.com/rjsf-team/react-jsonschema-form/issues/2135
218
- // eslint-disable-next-line
219
- // @ts -ignore
220
- ref = { name_form }
221
- >
222
- < div
223
- // Cancels native submit button
224
- > </ div >
225
- </ Form >
226
- < Form
227
- schema = { props . v . schema }
228
- onSubmit = { submit }
229
- // NOTE: This is a bug documented here
230
- // https://github.com/rjsf-team/react-jsonschema-form/issues/2135
231
- // eslint-disable-next-line
232
- // @ts -ignore
233
- ref = { form }
234
- > </ Form >
203
+ < MemoizeContForm { ...props } />
235
204
</ DialogContent >
236
205
< DialogActions >
237
206
< Button onClick = { ( ) => dispatch ( recreate_contract ( ) ) } >
@@ -243,3 +212,61 @@ function ContinuationOption(props: { k: string; v: Continuation }) {
243
212
</ div >
244
213
) ;
245
214
}
215
+
216
+ const name_schema : JSONSchema7 = {
217
+ title : 'Name for this Update' ,
218
+ type : 'string' ,
219
+ } ;
220
+ const MemoizeContForm = React . memo ( ContForm , ( prev , next ) => {
221
+ return prev . v . path === next . v . path ;
222
+ } ) ;
223
+ function ContForm ( props : { v : Continuation } ) {
224
+ const dispatch = useDispatch ( ) ;
225
+ const form = React . useRef < any | null > ( null ) ;
226
+ const name_form = React . useRef < any | null > ( null ) ;
227
+ const this_effect_name = React . useRef ( '' ) ;
228
+ const submit = ( e : ISubmitEvent < any > ) => {
229
+ const name = this_effect_name . current ;
230
+ const data = e . formData ;
231
+ dispatch ( add_effect_to_contract ( [ props . v . path , name , data ] ) ) ;
232
+ } ;
233
+ const has_effect = useSelector ( ( s : RootState ) =>
234
+ selectHasEffect ( s , props . v . path )
235
+ ) ;
236
+ const validate_name_unique = (
237
+ data : string ,
238
+ errors : FormValidation
239
+ ) : FormValidation => {
240
+ if ( data === '' ) errors . addError ( 'Name Required' ) ;
241
+ if ( hasOwn ( has_effect , data ) ) errors . addError ( 'Name Already Used' ) ;
242
+ this_effect_name . current = data ;
243
+ return errors ;
244
+ } ;
245
+ return (
246
+ < div >
247
+ < Form
248
+ schema = { name_schema }
249
+ validate = { validate_name_unique }
250
+ liveValidate
251
+ // NOTE: This is a bug documented here
252
+ // https://github.com/rjsf-team/react-jsonschema-form/issues/2135
253
+ // eslint-disable-next-line
254
+ // @ts -ignore
255
+ ref = { name_form }
256
+ >
257
+ < div
258
+ // Cancels native submit button
259
+ > </ div >
260
+ </ Form >
261
+ < Form
262
+ schema = { props . v . schema }
263
+ onSubmit = { submit }
264
+ // NOTE: This is a bug documented here
265
+ // https://github.com/rjsf-team/react-jsonschema-form/issues/2135
266
+ // eslint-disable-next-line
267
+ // @ts -ignore
268
+ ref = { form }
269
+ > </ Form >
270
+ </ div >
271
+ ) ;
272
+ }
0 commit comments