import { ReactNode, useMemo } from "react"; import { Button, ButtonStatusType } from "../Button"; import clsx from "clsx"; import Container from "./Container"; import ListItem from "./ListItem"; interface SignTxPageProps { title?: string; TxInfo: { network: string | ReactNode; from: string | ReactNode; to?: string | ReactNode; amount?: string | ReactNode; networkFee?: string | ReactNode; description?: string | ReactNode; rawData?: string | ReactNode; }; TxFields?: { network?: string | ReactNode; from?: string | ReactNode; to?: string | ReactNode; amount?: string | ReactNode; networkFee?: string | ReactNode; description?: string | ReactNode; rawData?: string | ReactNode; }; AmountNetworkFeeSlot?: ReactNode; onConfirm: () => unknown; onReject: () => unknown; confirmBtnStatus?: ButtonStatusType; confirmDisabled?: boolean; } const defaultFieldTitles = { network: "Network", from: "From", to: "To", amount: "Amount", networkFee: "Network Fee", description: "Description", rawData: "Raw Data", }; function getTxInfoList( TxInfo: SignTxPageProps["TxInfo"], TxFields: SignTxPageProps["TxFields"] = {}, slots: { AmountNetworkFeeSlot?: ReactNode }, ) { const netWorkTitle = TxFields.network || defaultFieldTitles.network; const fromTitle = TxFields.from || defaultFieldTitles.from; const toTitle = TxFields.to || defaultFieldTitles.to; const amountTitle = TxFields.amount || defaultFieldTitles.amount; const networkFeeTitle = TxFields.networkFee || defaultFieldTitles.networkFee; const descriptionTitle = TxFields.description || defaultFieldTitles.description; const rawDataTitle = TxFields.rawData || defaultFieldTitles.rawData; const list = [ { title: netWorkTitle, content: TxInfo.network, }, { title: fromTitle, content: TxInfo.from, }, { title: toTitle, content: TxInfo.to, }, { title: amountTitle, content: TxInfo.amount, }, { slot: slots.AmountNetworkFeeSlot, }, { title: networkFeeTitle, content: TxInfo.networkFee, }, { title: descriptionTitle, content: TxInfo.description, }, { ellipsis: true, title: rawDataTitle, content: TxInfo.rawData, }, ]; return list.filter((i) => i.content || i.slot); } export default function SignTransaction(props: SignTxPageProps) { const { TxInfo, onConfirm, onReject, confirmBtnStatus = "normal", TxFields = {}, confirmDisabled, AmountNetworkFeeSlot, title = "Sign Tx", } = props; const txInfoList = useMemo(() => { return getTxInfoList(TxInfo, TxFields, { AmountNetworkFeeSlot }); }, [TxInfo, TxFields]); const Footer = (
); return ( {/* Network */} {txInfoList.map(({ title, content, slot, ellipsis }, index) => { if (slot) return slot; return (
{content}
); })}
); }