Add settled_by_admin field in order.ts model and improve getDetailedOrder output.#747
Add settled_by_admin field in order.ts model and improve getDetailedOrder output.#747Luquitasjeffrey wants to merge 3 commits intomainfrom
Conversation
…d_by_admin' field denoting that, and modified the 'getDetailedOrder' function output to show if an order was completed by an admin or not
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughRefactors admin-settlement tracking: removes the COMPLETED_BY_ADMIN status enum and replaces it with a boolean Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
🚨 Request Changes - Critical Issues FoundI 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:
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 FieldIn models/order.ts: settled_by_admin?: boolean; // Optional - BADProblem: Optional fields can be undefined, leading to inconsistent data. Required: settled_by_admin: { type: Boolean, default: false, required: true }4. Missing CodeRabbit ReviewThis 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
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. |
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
Updates