From c7c187aec2cd55610cff1ed8ff22677b92a90c96 Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Mon, 9 Dec 2024 16:34:36 -0500 Subject: [PATCH] Fix Starknet Config --- .../keychain/src/components/ErrorAlert.tsx | 22 +++---- .../src/components/Provider/index.tsx | 62 ++++++++++++++++--- 2 files changed, 61 insertions(+), 23 deletions(-) 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" ? ( { - return num.toBigInt(connection.chainId || 0); - }, [connection.chainId]); + const config = useCallback(() => { + 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: [ + { + id: num.toBigInt(connection.chainId || 0), + network: "slot", + name: "Slot", + nativeCurrency: { + address: STRK_CONTRACT_ADDRESS as Address, + name: "Stark", + symbol: "STRK", + decimals: 18, + }, + testnet: true, + rpcUrls: { + default: { + http: [connection.rpcUrl || ""], + }, + public: { + http: [connection.rpcUrl || ""], + }, + }, + explorers: { + worldexplorer: [""], + }, + }, + ], + provider: jsonRpcProvider({ rpc }), + }; + } + }, [connection.chainId, rpc]); + + const { explorer, chains, provider } = config(); return ( @@ -38,10 +85,9 @@ export function Provider({ children }: PropsWithChildren) { {children}