diff --git a/packages/keychain/src/components/ErrorAlert.tsx b/packages/keychain/src/components/ErrorAlert.tsx index c9f26529c..5ce8a66f1 100644 --- a/packages/keychain/src/components/ErrorAlert.tsx +++ b/packages/keychain/src/components/ErrorAlert.tsx @@ -28,6 +28,7 @@ import { useConnection } from "hooks/connection"; import { constants } from "starknet"; import { parseExecutionError, parseValidationError } from "utils/errors"; import { formatAddress } from "@cartridge/utils"; +import { useExplorer } from "@starknet-react/core"; export function ErrorAlert({ title, @@ -336,17 +337,7 @@ function StackTraceDisplay({ stackTrace: ReturnType["stack"]; }) { const { chainId } = useConnection(); - - const getExplorerUrl = (type: "contract" | "class", value: string) => { - if (!chainId) return; - - const baseUrl = { - [constants.StarknetChainId.SN_SEPOLIA]: "https://sepolia.starkscan.co", - [constants.StarknetChainId.SN_MAIN]: "https://starkscan.co", - }[chainId]; - - return baseUrl ? `${baseUrl}/${type}/${value}` : undefined; - }; + const explorer = useExplorer(); const isExternalLink = [ constants.StarknetChainId.SN_SEPOLIA, @@ -377,10 +368,11 @@ function StackTraceDisplay({ {key === "address" || key === "class" ? ( { + switch (connection.chainId) { + case constants.StarknetChainId.SN_MAIN: + return { + explorer: voyager, + chains: [mainnet], + provider: jsonRpcProvider({ rpc }), + }; + case constants.StarknetChainId.SN_SEPOLIA: + return { + explorer: voyager, + chains: [sepolia], + provider: jsonRpcProvider({ rpc }), + }; + default: + return { + explorer: undefined, + chains: [], + provider: jsonRpcProvider({ rpc }), + }; + } + }, [connection.chainId, rpc]); + + const { explorer, chains, provider } = config(); + return ( {children}