diff --git a/src/components/Alert.tsx b/src/components/Alert.tsx index ba8ecc02..55d42501 100644 --- a/src/components/Alert.tsx +++ b/src/components/Alert.tsx @@ -5,6 +5,7 @@ export interface Props extends HTMLAttributes { as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "div"; children: ReactNode; color?: Colors; + className?: string; } const colors = { @@ -16,7 +17,12 @@ const colors = { type Colors = keyof typeof colors; -export const Alert = ({ as = "p", color = "success", children }: Props) => { +export const Alert = ({ + as = "p", + color = "success", + className, + children, +}: Props) => { const Component = as; return ( @@ -24,6 +30,7 @@ export const Alert = ({ as = "p", color = "success", children }: Props) => { className={twMerge( "rounded-xl border p-4 text-center font-semibold", colors[color], + className, )} > {children} diff --git a/src/components/Message.tsx b/src/components/Message.tsx deleted file mode 100644 index f2a89a88..00000000 --- a/src/components/Message.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { FC } from "react"; - -type Props = { - color?: string; - message: string; -}; - -const Message: FC = ({ message, color = "bg-red-500" }) => { - return ( -

- {message} -

- ); -}; - -export default Message; diff --git a/src/pages/Home/ListChannelModal/Channel.tsx b/src/pages/Home/ListChannelModal/Channel.tsx index 3cdc0829..c111eb9a 100644 --- a/src/pages/Home/ListChannelModal/Channel.tsx +++ b/src/pages/Home/ListChannelModal/Channel.tsx @@ -1,30 +1,23 @@ +import { Alert } from "@/components/Alert"; import { AppContext, Unit } from "@/context/app-context"; import { LightningChannel } from "@/models/lightning-channel"; import { convertSatToBtc, convertToString } from "@/utils/format"; -import { ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline"; +import { Checkbox } from "@nextui-org/checkbox"; import { Button } from "@nextui-org/react"; -import { FC, useContext, useRef, useState } from "react"; +import { FC, useContext, useState } from "react"; import { useTranslation } from "react-i18next"; type Props = { isLoading: boolean; - showDetails: boolean; channel: LightningChannel; - onClick: (channelId: string) => void; onDelete: (channelId: string, forceClose: boolean) => void; }; -const Channel: FC = ({ - isLoading, - showDetails, - channel, - onClick, - onDelete, -}) => { - const { unit } = useContext(AppContext); +const Channel: FC = ({ isLoading, channel, onDelete }) => { const { t } = useTranslation(); + const { unit } = useContext(AppContext); const [confirm, setConfirm] = useState(false); - const forceCloseEl = useRef(null); + const [isForceClose, setIsForceClose] = useState(false); const convertedLocal = unit === Unit.SAT @@ -35,95 +28,83 @@ const Channel: FC = ({ ? convertToString(unit, channel.balance_remote) : convertSatToBtc(channel.balance_remote); - const clickHandler = () => { - setConfirm(false); - onClick(channel.channel_id); - }; - const closeChannelHandler = () => { - onDelete(channel.channel_id, forceCloseEl.current?.checked || false); + onDelete(channel.channel_id, isForceClose); }; return ( -
  • -
    - {channel.peer_alias} - {showDetails && } - {!showDetails && } -
    +
    +
    +
    +

    {t("home.channel_id")}

    +

    {channel.channel_id}

    +
    +
    +

    {t("home.active")}

    +

    + {channel.active ? t("setup.yes") : t("home.no")} +

    +
    +
    +
    +
    +

    {t("home.local_balance")}

    +

    + {convertedLocal} {unit} +

    +
    +
    +

    {t("home.remote_balance")}

    +

    + {convertedRemote} {unit} +

    +
    +
    - {showDetails && ( -
    -
    -
    -

    {t("home.channel_id")}

    -

    {channel.channel_id}

    -
    -
    -

    {t("home.active")}

    -

    - {channel.active ? t("setup.yes") : t("home.no")} -

    -
    -
    -
    -
    -

    {t("home.local_balance")}

    -

    - {convertedLocal} {unit} -

    -
    -
    -

    {t("home.remote_balance")}

    -

    - {convertedRemote} {unit} -

    -
    -
    - -
    - +
    + - {/*TODO should be confirm modal*/} - {confirm && ( -
    - {t("home.confirm_channel_close")} + {/* TODO should be confirm modal maybe? */} + {confirm && ( + +
    +

    {t("home.confirm_channel_close")}

    -
    - - -
    +
    + + {t("home.force_close")} + +
    -
    - - -
    +
    + +
    - )} -
    -
    - )} -
  • + + + )} + + ); }; diff --git a/src/pages/Home/ListChannelModal/ChannelList.tsx b/src/pages/Home/ListChannelModal/ChannelList.tsx index c120a540..9e7651cf 100644 --- a/src/pages/Home/ListChannelModal/ChannelList.tsx +++ b/src/pages/Home/ListChannelModal/ChannelList.tsx @@ -1,6 +1,7 @@ import Channel from "./Channel"; import { LightningChannel } from "@/models/lightning-channel"; -import { FC, useState } from "react"; +import { Accordion, AccordionItem } from "@nextui-org/react"; +import { FC } from "react"; type Props = { isLoading: boolean; @@ -9,30 +10,18 @@ type Props = { }; const ChannelList: FC = ({ isLoading, channel, onDelete }) => { - const [showDetails, setShowDetails] = useState(null); - - const toggleDetailHandler = (channelId: string) => { - setShowDetails((prev) => { - if (prev === channelId) { - return null; - } - return channelId; - }); - }; - return ( -
      + {channel.map((c) => ( - + aria-label={`Channel: ${c.peer_alias}`} + title={c.peer_alias} + > + + ))} -
    + ); }; diff --git a/src/pages/Home/ListChannelModal/ListChannelModal.tsx b/src/pages/Home/ListChannelModal/ListChannelModal.tsx index a3b22cef..ba121121 100644 --- a/src/pages/Home/ListChannelModal/ListChannelModal.tsx +++ b/src/pages/Home/ListChannelModal/ListChannelModal.tsx @@ -4,7 +4,6 @@ import { ConfirmModal, type Props as ConfirmModalProps, } from "@/components/ConfirmModal"; -import Message from "@/components/Message"; import { LightningChannel } from "@/models/lightning-channel"; import { checkError } from "@/utils/checkError"; import { instance } from "@/utils/interceptor"; @@ -84,7 +83,7 @@ export default function ListChannelModal({ isLoading={isLoading} /> )} - {error && } + {error && {error}} );