-
Notifications
You must be signed in to change notification settings - Fork 13
format ethereum address in social previews #917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe change updates the API route handler to import and use the Changes
Possibly related PRs
Suggested reviewers
✨ Finishing Touches
🧪 Generate Unit Tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/app/api/og/route.tsx
(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/app/api/og/route.tsx (1)
src/utils/general.utils.ts (1)
printableAddress
(57-60)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Deploy-Preview
🔇 Additional comments (1)
src/app/api/og/route.tsx (1)
10-10
: Verify barrel export path forprintableAddress
.
printableAddress
lives insrc/utils/general.utils.ts
.
This import assumes thatsrc/utils/index.ts
(aliased as@/utils
) re-exports it; otherwise the build will fail with “export not found”.
Please confirm the barrel is in place or import directly from@/utils/general.utils
.
const username = | ||
searchParams.get('username')!.length > 12 | ||
? printableAddress(searchParams.get('username')!) | ||
: searchParams.get('username')! // username will always exist. If it doesn't, page will 404 + format the length if its too long/an ethereum address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Eliminate duplicate searchParams.get()
calls and add null-safety.
searchParams.get('username')
is invoked three times and is blindly asserted non-null (!
).
A missing param would throw at runtime before your 404 logic can run.
- const username =
- searchParams.get('username')!.length > 12
- ? printableAddress(searchParams.get('username')!)
- : searchParams.get('username')!
+ const rawUsername = searchParams.get('username')
+ if (!rawUsername) {
+ return new NextResponse('Missing "username" query param', { status: 400 })
+ }
+ const username =
+ rawUsername.length > 12 ? printableAddress(rawUsername) : rawUsername
This removes redundant look-ups, guards against null
, and keeps the formatting logic unchanged.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const username = | |
searchParams.get('username')!.length > 12 | |
? printableAddress(searchParams.get('username')!) | |
: searchParams.get('username')! // username will always exist. If it doesn't, page will 404 + format the length if its too long/an ethereum address | |
const rawUsername = searchParams.get('username') | |
if (!rawUsername) { | |
return new NextResponse('Missing "username" query param', { status: 400 }) | |
} | |
const username = | |
rawUsername.length > 12 ? printableAddress(rawUsername) : rawUsername |
🤖 Prompt for AI Agents
In src/app/api/og/route.tsx around lines 48 to 51, the code calls
searchParams.get('username') multiple times and uses non-null assertions,
risking runtime errors if the parameter is missing. To fix this, store the
result of searchParams.get('username') in a variable once, check if it is null
before proceeding, and then apply the length check and formatting logic on this
variable. This eliminates redundant calls and adds null-safety while preserving
the existing behavior.
one liner that fixes: https://www.notion.so/peanutprotocol/Feat-shorter-address-on-preview-21483811757980aab7bef5a6bb319567
social previews still have some work to do, but any changes/improvements are agnostic to this simple modification, so we can still merge it