Skip to content
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

wallet-amount #925

Merged

Conversation

Bosun-Josh121
Copy link
Contributor

@Bosun-Josh121 Bosun-Josh121 commented Nov 3, 2024

Pull Request type

Please add the labels corresponding to the type of changes your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Testing
  • Other (please describe):

Resolves: #NA

Other information

Summary by CodeRabbit

  • New Features

    • Introduced a new balance management feature in the Profile Card, displaying the user's total balance fetched asynchronously.
    • Added functionality to calculate the total balance based on user tokens and their respective values.
  • Bug Fixes

    • Improved error handling during balance calculation to ensure robustness.
    • Enhanced loading experience with a skeleton display while fetching the user's total balance.
    • Refined error handling for task names in the AdminQuestDetails and QuestDetails components to ensure accurate messaging.

Copy link

vercel bot commented Nov 3, 2024

@Josh-121 is attempting to deploy a commit to the LFG Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Nov 3, 2024

Walkthrough

The changes involve the addition of a new state variable totalBalance in the profileCard.tsx component to manage and display a user's total balance fetched asynchronously from the argentPortfolioService. A new function calculateTotalBalance is introduced in the argentPortfolioService.ts file to compute the total value of user tokens based on their wallet address. The component's rendering logic is updated to reflect this new balance. Modifications are also made in the questDetails.tsx and questDetails.tsx components to improve error handling for task names, while adjustments in parser.ts streamline tile data processing.

Changes

File Change Summary
components/UI/profileCard/profileCard.tsx - Added state variable `totalBalance: number
services/argentPortfolioService.ts - Introduced asynchronous function `calculateTotalBalance(walletAddress: string, currency: "USD"
components/admin/questDetails.tsx - Updated logic for customError prop to use case-insensitive check for task names.
components/quests/questDetails.tsx - Refined logic for customError prop with case-insensitive check for task names.
utils/parser.ts - Removed null coalescing operators in calculations within buildTileData method, affecting tile data processing.

Possibly related PRs

  • feat: fetch data for "Portfolio by asset type" donut chart #920: The changes in services/argentPortfolioService.ts related to the calculateTotalBalance function and the new retry mechanism for data fetching are directly connected to the modifications in the main PR, as both involve fetching and calculating user token balances.

Suggested reviewers

  • Marchand-Nicolas

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 438d14f and 803a29f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • components/UI/profileCard/profileCard.tsx (5 hunks)
  • components/quests/questDetails.tsx (1 hunks)
  • services/argentPortfolioService.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/UI/profileCard/profileCard.tsx
  • components/quests/questDetails.tsx
🔇 Additional comments (3)
services/argentPortfolioService.ts (3)

28-28: LGTM! Improved error message format.

The enhanced error message now includes the response text, which will help with debugging API issues.


137-171: Well-implemented balance calculation with proper error handling!

Good practices observed:

  • Proper error handling at both function and loop levels
  • Correct handling of token decimals
  • AbortController support for cancellation
  • Detailed error logging

146-164: 🛠️ Refactor suggestion

Consider caching token info outside the loop.

The current implementation fetches token info for each token inside the loop. This could be optimized by fetching all token info once before the loop.

  try {
    const tokens = await fetchUserTokens(walletAddress, { signal }); // Fetch all tokens in wallet
+   const tokenInfo = await fetchTokens({ signal }); // Fetch once outside loop
    let totalBalance = 0;

    for (const token of tokens) {
      try {
-       const tokenInfo = await fetchTokens({ signal });
        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
        const adjustedBalance = Number(token.tokenBalance) / 10 ** decimals;

Additionally, consider implementing the parallel processing optimization from the previous review using Promise.all to improve performance further.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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

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 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
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: 4

🧹 Outside diff range and nitpick comments (2)
services/argentPortfolioService.ts (1)

85-87: Enhance error logging for better debugging.

While the error handling strategy is good, the error messages could be more informative by including additional context.

-        console.error(`Error calculating price for token ${token.tokenAddress}:`, err);
+        console.error(`Error calculating price for token ${token.tokenAddress} in wallet ${walletAddress}:`, err, {
+          tokenBalance: token.tokenBalance,
+          currency
+        });
-    console.error("Error calculating total balance:", err);
+    console.error(`Error calculating total balance for wallet ${walletAddress}:`, err, { currency });

Also applies to: 92-93

components/UI/profileCard/profileCard.tsx (1)

24-24: Consider using path aliases for better maintainability.

Instead of using relative paths with multiple levels (../../../), consider using path aliases (e.g., @services/argentPortfolioService) for better maintainability and readability.

-import { calculateTotalBalance } from '../../../services/argentPortfolioService';
+import { calculateTotalBalance } from '@services/argentPortfolioService';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a38ff87 and e5cfb8e.

📒 Files selected for processing (2)
  • components/UI/profileCard/profileCard.tsx (4 hunks)
  • services/argentPortfolioService.ts (1 hunks)
🔇 Additional comments (3)
services/argentPortfolioService.ts (2)

68-71: Function signature looks good!

The type definitions are well-structured with proper parameter typing and return type specification.


72-74: ⚠️ Potential issue

Add input validation and handle numerical precision.

When dealing with financial calculations, consider these security aspects:

  1. Validate wallet address format:
 try {
+    if (!/^0x[a-fA-F0-9]{63,64}$/.test(walletAddress)) {
+      throw new Error('Invalid StarkNet wallet address format');
+    }
     const tokens = await fetchUserTokens(walletAddress);
     let totalBalance = 0;
  1. Handle numerical precision:
-    let totalBalance = 0;
+    let totalBalance = 0n;  // Use BigInt for precise calculations
  1. Consider implementing rate limiting to prevent API abuse.

Let's verify the wallet address format used in the codebase:

components/UI/profileCard/profileCard.tsx (1)

24-24: Verify argentPortfolioService implementation and error handling.

Let's verify the implementation of the calculateTotalBalance function and its error handling capabilities.

Also applies to: 53-64

✅ Verification successful

Implementation and error handling are properly implemented

The calculateTotalBalance function is well-implemented with comprehensive error handling:

  • Properly handles API errors through the fetchData utility
  • Implements nested try-catch blocks to handle both overall balance calculation and individual token price calculation errors
  • Gracefully continues calculation even if individual token price calculations fail
  • Properly propagates critical errors while logging error details
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the implementation of calculateTotalBalance in argentPortfolioService

# Test 1: Verify the function implementation
echo "Checking calculateTotalBalance implementation..."
rg -A 10 "calculateTotalBalance.*=.*async" --type typescript

# Test 2: Check for error handling patterns
echo "Checking error handling patterns..."
rg "throw.*Error" --type typescript services/argentPortfolioService.ts

Length of output: 393


Script:

#!/bin/bash
# Let's try different approaches to locate and analyze the service

# Find the service file first
echo "Locating argentPortfolioService file..."
fd argentPortfolioService

# Search for calculateTotalBalance function with ripgrep without file type
echo "Searching for calculateTotalBalance implementation..."
rg -A 10 "calculateTotalBalance"

# Look for error handling patterns
echo "Checking error handling patterns..."
rg "throw.*Error" services

Length of output: 2782


Script:

#!/bin/bash
# Let's check the complete implementation and error handling in argentPortfolioService

# Get the full content of argentPortfolioService
echo "Getting full service implementation..."
cat services/argentPortfolioService.ts

# Check for try-catch blocks in the service
echo "Checking error handling patterns..."
rg -A 5 "try \{" services/argentPortfolioService.ts

Length of output: 4130

Comment on lines 76 to 84
for (const token of tokens) {
try {
// Calculate the price of each token and add it to the total balance
const tokenValue = await calculateTokenPrice(
token.tokenAddress,
token.tokenBalance,
currency
);
totalBalance += tokenValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize performance with parallel processing and caching.

The sequential API calls in the loop could be slow for wallets with many tokens. Consider these optimizations:

-    for (const token of tokens) {
-      try {
-        const tokenValue = await calculateTokenPrice(
-          token.tokenAddress,
-          token.tokenBalance,
-          currency
-        );
-        totalBalance += tokenValue;
+    const tokenPromises = tokens.map(token => 
+      calculateTokenPrice(token.tokenAddress, token.tokenBalance, currency)
+        .catch(err => {
+          console.error(`Error calculating price for token ${token.tokenAddress}:`, err);
+          return 0;
+        })
+    );
+    const tokenValues = await Promise.all(tokenPromises);
+    totalBalance = tokenValues.reduce((sum, value) => sum + value, 0);

Also, consider implementing a caching mechanism for token prices to reduce API calls:

  1. Cache token prices with a short TTL (e.g., 5 minutes)
  2. Implement rate limiting to avoid API throttling
  3. Consider batch price fetching if the API supports it

Committable suggestion skipped: line range outside the PR's diff.

components/UI/profileCard/profileCard.tsx Show resolved Hide resolved
@@ -108,7 +123,7 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
type={TEXT_TYPE.BODY_SMALL}
className={`${styles.wallet_amount} font-extrabold`}
>
$2,338.34
{totalBalance !== null ? `$${totalBalance.toFixed(2)}` : "Loading..."}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve balance display with better error handling and formatting.

The current implementation could be enhanced with:

  1. Error state display
  2. Proper number formatting for different locales
  3. Edge case handling for very large or small numbers
-{totalBalance !== null ? `$${totalBalance.toFixed(2)}` : "Loading..."}
+{balanceError ? (
+  <span className="text-red-500">{balanceError}</span>
+) : totalBalance !== null ? (
+  new Intl.NumberFormat('en-US', {
+    style: 'currency',
+    currency: 'USD',
+    minimumFractionDigits: 2,
+    maximumFractionDigits: 2
+  }).format(totalBalance)
+) : (
+  "Loading..."
+)}

Committable suggestion skipped: line range outside the PR's diff.

components/UI/profileCard/profileCard.tsx Outdated Show resolved Hide resolved
Copy link

vercel bot commented Nov 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 5, 2024 2:42pm

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

Screenshot 2024-11-03 at 10 19 34 PM It shows a really weird amount. You can test with my address: 0x05f1f8de723d8117daa26ec24320d0eacabc53a3d642acb0880846486e73283a

@Marchand-Nicolas Marchand-Nicolas added the ❌ Change request Change requested from reviewer label Nov 3, 2024
Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

One more comment;

Also, for the invalid computation, I suggest you to log all the tokens for my address and find which one(s) is wrong (or maybe the whole computation is).

@@ -108,7 +123,7 @@ const ProfileCard: FunctionComponent<ProfileCardProps> = ({
type={TEXT_TYPE.BODY_SMALL}
className={`${styles.wallet_amount} font-extrabold`}
>
$2,338.34
{totalBalance !== null ? `$${totalBalance.toFixed(2)}` : "Loading..."}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use a skeleton instead of "Loading..."

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e5cfb8e and 94fcd2d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • components/UI/profileCard/profileCard.tsx (5 hunks)
  • services/argentPortfolioService.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/UI/profileCard/profileCard.tsx
🔇 Additional comments (4)
services/argentPortfolioService.ts (4)

68-71: LGTM! Function signature is well-defined.

The function signature is consistent with the codebase patterns and has proper type constraints.


72-75: LGTM! Error handling is robust and well-structured.

The implementation properly handles errors at different levels:

  • Continues processing on token-level failures
  • Provides detailed error context
  • Maintains proper error propagation

Also applies to: 86-89, 91-95


76-85: Consider implementing the suggested performance optimizations.

The sequential processing of tokens could impact performance for wallets with many tokens.

The previous review comment about implementing parallel processing and caching is still applicable.


68-96: Verify error handling in the consuming component.

Let's ensure the profileCard component properly handles errors from this service.

✅ Verification successful

Error handling is properly implemented in the consuming component

The profileCard component has appropriate error handling for calculateTotalBalance:

  • Uses try-catch block around the service call
  • Logs errors appropriately with console.error
  • Gracefully handles errors by not updating state, which maintains the loading state (Skeleton) in the UI
  • Does not propagate errors to prevent component crashes
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check error handling in profileCard.tsx for calculateTotalBalance usage

# Test: Look for try-catch blocks around calculateTotalBalance calls
rg -A 5 "calculateTotalBalance.*catch" --type tsx

Length of output: 79


Script:

#!/bin/bash
# First, let's find the profile card component file
fd -e tsx -e ts "profileCard"

# Then, let's search for calculateTotalBalance usage in all TypeScript files
rg -t ts -t typescript "calculateTotalBalance" -A 5

Length of output: 203


Script:

#!/bin/bash
# Let's examine the profile card component content
cat components/UI/profileCard/profileCard.tsx

# Also search for calculateTotalBalance usage with ripgrep without file type specification
rg "calculateTotalBalance" -A 5

Length of output: 8517

services/argentPortfolioService.ts Outdated Show resolved Hide resolved
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
services/argentPortfolioService.ts (1)

33-38: LGTM! Well-structured API implementations with proper typing.

The implementations are clean, type-safe, and follow consistent patterns. However, consider implementing rate limiting for these API calls to prevent potential throttling issues.

Consider implementing a rate limiter utility to manage API request frequency:

class RateLimiter {
  private queue: Array<() => Promise<any>> = [];
  private processing = false;
  private lastCallTime = 0;
  private minInterval: number;

  constructor(requestsPerSecond: number) {
    this.minInterval = 1000 / requestsPerSecond;
  }

  async enqueue<T>(fn: () => Promise<T>): Promise<T> {
    return new Promise((resolve, reject) => {
      this.queue.push(async () => {
        try {
          resolve(await fn());
        } catch (error) {
          reject(error);
        }
      });
      this.process();
    });
  }

  private async process() {
    if (this.processing) return;
    this.processing = true;
    
    while (this.queue.length > 0) {
      const now = Date.now();
      const waitTime = Math.max(0, this.lastCallTime + this.minInterval - now);
      await new Promise(resolve => setTimeout(resolve, waitTime));
      
      const fn = this.queue.shift();
      if (fn) {
        this.lastCallTime = Date.now();
        await fn();
      }
    }
    
    this.processing = false;
  }
}

Also applies to: 42-47, 51-53, 58-60, 69-71

🛑 Comments failed to post (2)
services/argentPortfolioService.ts (2)

91-93: ⚠️ Potential issue

Optimize token info fetching to prevent memory leaks.

The fetchTokens call inside the loop could lead to memory issues and unnecessary API calls. Consider fetching token info once before the loop.

  try {
    const tokens = await fetchUserTokens(walletAddress);
+   const tokenInfo = await fetchTokens(); // Fetch once before loop
    let totalBalance = 0;

    for (const token of tokens) {
      try {
-       const tokenInfo = await fetchTokens();
        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
📝 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 tokenInfo = await fetchTokens();
        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
        const adjustedBalance = Number(token.tokenBalance) / 10 ** decimals;

88-106: 🛠️ Refactor suggestion

Consider parallel processing for better performance.

The sequential processing of tokens could be slow for wallets with many tokens. Consider using Promise.all for parallel processing.

-    for (const token of tokens) {
-      try {
-        const tokenInfo = await fetchTokens();
-        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
-        const adjustedBalance = Number(token.tokenBalance) / 10 ** decimals;
-        const tokenValue = await calculateTokenPrice(
-          token.tokenAddress,
-          adjustedBalance.toString(),
-          currency
-        );
-        totalBalance += tokenValue;
-      } catch (err) {
-        console.error(
-          `Error calculating price for token ${token.tokenAddress}:`,
-          err
-        );
-      }
-    }
+    const tokenInfo = await fetchTokens();
+    const tokenPromises = tokens.map(async (token) => {
+      try {
+        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
+        const adjustedBalance = Number(token.tokenBalance) / 10 ** decimals;
+        return await calculateTokenPrice(
+          token.tokenAddress,
+          adjustedBalance.toString(),
+          currency
+        );
+      } catch (err) {
+        console.error(`Error calculating price for token ${token.tokenAddress}:`, err);
+        return 0;
+      }
+    });
+    
+    const tokenValues = await Promise.all(tokenPromises);
+    totalBalance = tokenValues.reduce((sum, value) => sum + value, 0);
📝 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 tokenInfo = await fetchTokens();
    const tokenPromises = tokens.map(async (token) => {
      try {
        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
        const adjustedBalance = Number(token.tokenBalance) / 10 ** decimals;
        return await calculateTokenPrice(
          token.tokenAddress,
          adjustedBalance.toString(),
          currency
        );
      } catch (err) {
        console.error(`Error calculating price for token ${token.tokenAddress}:`, err);
        return 0;
      }
    });
    
    const tokenValues = await Promise.all(tokenPromises);
    totalBalance = tokenValues.reduce((sum, value) => sum + value, 0);

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: 1

🧹 Outside diff range and nitpick comments (3)
services/argentPortfolioService.ts (1)

33-38: LGTM! Well-structured API functions with proper typing.

The refactored functions provide good type safety and efficient data transformations. Consider adding specific error types for better error handling across the service.

// Add at the top of the file
class ArgentAPIError extends Error {
  constructor(public status?: number, message?: string) {
    super(message);
    this.name = 'ArgentAPIError';
  }
}

Also applies to: 42-47, 51-53, 58-60, 69-71

components/admin/questDetails.tsx (1)

177-177: LGTM! The case-insensitive check improves robustness.

The change to use toLowerCase() makes the Discord task detection more reliable by handling different case variations.

Consider extracting "discord" as a constant to improve maintainability:

+const DISCORD_TASK_IDENTIFIER = "discord";
+
 const AdminQuestDetails: FunctionComponent<QuestDetailsProps> = ({
   // ...
   customError={
-    task?.name?.toLowerCase().includes("discord")
+    task?.name?.toLowerCase().includes(DISCORD_TASK_IDENTIFIER)
       ? customError
       : ""
   }
components/quests/questDetails.tsx (1)

382-382: LGTM! Consider adding null/undefined check for better safety.

The change to use case-insensitive comparison for Discord task error handling is a good improvement. However, we can make it even more robust by adding a null/undefined check.

Consider this safer version:

-                    task?.name?.toLowerCase().includes("discord")
+                    task?.name?.toLowerCase?.()?.includes("discord") ?? false

This ensures the code handles cases where toLowerCase() might not be available (e.g., if name is unexpectedly not a string).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7d6ada3 and 92109f1.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • components/UI/profileCard/profileCard.tsx (5 hunks)
  • components/admin/questDetails.tsx (1 hunks)
  • components/quests/questDetails.tsx (1 hunks)
  • services/argentPortfolioService.ts (3 hunks)
  • utils/parser.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/UI/profileCard/profileCard.tsx
🔇 Additional comments (5)
services/argentPortfolioService.ts (3)

23-23: LGTM! Enhanced error handling.

The improved error message now includes both the status code and response text, making debugging easier.


91-93: LGTM! Proper handling of token decimals.

The implementation correctly handles different token decimal places by fetching token info and using the appropriate decimal value.


88-106: 🛠️ Refactor suggestion

Optimize token info fetching.

The current implementation fetches token info inside the loop, which could lead to unnecessary API calls and potential performance issues.

Consider fetching all token info once before the loop:

  try {
    const tokens = await fetchUserTokens(walletAddress);
+   const tokenInfo = await fetchTokens(); // Fetch once outside the loop
    let totalBalance = 0;

    for (const token of tokens) {
      try {
-       const tokenInfo = await fetchTokens();
        const decimals = tokenInfo[token.tokenAddress]?.decimals ?? 18;
        const adjustedBalance = Number(token.tokenBalance) / 10 ** decimals;

Additionally, the previous review comment about parallel processing using Promise.all() is still valid and worth considering for further optimization.

components/admin/questDetails.tsx (1)

Line range hint 1-248: Verify PR scope and title.

The PR is titled "wallet-amount" and the AI summary mentions wallet balance changes, but the code changes in this file only improve Discord task error handling. This suggests there might be additional changes not included in this review or the PR title might need updating.

Let's check for wallet-related changes in the codebase:

utils/parser.ts (1)

125-128: LGTM! Simplified sprite calculations.

The removal of null coalescing operators is safe here since the tileset existence is already validated by the guard clause above.

utils/parser.ts Show resolved Hide resolved
Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

It doesn't retry long enough (It can take like 10 seconds for the requests to start working, or even more) you need to retry much longer (indefinitely ?)

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

Lgtm!

@Marchand-Nicolas Marchand-Nicolas merged commit 3d38044 into lfglabs-dev:testnet Nov 5, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❌ Change request Change requested from reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants