Skip to content

Commit

Permalink
Decode network id
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Jan 7, 2025
1 parent 9da6f9a commit 219db54
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions examples/next/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { Button } from "@cartridge/ui-next";
import ControllerConnector from "@cartridge/connector/controller";
import { useAccount, useConnect, useDisconnect } from "@starknet-react/core";
import { useState } from "react";
import { useMemo, useState } from "react";
import { constants, num } from "starknet";

const Header = ({
showBack,
Expand All @@ -14,21 +15,21 @@ const Header = ({
}) => {
const { connect, connectors } = useConnect();
const { disconnect } = useDisconnect();
const { address, connector } = useAccount();
const { address, connector, chainId } = useAccount();
const controllerConnector = connector as never as ControllerConnector;
const chains = [
{ name: "Mainnet", id: "mainnet" },
{ name: "Sepolia (Testnet)", id: "sepolia" },
{ name: "Slot (L3)", id: "slot" },
{ name: "Mainnet", id: constants.StarknetChainId.SN_MAIN },
{ name: "Sepolia", id: constants.StarknetChainId.SN_SEPOLIA },
];

const chainName = "chain name";
const [networkOpen, setNetworkOpen] = useState(false);
const [profileOpen, setProfileOpen] = useState(false);

// const chainName = useMemo(() => {
// return chains.find((c) => c.id === getCurrentChain())?.name;
// }, [chains, getCurrentChain]);
const chainName = useMemo(() => {
if (chainId) {
return chains.find((c) => c.id === num.toHex(chainId))?.name;
}
}, [chains, chainId]);

return (
<div className="w-full absolute top-0 left-0 p-5 flex items-center">
Expand All @@ -43,7 +44,7 @@ const Header = ({
</button>
)}
<div className="flex-1" />
<div className="relative">
{chainId && <div className="relative">
<Button
onClick={() => {
setNetworkOpen(!networkOpen);
Expand Down Expand Up @@ -77,7 +78,7 @@ const Header = ({
))}
</div>
)}
</div>
</div>}
{address ? (
<div className="relative ml-2">
<Button
Expand Down

0 comments on commit 219db54

Please sign in to comment.