/** * rExchange applet definitions — Rate Card + Trade Status. */ import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types"; const rateCard: AppletDefinition = { id: "rate-card", label: "Rate Card", icon: "💱", accentColor: "#047857", ports: [ { name: "pair-in", type: "string", direction: "input" }, { name: "rate-out", type: "number", direction: "output" }, ], renderCompact(data: AppletLiveData): string { const { snapshot } = data; const pair = (snapshot.pair as string) || "—/—"; const rate = (snapshot.rate as number) || 0; const change24h = (snapshot.change24h as number) || 0; const changeColor = change24h >= 0 ? "#22c55e" : "#ef4444"; const arrow = change24h >= 0 ? "▲" : "▼"; return `
${pair}
${rate.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 6 })}
${arrow} ${Math.abs(change24h).toFixed(2)}%
`; }, onInputReceived(portName, value, ctx) { if (portName === "pair-in" && typeof value === "string") { ctx.emitOutput("rate-out", 0); } }, }; const tradeStatus: AppletDefinition = { id: "trade-status", label: "Trade Status", icon: "🔄", accentColor: "#047857", ports: [ { name: "trade-in", type: "json", direction: "input" }, { name: "status-out", type: "string", direction: "output" }, ], renderCompact(data: AppletLiveData): string { const { snapshot } = data; const type = (snapshot.type as string) || "trade"; const amount = (snapshot.amount as number) || 0; const asset = (snapshot.asset as string) || "—"; const status = (snapshot.status as string) || "pending"; const statusColor = status === "filled" ? "#22c55e" : status === "cancelled" ? "#ef4444" : "#f59e0b"; return `
${type} ${status}
${amount.toLocaleString()}
${asset}
`; }, onInputReceived(portName, value, ctx) { if (portName === "trade-in" && value && typeof value === "object") { const trade = value as Record; ctx.emitOutput("status-out", (trade.status as string) || "pending"); } }, }; export const exchangeApplets: AppletDefinition[] = [rateCard, tradeStatus];