diff --git a/.env b/.env new file mode 100644 index 00000000..0e550378 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +NEXT_PUBLIC_CELO_EXPLORER_API_URL=https://explorer.celo.org/mainnet/graphiql +NEXT_PUBLIC_CELO_EXPLORER_API_URL_ALFAJORES=https://explorer.celo.org/alfajores/graphiql +NEXT_PUBLIC_CELO_EXPLORER_API_URL_BAKLAVA=https://explorer.celo.org/baklava/graphiql +NEXT_PUBLIC_WALLET_CONNECT_ID=3f6f578ca4a77fd09bc984689c9d095f +NEXT_PUBLIC_SUBGRAPH_URL=https://api.studio.thegraph.com/query/63311/mento/version/latest diff --git a/.eslintignore b/.eslintignore index b23c34b8..ed13b0e4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -app/graphql/generated \ No newline at end of file +app/graphql/**/generated \ No newline at end of file diff --git a/app/(routes)/proposals/[id]/_components/execution-code.component.tsx b/app/(routes)/proposals/[id]/_components/execution-code.component.tsx index 95237f30..b66c594e 100644 --- a/app/(routes)/proposals/[id]/_components/execution-code.component.tsx +++ b/app/(routes)/proposals/[id]/_components/execution-code.component.tsx @@ -1,27 +1,64 @@ import BlockExplorerLink from "@/app/components/_shared/block-explorer-link/block-explorer-link.component"; -import type { ProposalCall } from "@/app/graphql"; -import { useAccount } from "wagmi"; +import { + GetContractsInfo, + type GetContractsInfoQuery, + type ProposalCall, +} from "@/app/graphql"; +import { useCeloExplorerApi } from "@/app/hooks/useCeloExplorer"; +import { useQuery } from "@apollo/experimental-nextjs-app-support/ssr"; +import { useMemo } from "react"; +import { decodeFunctionData } from "viem"; type Props = { calls: ProposalCall[]; }; +type ContractInfo = { + [address: string]: { + abi?: string; + name?: string; + }; +}; + export default function ExecutionCode({ calls }: Props) { - const { chain } = useAccount(); - const blockExplorerUrl = chain?.blockExplorers?.default.url; + const { name: apiName } = useCeloExplorerApi(); + + const { data, error: apolloError } = useQuery(GetContractsInfo, { + variables: { + addresses: calls.map((call) => call.target.id), + }, + context: { apiName }, + skip: !calls.length, + }); + + if (apolloError) { + // TODO: Sentrify me + console.error( + "Failed to fetch contract metadata from Celo Explorer", + apolloError, + ); + } + + const contractMetadata = getContractMetadata(data); + + const formattedCalls = useMemo( + () => calls.map((call) => formatCall(call, contractMetadata)), + [calls, contractMetadata], + ); + return (
-- {call.target.id} + + {call.target}