diff --git a/front-end-tools/src/components/InitComponent.tsx b/front-end-tools/src/components/InitComponent.tsx index 9ba86e95..ffe2ba3a 100644 --- a/front-end-tools/src/components/InitComponent.tsx +++ b/front-end-tools/src/components/InitComponent.tsx @@ -23,7 +23,20 @@ import { TxHashLink } from './CCDScanLinks'; import Box from './Box'; import { initialize } from '../writing_to_blockchain'; import { getObjectExample, getArrayExample } from '../utils'; -import { REFRESH_INTERVAL, INPUT_PARAMETER_TYPES_OPTIONS, hexRegex, MODULE_REFERENCE_PLACEHOLDER } from '../constants'; +import { + REFRESH_INTERVAL, + INPUT_PARAMETER_TYPES_OPTIONS, + hexRegex, + MODULE_REFERENCE_PLACEHOLDER, + OPTIONS_DERIVE_FROM_MODULE_REFERENCE, + DO_NOT_DERIVE, + DERIVE_FROM_STEP_1, + DERIVE_FROM_CHAIN, + INPUT_PARAMETER_TYPE_ARRAY, + INPUT_PARAMETER_TYPE_OBJECT, + INPUT_PARAMETER_TYPE_STRING, + INPUT_PARAMETER_TYPE_NUMBER, +} from '../constants'; import { getModuleSource } from '../reading_from_blockchain'; interface ConnectionProps { @@ -78,7 +91,7 @@ export default function InitComponent(props: ConnectionProps) { const [moduleReferenceLengthError, setModuleReferenceLengthError] = useState(undefined); const [schemaError, setSchemaError] = useState(undefined); - const [isModuleReferenceAlreadyDeployedStep2, setIsModuleReferenceAlreadyDeployedStep2] = useState(false); + const [isModuleReferenceAlreadyDeployed, setIsModuleReferenceAlreadyDeployed] = useState(false); const [txHash, setTxHash] = useState(undefined); @@ -133,13 +146,13 @@ export default function InitComponent(props: ConnectionProps) { .getModuleSource(moduleReference) .then((value) => { if (value === undefined) { - setIsModuleReferenceAlreadyDeployedStep2(false); + setIsModuleReferenceAlreadyDeployed(false); } else { - setIsModuleReferenceAlreadyDeployedStep2(true); + setIsModuleReferenceAlreadyDeployed(true); } }) .catch(() => { - setIsModuleReferenceAlreadyDeployedStep2(false); + setIsModuleReferenceAlreadyDeployed(false); }); } }, [connection, client, moduleReference]); @@ -192,23 +205,23 @@ export default function InitComponent(props: ConnectionProps) { setInputParameterTemplate(initTemplate); } } catch (e) { - if (deriveFromModuleRefernce === "Don't derive") { + if (deriveFromModuleRefernce === DO_NOT_DERIVE.value) { setSchemaError( `Could not get schema from uploaded schema. Uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}` ); } else { setSchemaError( - `Could not get embedded schema from the module. Select "Don't derive" to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}` + `Could not get embedded schema from the module. Select "${DO_NOT_DERIVE.label}" to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}` ); } } - if (initTemplate) { - if (inputParameterType === 'array') { - form.setValue('inputParameter', JSON.stringify(JSON.parse(initTemplate), undefined, 2)); - } else if (inputParameterType === 'object') { - form.setValue('inputParameter', JSON.stringify(JSON.parse(initTemplate), undefined, 2)); - } + if ( + initTemplate && + (inputParameterType === INPUT_PARAMETER_TYPE_ARRAY.value || + inputParameterType === INPUT_PARAMETER_TYPE_OBJECT.value) + ) { + form.setValue('inputParameter', JSON.stringify(JSON.parse(initTemplate), undefined, 2)); } }, [hasInputParameter, smartContractName, schema, inputParameterType]); @@ -275,7 +288,7 @@ export default function InitComponent(props: ConnectionProps) { const tx = initialize( connection, AccountAddress.fromBase58(account), - isModuleReferenceAlreadyDeployedStep2, + isModuleReferenceAlreadyDeployed, moduleReference, data.inputParameter, data.smartContractName ? ContractName.fromString(data.smartContractName) : undefined, @@ -296,20 +309,7 @@ export default function InitComponent(props: ConnectionProps) { DeriveFromModuleRefernce )} - {inputParameterType === 'object' && ( + {inputParameterType === INPUT_PARAMETER_TYPE_OBJECT.value && (