mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* display methods accordion * add method_id to methods * query read method via public client * query read methods without inputs at accordion section open * add custom abi tabs * add proxy tabs * custom wagmi config if wc is not configured * remove ContractAbiItemConstant component * display tuple properties in method outputs * display read result * clean up * support nested arrays in the read result * re-write test for contract methods * change result view for address output * refactoring * fix tests * remove web3 provider fallback * fix tab loading * refactoring * add implementation contract selector * add "copy to clipboard" for address, remove top-level square brackets * add preview mode to contract method result * tests for read result * fix tests * change styles for result preview * review fix
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import { Box } from '@chakra-ui/react';
|
|
import React from 'react';
|
|
|
|
import type { MethodType } from './types';
|
|
import type { AddressImplementation } from 'types/api/addressParams';
|
|
|
|
import useApiQuery from 'lib/api/useApiQuery';
|
|
|
|
import ContractConnectWallet from './ContractConnectWallet';
|
|
import ContractImplementationAddress from './ContractImplementationAddress';
|
|
import ContractMethods from './ContractMethods';
|
|
import { isReadMethod, isWriteMethod } from './utils';
|
|
|
|
interface Props {
|
|
type: MethodType;
|
|
implementations: Array<AddressImplementation>;
|
|
isLoading?: boolean;
|
|
}
|
|
|
|
const ContractMethodsProxy = ({ type, implementations, isLoading: isInitialLoading }: Props) => {
|
|
|
|
const [ selectedItem, setSelectedItem ] = React.useState(implementations[0]);
|
|
|
|
const contractQuery = useApiQuery('contract', {
|
|
pathParams: { hash: selectedItem.address },
|
|
queryOptions: {
|
|
enabled: Boolean(selectedItem.address),
|
|
refetchOnMount: false,
|
|
},
|
|
});
|
|
|
|
const handleItemSelect = React.useCallback((event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
const nextOption = implementations.find(({ address }) => address === event.target.value);
|
|
if (nextOption) {
|
|
setSelectedItem(nextOption);
|
|
}
|
|
}, [ implementations ]);
|
|
|
|
const abi = contractQuery.data?.abi?.filter(type === 'read' ? isReadMethod : isWriteMethod) || [];
|
|
|
|
return (
|
|
<Box>
|
|
<ContractConnectWallet isLoading={ isInitialLoading }/>
|
|
<ContractImplementationAddress
|
|
implementations={ implementations }
|
|
selectedItem={ selectedItem }
|
|
onItemSelect={ handleItemSelect }
|
|
isLoading={ isInitialLoading }
|
|
/>
|
|
<ContractMethods
|
|
key={ selectedItem.address }
|
|
abi={ abi }
|
|
isLoading={ isInitialLoading || contractQuery.isPending }
|
|
isError={ contractQuery.isError }
|
|
type={ type }
|
|
/>
|
|
</Box>
|
|
);
|
|
};
|
|
|
|
export default React.memo(ContractMethodsProxy);
|