Purchase Dialog
The confirm step of any purchase. It shows the item, a quantity stepper for bundles, the total, and "Balance 1,250 → 1,130" for each in-game currency. If the wallet falls short, Buy is disabled and the dialog says "Need 70 more Coins" with an optional Get more button. onConfirm can return a Promise: the button spins, then a success view pops up (or the error appears with a retry). Free items say Claim; real-money prices are shown as given.
Five items: a cheap lantern, a teapot you cannot afford (it shows Get more), a seed bundle with a stepper, a real-money gem pack, and a free gift. onConfirm returns a Promise that resolves after 800 ms and the CurrencyBar updates.
Installation
Usage
PurchaseDialog never charges anything. A price like { real: "$4.99" } is only text: call your store SDK (App Store, Google Play, Stripe) from onConfirm, and reject the Promise if it fails.
While pending, the close button, Escape, outside click and Cancel are disabled so a payment cannot be abandoned half way. The success view is an aria-live region; errors use role="alert".
The dialog opens fresh (idle, default quantity) each time. Validate the purchase again on your server: the wallet check here is only for the button.
Examples
Controlled status
Games that talk to a server can drive the dialog with status ("idle", "pending", "success", "error") and error. Here the first try fails and the retry works.
The first try fails, the retry works. Status: idle
Two currencies, details and translation
price can be a list (600 coins plus 12 gems). renderDetails adds content under the item, trigger opens the dialog, and labels translates every string.
API
Everything else is passed through to the underlying element or Radix primitive.
| Prop | Type | Default | Description |
|---|---|---|---|
open / defaultOpen / onOpenChange | boolean / boolean / (open) => void | false | Open state. It never asks to close while a purchase is pending. |
item | PurchaseItem<T> | – | { id, name, label?, icon?, description?, price, rarity?, quantity?, data? }. `price` is a Price or a list of Prices. `quantity` is the units per purchase (a bundle of 10 shows "×10"). `label` is the plain-text name used in the success message. |
wallet / currencies | Wallet / Record<string, Currency> | none / DEFAULT_CURRENCIES | With a wallet the dialog shows balances and blocks Buy when it cannot pay. Without one it never blocks. |
maxQuantity / quantity / defaultQuantity / onQuantityChange | number / number / number / (n) => void | 1 / 1 | The stepper shows when maxQuantity is above 1. Quantity is the number of purchases, not units. Shift+click steps by 10, and so does holding a button on touch. Real-money prices always buy 1. |
onConfirm | (item, quantity) => void | Promise | – | Called when the player confirms. Return a Promise for the busy state, then success; a rejection shows its message and a Try again button. Return nothing to go straight to success. Charge the player here: the component charges nothing. |
status / error | "idle" | "pending" | "success" | "error" / ReactNode | from onConfirm | Drive the state yourself, e.g. from a server response. |
onDone | () => void | – | Called when the success view closes. |
onGetMore | (currencyId, missing) => void | – | Shows a "Get more Coins" button next to each missing amount. |
realMoneyNote | ReactNode | – | Shown under the total for real-money prices, e.g. "Charged by the App Store". |
renderDetails / trigger / rarities | fn / ReactNode / Record<string, RarityConfig> | – | Content under the item, an element that opens the dialog, and your own rarity set. |
labels | Partial<PurchaseDialogLabels> | English | title, claimTitle, description, confirm, claim, cancel, retry, quantity, decrease, increase, units, total, free, balance, need, getMore, pending, successTitle, success, claimed, close, error. Placeholders: {quantity} {name} {amount} {currency} {units}. |