Skip to content

fix: show sats amount on fixed orders - #852

Merged
grunch merged 3 commits into
mainfrom
fix-show-sats-amount-fixed-order
Jul 2, 2026
Merged

fix: show sats amount on fixed orders#852
grunch merged 3 commits into
mainfrom
fix-show-sats-amount-fixed-order

Conversation

@Catrya

@Catrya Catrya commented Jul 1, 2026

Copy link
Copy Markdown
Member

PR #770 moved the order title into a single i18n string and dropped the sats amount, so fixed orders showed "Selling sats" instead of "Selling 100 sats".

Restores the amount via a ${amount} placeholder in the locale keys (all languages) and computes it in getOrderTitleMessage: shown for fixed orders, omitted for market/range orders.

Summary by CodeRabbit

  • New Features
    • Order status notifications now display the satoshi amount for buy/sell.
    • Username-specific variants show both the username and the satoshi amount.
    • Amount display is adjusted for cases where pricing is sourced from the API.
  • Localization
    • Updated buy/sell translated strings across supported languages to include ${amount} consistently (including username variants).
  • Tests
    • Added automated coverage to verify title formatting for fixed vs. range/market scenarios and conditional username inclusion.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 355de067-d251-4a2c-a3f7-109e6fd26291

📥 Commits

Reviewing files that changed from the base of the PR and between c48da5a and f45572f.

📒 Files selected for processing (1)
  • tests/bot/ordersActions.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/bot/ordersActions.spec.ts

Walkthrough

Order title generation now passes amount-related data into getOrderTitleMessage, which formats the first line with translated amount-aware text. The matching locale strings were updated across languages, and tests cover fixed-amount and zero-amount cases.

Changes

Amount-aware order title messages

Layer / File(s) Summary
Order title logic changes
bot/ordersActions.ts
buildDescription now passes amount, fiatCode, and priceFromAPI to getOrderTitleMessage, which computes amountText conditionally and includes it in both username-visible and username-hidden translations; the helper is also exported.
Order title message tests
tests/bot/ordersActions.spec.ts
A real i18n-backed test suite checks getOrderTitleMessage for fixed amounts and zero-amount orders, with and without username display.
Locale string updates
locales/de.yaml, locales/en.yaml, locales/es.yaml, locales/fa.yaml, locales/fr.yaml, locales/it.yaml, locales/ko.yaml, locales/pt.yaml, locales/ru.yaml, locales/uk.yaml
selling_sats, buying_sats, showusername_buying_sats, and showusername_selling_sats now interpolate ${amount} in the rendered text.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

  • lnp2pBot/bot#770: Both PRs touch bot/ordersActions.ts and the showusername_*_sats/selling_sats/buying_sats locale keys used to build the first-line order message.

Suggested reviewers: Luquitasjeffrey, mostronatorcoder

Poem

I hop through strings with care and glee,
Each sats amount now helps me see.
No more vague text in bunny land,
The titles fit just as planned. 🐇
With numbers here, the message sings—
A tidy hop of translated things.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: restoring sats amounts on fixed orders.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-show-sats-amount-fixed-order

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Catrya
Catrya requested review from Luquitasjeffrey and grunch July 1, 2026 22:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
bot/ordersActions.ts (1)

286-288: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Whitespace baked into interpolated value is fragile.

amountText embeds a trailing space (`${numberFormat(fiatCode, amount)} `) so that locale strings like 'Selling ${amount}sats' render correctly. This couples the JS logic to an undocumented assumption about every locale template's spacing (no space before sats/equivalent). A future locale edit that adds a space before the placeholder will silently produce a double space.

Consider keeping amountText as just the formatted number (or empty) and letting each locale template own the spacing, e.g. ${amount} sats with a conditional/trim, or exposing a separate hasAmount flag to the templates.

♻️ Possible approach
-  const amountText = priceFromAPI ? '' : `${numberFormat(fiatCode, amount)} `;
+  const amountText = priceFromAPI ? '' : `${numberFormat(fiatCode, amount)}`;

Then update locale strings to 'Selling ${amount} sats' and have market/range variants use a dedicated string without the amount placeholder, instead of relying on an empty interpolated value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bot/ordersActions.ts` around lines 286 - 288, The spacing for order amount
rendering is currently baked into `amountText` in `ordersActions.ts`, which
makes locale templates fragile. Update the `amountText` handling in the order
formatting logic so it only returns the formatted number or an empty string, and
move spacing decisions into the locale strings used by the sell/order templates.
Adjust the relevant template entries and any callers in the order action flow so
fixed orders and market/range orders render correctly without relying on a
trailing space inside `amountText`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@bot/ordersActions.ts`:
- Around line 286-288: The spacing for order amount rendering is currently baked
into `amountText` in `ordersActions.ts`, which makes locale templates fragile.
Update the `amountText` handling in the order formatting logic so it only
returns the formatted number or an empty string, and move spacing decisions into
the locale strings used by the sell/order templates. Adjust the relevant
template entries and any callers in the order action flow so fixed orders and
market/range orders render correctly without relying on a trailing space inside
`amountText`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 672a802a-ca1c-40ff-83de-daf963947d86

📥 Commits

Reviewing files that changed from the base of the PR and between fea5d84 and 9041ba3.

📒 Files selected for processing (11)
  • bot/ordersActions.ts
  • locales/de.yaml
  • locales/en.yaml
  • locales/es.yaml
  • locales/fa.yaml
  • locales/fr.yaml
  • locales/it.yaml
  • locales/ko.yaml
  • locales/pt.yaml
  • locales/ru.yaml
  • locales/uk.yaml

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/bot/ordersActions.spec.ts (2)

17-97: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Coverage gaps: missing buy+username (fixed) and sell+username (market) cases.

The fixed-orders block covers sell/no-username, buy/no-username, sell/username, but not buy/username. The market/range block covers sell/no-username, buy/no-username, buy/username, but not sell/username. Since this suite is meant to guard against the amount-omission regression, filling in the missing permutations would give full confidence across both isSell branches and both show_username branches.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/bot/ordersActions.spec.ts` around lines 17 - 97, Add the missing
permutation tests in ordersActions.spec for getOrderTitleMessage so both
branches are covered: in the fixed orders describe block, add a publicUser buy
case expecting the username plus “100 sats”, and in the market/range describe
block, add a publicUser sell case expecting the username plus “sats” without an
amount. Use the existing anonymousUser, publicUser, i18nCtx, and
getOrderTitleMessage setup to mirror the surrounding assertions and cover both
isSell and show_username combinations.

14-15: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid any for test fixtures; type against UserDocument.

Using a typed partial (e.g., Partial<UserDocument> or a minimal interface) instead of any would catch fixture drift if UserDocument's shape changes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/bot/ordersActions.spec.ts` around lines 14 - 15, Replace the
`any`-typed test fixtures in `ordersActions.spec.ts` with a typed
`Partial<UserDocument>` (or a minimal fixture interface) for `anonymousUser` and
`publicUser`. Update the fixture declarations near the `UserDocument`-related
test setup so the objects are checked against the expected shape, keeping only
the fields needed by the tests. This will make the `UserDocument` fixtures in
the spec resilient to drift without relying on `any`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/bot/ordersActions.spec.ts`:
- Around line 1-3: The spec file is using CommonJS require() imports, which
violates the TypeScript/ESLint import style. Update the top-level imports in
ordersActions.spec.ts to use ES import syntax for expect, I18n, and
getOrderTitleMessage so the file follows Standard + TypeScript rules and keeps
type-checking intact.

---

Nitpick comments:
In `@tests/bot/ordersActions.spec.ts`:
- Around line 17-97: Add the missing permutation tests in ordersActions.spec for
getOrderTitleMessage so both branches are covered: in the fixed orders describe
block, add a publicUser buy case expecting the username plus “100 sats”, and in
the market/range describe block, add a publicUser sell case expecting the
username plus “sats” without an amount. Use the existing anonymousUser,
publicUser, i18nCtx, and getOrderTitleMessage setup to mirror the surrounding
assertions and cover both isSell and show_username combinations.
- Around line 14-15: Replace the `any`-typed test fixtures in
`ordersActions.spec.ts` with a typed `Partial<UserDocument>` (or a minimal
fixture interface) for `anonymousUser` and `publicUser`. Update the fixture
declarations near the `UserDocument`-related test setup so the objects are
checked against the expected shape, keeping only the fields needed by the tests.
This will make the `UserDocument` fixtures in the spec resilient to drift
without relying on `any`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6914f968-0d86-4aaa-a38c-d5a8ecbd102a

📥 Commits

Reviewing files that changed from the base of the PR and between 9041ba3 and c48da5a.

📒 Files selected for processing (2)
  • bot/ordersActions.ts
  • tests/bot/ordersActions.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • bot/ordersActions.ts

Comment thread tests/bot/ordersActions.spec.ts Outdated

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict review done. LGTM.

Verified

  • Faithful restoration of the pre-#770 behavior: compared against 66e0004's parent — same guard (priceFromAPI), same formatting (numberFormat(fiatCode, amount)), same output for every case.
  • Market/range orders: priceFromAPI = !amount in createOrder, so orders with amount === 0 (market and range, including range child orders) correctly omit the amount.
  • numberFormat can't return false in this path: createOrder validates getCurrency(fiatCode) before buildDescription, and buildDescription has a single caller.
  • No orphaned call sites: nothing else consumes selling_sats/buying_sats/showusername_*, so no literal ${amount} can leak into output. All 10 locales updated consistently.
  • No retroactive impact: descriptions are persisted at order creation.

Added on this branch

  • tests/bot/ordersActions.spec.ts (c48da5a, f45572f): regression test for getOrderTitleMessage using a real i18n context against locales/en.yaml — the #770 regression lived exactly in the code↔YAML ${amount} interpolation contract, which a stubbed i18n.t wouldn't catch. Covers fixed vs market/range orders, with and without show_username. Full suite: 150 passing, lint clean.

Follow-ups filed separately (pre-existing, not blockers)

  • #854 — fragile ${amount}-with-embedded-space i18n pattern (+ two minor code nits in getOrderTitleMessage)
  • #855numberFormat() returns false | number | string
  • #856ru.yaml "сат"/"саты" wording inconsistency

Thanks @Catrya!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants