Standardize 'sat' vs 'sats' currency string end-to-end #70

Open
opened 2026-05-23 17:53:19 +00:00 by padreug · 0 comments
Owner

Problem

The webapp uses 'sat' and 'sats' interchangeably across modules — same concept, two different string literals. Every comparison defensively handles both, which is workable but accumulates dead bytes and creates real bugs when someone writes a strict comparison.

grep -rn "['\"]sat['\"]\|['\"]sats['\"]" src/ returns ~85 matches. Sampler:

  • src/modules/activities/services/TicketApiService.ts:293getCurrencies() returns ['sats', ...] (plural)
  • src/modules/activities/components/CreateEventDialog.vue:123 — schema default 'sat' (singular)
  • src/modules/activities/components/CreateEventDialog.vue:166 — initialValues 'sat'
  • src/modules/market/services/nostrmarketAPI.ts:456,459 — fallback ['sat']
  • src/modules/market/types/market.ts:57 — default 'sats'
  • src/modules/market/components/ProductCard.vue:234, CartItem.vue:246, ShoppingCart.vue:242, CartSummary.vue:226, CheckoutPage.vue:525, ProductDetailPage.vue:199 — defensive comparisons currency === 'sat' || currency === 'sats'

PR #68 hit a real bug from this: introducing a currency === 'sat' conditional on CreateEventDialog worked locally with the schema default but failed as soon as the user picked from the populated dropdown (which contains 'sats' from getCurrencies()). Patched with the same defensive 'sat' || 'sats' pattern, but that's a workaround.

Proposed approach

  1. Pick one canonical spelling. 'sats' (plural) is more common across the codebase + matches what both events.getCurrencies() and nostrmarket return from the LNbits backends, so the conversion direction is "schema/UI catches up to backend." Open to 'sat' if there's a reason — but pick one.
  2. Migrate writes first. Schema defaults, initialValues, hard-coded fallbacks (|| 'sat') → canonicalize.
  3. Then drop the defensive comparisons. All currency === 'sat' || currency === 'sats' collapse to a single comparison.
  4. Backend audit. Spot-check that no Python-side LNbits code emits the other spelling. The events + market extensions return 'sats'; double-check before tightening the webapp comparisons.

Out of scope for this issue

  • Display formatting (100 sats vs 100 sat) is a separate UX question — this issue only covers the identifier string used in code comparisons / API payloads.

Why now

Cleaning this up unblocks future strict-from-the-start conditionals (the v2 / pre-launch policy applies — backwards-compat shims like the defensive comparison are the explicit thing we want to avoid carrying forward). The longer this lingers the more new code will accrete the same || pattern.

## Problem The webapp uses `'sat'` and `'sats'` interchangeably across modules — same concept, two different string literals. Every comparison defensively handles both, which is workable but accumulates dead bytes and creates real bugs when someone writes a strict comparison. `grep -rn "['\"]sat['\"]\|['\"]sats['\"]" src/` returns ~85 matches. Sampler: - `src/modules/activities/services/TicketApiService.ts:293` — `getCurrencies()` returns `['sats', ...]` (plural) - `src/modules/activities/components/CreateEventDialog.vue:123` — schema default `'sat'` (singular) - `src/modules/activities/components/CreateEventDialog.vue:166` — initialValues `'sat'` - `src/modules/market/services/nostrmarketAPI.ts:456,459` — fallback `['sat']` - `src/modules/market/types/market.ts:57` — default `'sats'` - `src/modules/market/components/ProductCard.vue:234`, `CartItem.vue:246`, `ShoppingCart.vue:242`, `CartSummary.vue:226`, `CheckoutPage.vue:525`, `ProductDetailPage.vue:199` — defensive comparisons `currency === 'sat' || currency === 'sats'` PR #68 hit a real bug from this: introducing a `currency === 'sat'` conditional on `CreateEventDialog` worked locally with the schema default but failed as soon as the user picked from the populated dropdown (which contains `'sats'` from `getCurrencies()`). Patched with the same defensive `'sat' || 'sats'` pattern, but that's a workaround. ## Proposed approach 1. **Pick one canonical spelling.** `'sats'` (plural) is more common across the codebase + matches what both `events.getCurrencies()` and `nostrmarket` return from the LNbits backends, so the conversion direction is "schema/UI catches up to backend." Open to `'sat'` if there's a reason — but pick one. 2. **Migrate writes first.** Schema defaults, initialValues, hard-coded fallbacks (`|| 'sat'`) → canonicalize. 3. **Then drop the defensive comparisons.** All `currency === 'sat' || currency === 'sats'` collapse to a single comparison. 4. **Backend audit.** Spot-check that no Python-side LNbits code emits the other spelling. The events + market extensions return `'sats'`; double-check before tightening the webapp comparisons. ## Out of scope for this issue - Display formatting (`100 sats` vs `100 sat`) is a separate UX question — this issue only covers the *identifier* string used in code comparisons / API payloads. ## Why now Cleaning this up unblocks future strict-from-the-start conditionals (the v2 / pre-launch policy applies — backwards-compat shims like the defensive comparison are the explicit thing we want to avoid carrying forward). The longer this lingers the more new code will accrete the same `||` pattern.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
aiolabs/webapp#70
No description provided.