@@ -2,14 +2,10 @@ import { SyntheticEvent, useCallback, useMemo } from 'react'
2
2
import { DropdownProps , Field , InputOnChangeData , SelectField , TextAreaField , TextAreaProps } from 'decentraland-ui'
3
3
import { MappingType , MultipleMapping } from '@dcl/schemas'
4
4
import { t } from 'decentraland-dapps/dist/modules/translation'
5
- import { LinkedContractProtocol } from 'modules/thirdParty/types'
6
- import { shorten } from 'lib/address'
7
5
import allIcon from '../../icons/all.svg'
8
6
import multipleIcon from '../../icons/multiple.svg'
9
7
import singleIcon from '../../icons/single.svg'
10
8
import rangeIcon from '../../icons/range.svg'
11
- import ethereumSvg from '../../icons/ethereum.svg'
12
- import polygonSvg from '../../icons/polygon.svg'
13
9
import { Props } from './MappingEditor.types'
14
10
import styles from './MappingEditor.module.css'
15
11
@@ -19,25 +15,9 @@ const mappingTypeIcons = {
19
15
[ MappingType . SINGLE ] : singleIcon ,
20
16
[ MappingType . RANGE ] : rangeIcon
21
17
}
22
- const imgSrcByNetwork = {
23
- [ LinkedContractProtocol . MAINNET ] : ethereumSvg ,
24
- [ LinkedContractProtocol . MATIC ] : polygonSvg ,
25
- [ LinkedContractProtocol . SEPOLIA ] : ethereumSvg ,
26
- [ LinkedContractProtocol . AMOY ] : polygonSvg
27
- }
28
18
29
19
export const MappingEditor = ( props : Props ) => {
30
- const { mapping, error, disabled, contract, contracts, onChange } = props
31
- const linkedContractsOptions = useMemo (
32
- ( ) =>
33
- contracts . map ( ( contract , index ) => ( {
34
- value : index ,
35
- key : index ,
36
- image : imgSrcByNetwork [ contract . network ] ,
37
- text : shorten ( contract . address , 14 , 14 )
38
- } ) ) ,
39
- [ contracts , imgSrcByNetwork ]
40
- )
20
+ const { mapping, error, disabled, onChange } = props
41
21
42
22
const [ mappingType , mappingValue ] = useMemo ( ( ) => {
43
23
switch ( mapping . type ) {
@@ -68,82 +48,56 @@ export const MappingEditor = (props: Props) => {
68
48
const mappingType = value as MappingType
69
49
switch ( mappingType ) {
70
50
case MappingType . ANY :
71
- onChange ( { type : mappingType } , contract )
51
+ onChange ( { type : mappingType } )
72
52
break
73
53
case MappingType . MULTIPLE :
74
- onChange ( { type : mappingType , ids : [ ] } , contract )
54
+ onChange ( { type : mappingType , ids : [ ] } )
75
55
break
76
56
case MappingType . SINGLE :
77
- onChange ( { type : mappingType , id : '' } , contract )
57
+ onChange ( { type : mappingType , id : '' } )
78
58
break
79
59
case MappingType . RANGE :
80
- onChange ( { type : mappingType , to : '' , from : '' } , contract )
60
+ onChange ( { type : mappingType , to : '' , from : '' } )
81
61
break
82
62
}
83
63
} ,
84
- [ contract , onChange ]
64
+ [ onChange ]
85
65
)
86
66
87
- const handleSingleMappingValueChange = useCallback (
88
- ( _ : React . ChangeEvent < HTMLInputElement > , data : InputOnChangeData ) => {
89
- onChange ( { type : MappingType . SINGLE , id : data . value } , contract )
90
- } ,
91
- [ contract ]
92
- )
67
+ const handleSingleMappingValueChange = useCallback ( ( _ : React . ChangeEvent < HTMLInputElement > , data : InputOnChangeData ) => {
68
+ onChange ( { type : MappingType . SINGLE , id : data . value } )
69
+ } , [ ] )
93
70
94
- const handleMultipleMappingValueChange = useCallback (
95
- ( _ : React . ChangeEvent < HTMLTextAreaElement > , data : TextAreaProps ) => {
96
- const ids =
97
- data . value
98
- ?. toString ( )
99
- . replaceAll ( / [ ^ 0 - 9 , \s ] / g, '' )
100
- . split ( ',' )
101
- . map ( value => value . trim ( ) ) ?? [ ]
71
+ const handleMultipleMappingValueChange = useCallback ( ( _ : React . ChangeEvent < HTMLTextAreaElement > , data : TextAreaProps ) => {
72
+ const ids =
73
+ data . value
74
+ ?. toString ( )
75
+ . replaceAll ( / [ ^ 0 - 9 , \s ] / g, '' )
76
+ . split ( ',' )
77
+ . map ( value => value . trim ( ) ) ?? [ ]
102
78
103
- onChange (
104
- {
105
- type : MappingType . MULTIPLE ,
106
- ids
107
- } ,
108
- contract
109
- )
110
- } ,
111
- [ contract ]
112
- )
79
+ onChange ( {
80
+ type : MappingType . MULTIPLE ,
81
+ ids
82
+ } )
83
+ } , [ ] )
113
84
114
85
const handleFromMappingValueChange = useCallback (
115
86
( _ : React . ChangeEvent < HTMLInputElement > , data : InputOnChangeData ) => {
116
- onChange ( { type : MappingType . RANGE , from : data . value , to : mappingValue . split ( ',' ) [ 1 ] } , contract )
87
+ onChange ( { type : MappingType . RANGE , from : data . value , to : mappingValue . split ( ',' ) [ 1 ] } )
117
88
} ,
118
- [ mappingValue , contract ]
89
+ [ mappingValue ]
119
90
)
120
91
121
92
const handleToMappingValueChange = useCallback (
122
93
( _ : React . ChangeEvent < HTMLInputElement > , data : InputOnChangeData ) => {
123
- onChange ( { type : MappingType . RANGE , from : mappingValue . split ( ',' ) [ 0 ] , to : data . value } , contract )
94
+ onChange ( { type : MappingType . RANGE , from : mappingValue . split ( ',' ) [ 0 ] , to : data . value } )
124
95
} ,
125
- [ mappingValue , contract ]
126
- )
127
-
128
- const handleLinkedContractChange = useCallback (
129
- ( _ : SyntheticEvent < HTMLElement , Event > , { value } : DropdownProps ) => {
130
- onChange ( mapping , contracts [ value as number ] )
131
- } ,
132
- [ mapping , contracts ]
96
+ [ mappingValue ]
133
97
)
134
98
135
99
return (
136
100
< div className = { styles . main } >
137
- < SelectField
138
- label = { t ( 'create_linked_wearable_collection_modal.linked_contract_field.label' ) }
139
- className = { styles . linkedContractSelect }
140
- disabled = { linkedContractsOptions . length === 0 }
141
- value = { contract ? contracts . indexOf ( contract ) : undefined }
142
- options = { linkedContractsOptions }
143
- search = { false }
144
- onChange = { handleLinkedContractChange }
145
- message = { linkedContractsOptions . length === 0 ? t ( 'create_linked_wearable_collection_modal.linked_contract_field.message' ) : '' }
146
- />
147
101
< SelectField
148
102
label = { t ( 'mapping_editor.mapping_type_label' ) }
149
103
onChange = { handleMappingTypeChange }
0 commit comments