Commit 5787ed47 authored by tom's avatar tom

tweaks

parent 7965c405
...@@ -58,7 +58,7 @@ function getFloatingVariantStylesForSize(size: 'md' | 'lg', props: StyleFunction ...@@ -58,7 +58,7 @@ function getFloatingVariantStylesForSize(size: 'md' | 'lg', props: StyleFunction
label: activeLabelStyles, label: activeLabelStyles,
'input, textarea': activeInputStyles, 'input, textarea': activeInputStyles,
}, },
'&[aria-active=true] label': activeLabelStyles, '&[data-active=true] label': activeLabelStyles,
// label styles // label styles
label: FormLabel.sizes?.[size](props) || {}, label: FormLabel.sizes?.[size](props) || {},
......
...@@ -39,6 +39,7 @@ const ContractVerificationFieldCode = ({ isVyper }: Props) => { ...@@ -39,6 +39,7 @@ const ContractVerificationFieldCode = ({ isVyper }: Props) => {
control={ control } control={ control }
render={ renderControl } render={ renderControl }
rules={{ required: true }} rules={{ required: true }}
defaultValue=""
/> />
{ isVyper ? null : ( { isVyper ? null : (
<> <>
......
...@@ -39,8 +39,8 @@ const ContractVerificationFieldCompiler = ({ isVyper }: Props) => { ...@@ -39,8 +39,8 @@ const ContractVerificationFieldCompiler = ({ isVyper }: Props) => {
const handleCheckboxChange = React.useCallback(() => { const handleCheckboxChange = React.useCallback(() => {
if (isNightly) { if (isNightly) {
const value = getValues('compiler'); const field = getValues('compiler');
value.includes('nightly') && resetField('compiler'); field.value.includes('nightly') && resetField('compiler', { defaultValue: null });
} }
setIsNightly(prev => !prev); setIsNightly(prev => !prev);
}, [ getValues, isNightly, resetField ]); }, [ getValues, isNightly, resetField ]);
......
...@@ -40,6 +40,7 @@ const ContractVerificationFieldName = ({ hint }: Props) => { ...@@ -40,6 +40,7 @@ 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> : (
<> <>
......
...@@ -33,8 +33,8 @@ const ContractVerificationFieldOptimization = () => { ...@@ -33,8 +33,8 @@ const ContractVerificationFieldOptimization = () => {
<Input <Input
{ ...field } { ...field }
required required
maxLength={ 255 }
isDisabled={ formState.isSubmitting } isDisabled={ formState.isSubmitting }
type="number"
/> />
<InputPlaceholder text="Optimization runs"/> <InputPlaceholder text="Optimization runs"/>
</FormControl> </FormControl>
...@@ -57,6 +57,7 @@ const ContractVerificationFieldOptimization = () => { ...@@ -57,6 +57,7 @@ const ContractVerificationFieldOptimization = () => {
control={ control } control={ control }
render={ renderInputControl } render={ renderInputControl }
rules={{ required: true }} rules={{ required: true }}
defaultValue=""
/> />
</ContractVerificationFormRow> </ContractVerificationFormRow>
) } ) }
......
import type { Option } from 'ui/shared/FancySelect/types';
export type VerificationMethod = 'flatten_source_code' | 'standard_input' | 'sourcify' | 'multi_part_file' | 'vyper_contract' export type VerificationMethod = 'flatten_source_code' | 'standard_input' | 'sourcify' | 'multi_part_file' | 'vyper_contract'
export interface ContractLibrary { export interface ContractLibrary {
...@@ -8,8 +10,8 @@ export interface FormFieldsFlattenSourceCode { ...@@ -8,8 +10,8 @@ export interface FormFieldsFlattenSourceCode {
method: 'flatten_source_code'; method: 'flatten_source_code';
is_yul: boolean; is_yul: boolean;
name: string; name: string;
compiler: string; compiler: Option;
evm_version: string; evm_version: Option;
is_optimization_enabled: boolean; is_optimization_enabled: boolean;
optimization_runs: string; optimization_runs: string;
code: string; code: string;
...@@ -20,7 +22,7 @@ export interface FormFieldsFlattenSourceCode { ...@@ -20,7 +22,7 @@ export interface FormFieldsFlattenSourceCode {
export interface FormFieldsStandardInput { export interface FormFieldsStandardInput {
method: 'standard_input'; method: 'standard_input';
name: string; name: string;
compiler: string; compiler: Option;
sources: Array<File>; sources: Array<File>;
} }
...@@ -31,8 +33,8 @@ export interface FormFieldsSourcify { ...@@ -31,8 +33,8 @@ export interface FormFieldsSourcify {
export interface FormFieldsMultiPartFile { export interface FormFieldsMultiPartFile {
method: 'multi_part_file'; method: 'multi_part_file';
compiler: string; compiler: Option;
evm_version: string; evm_version: Option;
is_optimization_enabled: boolean; is_optimization_enabled: boolean;
optimization_runs: string; optimization_runs: string;
sources: Array<File>; sources: Array<File>;
...@@ -41,7 +43,7 @@ export interface FormFieldsMultiPartFile { ...@@ -41,7 +43,7 @@ export interface FormFieldsMultiPartFile {
export interface FormFieldsVyperContract { export interface FormFieldsVyperContract {
method: 'vyper_contract'; method: 'vyper_contract';
name: string; name: string;
compiler: string; compiler: Option;
code: string; code: string;
abi_encoded_args: string; abi_encoded_args: string;
} }
......
...@@ -2,7 +2,7 @@ import { FormControl, useToken, useColorMode } from '@chakra-ui/react'; ...@@ -2,7 +2,7 @@ import { FormControl, useToken, useColorMode } from '@chakra-ui/react';
import type { Size, CSSObjectWithLabel, OptionsOrGroups, GroupBase, SingleValue, MultiValue } from 'chakra-react-select'; import type { Size, CSSObjectWithLabel, OptionsOrGroups, GroupBase, SingleValue, MultiValue } from 'chakra-react-select';
import { Select } from 'chakra-react-select'; import { Select } from 'chakra-react-select';
import React from 'react'; import React from 'react';
import type { FieldError } from 'react-hook-form'; import type { FieldError, FieldErrorsImpl, Merge } from 'react-hook-form';
import type { Option } from './types'; import type { Option } from './types';
...@@ -14,46 +14,18 @@ interface Props { ...@@ -14,46 +14,18 @@ interface Props {
options: OptionsOrGroups<Option, GroupBase<Option>>; options: OptionsOrGroups<Option, GroupBase<Option>>;
placeholder: string; placeholder: string;
name: string; name: string;
onChange: (newValue: string) => void; onChange: (newValue: SingleValue<Option> | MultiValue<Option>) => void;
onBlur?: () => void; onBlur?: () => void;
isDisabled?: boolean; isDisabled?: boolean;
isRequired?: boolean; isRequired?: boolean;
error?: FieldError; error?: Merge<FieldError, FieldErrorsImpl<Option>> | undefined;
value?: string; value?: SingleValue<Option> | MultiValue<Option>;
} }
const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur, isDisabled, isRequired, error, value: valueFromProps }: Props) => { const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur, isDisabled, isRequired, error, value }: Props) => {
const [ value, setValue ] = React.useState<SingleValue<Option> | MultiValue<Option>>();
const menuZIndex = useToken('zIndices', 'dropdown'); const menuZIndex = useToken('zIndices', 'dropdown');
const { colorMode } = useColorMode(); const { colorMode } = useColorMode();
React.useEffect(() => {
if (!valueFromProps && value) {
setValue(null);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ valueFromProps ]);
const handleChange = React.useCallback((newValue: SingleValue<Option> | MultiValue<Option>) => {
setValue(newValue);
if (Array.isArray(newValue)) {
return;
}
const _newValue = newValue as SingleValue<Option>;
if (!_newValue) {
return;
}
onChange(_newValue.value);
}, [ onChange ]);
const handleBlur = React.useCallback(() => {
onBlur?.();
}, [ onBlur ]);
const styles = React.useMemo(() => ({ const styles = React.useMemo(() => ({
menuPortal: (provided: CSSObjectWithLabel) => ({ ...provided, zIndex: menuZIndex }), menuPortal: (provided: CSSObjectWithLabel) => ({ ...provided, zIndex: menuZIndex }),
}), [ menuZIndex ]); }), [ menuZIndex ]);
...@@ -67,7 +39,7 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur ...@@ -67,7 +39,7 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur
isRequired={ isRequired } isRequired={ isRequired }
{ ...(error ? { 'aria-invalid': true } : {}) } { ...(error ? { 'aria-invalid': true } : {}) }
{ ...(isDisabled ? { 'aria-disabled': true } : {}) } { ...(isDisabled ? { 'aria-disabled': true } : {}) }
{ ...(value ? { 'aria-active': true } : {}) } { ...(value ? { 'data-active': true } : {}) }
> >
<Select <Select
menuPortalTarget={ window.document.body } menuPortalTarget={ window.document.body }
...@@ -78,8 +50,8 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur ...@@ -78,8 +50,8 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur
styles={ styles } styles={ styles }
chakraStyles={ chakraStyles } chakraStyles={ chakraStyles }
useBasicStyles useBasicStyles
onChange={ handleChange } onChange={ onChange }
onBlur={ handleBlur } onBlur={ onBlur }
isDisabled={ isDisabled } isDisabled={ isDisabled }
isRequired={ isRequired } isRequired={ isRequired }
isInvalid={ Boolean(error) } isInvalid={ Boolean(error) }
...@@ -94,4 +66,4 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur ...@@ -94,4 +66,4 @@ const FancySelect = ({ size = 'md', options, placeholder, name, onChange, onBlur
); );
}; };
export default React.memo(FancySelect); export default React.memo(React.forwardRef(FancySelect));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment