Skip to content

Commit

Permalink
Fix Starknet Config
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Dec 9, 2024
1 parent 59c866c commit 6a737a1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
22 changes: 7 additions & 15 deletions packages/keychain/src/components/ErrorAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -336,17 +337,7 @@ function StackTraceDisplay({
stackTrace: ReturnType<typeof parseExecutionError>["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,
Expand Down Expand Up @@ -377,10 +368,11 @@ function StackTraceDisplay({
</Text>
{key === "address" || key === "class" ? (
<Link
href={getExplorerUrl(
key === "address" ? "contract" : "class",
value as string,
)}
href={
key === "address"
? explorer.contract(value as string)
: explorer.class(value as string)
}
isExternal={isExternalLink}
wordBreak="break-all"
textAlign="left"
Expand Down
31 changes: 28 additions & 3 deletions packages/keychain/src/components/Provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,40 @@ export function Provider({ children }: PropsWithChildren) {
[connection.rpcUrl],
);

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: [],
provider: jsonRpcProvider({ rpc }),
};
}
}, [connection.chainId, rpc]);

const { explorer, chains, provider } = config();

return (
<CartridgeAPIProvider url={ENDPOINT}>
<QueryClientProvider client={queryClient}>
<ConnectionContext.Provider value={connection}>
<ControllerThemeProvider>
<StarknetConfig
explorer={voyager}
chains={[sepolia, mainnet]}
provider={jsonRpcProvider({ rpc })}
explorer={explorer}
chains={chains}
provider={provider}
>
<PostHogProvider client={posthog}>{children}</PostHogProvider>
</StarknetConfig>
Expand Down

0 comments on commit 6a737a1

Please sign in to comment.