Skip to content

RateTicker

Live multi-pair ticker with value flash.
Implemented
Status
Implemented
Family
4 of 13
Registry
@lopifi/rate-ticker
npx shadcn@latest add @lopifi/theme @lopifi/rate-ticker

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

Live multi-pair ticker. The value flash is the whole point. Pauses off-screen and on tab hide. Never a marquee — a scrolling ticker is continuous large-surface motion that can't be read and can't be paused.

Lifted verbatim from Swaps & FX. The doc and this page are the same paragraphs, so they cannot disagree.

What lands in your repository

One component is never one file. Everything below is copied into your project, where you own it.

Files

components/ledger/rate-ticker.tsx

Lopifi dependencies · 4
cnformat-moneymoney.typesuse-live-value
npm packages
clsxtailwind-merge
Registry entry
/r/rate-ticker.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/rate-ticker.tsx
"use client";

import * as React from "react";
import { useLiveTicker, useValueFlash } from "@/hooks/ledger/use-live-value";
import { cn } from "@/lib/ledger/cn";
import { formatRate } from "@/lib/ledger/format-money";

export type Pair = { from: string; to: string; rate: number };

export interface RateTickerProps {
  className?: string;
  pairs: Pair[];
}

/**
 * The value flash is the whole point. Never a marquee — a scrolling ticker
 * is continuous large-surface motion that can't be read and can't be paused.
 * Pauses off-screen and on tab hide.
 */
export function RateTicker({ pairs: initial, className }: RateTickerProps) {
  const [pairs, setPairs] = React.useState(initial);
  const ref = useLiveTicker(() => {
    setPairs((prev) =>
      prev.map((p) => ({
        ...p,
        rate: p.rate * (1 + (Math.random() - 0.5) * 0.0018),
      })),
    );
  }, 2400);

  return (
    <section
      aria-label="Live exchange rates"
      className={cn(
        "flex flex-wrap gap-x-6 gap-y-2 rounded-md border border-border bg-surface px-4 py-3",
        className,
      )}
      ref={ref}
    >
      {pairs.map((p) => (
        <TickerCell key={`${p.from}/${p.to}`} pair={p} />
      ))}
    </section>
  );
}

function TickerCell({ pair }: { pair: Pair }) {
  // Throttled to one flash per 400ms by the tick interval itself.
  const { flash, key } = useValueFlash(pair.rate);
  return (
    <span className="flex items-baseline gap-2">
      <span className="text-caption text-text-secondary">
        {pair.from}/{pair.to}
      </span>
      <span
        className={cn(
          "numeric rounded-xs px-1 text-figure-sm",
          flash === "positive" && "ledger-flash-positive",
          flash === "negative" && "ledger-flash-negative",
        )}
        key={key}
      >
        {formatRate(pair.rate)}
      </span>
    </span>
  );
}

Also in Swaps & FX

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where RateTicker sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Swaps & FX changes

Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.