mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
constructor args field
This commit is contained in:
+1
-1
@@ -45,6 +45,6 @@ export namespace SocketMessage {
|
||||
export type AddressTxsPending = SocketMessageParamsGeneric<'pending_transaction', { transaction: Transaction }>;
|
||||
export type AddressTokenTransfer = SocketMessageParamsGeneric<'token_transfer', { token_transfer: TokenTransfer }>;
|
||||
export type TokenTransfers = SocketMessageParamsGeneric<'token_transfer', {token_transfer: number }>;
|
||||
export type ContractVerification = SocketMessageParamsGeneric<'verification', unknown>;
|
||||
export type ContractVerification = SocketMessageParamsGeneric<'verification_result', unknown>;
|
||||
export type Unknown = SocketMessageParamsGeneric<undefined, unknown>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import React from 'react';
|
||||
import type { ControllerRenderProps } from 'react-hook-form';
|
||||
import { Controller, useFormContext } from 'react-hook-form';
|
||||
|
||||
import type { FormFields } from '../types';
|
||||
|
||||
import CheckboxInput from 'ui/shared/CheckboxInput';
|
||||
|
||||
import ContractVerificationFormRow from '../ContractVerificationFormRow';
|
||||
import ContractVerificationFieldConstructorArgs from './ContractVerificationFieldConstructorArgs';
|
||||
|
||||
const ContractVerificationFieldAutodetectArgs = () => {
|
||||
const [ isOn, setIsOn ] = React.useState(true);
|
||||
const { formState, control, resetField } = useFormContext<FormFields>();
|
||||
|
||||
const handleCheckboxChange = React.useCallback(() => {
|
||||
!isOn && resetField('constructor_args');
|
||||
setIsOn(prev => !prev);
|
||||
}, [ isOn, resetField ]);
|
||||
|
||||
const renderControl = React.useCallback(({ field }: {field: ControllerRenderProps<FormFields, 'autodetect_constructor_args'>}) => (
|
||||
<CheckboxInput<FormFields, 'autodetect_constructor_args'>
|
||||
text="Try to fetch constructor arguments automatically"
|
||||
field={ field }
|
||||
isDisabled={ formState.isSubmitting }
|
||||
onChange={ handleCheckboxChange }
|
||||
/>
|
||||
), [ formState.isSubmitting, handleCheckboxChange ]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ContractVerificationFormRow>
|
||||
<Controller
|
||||
name="autodetect_constructor_args"
|
||||
control={ control }
|
||||
render={ renderControl }
|
||||
defaultValue={ true }
|
||||
/>
|
||||
</ContractVerificationFormRow>
|
||||
{ !isOn && <ContractVerificationFieldConstructorArgs/> }
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(ContractVerificationFieldAutodetectArgs);
|
||||
@@ -1,33 +0,0 @@
|
||||
import React from 'react';
|
||||
import type { ControllerRenderProps } from 'react-hook-form';
|
||||
import { Controller, useFormContext } from 'react-hook-form';
|
||||
|
||||
import type { FormFields } from '../types';
|
||||
|
||||
import CheckboxInput from 'ui/shared/CheckboxInput';
|
||||
|
||||
import ContractVerificationFormRow from '../ContractVerificationFormRow';
|
||||
|
||||
const ContractVerificationFieldConstArgs = () => {
|
||||
const { formState, control } = useFormContext<FormFields>();
|
||||
|
||||
const renderControl = React.useCallback(({ field }: {field: ControllerRenderProps<FormFields, 'constructor_args'>}) => (
|
||||
<CheckboxInput<FormFields, 'constructor_args'>
|
||||
text="Try to fetch constructor arguments automatically"
|
||||
field={ field }
|
||||
isDisabled={ formState.isSubmitting }
|
||||
/>
|
||||
), [ formState.isSubmitting ]);
|
||||
|
||||
return (
|
||||
<ContractVerificationFormRow>
|
||||
<Controller
|
||||
name="constructor_args"
|
||||
control={ control }
|
||||
render={ renderControl }
|
||||
/>
|
||||
</ContractVerificationFormRow>
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(ContractVerificationFieldConstArgs);
|
||||
+4
-4
@@ -9,10 +9,10 @@ import InputPlaceholder from 'ui/shared/InputPlaceholder';
|
||||
|
||||
import ContractVerificationFormRow from '../ContractVerificationFormRow';
|
||||
|
||||
const ContractVerificationFieldAbiEncodedArgs = () => {
|
||||
const ContractVerificationFieldConstructorArgs = () => {
|
||||
const { formState, control } = useFormContext<FormFields>();
|
||||
|
||||
const renderControl = React.useCallback(({ field }: {field: ControllerRenderProps<FormFields, 'abi_encoded_args'>}) => {
|
||||
const renderControl = React.useCallback(({ field }: {field: ControllerRenderProps<FormFields, 'constructor_args'>}) => {
|
||||
return (
|
||||
<FormControl variant="floating" id={ field.name } size={{ base: 'md', lg: 'lg' }}>
|
||||
<Textarea
|
||||
@@ -28,7 +28,7 @@ const ContractVerificationFieldAbiEncodedArgs = () => {
|
||||
return (
|
||||
<ContractVerificationFormRow>
|
||||
<Controller
|
||||
name="abi_encoded_args"
|
||||
name="constructor_args"
|
||||
control={ control }
|
||||
render={ renderControl }
|
||||
/>
|
||||
@@ -44,4 +44,4 @@ const ContractVerificationFieldAbiEncodedArgs = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(ContractVerificationFieldAbiEncodedArgs);
|
||||
export default React.memo(ContractVerificationFieldConstructorArgs);
|
||||
@@ -11,7 +11,7 @@ import InputPlaceholder from 'ui/shared/InputPlaceholder';
|
||||
import ContractVerificationFormRow from '../ContractVerificationFormRow';
|
||||
|
||||
const ContractVerificationFieldOptimization = () => {
|
||||
const [ isEnabled, setIsEnabled ] = React.useState(false);
|
||||
const [ isEnabled, setIsEnabled ] = React.useState(true);
|
||||
const { formState, control } = useFormContext<FormFields>();
|
||||
|
||||
const handleCheckboxChange = React.useCallback(() => {
|
||||
@@ -49,6 +49,7 @@ const ContractVerificationFieldOptimization = () => {
|
||||
name="is_optimization_enabled"
|
||||
control={ control }
|
||||
render={ renderCheckboxControl }
|
||||
defaultValue={ true }
|
||||
/>
|
||||
</ContractVerificationFormRow>
|
||||
{ isEnabled && (
|
||||
@@ -58,7 +59,7 @@ const ContractVerificationFieldOptimization = () => {
|
||||
control={ control }
|
||||
render={ renderInputControl }
|
||||
rules={{ required: true }}
|
||||
defaultValue=""
|
||||
defaultValue="200"
|
||||
/>
|
||||
</ContractVerificationFormRow>
|
||||
) }
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
|
||||
import ContractVerificationMethod from '../ContractVerificationMethod';
|
||||
import ContractVerificationFieldAutodetectArgs from '../fields/ContractVerificationFieldAutodetectArgs';
|
||||
import ContractVerificationFieldCode from '../fields/ContractVerificationFieldCode';
|
||||
import ContractVerificationFieldCompiler from '../fields/ContractVerificationFieldCompiler';
|
||||
import ContractVerificationFieldConstArgs from '../fields/ContractVerificationFieldConstArgs';
|
||||
import ContractVerificationFieldEvmVersion from '../fields/ContractVerificationFieldEvmVersion';
|
||||
import ContractVerificationFieldIsYul from '../fields/ContractVerificationFieldIsYul';
|
||||
import ContractVerificationFieldLibraries from '../fields/ContractVerificationFieldLibraries';
|
||||
@@ -19,7 +19,7 @@ const ContractVerificationFlattenSourceCode = () => {
|
||||
<ContractVerificationFieldEvmVersion/>
|
||||
<ContractVerificationFieldOptimization/>
|
||||
<ContractVerificationFieldCode/>
|
||||
<ContractVerificationFieldConstArgs/>
|
||||
<ContractVerificationFieldAutodetectArgs/>
|
||||
<ContractVerificationFieldLibraries/>
|
||||
</ContractVerificationMethod>
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
|
||||
import ContractVerificationMethod from '../ContractVerificationMethod';
|
||||
import ContractVerificationFieldAutodetectArgs from '../fields/ContractVerificationFieldAutodetectArgs';
|
||||
import ContractVerificationFieldCompiler from '../fields/ContractVerificationFieldCompiler';
|
||||
import ContractVerificationFieldConstArgs from '../fields/ContractVerificationFieldConstArgs';
|
||||
import ContractVerificationFieldName from '../fields/ContractVerificationFieldName';
|
||||
import ContractVerificationFieldSources from '../fields/ContractVerificationFieldSources';
|
||||
|
||||
@@ -16,7 +16,7 @@ const ContractVerificationStandardInput = () => {
|
||||
title="Standard Input JSON"
|
||||
hint="Upload the standard input JSON file created during contract compilation."
|
||||
/>
|
||||
<ContractVerificationFieldConstArgs/>
|
||||
<ContractVerificationFieldAutodetectArgs/>
|
||||
</ContractVerificationMethod>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React from 'react';
|
||||
|
||||
import ContractVerificationMethod from '../ContractVerificationMethod';
|
||||
import ContractVerificationFieldAbiEncodedArgs from '../fields/ContractVerificationFieldAbiEncodedArgs';
|
||||
import ContractVerificationFieldCode from '../fields/ContractVerificationFieldCode';
|
||||
import ContractVerificationFieldCompiler from '../fields/ContractVerificationFieldCompiler';
|
||||
import ContractVerificationFieldConstructorArgs from '../fields/ContractVerificationFieldConstructorArgs';
|
||||
import ContractVerificationFieldName from '../fields/ContractVerificationFieldName';
|
||||
|
||||
const ContractVerificationVyperContract = () => {
|
||||
@@ -12,7 +12,7 @@ const ContractVerificationVyperContract = () => {
|
||||
<ContractVerificationFieldName hint="Must match the name specified in the code."/>
|
||||
<ContractVerificationFieldCompiler isVyper/>
|
||||
<ContractVerificationFieldCode isVyper/>
|
||||
<ContractVerificationFieldAbiEncodedArgs/>
|
||||
<ContractVerificationFieldConstructorArgs/>
|
||||
</ContractVerificationMethod>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,7 +13,8 @@ export interface FormFieldsFlattenSourceCode {
|
||||
is_optimization_enabled: boolean;
|
||||
optimization_runs: string;
|
||||
code: string;
|
||||
constructor_args: boolean;
|
||||
autodetect_constructor_args: boolean;
|
||||
constructor_args: string;
|
||||
libraries: Array<ContractLibrary>;
|
||||
}
|
||||
|
||||
@@ -22,7 +23,8 @@ export interface FormFieldsStandardInput {
|
||||
name: string;
|
||||
compiler: Option;
|
||||
sources: Array<File>;
|
||||
constructor_args: boolean;
|
||||
autodetect_constructor_args: boolean;
|
||||
constructor_args: string;
|
||||
}
|
||||
|
||||
export interface FormFieldsSourcify {
|
||||
@@ -45,7 +47,7 @@ export interface FormFieldsVyperContract {
|
||||
name: string;
|
||||
compiler: Option;
|
||||
code: string;
|
||||
abi_encoded_args: string;
|
||||
constructor_args: string;
|
||||
}
|
||||
|
||||
export interface FormFieldsVyperMultiPartFile {
|
||||
|
||||
@@ -51,7 +51,8 @@ export function prepareRequestBody(data: FormFields): FetchParams['body'] {
|
||||
contract_name: data.name,
|
||||
libraries: reduceLibrariesArray(data.libraries),
|
||||
evm_version: data.evm_version.value,
|
||||
autodetect_constructor_args: data.constructor_args,
|
||||
autodetect_constructor_args: data.autodetect_constructor_args,
|
||||
constructor_args: data.constructor_args,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,7 +60,8 @@ export function prepareRequestBody(data: FormFields): FetchParams['body'] {
|
||||
const body = new FormData();
|
||||
body.set('compiler_version', data.compiler.value);
|
||||
body.set('contract_name', data.name);
|
||||
body.set('autodetect_constructor_args', String(Boolean(data.constructor_args)));
|
||||
body.set('autodetect_constructor_args', String(Boolean(data.autodetect_constructor_args)));
|
||||
body.set('constructor_args', data.constructor_args);
|
||||
addFilesToFormData(body, data.sources);
|
||||
|
||||
return body;
|
||||
@@ -91,10 +93,19 @@ export function prepareRequestBody(data: FormFields): FetchParams['body'] {
|
||||
compiler_version: data.compiler.value,
|
||||
source_code: data.code,
|
||||
contract_name: data.name,
|
||||
constructor_args: data.abi_encoded_args,
|
||||
constructor_args: data.constructor_args,
|
||||
};
|
||||
}
|
||||
|
||||
case 'vyper_multi_part': {
|
||||
const body = new FormData();
|
||||
body.set('compiler_version', data.compiler.value);
|
||||
body.set('evm_version', data.evm_version.value);
|
||||
addFilesToFormData(body, data.sources);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
default: {
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user