Skip to content

feat: use url params as fallback for available_routes tracking event#2848

Merged
mmioana merged 2 commits into
developfrom
feature/jum-898-add-sending_amount_usd-property-to-action_available_routes
May 8, 2026
Merged

feat: use url params as fallback for available_routes tracking event#2848
mmioana merged 2 commits into
developfrom
feature/jum-898-add-sending_amount_usd-property-to-action_available_routes

Conversation

@mmioana
Copy link
Copy Markdown
Contributor

@mmioana mmioana commented May 7, 2026

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

  • I have performed a self-review of my code
  • This pull request is as small as possible and only tackles one problem
  • I have added tests that cover the functionality / test the bug
  • If this changed the API, I have updated the documentation
  • I have provided QA instructions for the feature / fix implemented in this PR (if applicable)
  • I have provided instructions for any environment / deployment changes that this PR needs when merged

Summary by CodeRabbit

  • Refactor
    • Improved widget tracking accuracy and stability by eliminating stale parameter references in event callbacks.
    • Enhanced URL-parameter handling so token/chain selections and quoted amounts (including USD equivalents) are reported more consistently and reliably in tracking events.

@mmioana mmioana self-assigned this May 7, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
jumper-exchange Ready Ready Preview, Comment May 7, 2026 0:17am
jumper-exchange-storybook Ready Ready Preview, Comment May 7, 2026 0:17am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

Walkthrough

WidgetTrackingProvider 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.

Changes

URL-Based Tracking Parameters

Layer / File(s) Summary
Dependencies & Imports
src/providers/WidgetTrackingProvider.tsx
Added useUrlParams import to enable URL-parameter sourcing inside the provider.
State Management & Token Lookup
src/providers/WidgetTrackingProvider.tsx
Introduced urlParams via useUrlParams, added urlParamsRef synchronized from urlParams, and obtained getToken from useTokens() for USD conversion fallback.
Available Routes Callback
src/providers/WidgetTrackingProvider.tsx
Reworked availableRoutes to derive from/to token and chain from selected refs with URL fallback, compute fromAmount fallback (first route or URL), and compute fromAmountUSD from route value or token-price-based conversion.
Amount Comparison Guard
src/providers/WidgetTrackingProvider.tsx
Updated the “current from amount” tracking guard to compare against the newly computed fromAmount rather than the first route’s raw value.
Tracking Event Payload
src/providers/WidgetTrackingProvider.tsx
Changed routes_available event payload to source FromToken/FromChainId/ToToken/ToChainId from selected refs or URL params and to emit the computed fromAmountUSD/fromAmount.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble URLs and stash their seeds,
Keep refs alive to banish stale deeds,
Tokens priced, amounts kissed by math,
Events hop out on the correct path!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: use url params as fallback for available_routes tracking event' accurately summarizes the main change: using URL parameters as a fallback source for the tracking event payload, which is the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/jum-898-add-sending_amount_usd-property-to-action_available_routes

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

✅ All snapshot tests passed

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a 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

🧹 Nitpick comments (1)
src/providers/WidgetTrackingProvider.tsx (1)

12-12: ⚡ Quick win

Use the repo alias for the new hook import.

This new import should use @/hooks/useToken to 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 @/ over src/ 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

📥 Commits

Reviewing files that changed from the base of the PR and between e173ebb and 1dcbbbb.

📒 Files selected for processing (1)
  • src/providers/WidgetTrackingProvider.tsx

Comment thread src/providers/WidgetTrackingProvider.tsx Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Playwright test results

failed  2 failed
passed  54 passed
skipped  1 skipped

Details

stats  57 tests across 11 suites
duration  12 minutes, 27 seconds
commit  97adddf

Failed tests

chromium › earnPage.spec.ts › Analytics filters on Earn page › Should be able to verify analytics buttons are visible (Qase ID: 47)
chromium › landingPage.spec.ts › Landing page and navigation › Should navigate to the homepage and change tabs (Qase ID: 2)

Skipped tests

chromium › 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)

📋 View Detailed Qase Report

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a 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

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1dcbbbb and 97adddf.

📒 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';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ 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.

Suggested change
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.

@mmioana mmioana merged commit 783f227 into develop May 8, 2026
17 of 18 checks passed
@mmioana mmioana deleted the feature/jum-898-add-sending_amount_usd-property-to-action_available_routes branch May 8, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants