Skip to content

Commit 14dc53f

Browse files
authored
(feat) add hyperlink api reference (#1855)
* initial commit * pre-commit * bug fix * requested changes * requested changes
1 parent c967a84 commit 14dc53f

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

apps/api-reference/src/components/EvmApi/run-button.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,27 @@ export const RunButton = <ParameterName extends string>(
8888
{status.type === StatusType.Results && (
8989
<div>
9090
<h3 className="mb-2 text-lg font-bold">Results</h3>
91-
<Code language="json">{stringifyResponse(status.data)}</Code>
91+
{props.type === EvmApiType.Write &&
92+
status.data &&
93+
typeof status.data === "object" &&
94+
"hash" in status.data &&
95+
typeof status.data.hash === "string" ? (
96+
<>
97+
<p>{`Tx Hash: ${status.data.hash}`}</p>
98+
{"link" in status.data &&
99+
typeof status.data.link === "string" && (
100+
<InlineLink
101+
href={status.data.link}
102+
target="_blank"
103+
className="text-sm text-blue-500 hover:underline"
104+
>
105+
Open in explorer↗
106+
</InlineLink>
107+
)}
108+
</>
109+
) : (
110+
<Code language="json">{stringifyResponse(status.data)}</Code>
111+
)}
92112
</div>
93113
)}
94114
{status.type === StatusType.Error && (
@@ -175,7 +195,17 @@ const useRunButton = <ParameterName extends string>({
175195
})
176196
.then(({ request }) => writeContract(config, request))
177197
.then((result) => {
178-
setStatus(Results(result));
198+
const explorer = config.chains.find(
199+
(chain) => chain.id === config.state.chainId,
200+
)?.blockExplorers?.default;
201+
setStatus(
202+
Results({
203+
hash: result,
204+
link: explorer
205+
? new URL(`/tx/${result}`, explorer.url).toString()
206+
: undefined,
207+
}),
208+
);
179209
})
180210
.catch((error: unknown) => {
181211
setStatus(ErrorStatus(error));

0 commit comments

Comments
 (0)