Skip to content

Commit

Permalink
Merge pull request #1628 from blockscout/tom2drum/issue-1624
Browse files Browse the repository at this point in the history
`outputs` field is not required for contract read method
  • Loading branch information
isstuev authored Feb 20, 2024
2 parents d20c632 + 043609f commit 90c4ca7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion types/api/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions ui/address/contract/ContractMethodCallable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>
Expand Down Expand Up @@ -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> }
</>
);
}) }
Expand Down
2 changes: 1 addition & 1 deletion ui/address/contract/ContractRead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }/>) }
Expand Down
2 changes: 1 addition & 1 deletion ui/address/contract/useContractAbi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function useContractAbi({ addressHash, isProxy, isCustomAbi }: Pa
}

if (isCustomAbi) {
return customInfo;
return customInfo as Abi;
}

return contractInfo?.abi ?? undefined;
Expand Down

0 comments on commit 90c4ca7

Please sign in to comment.