Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import { CopyTextButton } from "@/components/ui/CopyTextButton";
import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import { useDashboardRouter } from "@/lib/DashboardRouter";
import { cn } from "@/lib/utils";
Expand Down Expand Up @@ -34,7 +36,7 @@ import * as ERC721Ext from "thirdweb/extensions/erc721";
import * as ERC1155Ext from "thirdweb/extensions/erc1155";
import { useReadContract } from "thirdweb/react";
import { toFunctionSelector } from "thirdweb/utils";
import { Badge, Button, Card, Heading, Text } from "tw-components";
import { Button, Card, Heading, Text } from "tw-components";
import { useDebounce } from "use-debounce";
import { useContractFunctionSelectors } from "../../contract-ui/hooks/useContractFunctionSelectors";
import {
Expand Down Expand Up @@ -85,6 +87,11 @@ function ContractFunctionInner({ contract, fn }: ContractFunctionProps) {
return undefined;
}, [isERC20, isERC721Query.data, isERC1155Query.data]);

const functionSelector = useMemo(
() => (fn?.type === "function" ? toFunctionSelector(fn) : undefined),
[fn],
);

if (!fn) {
return null;
}
Expand All @@ -111,21 +118,22 @@ function ContractFunctionInner({ contract, fn }: ContractFunctionProps) {

return (
<Flex direction="column" gap={1.5}>
<Flex
alignItems={{ base: "start", md: "center" }}
gap={2}
direction={{ base: "column", md: "row" }}
>
<Flex alignItems="center" gap={2} direction="row" flexWrap="wrap">
<Flex alignItems="baseline" gap={1} flexWrap="wrap">
<Heading size="subtitle.md">{camelToTitle(fn.name)}</Heading>
<Heading size="subtitle.sm" className="text-muted-foreground">
({fn.name})
</Heading>
</Flex>
{isFunction && (
<Badge size="label.sm" variant="subtle" colorScheme="green">
{fn.stateMutability}
</Badge>
{isFunction && <Badge variant="success">{fn.stateMutability}</Badge>}
{functionSelector && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how helpful the function selector is, Deferring this to @jnsdls to decide whether this should be added or not

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels somewhat not that useful but also doesn't hurt - let's try it for a bit

<CopyTextButton
textToCopy={functionSelector}
textToShow={functionSelector}
copyIconPosition="right"
tooltip="The selector of this function"
className="ml-auto text-xs"
/>
)}
</Flex>

Expand Down Expand Up @@ -173,11 +181,7 @@ function ContractFunctionInputs(props: {
({fn.name})
</Heading>
</Flex>
{isFunction && (
<Badge size="label.sm" variant="subtle" colorScheme="green">
{fn.stateMutability}
</Badge>
)}
{isFunction && <Badge variant="success">{fn.stateMutability}</Badge>}
</Flex>

{fn.inputs?.length ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { Badge } from "@/components/ui/badge";
import { InlineCode } from "@/components/ui/inline-code";
import { ToolTipLabel } from "@/components/ui/tooltip";
import {
Expand Down Expand Up @@ -416,7 +417,15 @@ export const InteractiveAbiFunction: React.FC<InteractiveAbiFunctionProps> = ({
) : formattedResponseData ? (
<>
<Divider />
<Heading size="label.sm">Output</Heading>
<div className="flex flex-row items-center gap-2">
<Heading size="label.sm">Output</Heading>
{/* Show the Solidity type of the function's output */}
{abiFunction.outputs.length > 0 && (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the right way to retrieve a function's output? Since it's an array I'm not sure about my code here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc. @jnsdls

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, a function MAY have multiple outputs, but usually this should be fine

<Badge variant="default">
{abiFunction.outputs[0]?.type}
</Badge>
)}
</div>
<CodeBlock
w="full"
position="relative"
Expand Down
Loading