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
9933b2a2
Unverified
Commit
9933b2a2
authored
Mar 19, 2024
by
tom goriunov
Committed by
GitHub
Mar 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix: Cannot convert string to buffer while write to the contract (#1724)
Fixes #1717
parent
d833ceb5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
12 deletions
+17
-12
ContractMethodForm.tsx
ui/address/contract/methodForm/ContractMethodForm.tsx
+6
-1
useFormatFieldValue.tsx
ui/address/contract/methodForm/useFormatFieldValue.tsx
+3
-3
useValidateField.tsx
ui/address/contract/methodForm/useValidateField.tsx
+7
-7
utils.ts
ui/address/contract/methodForm/utils.ts
+1
-1
No files found.
ui/address/contract/methodForm/ContractMethodForm.tsx
View file @
9933b2a2
import
{
Box
,
Button
,
Flex
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
Box
,
Button
,
Flex
,
chakra
}
from
'
@chakra-ui/react
'
;
import
_mapValues
from
'
lodash/mapValues
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
import
{
useForm
,
FormProvider
}
from
'
react-hook-form
'
;
import
{
useForm
,
FormProvider
}
from
'
react-hook-form
'
;
...
@@ -35,7 +36,11 @@ const ContractMethodForm = <T extends SmartContractMethod>({ data, onSubmit, res
...
@@ -35,7 +36,11 @@ const ContractMethodForm = <T extends SmartContractMethod>({ data, onSubmit, res
});
});
const
onFormSubmit
:
SubmitHandler
<
ContractMethodFormFields
>
=
React
.
useCallback
(
async
(
formData
)
=>
{
const
onFormSubmit
:
SubmitHandler
<
ContractMethodFormFields
>
=
React
.
useCallback
(
async
(
formData
)
=>
{
const
args
=
transformFormDataToMethodArgs
(
formData
);
// The API used for reading from contracts expects all values to be strings.
const
formattedData
=
methodType
===
'
read
'
?
_mapValues
(
formData
,
(
value
)
=>
value
!==
undefined
?
String
(
value
)
:
undefined
)
:
formData
;
const
args
=
transformFormDataToMethodArgs
(
formattedData
);
setResult
(
undefined
);
setResult
(
undefined
);
setLoading
(
true
);
setLoading
(
true
);
...
...
ui/address/contract/methodForm/useFormatFieldValue.tsx
View file @
9933b2a2
...
@@ -18,7 +18,7 @@ export default function useFormatFieldValue({ argType, argTypeMatchInt }: Params
...
@@ -18,7 +18,7 @@ export default function useFormatFieldValue({ argType, argTypeMatchInt }: Params
if
(
argTypeMatchInt
)
{
if
(
argTypeMatchInt
)
{
const
formattedString
=
value
.
replace
(
/
\s
/g
,
''
);
const
formattedString
=
value
.
replace
(
/
\s
/g
,
''
);
return
formattedString
;
return
parseInt
(
formattedString
)
;
}
}
if
(
argType
===
'
bool
'
)
{
if
(
argType
===
'
bool
'
)
{
...
@@ -26,11 +26,11 @@ export default function useFormatFieldValue({ argType, argTypeMatchInt }: Params
...
@@ -26,11 +26,11 @@ export default function useFormatFieldValue({ argType, argTypeMatchInt }: Params
switch
(
formattedValue
)
{
switch
(
formattedValue
)
{
case
'
true
'
:
{
case
'
true
'
:
{
return
'
true
'
;
return
true
;
}
}
case
'
false
'
:{
case
'
false
'
:{
return
'
false
'
;
return
false
;
}
}
default
:
default
:
...
...
ui/address/contract/methodForm/useValidateField.tsx
View file @
9933b2a2
...
@@ -18,13 +18,15 @@ export default function useValidateField({ isOptional, argType, argTypeMatchInt
...
@@ -18,13 +18,15 @@ export default function useValidateField({ isOptional, argType, argTypeMatchInt
return
argType
.
match
(
BYTES_REGEXP
);
return
argType
.
match
(
BYTES_REGEXP
);
},
[
argType
]);
},
[
argType
]);
return
React
.
useCallback
((
value
:
string
|
undefined
)
=>
{
// some values are formatted before they are sent to the validator
// see ./useFormatFieldValue.tsx hook
return
React
.
useCallback
((
value
:
string
|
number
|
boolean
|
undefined
)
=>
{
if
(
value
===
undefined
||
value
===
''
)
{
if
(
value
===
undefined
||
value
===
''
)
{
return
isOptional
?
true
:
'
Field is required
'
;
return
isOptional
?
true
:
'
Field is required
'
;
}
}
if
(
argType
===
'
address
'
)
{
if
(
argType
===
'
address
'
)
{
if
(
!
isAddress
(
value
))
{
if
(
typeof
value
!==
'
string
'
||
!
isAddress
(
value
))
{
return
'
Invalid address format
'
;
return
'
Invalid address format
'
;
}
}
...
@@ -39,13 +41,11 @@ export default function useValidateField({ isOptional, argType, argTypeMatchInt
...
@@ -39,13 +41,11 @@ export default function useValidateField({ isOptional, argType, argTypeMatchInt
}
}
if
(
argTypeMatchInt
)
{
if
(
argTypeMatchInt
)
{
const
formattedValue
=
Number
(
value
);
if
(
typeof
value
!==
'
number
'
||
Object
.
is
(
value
,
NaN
))
{
if
(
Object
.
is
(
formattedValue
,
NaN
))
{
return
'
Invalid integer format
'
;
return
'
Invalid integer format
'
;
}
}
if
(
formattedValue
>
argTypeMatchInt
.
max
||
formattedV
alue
<
argTypeMatchInt
.
min
)
{
if
(
value
>
argTypeMatchInt
.
max
||
v
alue
<
argTypeMatchInt
.
min
)
{
const
lowerBoundary
=
argTypeMatchInt
.
isUnsigned
?
'
0
'
:
`-1 * 2 ^
${
Number
(
argTypeMatchInt
.
power
)
-
1
}
`
;
const
lowerBoundary
=
argTypeMatchInt
.
isUnsigned
?
'
0
'
:
`-1 * 2 ^
${
Number
(
argTypeMatchInt
.
power
)
-
1
}
`
;
const
upperBoundary
=
argTypeMatchInt
.
isUnsigned
?
`2 ^
${
argTypeMatchInt
.
power
}
- 1`
:
`2 ^
${
Number
(
argTypeMatchInt
.
power
)
-
1
}
- 1`
;
const
upperBoundary
=
argTypeMatchInt
.
isUnsigned
?
`2 ^
${
argTypeMatchInt
.
power
}
- 1`
:
`2 ^
${
Number
(
argTypeMatchInt
.
power
)
-
1
}
- 1`
;
return
`Value should be in range from "
${
lowerBoundary
}
" to "
${
upperBoundary
}
" inclusively`
;
return
`Value should be in range from "
${
lowerBoundary
}
" to "
${
upperBoundary
}
" inclusively`
;
...
@@ -55,7 +55,7 @@ export default function useValidateField({ isOptional, argType, argTypeMatchInt
...
@@ -55,7 +55,7 @@ export default function useValidateField({ isOptional, argType, argTypeMatchInt
}
}
if
(
argType
===
'
bool
'
)
{
if
(
argType
===
'
bool
'
)
{
if
(
value
!==
'
true
'
&&
value
!==
'
false
'
)
{
if
(
typeof
value
!==
'
boolean
'
)
{
return
'
Invalid boolean format. Allowed values: true, false
'
;
return
'
Invalid boolean format. Allowed values: true, false
'
;
}
}
}
}
...
...
ui/address/contract/methodForm/utils.ts
View file @
9933b2a2
...
@@ -2,7 +2,7 @@ import _set from 'lodash/set';
...
@@ -2,7 +2,7 @@ import _set from 'lodash/set';
import
type
{
SmartContractMethodInput
}
from
'
types/api/contract
'
;
import
type
{
SmartContractMethodInput
}
from
'
types/api/contract
'
;
export
type
ContractMethodFormFields
=
Record
<
string
,
string
|
undefined
>
;
export
type
ContractMethodFormFields
=
Record
<
string
,
string
|
boolean
|
number
|
undefined
>
;
export
const
INT_REGEXP
=
/^
(
u
)?
int
(\d
+
)?
$/i
;
export
const
INT_REGEXP
=
/^
(
u
)?
int
(\d
+
)?
$/i
;
...
...
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