Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
2334ef5b
Commit
2334ef5b
authored
Dec 12, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed size array
parent
ab6e752e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
ContractMethodField.tsx
ui/address/contract/ContractMethodField.tsx
+9
-3
ContractMethodFieldArray.tsx
ui/address/contract/ContractMethodFieldArray.tsx
+16
-5
No files found.
ui/address/contract/ContractMethodField.tsx
View file @
2334ef5b
...
@@ -100,7 +100,7 @@ const ContractMethodField = ({ control, name, groupName, index, argType, placeho
...
@@ -100,7 +100,7 @@ const ContractMethodField = ({ control, name, groupName, index, argType, placeho
autoComplete=
"off"
autoComplete=
"off"
/>
/>
<
InputRightElement
w=
"auto"
right=
{
1
}
>
<
InputRightElement
w=
"auto"
right=
{
1
}
>
{
field
.
value
&&
<
ClearButton
onClick=
{
handleClear
}
isDisabled=
{
isDisabled
}
/>
}
{
typeof
field
.
value
===
'
string
'
&&
field
.
value
.
replace
(
'
\n
'
,
''
)
&&
<
ClearButton
onClick=
{
handleClear
}
isDisabled=
{
isDisabled
}
/>
}
{
hasZerosControl
&&
<
ContractMethodFieldZeroes
onClick=
{
handleAddZeroesClick
}
isDisabled=
{
isDisabled
}
/>
}
{
hasZerosControl
&&
<
ContractMethodFieldZeroes
onClick=
{
handleAddZeroesClick
}
isDisabled=
{
isDisabled
}
/>
}
</
InputRightElement
>
</
InputRightElement
>
</
InputGroup
>
</
InputGroup
>
...
@@ -110,11 +110,17 @@ const ContractMethodField = ({ control, name, groupName, index, argType, placeho
...
@@ -110,11 +110,17 @@ const ContractMethodField = ({ control, name, groupName, index, argType, placeho
);
);
},
[
index
,
groupName
,
name
,
intMatch
,
isDisabled
,
placeholder
,
handleClear
,
handleAddZeroesClick
]);
},
[
index
,
groupName
,
name
,
intMatch
,
isDisabled
,
placeholder
,
handleClear
,
handleAddZeroesClick
]);
const
validate
=
React
.
useCallback
((
value
:
string
|
Array
<
string
>
)
=>
{
const
validate
=
React
.
useCallback
((
_
value
:
string
|
Array
<
string
>
)
=>
{
if
(
typeof
value
===
'
object
'
||
!
value
)
{
if
(
typeof
_value
===
'
object
'
)
{
return
;
return
;
}
}
const
value
=
_value
.
replace
(
'
\n
'
,
''
);
if
(
!
value
)
{
return
'
Field is required
'
;
}
if
(
argType
===
'
address
'
)
{
if
(
argType
===
'
address
'
)
{
return
!
isAddress
(
value
)
?
'
Invalid address format
'
:
true
;
return
!
isAddress
(
value
)
?
'
Invalid address format
'
:
true
;
}
}
...
...
ui/address/contract/ContractMethodFieldArray.tsx
View file @
2334ef5b
...
@@ -22,15 +22,26 @@ interface Props {
...
@@ -22,15 +22,26 @@ interface Props {
onChange
:
()
=>
void
;
onChange
:
()
=>
void
;
}
}
const
ContractMethodFieldArray
=
({
control
,
name
,
setValue
,
getValues
,
isDisabled
,
argType
,
onChange
}:
Props
)
=>
{
const
ContractMethodFieldArray
=
({
control
,
name
,
setValue
,
getValues
,
isDisabled
,
argType
,
onChange
,
size
}:
Props
)
=>
{
const
{
fields
,
append
,
remove
}
=
useFieldArray
({
const
{
fields
,
append
,
remove
}
=
useFieldArray
({
name
:
name
as
never
,
name
:
name
as
never
,
control
,
control
,
});
});
React
.
useEffect
(()
=>
{
React
.
useEffect
(()
=>
{
fields
.
length
===
0
&&
append
(
''
);
if
(
fields
.
length
===
0
)
{
},
[
append
,
fields
.
length
]);
if
(
size
===
Infinity
)
{
append
(
''
);
}
else
{
for
(
let
i
=
0
;
i
<
size
-
1
;
i
++
)
{
// a little hack to append multiple empty fields in the array
// had to adjust code in ContractMethodField as well
append
(
'
\n
'
);
}
}
}
},
[
fields
.
length
,
append
,
size
]);
const
handleAddButtonClick
=
React
.
useCallback
(()
=>
{
const
handleAddButtonClick
=
React
.
useCallback
(()
=>
{
append
(
''
);
append
(
''
);
...
@@ -60,7 +71,7 @@ const ContractMethodFieldArray = ({ control, name, setValue, getValues, isDisabl
...
@@ -60,7 +71,7 @@ const ContractMethodFieldArray = ({ control, name, setValue, getValues, isDisabl
isDisabled=
{
isDisabled
}
isDisabled=
{
isDisabled
}
onChange=
{
onChange
}
onChange=
{
onChange
}
/>
/>
{
array
.
length
>
1
&&
(
{
array
.
length
>
1
&&
size
===
Infinity
&&
(
<
IconButton
<
IconButton
aria
-
label=
"remove"
aria
-
label=
"remove"
data
-
index=
{
index
}
data
-
index=
{
index
}
...
@@ -73,7 +84,7 @@ const ContractMethodFieldArray = ({ control, name, setValue, getValues, isDisabl
...
@@ -73,7 +84,7 @@ const ContractMethodFieldArray = ({ control, name, setValue, getValues, isDisabl
isDisabled=
{
isDisabled
}
isDisabled=
{
isDisabled
}
/>
/>
)
}
)
}
{
index
===
array
.
length
-
1
&&
(
{
index
===
array
.
length
-
1
&&
size
===
Infinity
&&
(
<
IconButton
<
IconButton
aria
-
label=
"add"
aria
-
label=
"add"
data
-
index=
{
index
}
data
-
index=
{
index
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment