Bugfix: Distinguish i18n contexts for buyer and seller in cancelShowH…#763
Bugfix: Distinguish i18n contexts for buyer and seller in cancelShowH…#763Matobi98 wants to merge 1 commit intolnp2pBot:mainfrom
Conversation
WalkthroughThis pull request refactors cancellation logic in bot/commands.ts to implement per-user i18n contexts. The cancelAddInvoice and cancelShowHoldInvoice functions now distinguish between seller and buyer contexts when sending messages, replacing a single unified context with role-specific ones. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bot/commands.ts`:
- Around line 499-504: The guard that checks order.status !== 'WAITING_PAYMENT'
currently always sends messages.genericErrorMessage(ctx, sellerUser,
i18nCtxSeller) which can DM the wrong person; change it to send the error to the
acting user instead: determine the acting user (the request initiator used
earlier in cancelOrder — e.g., the variable representing the caller) and its
i18n context (from getUserI18nContext), then call
messages.genericErrorMessage(ctx, actingUser, actingI18nCtx) when the status is
invalid, leaving sellerUser/buyerUser untouched for other flows.
| const i18nCtxSeller = await getUserI18nContext(sellerUser); | ||
| const i18nCtxBuyer = await getUserI18nContext(buyerUser); | ||
|
|
||
| // Sellers only can cancel orders with status WAITING_PAYMENT | ||
| if (order.status !== 'WAITING_PAYMENT') | ||
| return await messages.genericErrorMessage(ctx, sellerUser, i18nCtxSeller); |
There was a problem hiding this comment.
Send the invalid-status error to the acting user, not always the seller.
cancelOrder() routes WAITING_PAYMENT buy orders here for either side. If the status flips before this guard runs, Line 504 will still DM sellerUser, so a stale buyer action produces no feedback for the buyer and an unexpected generic error for the seller.
💡 Suggested fix
const i18nCtxSeller = await getUserI18nContext(sellerUser);
const i18nCtxBuyer = await getUserI18nContext(buyerUser);
// Sellers only can cancel orders with status WAITING_PAYMENT
- if (order.status !== 'WAITING_PAYMENT')
- return await messages.genericErrorMessage(ctx, sellerUser, i18nCtxSeller);
+ if (order.status !== 'WAITING_PAYMENT') {
+ const actingUser =
+ userAction && userTgId === buyerUser.tg_id ? buyerUser : sellerUser;
+ const actingI18n =
+ actingUser === buyerUser ? i18nCtxBuyer : i18nCtxSeller;
+
+ return await messages.genericErrorMessage(ctx, actingUser, actingI18n);
+ }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@bot/commands.ts` around lines 499 - 504, The guard that checks order.status
!== 'WAITING_PAYMENT' currently always sends messages.genericErrorMessage(ctx,
sellerUser, i18nCtxSeller) which can DM the wrong person; change it to send the
error to the acting user instead: determine the acting user (the request
initiator used earlier in cancelOrder — e.g., the variable representing the
caller) and its i18n context (from getUserI18nContext), then call
messages.genericErrorMessage(ctx, actingUser, actingI18nCtx) when the status is
invalid, leaving sellerUser/buyerUser untouched for other flows.
PR: Fix Timeout/Expiry Notifications Language Localization
Overview
This PR fixes a bug where timeout/expiry notifications for sell orders were being sent to both the buyer and the seller in the buyer's configured language. The system now correctly identifies each user's language preference and sends personalized notifications.
Key Changes
Language Localization
Updated
cancelShowHoldInvoiceinbot/commands.tsto fetch bothbuyerUserandsellerUserdata.Individual i18n Contexts
Every party now has their own i18n context retrieved via
getUserI18nContext().Targeted Messaging
Outgoing message functions:
toSellerDidntPayInvoiceMessagetoBuyerSellerDidntPayInvoiceMessagepublishBuyOrderMessageNow receive the specific language context for the recipient.
Error Handling
Added an explicit exception if the seller user is not found during the cancellation process to improve reliability.
Summary by CodeRabbit