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
df5ef8ee
Commit
df5ef8ee
authored
Feb 14, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form reset when method is changed
parent
fc54f262
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
16 deletions
+90
-16
ContractVerificationForm.tsx
ui/contractVerification/ContractVerificationForm.tsx
+12
-9
ContractVerificationFieldAutodetectArgs.tsx
...cation/fields/ContractVerificationFieldAutodetectArgs.tsx
+0
-1
ContractVerificationFieldCode.tsx
...ractVerification/fields/ContractVerificationFieldCode.tsx
+0
-1
ContractVerificationFieldLibraries.tsx
...erification/fields/ContractVerificationFieldLibraries.tsx
+10
-2
ContractVerificationFieldName.tsx
...ractVerification/fields/ContractVerificationFieldName.tsx
+0
-1
ContractVerificationFieldOptimization.tsx
...fication/fields/ContractVerificationFieldOptimization.tsx
+0
-2
utils.ts
ui/contractVerification/utils.ts
+68
-0
No files found.
ui/contractVerification/ContractVerificationForm.tsx
View file @
df5ef8ee
import
{
Button
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
Button
,
chakra
,
useUpdateEffect
}
from
'
@chakra-ui/react
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
import
type
{
SubmitHandler
}
from
'
react-hook-form
'
;
...
@@ -21,7 +21,7 @@ import ContractVerificationSourcify from './methods/ContractVerificationSourcify
...
@@ -21,7 +21,7 @@ import ContractVerificationSourcify from './methods/ContractVerificationSourcify
import
ContractVerificationStandardInput
from
'
./methods/ContractVerificationStandardInput
'
;
import
ContractVerificationStandardInput
from
'
./methods/ContractVerificationStandardInput
'
;
import
ContractVerificationVyperContract
from
'
./methods/ContractVerificationVyperContract
'
;
import
ContractVerificationVyperContract
from
'
./methods/ContractVerificationVyperContract
'
;
import
ContractVerificationVyperMultiPartFile
from
'
./methods/ContractVerificationVyperMultiPartFile
'
;
import
ContractVerificationVyperMultiPartFile
from
'
./methods/ContractVerificationVyperMultiPartFile
'
;
import
{
prepareRequestBody
,
formatSocketErrors
,
METHOD_LABEL
S
}
from
'
./utils
'
;
import
{
prepareRequestBody
,
formatSocketErrors
,
DEFAULT_VALUE
S
}
from
'
./utils
'
;
const
METHOD_COMPONENTS
=
{
const
METHOD_COMPONENTS
=
{
'
flattened-code
'
:
<
ContractVerificationFlattenSourceCode
/>
,
'
flattened-code
'
:
<
ContractVerificationFlattenSourceCode
/>
,
...
@@ -41,14 +41,9 @@ interface Props {
...
@@ -41,14 +41,9 @@ interface Props {
const
ContractVerificationForm
=
({
method
:
methodFromQuery
,
config
,
hash
}:
Props
)
=>
{
const
ContractVerificationForm
=
({
method
:
methodFromQuery
,
config
,
hash
}:
Props
)
=>
{
const
formApi
=
useForm
<
FormFields
>
({
const
formApi
=
useForm
<
FormFields
>
({
mode
:
'
onBlur
'
,
mode
:
'
onBlur
'
,
defaultValues
:
{
defaultValues
:
methodFromQuery
?
DEFAULT_VALUES
[
methodFromQuery
]
:
undefined
,
method
:
methodFromQuery
?
{
value
:
methodFromQuery
,
label
:
METHOD_LABELS
[
methodFromQuery
],
}
:
undefined
,
},
});
});
const
{
control
,
handleSubmit
,
watch
,
formState
,
setError
}
=
formApi
;
const
{
control
,
handleSubmit
,
watch
,
formState
,
setError
,
reset
}
=
formApi
;
const
submitPromiseResolver
=
React
.
useRef
<
(
value
:
unknown
)
=>
void
>
();
const
submitPromiseResolver
=
React
.
useRef
<
(
value
:
unknown
)
=>
void
>
();
const
apiFetch
=
useApiFetch
();
const
apiFetch
=
useApiFetch
();
...
@@ -129,6 +124,14 @@ const ContractVerificationForm = ({ method: methodFromQuery, config, hash }: Pro
...
@@ -129,6 +124,14 @@ const ContractVerificationForm = ({ method: methodFromQuery, config, hash }: Pro
const
method
=
watch
(
'
method
'
);
const
method
=
watch
(
'
method
'
);
const
content
=
METHOD_COMPONENTS
[
method
?.
value
]
||
null
;
const
content
=
METHOD_COMPONENTS
[
method
?.
value
]
||
null
;
const
methodValue
=
method
?.
value
;
useUpdateEffect
(()
=>
{
if
(
methodValue
)
{
reset
(
DEFAULT_VALUES
[
methodValue
]);
}
// !!! should run only when method is changed
},
[
methodValue
]);
return
(
return
(
<
FormProvider
{
...
formApi
}
>
<
FormProvider
{
...
formApi
}
>
...
...
ui/contractVerification/fields/ContractVerificationFieldAutodetectArgs.tsx
View file @
df5ef8ee
...
@@ -34,7 +34,6 @@ const ContractVerificationFieldAutodetectArgs = () => {
...
@@ -34,7 +34,6 @@ const ContractVerificationFieldAutodetectArgs = () => {
name=
"autodetect_constructor_args"
name=
"autodetect_constructor_args"
control=
{
control
}
control=
{
control
}
render=
{
renderControl
}
render=
{
renderControl
}
defaultValue=
{
true
}
/>
/>
</
ContractVerificationFormRow
>
</
ContractVerificationFormRow
>
{
!
isOn
&&
<
ContractVerificationFieldConstructorArgs
/>
}
{
!
isOn
&&
<
ContractVerificationFieldConstructorArgs
/>
}
...
...
ui/contractVerification/fields/ContractVerificationFieldCode.tsx
View file @
df5ef8ee
...
@@ -41,7 +41,6 @@ const ContractVerificationFieldCode = ({ isVyper }: Props) => {
...
@@ -41,7 +41,6 @@ const ContractVerificationFieldCode = ({ isVyper }: Props) => {
control=
{
control
}
control=
{
control
}
render=
{
renderControl
}
render=
{
renderControl
}
rules=
{
{
required
:
true
}
}
rules=
{
{
required
:
true
}
}
defaultValue=
""
/>
/>
{
isVyper
?
null
:
(
{
isVyper
?
null
:
(
<>
<>
...
...
ui/contractVerification/fields/ContractVerificationFieldLibraries.tsx
View file @
df5ef8ee
import
{
Checkbox
}
from
'
@chakra-ui/react
'
;
import
{
Checkbox
,
useUpdateEffect
}
from
'
@chakra-ui/react
'
;
import
React
from
'
react
'
;
import
React
from
'
react
'
;
import
{
useFieldArray
,
useFormContext
}
from
'
react-hook-form
'
;
import
{
useFieldArray
,
useFormContext
}
from
'
react-hook-form
'
;
...
@@ -8,13 +8,21 @@ import ContractVerificationFormRow from '../ContractVerificationFormRow';
...
@@ -8,13 +8,21 @@ import ContractVerificationFormRow from '../ContractVerificationFormRow';
import
ContractVerificationFieldLibraryItem
from
'
./ContractVerificationFieldLibraryItem
'
;
import
ContractVerificationFieldLibraryItem
from
'
./ContractVerificationFieldLibraryItem
'
;
const
ContractVerificationFieldLibraries
=
()
=>
{
const
ContractVerificationFieldLibraries
=
()
=>
{
const
{
formState
,
control
}
=
useFormContext
<
FormFields
>
();
const
{
formState
,
control
,
getValues
}
=
useFormContext
<
FormFields
>
();
const
{
fields
,
append
,
remove
,
insert
}
=
useFieldArray
({
const
{
fields
,
append
,
remove
,
insert
}
=
useFieldArray
({
name
:
'
libraries
'
,
name
:
'
libraries
'
,
control
,
control
,
});
});
const
[
isEnabled
,
setIsEnabled
]
=
React
.
useState
(
fields
.
length
>
0
);
const
[
isEnabled
,
setIsEnabled
]
=
React
.
useState
(
fields
.
length
>
0
);
const
value
=
getValues
(
'
libraries
'
);
useUpdateEffect
(()
=>
{
if
(
!
value
||
value
.
length
===
0
)
{
setIsEnabled
(
false
);
}
},
[
value
]);
const
handleCheckboxChange
=
React
.
useCallback
(()
=>
{
const
handleCheckboxChange
=
React
.
useCallback
(()
=>
{
if
(
!
isEnabled
)
{
if
(
!
isEnabled
)
{
append
({
name
:
''
,
address
:
''
});
append
({
name
:
''
,
address
:
''
});
...
...
ui/contractVerification/fields/ContractVerificationFieldName.tsx
View file @
df5ef8ee
...
@@ -41,7 +41,6 @@ const ContractVerificationFieldName = ({ hint }: Props) => {
...
@@ -41,7 +41,6 @@ const ContractVerificationFieldName = ({ hint }: Props) => {
control=
{
control
}
control=
{
control
}
render=
{
renderControl
}
render=
{
renderControl
}
rules=
{
{
required
:
true
}
}
rules=
{
{
required
:
true
}
}
defaultValue=
""
/>
/>
{
hint
?
<
span
>
{
hint
}
</
span
>
:
(
{
hint
?
<
span
>
{
hint
}
</
span
>
:
(
<>
<>
...
...
ui/contractVerification/fields/ContractVerificationFieldOptimization.tsx
View file @
df5ef8ee
...
@@ -55,7 +55,6 @@ const ContractVerificationFieldOptimization = () => {
...
@@ -55,7 +55,6 @@ const ContractVerificationFieldOptimization = () => {
name=
"is_optimization_enabled"
name=
"is_optimization_enabled"
control=
{
control
}
control=
{
control
}
render=
{
renderCheckboxControl
}
render=
{
renderCheckboxControl
}
defaultValue=
{
true
}
/>
/>
{
isEnabled
&&
(
{
isEnabled
&&
(
<
Controller
<
Controller
...
@@ -63,7 +62,6 @@ const ContractVerificationFieldOptimization = () => {
...
@@ -63,7 +62,6 @@ const ContractVerificationFieldOptimization = () => {
control=
{
control
}
control=
{
control
}
render=
{
renderInputControl
}
render=
{
renderInputControl
}
rules=
{
{
required
:
true
}
}
rules=
{
{
required
:
true
}
}
defaultValue=
"200"
/>
/>
)
}
)
}
</
Flex
>
</
Flex
>
...
...
ui/contractVerification/utils.ts
View file @
df5ef8ee
...
@@ -32,6 +32,74 @@ export const METHOD_LABELS: Record<SmartContractVerificationMethod, string> = {
...
@@ -32,6 +32,74 @@ export const METHOD_LABELS: Record<SmartContractVerificationMethod, string> = {
'
vyper-multi-part
'
:
'
Vyper (Multi-part files)
'
,
'
vyper-multi-part
'
:
'
Vyper (Multi-part files)
'
,
};
};
export
const
DEFAULT_VALUES
=
{
'
flattened-code
'
:
{
method
:
{
value
:
'
flattened-code
'
as
const
,
label
:
METHOD_LABELS
[
'
flattened-code
'
],
},
is_yul
:
false
,
name
:
''
,
compiler
:
null
,
evm_version
:
null
,
is_optimization_enabled
:
true
,
optimization_runs
:
'
200
'
,
code
:
''
,
autodetect_constructor_args
:
true
,
constructor_args
:
''
,
libraries
:
[],
},
'
standard-input
'
:
{
method
:
{
value
:
'
standard-input
'
as
const
,
label
:
METHOD_LABELS
[
'
standard-input
'
],
},
name
:
''
,
compiler
:
null
,
sources
:
[],
autodetect_constructor_args
:
true
,
constructor_args
:
''
,
},
sourcify
:
{
method
:
{
value
:
'
sourcify
'
as
const
,
label
:
METHOD_LABELS
.
sourcify
,
},
sources
:
[],
},
'
multi-part
'
:
{
method
:
{
value
:
'
multi-part
'
as
const
,
label
:
METHOD_LABELS
[
'
multi-part
'
],
},
compiler
:
null
,
evm_version
:
null
,
is_optimization_enabled
:
true
,
optimization_runs
:
200
,
sources
:
[],
libraries
:
[],
},
'
vyper-code
'
:
{
method
:
{
value
:
'
vyper-code
'
as
const
,
label
:
METHOD_LABELS
[
'
vyper-code
'
],
},
name
:
''
,
compiler
:
null
,
code
:
''
,
constructor_args
:
''
,
},
'
vyper-multi-part
'
:
{
method
:
{
value
:
'
vyper-multi-part
'
as
const
,
label
:
METHOD_LABELS
[
'
vyper-multi-part
'
],
},
compiler
:
null
,
evm_version
:
null
,
sources
:
[],
},
};
export
function
isValidVerificationMethod
(
method
?:
string
):
method
is
SmartContractVerificationMethod
{
export
function
isValidVerificationMethod
(
method
?:
string
):
method
is
SmartContractVerificationMethod
{
return
method
&&
SUPPORTED_VERIFICATION_METHODS
.
includes
(
method
as
SmartContractVerificationMethod
)
?
true
:
false
;
return
method
&&
SUPPORTED_VERIFICATION_METHODS
.
includes
(
method
as
SmartContractVerificationMethod
)
?
true
:
false
;
}
}
...
...
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