Pipewright fernhill / atlas-web / feat/cart-currency
currency.tscoupon.tspipewright.toml
14export function switchCurrency(cart: Cart, to: Code) {
15 const rate = rates.get(cart.currency, to);
16 const lines = cart.lines.map(l => ({ ...l, price: round(l.price * rate) }));
17 // keep the coupon: re-apply it in the new currency
18 const coupon = cart.coupon && reapply(cart.coupon, to);
19 return { ...cart, currency: to, lines, coupon };
20}
21
22function reapply(c: Coupon, to: Code) {
23 if (c.kind === 'percent') return c;
24 return { ...c, amount: convert(c.amount, c.currency, to), currency: to };
25}
26
27function convert(n: Minor, from: Code, to: Code) {
28 if (from === to) return n;
29 // minor units in, minor units out; round half to even
30 return bankersRound(n * rates.get(from, to));
31}
32
33export const SUPPORTED = ['EUR', 'GBP', 'USD', 'SEK'] as const;
atlas-web-a3f9c1e.preview.pipewright.dev/cart

Your cart

EURGBPUSD
Linen throw, oat£68.00
Stoneware mug ×2£28.00
Coupon AUTUMN15−£14.40
Total£81.60
Pipewright Preview

Building atlas-web0:00

fix(cart): keep coupon on currency switch feat/cart-currency · Maya Ostrowski
  1. Queued—
  2. Build—
  3. Checks—
  4. Live—
atlas-web-a3f9c1e.preview.pipewright.dev

Roll preview back to 9be20d4? This deploy stays in history.