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
e15756e0
Commit
e15756e0
authored
Sep 26, 2024
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Not possible to send an optional empty tuple
Fixes #2271
parent
53697bb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
1 deletion
+42
-1
ContractMethodFieldInputTuple.tsx
...s/contract/methods/form/ContractMethodFieldInputTuple.tsx
+1
-0
utils.test.ts
ui/address/contract/methods/form/utils.test.ts
+23
-0
utils.ts
ui/address/contract/methods/form/utils.ts
+18
-1
No files found.
ui/address/contract/methods/form/ContractMethodFieldInputTuple.tsx
View file @
e15756e0
...
@@ -42,6 +42,7 @@ const ContractMethodFieldInputTuple = ({ data, basePath, level, isDisabled, isOp
...
@@ -42,6 +42,7 @@ const ContractMethodFieldInputTuple = ({ data, basePath, level, isDisabled, isOp
basePath=
{
`${ basePath }:${ index }`
}
basePath=
{
`${ basePath }:${ index }`
}
level=
{
level
+
1
}
level=
{
level
+
1
}
isDisabled=
{
isDisabled
}
isDisabled=
{
isDisabled
}
isOptional=
{
isOptional
}
/>
/>
);
);
}
}
...
...
ui/address/contract/methods/form/utils.test.ts
View file @
e15756e0
...
@@ -74,4 +74,27 @@ describe('transformFormDataToMethodArgs', () => {
...
@@ -74,4 +74,27 @@ describe('transformFormDataToMethodArgs', () => {
],
],
]);
]);
});
});
it
(
'
should transform all nested empty arrays to empty arrays
'
,
()
=>
{
const
formData
=
{
'
0
'
:
'
0x1D415D28380ff51A507F7B176ca5F27833F7FffD
'
,
'
1
'
:
'
0x1D415D28380ff51A507F7B176ca5F27833F7FffD
'
,
'
2
'
:
'
3160
'
,
'
3
'
:
true
,
// tuple array without elements
'
4:0:0:0
'
:
undefined
,
'
4:0:1:0
'
:
undefined
,
'
4:0:1:1
'
:
undefined
,
'
4:0:1:2
'
:
undefined
,
'
4:0:1:3
'
:
undefined
,
};
const
result
=
transformFormDataToMethodArgs
(
formData
);
expect
(
result
).
toEqual
([
'
0x1D415D28380ff51A507F7B176ca5F27833F7FffD
'
,
'
0x1D415D28380ff51A507F7B176ca5F27833F7FffD
'
,
'
3160
'
,
true
,
[],
]);
});
});
});
ui/address/contract/methods/form/utils.ts
View file @
e15756e0
...
@@ -81,7 +81,9 @@ export function transformFormDataToMethodArgs(formData: ContractMethodFormFields
...
@@ -81,7 +81,9 @@ export function transformFormDataToMethodArgs(formData: ContractMethodFormFields
_set
(
result
,
field
.
replaceAll
(
'
:
'
,
'
.
'
),
value
);
_set
(
result
,
field
.
replaceAll
(
'
:
'
,
'
.
'
),
value
);
}
}
return
filterOutEmptyItems
(
result
);
const
filteredResult
=
filterOutEmptyItems
(
result
);
const
mappedResult
=
mapEmptyNestedArrays
(
filteredResult
);
return
mappedResult
;
}
}
function
filterOutEmptyItems
(
array
:
Array
<
unknown
>
):
Array
<
unknown
>
{
function
filterOutEmptyItems
(
array
:
Array
<
unknown
>
):
Array
<
unknown
>
{
...
@@ -90,11 +92,26 @@ function filterOutEmptyItems(array: Array<unknown>): Array<unknown> {
...
@@ -90,11 +92,26 @@ function filterOutEmptyItems(array: Array<unknown>): Array<unknown> {
// The only optional field is the native coin value, which is safely handled in the form submit handler.
// The only optional field is the native coin value, which is safely handled in the form submit handler.
// 2. When the user adds and removes items from a field array.
// 2. When the user adds and removes items from a field array.
// In this scenario, empty items need to be filtered out to maintain the correct sequence of arguments.
// In this scenario, empty items need to be filtered out to maintain the correct sequence of arguments.
// We don't use isEmptyField() function here because of the second case otherwise it will not keep the correct order of arguments.
return
array
return
array
.
map
((
item
)
=>
Array
.
isArray
(
item
)
?
filterOutEmptyItems
(
item
)
:
item
)
.
map
((
item
)
=>
Array
.
isArray
(
item
)
?
filterOutEmptyItems
(
item
)
:
item
)
.
filter
((
item
)
=>
item
!==
undefined
);
.
filter
((
item
)
=>
item
!==
undefined
);
}
}
function
isEmptyField
(
field
:
unknown
):
boolean
{
// the empty string is meant that the field was touched but left empty
// the undefined is meant that the field was not touched
return
field
===
undefined
||
field
===
''
;
}
function
isEmptyNestedArray
(
array
:
Array
<
unknown
>
):
boolean
{
return
array
.
flat
(
Infinity
).
filter
((
item
)
=>
!
isEmptyField
(
item
)).
length
===
0
;
}
function
mapEmptyNestedArrays
(
array
:
Array
<
unknown
>
):
Array
<
unknown
>
{
return
array
.
map
((
item
)
=>
Array
.
isArray
(
item
)
&&
isEmptyNestedArray
(
item
)
?
[]
:
item
);
}
export
function
getFieldLabel
(
input
:
ContractAbiItemInput
,
isRequired
?:
boolean
)
{
export
function
getFieldLabel
(
input
:
ContractAbiItemInput
,
isRequired
?:
boolean
)
{
const
name
=
input
.
name
||
input
.
internalType
||
'
<unnamed argument>
'
;
const
name
=
input
.
name
||
input
.
internalType
||
'
<unnamed argument>
'
;
return
`
${
name
}
(
${
input
.
type
}
)
${
isRequired
?
'
*
'
:
''
}
`
;
return
`
${
name
}
(
${
input
.
type
}
)
${
isRequired
?
'
*
'
:
''
}
`
;
...
...
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