fix: add maxLength to contact inputs (#72)#171
fix: add maxLength to contact inputs (#72)#171Emins25 wants to merge 1 commit intoPi-Defi-world:mainfrom
Conversation
📝 WalkthroughWalkthroughThis pull request adds input length constraints to form fields in the contact settings page by introducing two local constants ( Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 `@app/`(app)/me/settings/contacts/page.tsx:
- Around line 95-108: handleAdd currently relies only on input maxLength but
still posts whatever state holds; add a defensive submit-time validation inside
the handleAdd function to check addAlias.length <= ALIAS_MAX_LENGTH and
addPayUri.length <= PAY_URI_MAX_LENGTH before calling postContact. If either
check fails, prevent submission (return early) and surface a user-friendly error
(e.g., set an error state or show a toast) so invalid values are not sent to
postContact; keep the checks aligned to the existing ALIAS_MAX_LENGTH and
PAY_URI_MAX_LENGTH constants and update any existing error handling/state used
for other form errors.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 178165a7-ce32-43c1-9bd2-4e29de80bf3b
📒 Files selected for processing (1)
app/(app)/me/settings/contacts/page.tsx
| <Input | ||
| placeholder="Alias" | ||
| value={addAlias} | ||
| maxLength={ALIAS_MAX_LENGTH} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => setAddAlias(e.target.value)} | ||
| className="border-border" | ||
| /> | ||
| <Input | ||
| placeholder="Pay URI or address" | ||
| value={addPayUri} | ||
| maxLength={PAY_URI_MAX_LENGTH} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => setAddPayUri(e.target.value)} | ||
| className="border-border" | ||
| /> |
There was a problem hiding this comment.
Add submit-time length validation (not only input-level maxLength).
maxLength here is a good UI constraint, but handleAdd still posts whatever state contains. Add a defensive check before postContact so constraints are enforced at submit time too (and aligned with your “prevent unbounded input” objective).
💡 Suggested patch
const handleAdd = async (e: React.FormEvent) => {
e.preventDefault();
- if (!addAlias.trim() && !addPayUri.trim()) return;
+ const alias = addAlias.trim();
+ const payUri = addPayUri.trim();
+ if (!alias && !payUri) return;
+ if (alias.length > ALIAS_MAX_LENGTH || payUri.length > PAY_URI_MAX_LENGTH) {
+ setError(`Alias must be <= ${ALIAS_MAX_LENGTH} and Pay URI/address must be <= ${PAY_URI_MAX_LENGTH} characters.`);
+ return;
+ }
setAdding(true);
setError('');
try {
- await userApi.postContact({ alias: addAlias.trim() || undefined, pay_uri: addPayUri.trim() || undefined }, opts);
+ await userApi.postContact({ alias: alias || undefined, pay_uri: payUri || undefined }, opts);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/`(app)/me/settings/contacts/page.tsx around lines 95 - 108, handleAdd
currently relies only on input maxLength but still posts whatever state holds;
add a defensive submit-time validation inside the handleAdd function to check
addAlias.length <= ALIAS_MAX_LENGTH and addPayUri.length <= PAY_URI_MAX_LENGTH
before calling postContact. If either check fails, prevent submission (return
early) and surface a user-friendly error (e.g., set an error state or show a
toast) so invalid values are not sent to postContact; keep the checks aligned to
the existing ALIAS_MAX_LENGTH and PAY_URI_MAX_LENGTH constants and update any
existing error handling/state used for other form errors.
Summary
maxLengthlimits to the contacts alias and pay URI inputsTesting
npm run build(fails due pre-existing unrelated parse errors inapp/(app)/lending/page.tsx:725andapp/(app)/send/page.tsx:203)Summary by CodeRabbit