From 14e8c0a54ff87736f51e8cf3dc87c0e044b8888f Mon Sep 17 00:00:00 2001 From: broody Date: Thu, 9 Jan 2025 08:15:28 -1000 Subject: [PATCH] update ui --- examples/next/src/components/Header.tsx | 53 +++++++++++-------- .../next/src/components/ManualTransferEth.tsx | 28 +++++----- examples/next/src/components/Transfer.tsx | 27 +++++----- .../src/components/primitives/checkbox.tsx | 4 +- 4 files changed, 57 insertions(+), 55 deletions(-) diff --git a/examples/next/src/components/Header.tsx b/examples/next/src/components/Header.tsx index 939405b06..b0f4353a9 100644 --- a/examples/next/src/components/Header.tsx +++ b/examples/next/src/components/Header.tsx @@ -9,17 +9,11 @@ import { useNetwork, useSwitchChain, } from "@starknet-react/core"; -import { useState } from "react"; +import { useState, useEffect, useRef } from "react"; import { constants, num } from "starknet"; import { Chain } from "@starknet-react/chains"; -const Header = ({ - showBack, - lockChain, -}: { - showBack?: boolean; - lockChain?: boolean; -}) => { +const Header = () => { const { connect, connectors } = useConnect(); const { disconnect } = useDisconnect(); const { chain, chains } = useNetwork(); @@ -32,28 +26,41 @@ const Header = ({ chainId: constants.StarknetChainId.SN_SEPOLIA, }, }); + const networkRef = useRef(null); + const profileRef = useRef(null); + + useEffect(() => { + const handleClickOutside = (event: MouseEvent) => { + if ( + networkRef.current && + !networkRef.current.contains(event.target as Node) + ) { + setNetworkOpen(false); + } + if ( + profileRef.current && + !profileRef.current.contains(event.target as Node) + ) { + setProfileOpen(false); + } + }; + + document.addEventListener("mousedown", handleClickOutside); + return () => { + document.removeEventListener("mousedown", handleClickOutside); + }; + }, []); return (
- {showBack && ( - - )}
{status === "connected" && ( -
+
{networkOpen && ( -
+
{chains.map((c: Chain) => ( {profileOpen && ( -
+
@@ -60,16 +63,11 @@ export const ManualTransferEth = () => { Transfer 500 ETH to self {txnHash && ( -

- Transaction hash:{" "} - - {txnHash} - -

+ <> +

Transaction: {txnHash}

+ +

Chain: {network}

+ )}
); diff --git a/examples/next/src/components/Transfer.tsx b/examples/next/src/components/Transfer.tsx index 5b2d485a4..91ee89637 100644 --- a/examples/next/src/components/Transfer.tsx +++ b/examples/next/src/components/Transfer.tsx @@ -1,15 +1,16 @@ "use client"; import { Button } from "@cartridge/ui-next"; -import { useAccount, useExplorer } from "@starknet-react/core"; +import { useAccount, useNetwork } from "@starknet-react/core"; import { useCallback, useState } from "react"; import { STRK_CONTRACT_ADDRESS } from "./providers/StarknetProvider"; export const Transfer = () => { const [submitted, setSubmitted] = useState(false); const { account } = useAccount(); - const explorer = useExplorer(); + const { chain } = useNetwork(); const [txnHash, setTxnHash] = useState(); + const [network, setNetwork] = useState(); const execute = useCallback( async (amount: string) => { @@ -32,11 +33,14 @@ export const Transfer = () => { calldata: [account?.address, amount, "0x0"], }, ]) - .then(({ transaction_hash }) => setTxnHash(transaction_hash)) + .then(({ transaction_hash }) => { + setTxnHash(transaction_hash); + setNetwork(chain.network); + }) .catch((e) => console.error(e)) .finally(() => setSubmitted(false)); }, - [account], + [account, chain], ); if (!account) { @@ -46,7 +50,6 @@ export const Transfer = () => { return (

Session Transfer STRK

-

Address: {STRK_CONTRACT_ADDRESS}

{txnHash && ( -

- Transaction hash:{" "} - - {txnHash} - -

+ <> +

Transaction: {txnHash}

+

Chain: {network}

+ )}
); diff --git a/packages/ui-next/src/components/primitives/checkbox.tsx b/packages/ui-next/src/components/primitives/checkbox.tsx index 7d71813ed..b647170bc 100644 --- a/packages/ui-next/src/components/primitives/checkbox.tsx +++ b/packages/ui-next/src/components/primitives/checkbox.tsx @@ -30,8 +30,8 @@ const Checkbox = React.forwardRef< checked === "indeterminate" ? "minus-line" : checked - ? "line" - : "unchecked-line" + ? "line" + : "unchecked-line" } />