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 37d21a0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions examples/next/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 { num, shortString } from "starknet";

const Header = ({
showBack,
Expand All @@ -14,15 +15,14 @@ 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" },
];

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

Expand All @@ -43,7 +43,7 @@ const Header = ({
</button>
)}
<div className="flex-1" />
<div className="relative">
{chainId && <div className="relative">
<Button
onClick={() => {
setNetworkOpen(!networkOpen);
Expand All @@ -52,7 +52,7 @@ const Header = ({
disabled={lockChain}
className="flex items-center gap-2 min-w-[120px]"
>
{chainName}
{shortString.decodeShortString(num.toHex(chainId))}
<span
className={`transition-transform duration-200 ${
networkOpen ? "rotate-180" : ""
Expand All @@ -77,7 +77,7 @@ const Header = ({
))}
</div>
)}
</div>
</div>}
{address ? (
<div className="relative ml-2">
<Button
Expand Down

0 comments on commit 37d21a0

Please sign in to comment.