Merge pull request #173 from Severino/master

Fixed And Improved Abi Viewer Return Params
pull/193/head
Victa Kwok Wai Phu 3 years ago committed by GitHub
commit 7d24f95a33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 51
      src/components/ui/AbiParam.tsx
  2. 45
      src/pages/AddressPage/ContractDetails/AbiMethodView.tsx

@ -0,0 +1,51 @@
import { Box, TextInput } from "grommet";
import { palette } from "src/theme";
import styled from "styled-components";
interface IAbiParam {
name?: string;
readonly?: boolean;
type: string;
value: string;
}
const SmallTextInput = styled(TextInput)`
font-size: 14px;
font-weight: 400;
::placeholder {
font-size: 14px;
}
`;
const HeaderBox = styled(Box)`
font-size:12px;
`
const NameLabel = styled.div`
color: ${palette.ElectricBlue};
margin-right: 20px;
`
export const AbiParam = (props: IAbiParam) => {
const {
name,
readonly,
type,
value,
} = props;
function valueInput() {
return <SmallTextInput value={value} readOnly={readonly} />
}
return <Box className="param-box" direction="column" pad="none">
<HeaderBox direction="row" align="center">
{name && <NameLabel>{name}</NameLabel>}
<i>{type}</i>
</HeaderBox>
{valueInput()}
</Box>
};

@ -7,6 +7,7 @@ import {AbiItem} from 'web3-utils';
import {convertInputs} from './helpers';
import {uniqid} from 'src/pages/VerifyContract/VerifyContract';
import detectEthereumProvider from '@metamask/detect-provider';
import {AbiParam} from 'src/components/ui/AbiParam';
const Field = styled(Box)``;
@ -83,8 +84,8 @@ export const AbiMethodsView = (props: {
const web3URL = props.isRead
? process.env.REACT_APP_RPC_URL_SHARD0
: web3
? web3
: process.env.REACT_APP_RPC_URL_SHARD0;
? web3
: process.env.REACT_APP_RPC_URL_SHARD0;
const hmyWeb3 = new Web3(web3URL);
@ -102,7 +103,7 @@ export const AbiMethodsView = (props: {
const accounts = await ethereum.enable();
const account = accounts[0] || undefined; // if function is not a view method it will require a signer
console.log("account is", account);
res = await contract.methods[abiMethod.name]
@ -119,8 +120,8 @@ export const AbiMethodsView = (props: {
Array.isArray(res)
? res
: typeof res === 'object'
? Object.values(res)
: [res.toString()]
? Object.values(res)
: [res.toString()]
);
}
} catch (e) {
@ -147,7 +148,7 @@ export const AbiMethodsView = (props: {
};
return (
<ViewWrapper direction='column' margin={{bottom: 'medium'}}>
<ViewWrapper className='abi-view-wrapper' direction='column' margin={{bottom: 'medium'}}>
<NameWrapper background={'backgroundBack'}>
<Text size='small'>
{index + 1}. {abiMethod.name}
@ -293,30 +294,14 @@ export const AbiMethodsView = (props: {
) : null}
{abiMethod.outputs
? abiMethod.outputs.map((input) => {
return (
<Box>
{result.length ? (
<Text size='small'>
<GreySpan>
{input.name}
{` (${input.type})`}
</GreySpan>{' '}
{'-> '}
{result.length === 1 ? [result] : result.toString()}
</Text>
) : (
<Text size='small'>
<GreySpan>
{input.name}
{` (${input.type})`}
</GreySpan>{' '}
{'-> '}
</Text>
)}
</Box>
);
})
? abiMethod.outputs.map((input, idx) => {
return (<AbiParam
readonly={true}
type={input.type}
name={input.name}
value={result[idx]}
/>)
})
: null}
{error && (

Loading…
Cancel
Save