feat: use url params as fallback for available_routes tracking event#2848
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughWidgetTrackingProvider now reads URL params into a stable ref, resolves tokens for a USD fallback, computes fromAmount/fromAmountUSD fallbacks in availableRoutes, updates the amount comparison guard, and emits selected-or-URL token/chain fields plus computed amounts in routes_available events. ChangesURL-Based Tracking Parameters
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
✅ All snapshot tests passed |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/providers/WidgetTrackingProvider.tsx (1)
12-12: ⚡ Quick winUse the repo alias for the new hook import.
This new import should use
@/hooks/useTokento stay consistent with the repo alias convention.♻️ Suggested change
-import { useToken } from 'src/hooks/useToken'; +import { useToken } from '@/hooks/useToken';As per coding guidelines, "Prefer
@/oversrc/path aliases in new code (both resolve to./src/)."🤖 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 `@src/providers/WidgetTrackingProvider.tsx` at line 12, Update the import in WidgetTrackingProvider to use the repository alias: replace the current import of useToken from 'src/hooks/useToken' with the alias import from '@/hooks/useToken' so that the hook usage (useToken) remains the same but follows the repo alias convention.
🤖 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 `@src/providers/WidgetTrackingProvider.tsx`:
- Around line 132-146: The fallback USD amount stored in
fromAmountUSDFallback.current can become stale because useToken
(sourceTokenData) updates don't trigger a re-render when
sourceChainToken.current is mutated, which prevents availableRoutes from being
re-fired due to the isRoutesForCurrentFromAmountTracked guard; fix by making the
fallback reactive or resetting the tracking flag when token price changes:
either convert fromAmountUSDFallback into state (e.g., setFromAmountUSDFallback
derived from sourceTokenData, urlParams.fromAmount and formatTokenPrice) so
updates re-render and retrigger availableRoutes, or ensure you call
isRoutesForCurrentFromAmountTracked.current = false (or equivalent) when
sourceTokenData?.priceUSD changes so availableRoutes will re-run with the
corrected USD value.
---
Nitpick comments:
In `@src/providers/WidgetTrackingProvider.tsx`:
- Line 12: Update the import in WidgetTrackingProvider to use the repository
alias: replace the current import of useToken from 'src/hooks/useToken' with the
alias import from '@/hooks/useToken' so that the hook usage (useToken) remains
the same but follows the repo alias convention.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1260fe82-d583-4838-852b-5cb0f468fdb7
📒 Files selected for processing (1)
src/providers/WidgetTrackingProvider.tsx
Playwright test resultsDetails
Failed testschromium › earnPage.spec.ts › Analytics filters on Earn page › Should be able to verify analytics buttons are visible (Qase ID: 47) Skipped testschromium › themeManipulation.spec.ts › Switch between dark and light theme and check the background color › Partner theme should appear in theme menu and apply background color (Qase ID: 49) |
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 `@src/providers/WidgetTrackingProvider.tsx`:
- Line 13: Update the import in WidgetTrackingProvider.tsx to use the project
path alias: change the import of the hook useTokens from "src/hooks/useTokens"
to use "@/hooks/useTokens" (i.e. replace the "src/" prefix with "@/") so the
file follows the coding guideline; ensure any other occurrences in this file or
adjacent imports are updated similarly to remain consistent with the alias
convention.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f6809731-5055-4ff0-a476-e8965dba90b8
📒 Files selected for processing (1)
src/providers/WidgetTrackingProvider.tsx
| import { useWidgetEvents } from '@lifi/widget'; | ||
| import { formatTokenPrice, useWidgetEvents } from '@lifi/widget'; | ||
| import type { Address } from 'viem'; | ||
| import { useTokens } from 'src/hooks/useTokens'; |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Use @/ path alias instead of src/.
As per coding guidelines, prefer @/ over src/ path aliases in new code.
Proposed fix
-import { useTokens } from 'src/hooks/useTokens';
+import { useTokens } from '@/hooks/useTokens';📝 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.
| import { useTokens } from 'src/hooks/useTokens'; | |
| import { useTokens } from '@/hooks/useTokens'; |
🤖 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 `@src/providers/WidgetTrackingProvider.tsx` at line 13, Update the import in
WidgetTrackingProvider.tsx to use the project path alias: change the import of
the hook useTokens from "src/hooks/useTokens" to use "@/hooks/useTokens" (i.e.
replace the "src/" prefix with "@/") so the file follows the coding guideline;
ensure any other occurrences in this file or adjacent imports are updated
similarly to remain consistent with the alias convention.
Which Jira task belongs to this PR?
Closes https://linear.app/lifi-linear/issue/JUM-898/add-sending-amount-usd-property-to-action-available-routes-posthog
Why did I implement it this way?
Checklist before requesting a review
Summary by CodeRabbit