import React, { useEffect } from "react"; import { Chip, Typography, Skeleton, Card, CardTitle, CardContent, CardActions, Markdown, Timer, } from "@carrot-kpi/ui"; import { cva } from "class-variance-authority"; import { KPIToken, ResolvedKPIToken } from "@carrot-kpi/sdk"; import { Link } from "react-router-dom"; import { useResolvedKPIToken } from "@carrot-kpi/react"; import { useTranslation } from "react-i18next"; interface TimeLeftProps { kpiToken: ResolvedKPIToken; } const TimeLeft = ({ kpiToken }: TimeLeftProps) => { const { t } = useTranslation(); if (kpiToken.finalized) return ( {t("stateOptions.finalized")} ); if (kpiToken.expired) return ( {t("stateOptions.expired")} ); return ; }; const rootStyles = cva( [ "min-w-[320px]", "max-w-[320px]", "rounded-xxl", "flex", "flex-col", "justify-between", "border", "bg-white", "dark:bg-black", ], { variants: { noBorder: { true: ["border-white dark:border-black"], false: ["border-black dark:border-white"], }, }, defaultVariants: { noBorder: false, }, }, ); interface KPITokenCardProps { kpiToken?: KPIToken | ResolvedKPIToken; noBorder?: boolean; onResolved?: (resolved: ResolvedKPIToken) => void; } export const KPITokenCard = ({ kpiToken, noBorder, onResolved, }: KPITokenCardProps) => { const { loading, resolvedKPIToken } = useResolvedKPIToken({ kpiToken }); useEffect(() => { if (loading || !resolvedKPIToken || !onResolved) return; onResolved(resolvedKPIToken); }, [loading, resolvedKPIToken, onResolved]); return (
{!loading && !!resolvedKPIToken ? ( {resolvedKPIToken.specification.title} ) : ( )}
{/* TODO: handle logo fetching for creators */} {/* {!!resolvedKPIToken && (
)} */}
{!loading && !!resolvedKPIToken ? ( {resolvedKPIToken.specification.description} ) : (
)}
{!loading && !!resolvedKPIToken ? ( <> { resolvedKPIToken.template .specification.name } {resolvedKPIToken.specification.tags.map( (tag) => ( {tag} ), )} ) : ( <> )}
{!loading && !!resolvedKPIToken ? ( Time left ) : ( )}
{!loading && !!resolvedKPIToken ? ( ) : ( )}
{!loading && !!resolvedKPIToken ? ( ↳ VIEW CAMPAIGN ) : ( )}
); };