Commit 90c4ca73 authored by Igor Stuev's avatar Igor Stuev Committed by GitHub

Merge pull request #1628 from blockscout/tom2drum/issue-1624

`outputs` field is not required for contract read method
parents d20c632a 043609fb
......@@ -55,7 +55,7 @@ export interface SmartContractExternalLibrary {
export interface SmartContractMethodBase {
inputs: Array<SmartContractMethodInput>;
outputs: Array<SmartContractMethodOutput>;
outputs?: Array<SmartContractMethodOutput>;
constant: boolean;
name: string;
stateMutability: SmartContractMethodStateMutability;
......
......@@ -82,6 +82,8 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
});
}, [ inputs, onSubmit, data, isWrite ]);
const outputs = 'outputs' in data && data.outputs ? data.outputs : [];
return (
<Box>
<FormProvider { ...formApi }>
......@@ -163,16 +165,16 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, onSubmit,
</Button>
</chakra.form>
</FormProvider>
{ 'outputs' in data && !isWrite && data.outputs.length > 0 && (
{ !isWrite && outputs.length > 0 && (
<Flex mt={ 3 } fontSize="sm">
<IconSvg name="arrows/down-right" boxSize={ 5 } mr={ 1 }/>
<p>
{ data.outputs.map(({ type, name }, index) => {
{ outputs.map(({ type, name }, index) => {
return (
<>
<chakra.span fontWeight={ 500 }>{ name } </chakra.span>
<span>{ name ? `(${ type })` : type }</span>
{ index < data.outputs.length - 1 && <span>, </span> }
{ index < outputs.length - 1 && <span>, </span> }
</>
);
}) }
......
......@@ -63,7 +63,7 @@ const ContractRead = () => {
return <Alert status="error" fontSize="sm" wordBreak="break-word">{ item.error }</Alert>;
}
if (item.outputs.some(({ value }) => value !== undefined && value !== null)) {
if (item.outputs?.some(({ value }) => value !== undefined && value !== null)) {
return (
<Flex flexDir="column" rowGap={ 1 }>
{ item.outputs.map((output, index) => <ContractMethodConstant key={ index } data={ output }/>) }
......
......@@ -50,7 +50,7 @@ export default function useContractAbi({ addressHash, isProxy, isCustomAbi }: Pa
}
if (isCustomAbi) {
return customInfo;
return customInfo as Abi;
}
return contractInfo?.abi ?? undefined;
......
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