Skip to content

Add settled_by_admin field in order.ts model and improve getDetailedOrder output.#747

Open
Luquitasjeffrey wants to merge 3 commits intomainfrom
add-settled_by_admin-field
Open

Add settled_by_admin field in order.ts model and improve getDetailedOrder output.#747
Luquitasjeffrey wants to merge 3 commits intomainfrom
add-settled_by_admin-field

Conversation

@Luquitasjeffrey
Copy link
Collaborator

@Luquitasjeffrey Luquitasjeffrey commented Feb 16, 2026

This PR removes the 'COMPLETED_BY_ADMIN' status in an Order and adds a new boolean field 'settled_by_admin' that, as the name suggests, denotes if an order was indeed completed or not by an admin.
Also, now when an admin uses the checkorder command, it will display if the order was completed by an admin

Summary by CodeRabbit

  • New Features

    • Order details now show whether an admin settled the order, added across all supported languages.
  • Updates

    • Refined order status checks and settlement flow to better track admin-settled orders.
    • Adjusted blocking behavior to align with the updated status and settlement handling.

…d_by_admin' field denoting that, and modified the 'getDetailedOrder' function output to show if an order was completed by an admin or not
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8c9520 and 70e2038.

📒 Files selected for processing (2)
  • locales/en.yaml
  • locales/fa.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • locales/en.yaml
  • locales/fa.yaml

Walkthrough

Refactors admin-settlement tracking: removes the COMPLETED_BY_ADMIN status enum and replaces it with a boolean settled_by_admin; narrows status checks to PAID_HOLD_INVOICE; updates order detail rendering and locales to expose the new admin-settled indicator.

Changes

Cohort / File(s) Summary
Command & flow logic
bot/commands.ts, bot/modules/block/commands.ts, bot/start.ts
Removed/stop-checking COMPLETED_BY_ADMIN in status checks and query filters; changed /setinvoice lookup to only consider PAID_HOLD_INVOICE; set order.settled_by_admin = true before calling settlement and removed setting status to COMPLETED_BY_ADMIN.
Data model
models/order.ts
Added settled_by_admin boolean (default false) to schema and IOrder; removed 'COMPLETED_BY_ADMIN' from status enum.
Order detail rendering
util/index.ts
Added settledByAdmin derived from order.settled_by_admin and included it in data for the order_detail translation.
Localization
locales/{de,en,es,fa,fr,it,ko,pt,ru,uk}.yaml
Added a new order_detail line exposing ${settledByAdmin} in each language to show whether the order was settled by an admin.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • Catrya
  • grunch

Poem

🐰 A rabbit hops through status queues with glee,
Flags shine where statuses once would stand,
COMPLETED_BY_ADMIN hopped off the tree,
settled_by_admin waves its little hand.
Translations sing it near and far—now tidy, clear, and grand. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding a settled_by_admin field to the order model and improving order detail output display.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-settled_by_admin-field

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@bot/start.ts`:
- Around line 547-551: The code currently sets order.settled_by_admin = true and
calls await order.save() before calling settleHoldInvoice, which can leave the
flag persisted if settleHoldInvoice throws; change the flow so you first call
await settleHoldInvoice({ secret: order.secret }) and only after it succeeds set
order.settled_by_admin = true and call await order.save(), or wrap both calls in
a try/catch and roll back (reset) order.settled_by_admin and avoid saving if
settleHoldInvoice fails; refer to the order object, its save() method, and the
settleHoldInvoice function when updating the logic.

In `@locales/fa.yaml`:
- Around line 183-184: Replace the English label "Settled by admin:
${settledByAdmin}" in the Persian locale with a Persian translation to keep
localization consistent; update the entry in locales/fa.yaml (the string
"Settled by admin: ${settledByAdmin}") to a Persian equivalent such as "تسویه
شده توسط ادمین: ${settledByAdmin}" ensuring the placeholder ${settledByAdmin}
remains unchanged.

@mostronatorcoder
Copy link
Contributor

🚨 Request Changes - Critical Issues Found

I need to request changes before this PR can be merged. There are critical security and data integrity issues that must be addressed:

1. BREAKING CHANGE without Data Migration (CRITICAL)

Removing "COMPLETED_BY_ADMIN" from the status enum is a breaking change that will break existing orders in production.

Problem: Orders currently in "COMPLETED_BY_ADMIN" status will be in an invalid state after deployment.

Required: Add a database migration script that:

  • Finds all orders with status: "COMPLETED_BY_ADMIN"
  • Updates them to status: "PAID_HOLD_INVOICE"
  • Sets settled_by_admin: true

Without this migration, existing orders will be unreachable and potentially cause runtime errors.

2. Data Integrity Issue in bot/start.ts (SECURITY)

Current (WRONG):

order.settled_by_admin = true;
await order.save();
await settleHoldInvoice({ secret: order.secret });

Problem: If settleHoldInvoice() fails, the order is already marked as settled by admin but the hold invoice was NOT settled. This creates an inconsistent state where the database says "settled by admin" but the Lightning payment did not complete.

Required (CORRECT):

try {
  await settleHoldInvoice({ secret: order.secret });
  order.settled_by_admin = true;
  await order.save();
} catch (error) {
  // Handle error - do NOT mark as settled_by_admin
  throw error;
}

The settlement must succeed BEFORE marking the order as settled by admin.

3. Schema Issue - Optional Field

In models/order.ts:

settled_by_admin?: boolean;  // Optional - BAD

Problem: Optional fields can be undefined, leading to inconsistent data.

Required:

settled_by_admin: { type: Boolean, default: false, required: true }

4. Missing CodeRabbit Review

This PR has been pending CodeRabbit review. I should have waited for that automated analysis before reviewing. Please ensure all automated checks pass.


Summary of Required Changes

  1. Add database migration for existing "COMPLETED_BY_ADMIN" orders
  2. Fix order of operations in bot/start.ts - settle first, then mark
  3. Make field required with default false in schema
  4. Verify all existing orders with "COMPLETED_BY_ADMIN" are handled

This is financial software handling real Bitcoin. We cannot merge breaking changes without proper migration and data integrity guarantees.

Status: 🔴 Request Changes - DO NOT MERGE until issues are resolved.

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