Commit 8d1769a8 authored by tom's avatar tom

amends

parent 961fb314
...@@ -15,6 +15,7 @@ import ContractMethodField from './ContractMethodField'; ...@@ -15,6 +15,7 @@ import ContractMethodField from './ContractMethodField';
interface Props<T extends SmartContractMethod> { interface Props<T extends SmartContractMethod> {
data: T; data: T;
caller: (data: T, args: Array<string>) => Promise<Array<Array<string>>>; caller: (data: T, args: Array<string>) => Promise<Array<Array<string>>>;
isWrite?: boolean;
} }
const getFieldName = (name: string, index: number): string => name || String(index); const getFieldName = (name: string, index: number): string => name || String(index);
...@@ -35,7 +36,7 @@ const sortFields = (data: Array<SmartContractMethodInput>) => ([ a ]: [string, s ...@@ -35,7 +36,7 @@ const sortFields = (data: Array<SmartContractMethodInput>) => ([ a ]: [string, s
return 0; return 0;
}; };
const ContractMethodCallable = <T extends SmartContractMethod>({ data, caller }: Props<T>) => { const ContractMethodCallable = <T extends SmartContractMethod>({ data, caller, isWrite }: Props<T>) => {
const inputs = React.useMemo(() => { const inputs = React.useMemo(() => {
return data.payable && (!('inputs' in data) || data.inputs.length === 0) ? [ { return data.payable && (!('inputs' in data) || data.inputs.length === 0) ? [ {
...@@ -92,7 +93,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, caller }: ...@@ -92,7 +93,7 @@ const ContractMethodCallable = <T extends SmartContractMethod>({ data, caller }:
flexShrink={ 0 } flexShrink={ 0 }
type="submit" type="submit"
> >
Query { isWrite ? 'Write' : 'Query' }
</Button> </Button>
</chakra.form> </chakra.form>
{ 'outputs' in data && data.outputs.length > 0 && ( { 'outputs' in data && data.outputs.length > 0 && (
......
import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, Box, Flex, Link } from '@chakra-ui/react'; import { Accordion, AccordionButton, AccordionIcon, AccordionItem, AccordionPanel, Box, Flex, Icon, Link, Tooltip } from '@chakra-ui/react';
import _range from 'lodash/range'; import _range from 'lodash/range';
import React from 'react'; import React from 'react';
import type { SmartContractMethod } from 'types/api/contract'; import type { SmartContractMethod } from 'types/api/contract';
import infoIcon from 'icons/info.svg';
interface Props<T extends SmartContractMethod> { interface Props<T extends SmartContractMethod> {
data: Array<T>; data: Array<T>;
renderContent: (item: T, index: number, id: number) => React.ReactNode; renderContent: (item: T, index: number, id: number) => React.ReactNode;
...@@ -43,6 +45,19 @@ const ContractMethodsAccordion = <T extends SmartContractMethod>({ data, renderC ...@@ -43,6 +45,19 @@ const ContractMethodsAccordion = <T extends SmartContractMethod>({ data, renderC
<Box as="span" fontFamily="heading" fontWeight={ 500 } fontSize="lg" mr={ 1 }> <Box as="span" fontFamily="heading" fontWeight={ 500 } fontSize="lg" mr={ 1 }>
{ index + 1 }. { item.type === 'fallback' ? 'fallback' : item.name } { index + 1 }. { item.type === 'fallback' ? 'fallback' : item.name }
</Box> </Box>
{ item.type === 'fallback' && (
<Tooltip
label={ `The fallback function is executed on a call to the contract if none of the other functions match
the given function signature, or if no data was supplied at all and there is no receive Ether function.
The fallback function always receives data, but in order to also receive Ether it must be marked payable.` }
placement="top"
maxW="320px"
>
<Box cursor="pointer" display="inherit">
<Icon as={ infoIcon } boxSize={ 5 }/>
</Box>
</Tooltip>
) }
<AccordionIcon/> <AccordionIcon/>
</AccordionButton> </AccordionButton>
</h2> </h2>
......
...@@ -41,6 +41,7 @@ const ContractWrite = () => { ...@@ -41,6 +41,7 @@ const ContractWrite = () => {
key={ id + '_' + index } key={ id + '_' + index }
data={ item } data={ item }
caller={ contractCaller } caller={ contractCaller }
isWrite
/> />
); );
}, [ contractCaller ]); }, [ contractCaller ]);
......
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