Skip to content

Commit 87c8854

Browse files
committed
[Dashboard] Small update to allow open link with Explorer (#4930)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR enhances the `InteractiveAbiFunction` component by adding support for displaying links for both IPFS URIs and traditional URLs. It introduces an `ExternalLinkIcon` and a new `Link` component for external links, improving user accessibility to resources. ### Detailed summary - Added import for `ExternalLinkIcon` and `Link` from `next/link`. - Modified the `language` prop in `CodeBlock` based on the response data type. - Introduced a link for IPFS URIs that opens in a new tab. - Added a link for traditional URLs with an icon, enhancing user interaction. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent d5039f4 commit 87c8854

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

apps/dashboard/src/components/contract-functions/interactive-abi-function.tsx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { TransactionButton } from "components/buttons/TransactionButton";
1515
import { SolidityInput } from "contract-ui/components/solidity-inputs";
1616
import { camelToTitle } from "contract-ui/components/solidity-inputs/helpers";
1717
import { replaceIpfsUrl } from "lib/sdk";
18-
import { InfoIcon, PlayIcon } from "lucide-react";
18+
import { ExternalLinkIcon, InfoIcon, PlayIcon } from "lucide-react";
19+
import Link from "next/link";
1920
import { useEffect, useId, useMemo, useState } from "react";
2021
import { FormProvider, useFieldArray, useForm } from "react-hook-form";
2122
import { toast } from "sonner";
@@ -419,22 +420,39 @@ export const InteractiveAbiFunction: React.FC<InteractiveAbiFunctionProps> = ({
419420
<CodeBlock
420421
w="full"
421422
position="relative"
422-
language="json"
423+
language={
424+
formattedResponseData.startsWith("http") ||
425+
formattedResponseData.startsWith("ipfs")
426+
? "text"
427+
: "json"
428+
}
423429
code={formattedResponseData}
424430
/>
425-
{typeof formattedResponseData === "string" &&
426-
formattedResponseData.startsWith("ipfs://") && (
427-
<Text size="label.sm">
428-
<TrackedLink
429-
href={replaceIpfsUrl(formattedResponseData)}
430-
isExternal
431-
category="contract-explorer"
432-
label="open-in-gateway"
433-
>
434-
Open in gateway
435-
</TrackedLink>
436-
</Text>
437-
)}
431+
{/* If the result is an IPFS URI, show a handy link so that users can open it in a new tab */}
432+
{formattedResponseData.startsWith("ipfs://") && (
433+
<Text size="label.sm">
434+
<TrackedLink
435+
href={replaceIpfsUrl(formattedResponseData)}
436+
isExternal
437+
category="contract-explorer"
438+
label="open-in-gateway"
439+
>
440+
Open in gateway
441+
</TrackedLink>
442+
</Text>
443+
)}
444+
{/* Same with the logic above but this time it's applied to traditional urls */}
445+
{(formattedResponseData.startsWith("https://") ||
446+
formattedResponseData.startsWith("http://")) && (
447+
<Link
448+
href={formattedResponseData}
449+
target="_blank"
450+
className="mt-1 inline-flex items-center gap-2 text-muted-foreground text-sm hover:text-foreground"
451+
>
452+
Open link
453+
<ExternalLinkIcon className="size-4" />
454+
</Link>
455+
)}
438456
</>
439457
) : null}
440458
</Flex>

0 commit comments

Comments
 (0)