Skip to content

fix/PRO-3299/add-params-portfolio-endpoint#303

Merged
RanaBug merged 2 commits intostagingfrom
fix/PRO-3299/add-params-portfolio-endpoint
May 9, 2025
Merged

fix/PRO-3299/add-params-portfolio-endpoint#303
RanaBug merged 2 commits intostagingfrom
fix/PRO-3299/add-params-portfolio-endpoint

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented May 9, 2025

Description

  • Add parameters to the walletPortfolio Mobula's endpoint

How Has This Been Tested?

  • Unit tests and manual testing

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • New Features
    • Enhanced wallet portfolio queries to support filtering by selected blockchains and include options for unlisted assets, spam filtering, and profit/loss data.
  • Improvements
    • Updated token search and market data filters to use blockchain IDs instead of blockchain names for more consistent filtering across the app.

@RanaBug RanaBug requested a review from IAmKio May 9, 2025 14:27
@RanaBug RanaBug self-assigned this May 9, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 9, 2025

Walkthrough

The internal logic for constructing the POST request body in the getWalletPortfolio endpoint was updated. New parameters—blockchains, unlistedAssets, filterSpam, and pnl—are now included in the query. Additionally, several components and services that query tokens or token market data replaced the use of a chain ID to chain name mapping function with direct string conversions of chain IDs. No changes were made to exported or public function signatures.

Changes

File(s) Change Summary
src/services/pillarXApiWalletPortfolio.ts Extended POST request body for getWalletPortfolio with new parameters: blockchains, unlistedAssets, filterSpam, and pnl. No changes to public APIs.
src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx Changed filterBlockchains argument in useGetSearchTokensQuery from `chain
src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx Removed import of chainIdToChainNameTokensData; replaced filterBlockchains with string conversion of receiveChain.chainId or undefined if zero.
src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx Removed import of chainIdToChainNameTokensData; replaced filterBlockchains with string conversion of selectedChain.chainId or undefined if zero.
src/apps/token-atlas/index.tsx Removed import of chainIdToChainNameTokensData; replaced all usages with direct string conversions of chain IDs in token market data and search queries.
src/services/pillarXApiSearchTokens.ts Removed import of chainIdToChainNameTokensData; changed blockchains filter from chain names to raw chain ID strings in the request body.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant getWalletPortfolio
    participant API

    Caller->>getWalletPortfolio: Call with parameters
    getWalletPortfolio->>getWalletPortfolio: Build request body with new params (blockchains, unlistedAssets, filterSpam, pnl)
    getWalletPortfolio->>API: POST /getWalletPortfolio (with extended body)
    API-->>getWalletPortfolio: Respond with portfolio data
    getWalletPortfolio-->>Caller: Return result
Loading

Suggested reviewers

  • IAmKio

Poem

In the warren of code, a hop and a leap,
New blockchains and flags in the data we keep.
Unlisted and spam, now filtered with care,
PnL insights, floating through digital air.
A bunny’s delight in each tidy request—
More carrots for queries, all handled with zest! 🥕

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Collaborator

@IAmKio IAmKio left a comment

Choose a reason for hiding this comment

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

LGTM

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 9, 2025

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2bc9016
Status: ✅  Deploy successful!
Preview URL: https://f44281ee.x-e62.pages.dev
Branch Preview URL: https://fix-pro-3299-add-params-port.x-e62.pages.dev

View logs

Copy link
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: 0

🧹 Nitpick comments (1)
src/services/pillarXApiWalletPortfolio.ts (1)

71-73: Consider adding validation for empty chain names.

When mapping through the chain IDs, there's no handling for cases where chainIdToChainNameTokensData might return an empty string. This could lead to invalid comma-separated values like ", , Ethereum".

Consider filtering out empty strings before joining:

- blockchains: CompatibleChains.map((chain) =>
-   chainIdToChainNameTokensData(chain.chainId)
- ).join(', '),
+ blockchains: CompatibleChains.map((chain) =>
+   chainIdToChainNameTokensData(chain.chainId)
+ ).filter(Boolean).join(', '),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e6a1c6 and b0c94af.

⛔ Files ignored due to path filters (4)
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/TokenMarketDataRow/tests/__snapshots__/LeftColumnTokenMarketDataRow.test.tsx.snap is excluded by !**/*.snap
  • src/apps/pillarx-app/components/TokensWithMarketDataTile/test/__snapshots__/TokensWithMarketDataTile.test.tsx.snap is excluded by !**/*.snap
  • src/containers/__snapshots__/Main.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/services/pillarXApiWalletPortfolio.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/services/pillarXApiWalletPortfolio.ts (2)
src/utils/blockchain.ts (1)
  • CompatibleChains (260-289)
src/services/tokensData.ts (1)
  • chainIdToChainNameTokensData (213-234)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint
  • GitHub Check: unit-tests
  • GitHub Check: build
🔇 Additional comments (2)
src/services/pillarXApiWalletPortfolio.ts (2)

74-76: New feature flags enabled by default.

The code adds three new boolean parameters all set to 'true': unlistedAssets, filterSpam, and pnl. Since these are being enabled by default for all calls, verify that this behavior is intentional and won't cause unexpected side effects for existing functionality.

Is there a need for these parameters to be configurable rather than hardcoded to 'true'? Consider whether future use cases might require toggling these features.


71-77:

Details

❓ Verification inconclusive

Potential chain name inconsistency between declaration and usage.

The implementation adds new parameters to the wallet portfolio endpoint, which enhances the API's functionality. However, there's a potential inconsistency between the chain names defined in CompatibleChains and those returned by chainIdToChainNameTokensData:

  • ChainId 100: "Gnosis" vs "XDAI"
  • ChainId 10: "Optimism" vs "Optimistic"
  • ChainId 56: "BNB Smart Chain" vs "BNB Smart Chain (BEP20)"

Please verify that these chain names match what the backend API expects:


🏁 Script executed:

#!/bin/bash
# Compare chain names in CompatibleChains and chainIdToChainNameTokensData
echo "Comparing chain names in CompatibleChains and chainIdToChainNameTokensData:"

# Extract and compare for each chain ID
for chain_id in 1 137 8453 100 56 10 42161; do
  echo -n "Chain ID $chain_id: "
  name_in_compatible=$(rg "chainId: $chain_id" -A 1 | rg "chainName:" | head -1 | sed -E 's/.*chainName: .([^"]+).,.*/\1/')
  
  # Find the matching case in chainIdToChainNameTokensData
  name_in_function=$(rg "case $chain_id:" -A 1 src/services/tokensData.ts | rg "return" | head -1 | sed -E "s/.*return '([^']+)'.*/\1/")
  
  echo "CompatibleChains: \"$name_in_compatible\", chainIdToChainNameTokensData: \"$name_in_function\""
done

Length of output: 3783


I’d like to confirm the exact declarations for CompatibleChains and the 3 mappings in chainIdToChainNameTokensData. Running:


🏁 Script executed:

#!/bin/bash
set -eux

# 1) Find where CompatibleChains is defined and show its entries
echo "🔍 CompatibleChains declaration:"
rg -n "CompatibleChains" -n .
while IFS=: read -r file line _; do
  echo "---- $file (around line $line) ----"
  sed -n "$((line-3)),$((line+15))p" "$file"
done < <(rg -n "CompatibleChains" -n .)

# 2) Show mapping cases for chain IDs 10, 56, and 100
echo
for id in 10 56 100; do
  echo "🔍 chainIdToChainNameTokensData – case $id:"
  rg -n "case $id" -n src/services/tokensData.ts -C 2
done

Length of output: 4620


To accurately extract the declared CompatibleChains names and the exact mappings, let’s pull the full array block and the specific case statements:


🏁 Script executed:

#!/bin/bash
set -eux

# 1) Extract the CompatibleChains array from blockchain.ts
file="src/utils/blockchain.ts"
declaration_line=$(rg -n "export const CompatibleChains" -n "$file" | head -1 | cut -d: -f2)
echo "🔍 CompatibleChains declared at $file:$declaration_line"
sed -n "$((declaration_line-3)),$((declaration_line+60))p" "$file"

# 2) Show the chainIdToChainNameTokensData mappings for IDs 100, 56, and 10
for id in 100 56 10; do
  echo
  echo "🔍 Mapping in src/services/tokensData.ts – case $id"
  rg -n "case $id:" -C2 src/services/tokensData.ts
done

Length of output: 475


Confirm backend chain‐name expectations

The names returned by chainIdToChainNameTokensData don’t match the labels in CompatibleChains. Please verify which naming convention the wallet-portfolio endpoint expects and align both definitions accordingly:

• In src/utils/blockchain.ts – CompatibleChains declares:
– Chain ID 100 → “Gnosis”
– Chain ID 56 → “BNB Smart Chain”
– Chain ID 10 → “Optimism”

• In src/services/tokensData.ts – chainIdToChainNameTokensData maps:
– Chain ID 100 → “XDAI”
– Chain ID 56 → “BNB Smart Chain (BEP20)”
– Chain ID 10 → “Optimistic”

Action items:

  1. Confirm with the backend team which exact strings the API expects for these chains.
  2. Update either CompatibleChains or chainIdToChainNameTokensData (or both) so that they’re fully consistent.

@github-actions github-actions bot temporarily deployed to Preview (fix/PRO-3299/add-params-portfolio-endpoint) May 9, 2025 15:00 Inactive
@RanaBug RanaBug merged commit f116b07 into staging May 9, 2025
6 of 8 checks passed
Copy link
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: 0

🧹 Nitpick comments (2)
src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx (2)

62-62: Consider consistent handling of empty chain filters

While this change correctly uses the chain ID string directly, the handling of empty/undefined values differs from other components. Here you're using string interpolation with an empty fallback (${chain || ''}), while other components use undefined when no filter should be applied.

-      filterBlockchains: `${chain || ''}`,
+      filterBlockchains: chain || undefined,

1-154: Remaining chainIdToChainNameTokensData usages

This file still has usages of both chainIdToChainNameTokensData and chainNameToChainIdTokensData functions (lines 76 and 125-127) while the current PR is removing similar usages across the codebase. Consider updating these instances for consistency with the rest of the changes in this PR.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0c94af and 2bc9016.

📒 Files selected for processing (6)
  • src/apps/the-exchange/components/SwapReceiveCard/SwapReceiveCard.tsx (1 hunks)
  • src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx (1 hunks)
  • src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx (1 hunks)
  • src/apps/token-atlas/index.tsx (3 hunks)
  • src/services/pillarXApiSearchTokens.ts (1 hunks)
  • src/services/pillarXApiWalletPortfolio.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/services/pillarXApiWalletPortfolio.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/services/pillarXApiSearchTokens.ts (1)
src/utils/blockchain.ts (1)
  • CompatibleChains (260-289)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint
  • GitHub Check: unit-tests
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
src/services/pillarXApiSearchTokens.ts (1)

52-54: Good standardization of blockchain identifiers

This change correctly updates the code to use chain IDs directly rather than chain names, aligning with the broader standardization across the application.

src/apps/the-exchange/components/TokenSearchInput/TokenSearchInput.tsx (1)

92-93: Improved blockchain filtering approach

Good conversion to using direct chain IDs instead of mapped chain names for the filtering parameter. The conditional logic handles the case where no blockchain filter should be applied (when chainId is 0) by setting it to undefined.

src/apps/token-atlas/components/TokensSearchInput/TokensSearchInput.tsx (1)

71-72: Consistent chain ID filtering approach

This change correctly implements the same pattern for blockchain filtering as in the TokenSearchInput component, using the raw chain ID string instead of a mapped chain name when a filter should be applied.

src/apps/token-atlas/index.tsx (3)

141-141: Standardized blockchain parameter format

The change from using chain name mapping to direct string conversion of chain IDs aligns with the PR objective of standardizing blockchain parameters across the codebase.


155-155: Consistent use of string chain IDs

This change maintains consistency with other API calls by using string template literals for the chain ID.


171-171: Chain parameter formatting aligns with standard

The change to use template literals for chain IDs correctly handles the null/undefined case with fallback to empty string. This works well with the skip condition on line 173 that prevents API calls when both asset and chain are missing.

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