Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show "Read contract" tab even if WalletConnect is not configured #1315

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pages/api/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default handler;

export const config = {
api: {
// disable body parser otherwise it is impossible to upload large files (over 1Mb)
// e.g. when verifying a smart contract
bodyParser: false,
bodyParser: {
sizeLimit: '100mb',
},
},
};
2 changes: 1 addition & 1 deletion ui/address/AddressContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TAB_LIST_PROPS = {

const AddressContract = ({ tabs }: Props) => {
const fallback = React.useCallback(() => {
const noProviderTabs = tabs.filter(({ id }) => id === 'contact_code');
const noProviderTabs = tabs.filter(({ id }) => id === 'contact_code' || id.startsWith('read_'));
return (
<RoutedTabs tabs={ noProviderTabs } variant="outline" colorScheme="gray" size="sm" tabListProps={ TAB_LIST_PROPS }/>
);
Expand Down
12 changes: 6 additions & 6 deletions ui/address/contract/ContractRead.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Alert, Flex } from '@chakra-ui/react';
import React from 'react';
import { useAccount } from 'wagmi';

import type { SmartContractReadMethod, SmartContractQueryMethodRead } from 'types/api/contract';

Expand All @@ -16,6 +15,7 @@ import ContractImplementationAddress from './ContractImplementationAddress';
import ContractMethodCallable from './ContractMethodCallable';
import ContractMethodConstant from './ContractMethodConstant';
import ContractReadResult from './ContractReadResult';
import useWatchAccount from './useWatchAccount';

interface Props {
addressHash?: string;
Expand All @@ -25,13 +25,13 @@ interface Props {

const ContractRead = ({ addressHash, isProxy, isCustomAbi }: Props) => {
const apiFetch = useApiFetch();
const { address: userAddress } = useAccount();
const account = useWatchAccount();

const { data, isLoading, isError } = useApiQuery(isProxy ? 'contract_methods_read_proxy' : 'contract_methods_read', {
pathParams: { hash: addressHash },
queryParams: {
is_custom_abi: isCustomAbi ? 'true' : 'false',
from: userAddress,
from: account?.address,
},
queryOptions: {
enabled: Boolean(addressHash),
Expand All @@ -50,11 +50,11 @@ const ContractRead = ({ addressHash, isProxy, isCustomAbi }: Props) => {
args,
method_id: item.method_id,
contract_type: isProxy ? 'proxy' : 'regular',
from: userAddress,
from: account?.address,
},
},
});
}, [ addressHash, apiFetch, isCustomAbi, isProxy, userAddress ]);
}, [ account?.address, addressHash, apiFetch, isCustomAbi, isProxy ]);

const renderItemContent = React.useCallback((item: SmartContractReadMethod, index: number, id: number) => {
if (item.error) {
Expand Down Expand Up @@ -94,7 +94,7 @@ const ContractRead = ({ addressHash, isProxy, isCustomAbi }: Props) => {
return (
<>
{ isCustomAbi && <ContractCustomAbiAlert/> }
<ContractConnectWallet/>
{ account && <ContractConnectWallet/> }
{ isProxy && <ContractImplementationAddress hash={ addressHash }/> }
<ContractMethodsAccordion data={ data } addressHash={ addressHash } renderItemContent={ renderItemContent }/>
</>
Expand Down
24 changes: 24 additions & 0 deletions ui/address/contract/useWatchAccount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { watchAccount, getAccount } from '@wagmi/core';
import React from 'react';

export function getWalletAccount() {
try {
return getAccount();
} catch (error) {
return null;
}
}

export default function useWatchAccount() {
const [ account, setAccount ] = React.useState(getWalletAccount());

React.useEffect(() => {
if (!account) {
return;
}

return watchAccount(setAccount);
}, [ account ]);

return account;
}
Loading