Skip to content

Commit

Permalink
More resilient useAbi fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Aug 23, 2024
1 parent 34943b9 commit a69d798
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion components/input/function-params-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const FunctionParamsForm = ({
};

return (
<div className="w-full overflow-y-auto rounded-r-lg pt-4">
<div className="w-full rounded-r-lg pt-4">
<If true={functionAbi?.inputs.length || 0 > 0}>
<div className="flex flex-row items-center justify-between border-b border-neutral-200 pb-4">
<p className="text-md font-semibold text-neutral-800">Parameters</p>
Expand Down
13 changes: 6 additions & 7 deletions hooks/useAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { whatsabi } from "@shazow/whatsabi";
import { usePublicClient } from "wagmi";
import { AbiFunction } from "abitype";
import { useQuery } from "@tanstack/react-query";
import { isAddress, isContract } from "@/utils/evm";
import { ADDRESS_ZERO, isAddress, isContract } from "@/utils/evm";
import { PUB_CHAIN, PUB_ETHERSCAN_API_KEY } from "@/constants";
import { useAlerts } from "@/context/Alerts";
import { getImplementation, isProxyContract } from "@/utils/proxies";
import { getImplementation } from "@/utils/proxies";
import { ChainName } from "@/utils/chains";

const CHAIN_NAME = PUB_CHAIN.name.toLowerCase() as ChainName;
Expand All @@ -23,14 +23,13 @@ export const useAbi = (contractAddress: Address) => {
return null;
}

return isProxyContract(publicClient, contractAddress)
.then((isProxy) => {
if (!isProxy) return null;
return getImplementation(publicClient, contractAddress);
return getImplementation(publicClient, contractAddress)
.then((address) => {
if (!address || address === ADDRESS_ZERO) return null;
return address;
})
.catch(() => null);
},
initialData: null,
retry: 6,
refetchOnMount: false,
refetchOnReconnect: false,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
"dompurify": "^3.1.6",
"libsodium-wrappers": "^0.7.15",
"multiformats": "^13.2.2",
"next": "14.2.6",
"react": "^18.3.1",
"next": "14.1.4",
"react": "18.2.0",
"react-blockies": "^1.4.1",
"react-dom": "^18.3.1",
"react-dom": "18.2.0",
"react-hook-form": "^7.52.1",
"viem": "^2.19.8",
"wagmi": "2.12.7"
Expand All @@ -57,7 +57,7 @@
"autoprefixer": "^10.4.19",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-next": "14.2.6",
"eslint-config-next": "14.1.4",
"eslint-config-prettier": "^9.1.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
Expand Down
2 changes: 1 addition & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function StandardHome() {
<div className="flex justify-center">
<If true={isConnected}>
<Then>
<Button className="mb-2" variant="primary" href="https://devs.aragon.org/docs/osx/" target="_blank">
<Button className="mb-2" variant="primary" href="https://devs.aragon.org/" target="_blank">
Learn more about OSx
</Button>
</Then>
Expand Down
4 changes: 2 additions & 2 deletions utils/proxies.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, BaseError, ContractFunctionRevertedError, Hex, PublicClient, keccak256, parseAbi, toHex } from "viem";
import { PUB_CHAIN } from "@/constants";

const proxyAbi1 = parseAbi([
const proxyAbi = parseAbi([
"function implementation() external view returns (address)",
"function proxiableUUID() external view returns (bytes32)",
]);
Expand All @@ -14,7 +14,7 @@ export function isProxyContract(publicClient: PublicClient, contractAddress: Add
return publicClient
.simulateContract({
address: contractAddress,
abi: proxyAbi1,
abi: proxyAbi,
functionName: "implementation",
args: [],
chain: PUB_CHAIN,
Expand Down

0 comments on commit a69d798

Please sign in to comment.