Commit 043609fb authored by tom's avatar tom

`outputs` field is not required for contract read method

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