Skip to content

FxExposure

Position by currency with unrealized gain/loss.
Implemented
Status
Implemented
Family
4 of 13
Registry
@lopifi/fx-exposure
npx shadcn@latest add @lopifi/theme @lopifi/fx-exposure

The component, rendering

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

Preview

The four-layer spec

Position by currency with unrealized gain/loss. Uses polarity="standard" per position, and clearly separates realized from unrealized — they're different facts and conflating them misstates the position.

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/fx-exposure.tsx

Lopifi dependencies · 13
as-ofcncurrency-badgedeltafiscal-periodformat-moneymoneymoney.typespercentruletooltipuse-scroll-edgesuse-shared-now
npm packages
@base-ui-components/reactclass-variance-authorityclsxtailwind-merge
Registry entry
/r/fx-exposure.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/fx-exposure.tsx
import * as React from "react";
import { useScrollEdges } from "@/hooks/ledger/use-scroll-edges";
import { cn } from "@/lib/ledger/cn";
import type { MoneyValue } from "@/lib/ledger/money.types";
import { AsOf } from "@/components/ledger/as-of";
import { CurrencyBadge } from "@/components/ledger/currency-badge";
import { Delta } from "@/components/ledger/delta";
import { Money } from "@/components/ledger/money";
import { Rule } from "@/components/ledger/rule";

export type Position = {
  currency: string;
  position: MoneyValue;
  /** In the presentation currency, at the stated rate. */
  presentationValue: MoneyValue;
  rate: number;
  /** Realized and unrealized are different facts. Never combined. */
  unrealized: MoneyValue;
  realized: MoneyValue;
};

export interface FxExposureProps extends React.ComponentPropsWithoutRef<"div"> {
  asOf: Date;
  /** Caps the scroller so the header and the currency column can freeze. */
  maxHeight?: number;
  positions: Position[];
  presentationCurrency: string;
  totalRealized: MoneyValue;
  totalUnrealized: MoneyValue;
}

export const FxExposure = React.forwardRef<HTMLDivElement, FxExposureProps>(
  (
    {
      className,
      positions,
      presentationCurrency,
      totalUnrealized,
      totalRealized,
      asOf,
      maxHeight = 520,
      ...props
    },
    ref,
  ) => {
    const scroller = useScrollEdges<HTMLDivElement>();
    return (
      <div className={cn("rounded-xl border border-border bg-surface", className)} ref={ref} {...props}>
        <div className="px-6 pb-4 pt-6">
          <p className="text-title-sm font-medium">FX exposure</p>
          <p className="text-caption text-text-secondary">
            Presented in {presentationCurrency} · <AsOf date={asOf} />
          </p>
        </div>
        <div className="ledger-frozen scrollbar-thin" ref={scroller} style={{ maxHeight }}>
          <table className="w-full min-w-[640px]">
            <caption className="sr-only">FX exposure, presented in {presentationCurrency}</caption>
            <thead>
              <tr className="border-b border-border-subtle">
                <th className="px-6 py-3 text-left text-label text-text-secondary" scope="col">
                  Currency
                </th>
                <th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
                  Position
                </th>
                <th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
                  Rate
                </th>
                <th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
                  Value ({presentationCurrency})
                </th>
                <th className="px-3 py-3 text-right text-label text-text-secondary" scope="col">
                  Unrealized
                </th>
                <th className="px-6 py-3 text-right text-label text-text-secondary" scope="col">
                  Realized
                </th>
              </tr>
            </thead>
            <tbody>
              {positions.map((p) => (
                <tr className="border-b border-border-subtle" key={p.currency}>
                  <th className="px-6 py-3 text-left" scope="row">
                    <CurrencyBadge currency={p.currency} />
                  </th>
                  <td className="px-3 py-3 text-right">
                    <Money accounting showCode value={p.position} />
                  </td>
                  <td className="numeric px-3 py-3 text-right text-figure-sm text-text-secondary">
                    {p.rate.toFixed(5)}
                  </td>
                  <td className="px-3 py-3 text-right">
                    <Money accounting value={p.presentationValue} />
                  </td>
                  <td className="px-3 py-3 text-right">
                    <Delta polarity="standard" showArrow={false} value={p.unrealized} />
                  </td>
                  <td className="px-6 py-3 text-right">
                    <Delta polarity="standard" showArrow={false} value={p.realized} />
                  </td>
                </tr>
              ))}
            </tbody>
            <tfoot>
              <tr>
                <td colSpan={4} />
                <td className="px-3">
                  <Rule variant="subtotal" />
                </td>
                <td className="px-6">
                  <Rule variant="subtotal" />
                </td>
              </tr>
              <tr>
                <th className="px-6 py-3 text-left text-label font-medium" scope="row">
                  Total
                </th>
                <td colSpan={3} />
                <td className="px-3 py-3 text-right">
                  <Money accounting size="md" value={totalUnrealized} />
                </td>
                <td className="px-6 py-3 text-right">
                  <Money accounting size="md" value={totalRealized} />
                </td>
              </tr>
            </tfoot>
          </table>
        </div>
      </div>
    );
  },
);
FxExposure.displayName = "FxExposure";

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 FxExposure 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.