feat: add counterparty requirements configuration in /settings#827
feat: add counterparty requirements configuration in /settings#827Matobi98 wants to merge 3 commits into
Conversation
|
Ready to act? Review this PR in Change Stack to turn feedback into patch suggestions you can inspect and refine. Warning Review limit reached
More reviews will be available in 13 minutes and 18 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
WalkthroughUsers can set minimum counterparty account age and completed-orders via new ChangesCounterparty Requirements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
5426763 to
f56f0f9
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
bot/modules/user/scenes/settings.ts (1)
147-148: ⚡ Quick winUse camelCase local variable names in TypeScript handlers.
Line 147 (
min_days) and Line 191 (min_orders) should be camelCase for consistency with repository TS naming rules.Suggested fix
-const min_days = parseInt(days); -if (isNaN(min_days) || min_days < 0) throw new Error('NotValidNumber'); +const minDays = parseInt(days); +if (isNaN(minDays) || minDays < 0) throw new Error('NotValidNumber'); ... -user.counterparty_requirements.min_days_using_bot = min_days; +user.counterparty_requirements.min_days_using_bot = minDays; ... -state.feedback = { i18n: 'counterpartyage_updated', days: min_days }; +state.feedback = { i18n: 'counterpartyage_updated', days: minDays };-const min_orders = parseInt(orders); -if (isNaN(min_orders) || min_orders < 0) +const minOrders = parseInt(orders); +if (isNaN(minOrders) || minOrders < 0) throw new Error('NotValidNumber'); ... -user.counterparty_requirements.min_completed_orders = min_orders; +user.counterparty_requirements.min_completed_orders = minOrders; ... -orders: min_orders, +orders: minOrders,As per coding guidelines:
**/*.{ts,tsx}: Use camelCase for functions and variables.Also applies to: 191-193
🤖 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/modules/user/scenes/settings.ts` around lines 147 - 148, Rename the snake_case local variables to camelCase: change min_days to minDays (and min_orders to minOrders where present) in the handler(s) that parse user input (the parseInt(days) block and the corresponding parseInt/orders block), update all local references within the same function/scene to use the new names, keep the exact validation logic (isNaN/min < 0) and type handling intact, and run a quick search in the file to update any remaining occurrences of min_days/min_orders to avoid leaving dangling references.
🤖 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 `@bot/modules/user/scenes/settings.ts`:
- Around line 171-176: The catch block currently maps every exception to
CommunityWizardState.error.i18n = 'invalid_number' (in the handler around
ctx.scene.state, updateMessage and user.save()), which hides real runtime
failures; change the handler to distinguish validation/parsing errors (e.g.,
number parse/validation or a specific ValidationError) and only set i18n =
'invalid_number' for those cases, while for other exceptions log the full error
and either rethrow or set a generic/internal error state (or call updateMessage
with a different i18n key) so Telegram/API/save errors are not reported as
invalid input.
- Around line 149-151: Validate and sanitize the environment cap values before
enforcing the range: for the MAX_COUNTERPARTY_AGE_REQUIREMENT parse (the maxAge
variable in bot/modules/user/scenes/settings.ts) and the other env parse around
lines 194-196 (e.g., maxDistance), ensure you parse with radix 10, check that
the result is a finite non-negative integer (and >0 if that’s the requirement),
and fall back to the literal default ('30' or the other default) when the env is
empty, non-numeric, negative, or NaN; replace the current direct parseInt usage
with this validated-value logic so the range guards always receive a correct
numeric cap.
---
Nitpick comments:
In `@bot/modules/user/scenes/settings.ts`:
- Around line 147-148: Rename the snake_case local variables to camelCase:
change min_days to minDays (and min_orders to minOrders where present) in the
handler(s) that parse user input (the parseInt(days) block and the corresponding
parseInt/orders block), update all local references within the same
function/scene to use the new names, keep the exact validation logic (isNaN/min
< 0) and type handling intact, and run a quick search in the file to update any
remaining occurrences of min_days/min_orders to avoid leaving dangling
references.
🪄 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: c597be7a-0669-4782-85f2-e8cfac278bda
📒 Files selected for processing (15)
.env-samplebot/messages.tsbot/modules/orders/takeOrder.tsbot/modules/user/scenes/settings.tslocales/de.yamllocales/en.yamllocales/es.yamllocales/fa.yamllocales/fr.yamllocales/it.yamllocales/ko.yamllocales/pt.yamllocales/ru.yamllocales/uk.yamlmodels/user.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@models/user.ts`:
- Around line 58-61: The counterparty_requirements nested object in the Mongoose
schema should be made truly optional to match the TypeScript interface and the
guard in takeOrder.ts (the `if (!orderCreator.counterparty_requirements)`
check). Update the schema entry for counterparty_requirements (in
models/user.ts) so it does not auto-create a default object—either wrap the two
fields in a sub-Schema and set required: false (or default: undefined), or
remove the default values for that object and explicitly set required:
false/default: undefined; keep the individual fields' min/defaults only if you
still want defaults when the object exists. This ensures the object can be
undefined for users who never configured it and makes the guard in takeOrder.ts
behave correctly.
🪄 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: 0a4963d4-443e-43e6-948a-7d71e9248708
📒 Files selected for processing (15)
.env-samplebot/messages.tsbot/modules/orders/takeOrder.tsbot/modules/user/scenes/settings.tslocales/de.yamllocales/en.yamllocales/es.yamllocales/fa.yamllocales/fr.yamllocales/it.yamllocales/ko.yamllocales/pt.yamllocales/ru.yamllocales/uk.yamlmodels/user.ts
✅ Files skipped from review due to trivial changes (6)
- locales/pt.yaml
- locales/fa.yaml
- locales/fr.yaml
- locales/de.yaml
- locales/ko.yaml
- locales/es.yaml
🚧 Files skipped from review as they are similar to previous changes (7)
- bot/messages.ts
- locales/uk.yaml
- .env-sample
- locales/ru.yaml
- locales/en.yaml
- bot/modules/user/scenes/settings.ts
- bot/modules/orders/takeOrder.ts
Summary
Adds counterparty requirements to the
/settingswizard. Users can now set minimum conditions that must be met before someone can take their orders.What's new
/counterpartyage <days>— sets the minimum account age (in days) required for the counterparty/counterpartyorders <orders>— sets the minimum number of completed orders required for the counterparty/resetrequirements— resets both values back to 0The
/settingspanel now shows the current requirements. If a user tries to take an order and doesn't meet the maker's requirements, they receive a notification and the order stays listed.Environment variables
Two new optional variables can be added to
.envto cap the maximum values users can set:Summary by CodeRabbit
New Features
Localization