-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
204 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
"use client"; | ||
|
||
import { Button } from "@cartridge/ui-next"; | ||
import ControllerConnector from "@cartridge/connector/controller"; | ||
import { useAccount, useConnect, useDisconnect } from "@starknet-react/core"; | ||
import { useState } from "react"; | ||
|
||
const Header = ({ | ||
showBack, | ||
lockChain, | ||
}: { | ||
showBack?: boolean; | ||
lockChain?: boolean; | ||
}) => { | ||
const { connect, connectors } = useConnect(); | ||
const { disconnect } = useDisconnect(); | ||
const { address, connector } = 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); | ||
|
||
// const chainName = useMemo(() => { | ||
// return chains.find((c) => c.id === getCurrentChain())?.name; | ||
// }, [chains, getCurrentChain]); | ||
|
||
return ( | ||
<div className="w-full absolute top-0 left-0 p-5 flex items-center"> | ||
{showBack && ( | ||
<button | ||
className="absolute top-5 left-5 w-6 h-6 cursor-pointer" | ||
onClick={() => { | ||
window.history.back(); | ||
}} | ||
> | ||
← | ||
</button> | ||
)} | ||
<div className="flex-1" /> | ||
<div className="relative"> | ||
<Button | ||
onClick={() => { | ||
setNetworkOpen(!networkOpen); | ||
setProfileOpen(false); | ||
}} | ||
disabled={lockChain} | ||
className="flex items-center gap-2 min-w-[120px]" | ||
> | ||
{chainName} | ||
<span | ||
className={`transition-transform duration-200 ${ | ||
networkOpen ? "rotate-180" : "" | ||
}`} | ||
> | ||
▼ | ||
</span> | ||
</Button> | ||
{networkOpen && ( | ||
<div className="absolute right-0 top-full mt-1 bg-gray-700 shadow-lg rounded-md min-w-[160px] py-1 z-10"> | ||
{chains.map((c) => ( | ||
<button | ||
key={c.id} | ||
className="block w-full px-4 py-2 text-left hover:bg-gray-600 transition-colors border-b border-gray-600 last:border-0" | ||
onClick={() => { | ||
console.log(c.id); | ||
setNetworkOpen(false); | ||
}} | ||
> | ||
{c.name} | ||
</button> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
{address ? ( | ||
<div className="relative ml-2"> | ||
<Button | ||
onClick={() => { | ||
setProfileOpen(!profileOpen); | ||
setNetworkOpen(false); | ||
}} | ||
className="flex items-center gap-2 min-w-[120px]" | ||
> | ||
<strong className="truncate max-w-[120px]">{address}</strong> | ||
<span | ||
className={`transition-transform duration-200 ${ | ||
profileOpen ? "rotate-180" : "" | ||
}`} | ||
> | ||
▼ | ||
</span> | ||
</Button> | ||
{profileOpen && ( | ||
<div className="absolute right-0 top-full mt-1 bg-gray-700 shadow-lg rounded-md min-w-[160px] py-1 z-10"> | ||
<button | ||
className="block w-full px-4 py-2 text-left hover:bg-gray-600 transition-colors border-b border-gray-600" | ||
onClick={() => controllerConnector.controller.openProfile()} | ||
> | ||
Profile | ||
</button> | ||
<button | ||
className="block w-full px-4 py-2 text-left hover:bg-gray-600 transition-colors border-b border-gray-600" | ||
onClick={() => controllerConnector.controller.openSettings()} | ||
> | ||
Settings | ||
</button> | ||
<button | ||
className="block w-full px-4 py-2 text-left hover:bg-gray-600 transition-colors" | ||
onClick={() => disconnect()} | ||
> | ||
Disconnect | ||
</button> | ||
</div> | ||
)} | ||
</div> | ||
) : ( | ||
<Button | ||
onClick={() => { | ||
connect({ connector: connectors[0] }); | ||
}} | ||
> | ||
Connect | ||
</Button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Header; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.