Skip to content

Commit

Permalink
Add documentation to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Feb 16, 2024
1 parent a911126 commit 9c61e14
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 80 deletions.
53 changes: 23 additions & 30 deletions front-end-tools/src/components/InitComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function InitComponent(props: ConnectionProps) {

type FormType = {
cCDAmount: number;
deriveFromModuleRefernce: string | undefined;
deriveFromModuleReference: string | undefined;
file: FileList | undefined;
hasInputParameter: boolean;
inputParameter: string | undefined;
Expand All @@ -69,11 +69,11 @@ export default function InitComponent(props: ConnectionProps) {

const form = useForm<FormType>({ mode: 'all' });

const [deriveFromModuleRefernce, hasInputParameter, inputParameterType, isPayable, smartContractName, file] =
const [deriveFromModuleReference, hasInputParameter, inputParameterType, isPayable, smartContractName, file] =
useWatch({
control: form.control,
name: [
'deriveFromModuleRefernce',
'deriveFromModuleReference',
'hasInputParameter',
'inputParameterType',
'isPayable',
Expand Down Expand Up @@ -145,11 +145,7 @@ export default function InitComponent(props: ConnectionProps) {
client
.getModuleSource(moduleReference)
.then((value) => {
if (value === undefined) {
setIsModuleReferenceAlreadyDeployed(false);
} else {
setIsModuleReferenceAlreadyDeployed(true);
}
setIsModuleReferenceAlreadyDeployed(value !== undefined);
})
.catch(() => {
setIsModuleReferenceAlreadyDeployed(false);
Expand All @@ -176,10 +172,7 @@ export default function InitComponent(props: ConnectionProps) {
}, [inputParameterTemplate, hasInputParameter]);

const shouldWarnNoEmbeddedSchema = useMemo(() => {

Check failure on line 174 in front-end-tools/src/components/InitComponent.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
if (schema?.length === 0) {
return true;
}
return false;
return schema?.length === 0;
}, [schema]);

useEffect(() => {
Expand All @@ -194,24 +187,24 @@ export default function InitComponent(props: ConnectionProps) {
}

if (schema) {
const inputParamterTypeSchemaBuffer = getInitContractParameterSchema(
const inputParameterTypeSchemaBuffer = getInitContractParameterSchema(
toBuffer(schema, 'base64'),
ContractName.fromString(smartContractName),
2
);

initTemplate = displayTypeSchemaTemplate(inputParamterTypeSchemaBuffer);
initTemplate = displayTypeSchemaTemplate(inputParameterTypeSchemaBuffer);

setInputParameterTemplate(initTemplate);
}
} catch (e) {
if (deriveFromModuleRefernce === DO_NOT_DERIVE.value) {
if (deriveFromModuleReference === 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}`
`Could not get schema from uploaded schema. Uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
);
} else {
setSchemaError(
`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}`
`Could not get embedded schema from the module. Select "${DO_NOT_DERIVE.label}" to manually upload a schema or uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
);
}
}
Expand Down Expand Up @@ -290,12 +283,12 @@ export default function InitComponent(props: ConnectionProps) {
AccountAddress.fromBase58(account),
isModuleReferenceAlreadyDeployed,
moduleReference,
data.inputParameter,
data.smartContractName ? ContractName.fromString(data.smartContractName) : undefined,
data.hasInputParameter,
data.deriveFromModuleRefernce,
schema,
data.inputParameter,
data.inputParameterType,
schema,
data.deriveFromModuleReference,
Energy.create(data.maxExecutionEnergy),
CcdAmount.fromMicroCcd(data.cCDAmount ?? 0)
);
Expand All @@ -306,12 +299,12 @@ export default function InitComponent(props: ConnectionProps) {
<Box header="Step 2: Initialize Smart Contract">
<Form onSubmit={form.handleSubmit(onSubmit)}>
<Form.Group className="justify-content-center">
<Form.Label>DeriveFromModuleRefernce</Form.Label>
<Form.Label>DeriveFromModuleReference</Form.Label>
<Select
{...form.register('deriveFromModuleRefernce', { required: true })}
{...form.register('deriveFromModuleReference', { required: true })}
options={OPTIONS_DERIVE_FROM_MODULE_REFERENCE}
onChange={async (e) => {
form.setValue('deriveFromModuleRefernce', e?.value);
form.setValue('deriveFromModuleReference', e?.value);

setModuleReferenceError(undefined);
setModuleReferenceLengthError(undefined);
Expand All @@ -320,7 +313,7 @@ export default function InitComponent(props: ConnectionProps) {
form.setValue('file', undefined);
setDisplayContracts([]);

const selectValue = form.getValues('deriveFromModuleRefernce');
const selectValue = form.getValues('deriveFromModuleReference');

if (selectValue === DERIVE_FROM_STEP_1.value) {
form.clearErrors('moduleReferenceString');
Expand Down Expand Up @@ -348,7 +341,7 @@ export default function InitComponent(props: ConnectionProps) {
}
}}
/>
{deriveFromModuleRefernce === DERIVE_FROM_STEP_1.value && (
{deriveFromModuleReference === DERIVE_FROM_STEP_1.value && (
<>
<br />
<Alert variant="info">
Expand All @@ -373,7 +366,7 @@ export default function InitComponent(props: ConnectionProps) {
<br />
</>
)}
{deriveFromModuleRefernce === DERIVE_FROM_CHAIN.value && (
{deriveFromModuleReference === DERIVE_FROM_CHAIN.value && (
<>
<br />
<Alert variant="info">
Expand Down Expand Up @@ -408,7 +401,7 @@ export default function InitComponent(props: ConnectionProps) {
<Form.Label> Module Reference</Form.Label>
<Form.Control
defaultValue={MODULE_REFERENCE_PLACEHOLDER}
disabled={deriveFromModuleRefernce === DERIVE_FROM_STEP_1.value}
disabled={deriveFromModuleReference === DERIVE_FROM_STEP_1.value}
{...form.register('moduleReferenceString', {
required: true,
validate: validateModuleReference,
Expand All @@ -423,7 +416,7 @@ export default function InitComponent(props: ConnectionProps) {
<Form.Text />
</Form.Group>

{deriveFromModuleRefernce !== DO_NOT_DERIVE.value && displayContracts.length > 0 ? (
{deriveFromModuleReference !== DO_NOT_DERIVE.value && displayContracts.length > 0 ? (
<Form.Group className="col-md-4 mb-3">
<Form.Label>Smart Contract Name</Form.Label>

Expand Down Expand Up @@ -536,7 +529,7 @@ export default function InitComponent(props: ConnectionProps) {

{hasInputParameter && (
<div className="box">
{deriveFromModuleRefernce === DO_NOT_DERIVE.value && (
{deriveFromModuleReference === DO_NOT_DERIVE.value && (
<Form.Group className="mb-3">
<Form.Label>Upload Smart Contract Module Schema File (e.g. schema.bin)</Form.Label>
<Form.Control
Expand Down Expand Up @@ -573,7 +566,7 @@ export default function InitComponent(props: ConnectionProps) {
<Form.Text />
</Form.Group>
)}
{deriveFromModuleRefernce === DO_NOT_DERIVE.value && schema && (
{deriveFromModuleReference === DO_NOT_DERIVE.value && schema && (
<div className="actionResultBox">
Schema in base64:
<div>{schema.toString().slice(0, 30)} ...</div>
Expand Down
10 changes: 5 additions & 5 deletions front-end-tools/src/components/ReadComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function ReadComponenet(props: ConnectionProps) {
const schema = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;
if (schema === undefined) {
setSchemaError(
'Schema was not uploaded or not embedded into the module. Uncheck the "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter'
'Schema was not uploaded or not embedded into the module. Uncheck the "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter'
);
return;
}
Expand All @@ -116,11 +116,11 @@ export default function ReadComponenet(props: ConnectionProps) {
} catch (e) {
if (deriveContractInfo) {
setSchemaError(
`Could not derive the embedded schema from the smart contract index. Uncheck "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
`Could not derive the embedded schema from the smart contract index. Uncheck "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
);
} else {
setSchemaError(
`Could not get schema from uploaded schema. Uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
`Could not get schema from uploaded schema. Uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
);
}
}
Expand All @@ -147,10 +147,10 @@ export default function ReadComponenet(props: ConnectionProps) {
ContractName.fromString(data.smartContractName),
BigInt(data.smartContractIndex),
data.entryPointName ? EntrypointName.fromString(data.entryPointName) : undefined,
schema,
data.hasInputParameter,
data.inputParameter,
data.inputParameterType,
data.hasInputParameter,
schema,
data.deriveFromSmartContractIndex
);

Expand Down
13 changes: 6 additions & 7 deletions front-end-tools/src/components/UpdateComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default function UpdateComponenet(props: ConnectionProps) {
const schema = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;
if (schema === undefined) {
setSchemaError(
'Schema was not uploaded or not embedded into the module. Uncheck the "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter'
'Schema was not uploaded or not embedded into the module. Uncheck the "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter'
);
return;
}
Expand All @@ -161,11 +161,11 @@ export default function UpdateComponenet(props: ConnectionProps) {
} catch (e) {
if (deriveContractInfo) {
setSchemaError(
`Could not derive the embedded schema from the smart contract index. Uncheck "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
`Could not derive the embedded schema from the smart contract index. Uncheck "Derive From Smart Contract Index" checkbox to manually upload a schema or uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
);
} else {
setSchemaError(
`Could not get schema from uploaded schema. Uncheck "Has Input Paramter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
`Could not get schema from uploaded schema. Uncheck "Has Input Parameter" checkbox if this entrypoint has no input parameter. Original error: ${e}`
);
}
}
Expand All @@ -187,17 +187,16 @@ export default function UpdateComponenet(props: ConnectionProps) {
const schema = deriveContractInfo ? embeddedModuleSchemaBase64 : uploadedModuleSchemaBase64;

// Send update transaction

const tx = update(
connection,
AccountAddress.fromBase58(account),
data.inputParameter,
ContractName.fromString(data.smartContractName),
data.entryPointName ? EntrypointName.fromString(data.entryPointName) : undefined,
data.hasInputParameter,
data.deriveFromSmartContractIndex,
schema,
data.hasInputParameter,
data.inputParameter,
data.inputParameterType,
schema,
Energy.create(data.maxExecutionEnergy),
BigInt(data.smartContractIndex),
CcdAmount.fromMicroCcd(data.cCDAmount ?? 0)
Expand Down
Loading

0 comments on commit 9c61e14

Please sign in to comment.