Skip to content

fix: render token details for peanut wallet#653

Merged
kushagrasarathe merged 3 commits intopeanut-walletfrom
fix/no-token-pw
Jan 30, 2025
Merged

fix: render token details for peanut wallet#653
kushagrasarathe merged 3 commits intopeanut-walletfrom
fix/no-token-pw

Conversation

@kushagrasarathe
Copy link
Copy Markdown
Contributor

@kushagrasarathe kushagrasarathe commented Jan 30, 2025

  • fixes TASK-8400 where tokens were not rendered for penaut wallet even if a user has balance in wallet
  • also fixes TASK-8399 where disconnect button would appear on all wallet pages, independent of the connection status

Summary by CodeRabbit

  • New Features

    • Enhanced wallet details page with improved connection logic.
    • Added support for displaying token details across different wallet types.
  • Improvements

    • Simplified wallet connection and balance rendering.
    • Made list item view component more flexible by making details prop optional.
  • Technical Updates

    • Introduced new constants for wallet token information, including the new token name.
    • Updated import and constant management for wallet-related configurations.

- fixes TASK-8400 where tokens were not rendered for penaut wallet even if a user has balance in wallet
- also fixes TASK-8399 where disconnect button would appear on all wallet pages, independent of the connection status
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 30, 2025

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

Name Status Preview Comments Updated (UTC)
peanut-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 30, 2025 3:10pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 30, 2025

Walkthrough

This pull request introduces changes to wallet management and UI components. The primary modifications occur in the WalletDetailsPage component, where wallet connection logic is simplified and enhanced. A new renderTokenDetails function is added to improve balance rendering, and the ListItemView component's props are made more flexible by making the details property optional. Additionally, a new constant PEANUT_WALLET_TOKEN_NAME is introduced in the ZeroDev constants file.

Changes

File Change Summary
src/app/(mobile-ui)/wallet/page.tsx - Added renderTokenDetails function
- Introduced useWalletConnection hook
- Updated wallet connection logic
- Added isPeanutWallet and isConnected variables
- Updated variable sources for wallets, focusedWallet, and disconnect
src/components/Global/ListItemView/index.tsx - Made details prop optional in ListItemViewProps interface
src/constants/zerodev.consts.ts - Added new constant PEANUT_WALLET_TOKEN_NAME = 'USDC'
- Reordered import statements
- Updated position of PEANUT_WALLET_TOKEN_DECIMALS

Possibly related PRs

Suggested reviewers

  • jjramirezn

Poem

🐰 A Wallet's Tale, Hopping Free

With connections swift and logic clear,
Our code now dances without fear.
Tokens bounce and wallets gleam,
In this rabbit's coding dream! 🌟

Hop, hop, hooray! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@notion-workspace
Copy link
Copy Markdown

@notion-workspace
Copy link
Copy Markdown

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

🧹 Nitpick comments (2)
src/app/(mobile-ui)/wallet/page.tsx (2)

35-37: Consider using type guard instead of type assertion.

The type assertion as IWallet in isWalletConnected(walletDetails as IWallet) could be unsafe. Consider using a type guard to ensure type safety.

-const isConnected = isWalletConnected(walletDetails as IWallet)
+const isConnected = walletDetails ? isWalletConnected(walletDetails) : false

48-102: Consider extracting common rendering logic and improving type safety.

While the function successfully addresses the token rendering issue, there are a few improvements that could be made:

  1. Extract common JSX structure to reduce duplication:
const BalanceSection = ({ title, children }: { title: string; children: React.ReactNode }) => (
  <div className="space-y-3">
    <div className="text-base font-semibold">Balance</div>
    <div className="border border-b-n-1">
      {children}
    </div>
  </div>
);
  1. Consider using constants for magic numbers in formatting:
const DECIMAL_PLACES = 2;
const formatValue = (value: number) => value.toFixed(DECIMAL_PLACES);
  1. Add early return type guard:
-if (!walletDetails) return null;
+if (!walletDetails || typeof walletDetails !== 'object') return null;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62e284c and e6ac588.

📒 Files selected for processing (1)
  • src/app/(mobile-ui)/wallet/page.tsx (3 hunks)
🔇 Additional comments (3)
src/app/(mobile-ui)/wallet/page.tsx (3)

3-21: LGTM! Clean import organization.

The new imports for wallet-related constants, types, and hooks are well-organized and align with the component's requirements.


128-129: Verify if top-up should be disabled.

The top-up button is hardcoded as disabled. Is this intentional or should it be conditionally disabled based on wallet state?


134-143: LGTM! Clean implementation of connect/disconnect button.

The conditional rendering and state management for the connect/disconnect button effectively addresses TASK-8399. The implementation properly handles the visibility based on wallet type and connection status.

() => wallets.find((wallet) => wallet.address === focusedWallet),
[focusedWallet, wallets]
)
const walletDetails = wallets.find((wallet) => wallet.address === focusedWallet)
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.

Nit: why wallet.address is the id in this case? accountId from BE would be better imo. Then again we also have accountIdentifier in Backend, so address works kinda too. But the var names should be renamed if we add banking accounts to selectable accounts

}}
metadata={{
tokenLogo: ARBITRUM_ICON,
subText: `${formatAmount(formatUnits(walletDetails.balance, PEANUT_WALLET_TOKEN_DECIMALS))} USDC`,
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.

I still hate formatAmount(formatUnits)

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.

formatformatformat

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ouch, this one can be fixed, my baddd, mee dummbbb

Copy link
Copy Markdown
Contributor

@Hugo0 Hugo0 left a comment

Choose a reason for hiding this comment

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

small pr, see no major issue. pls review comments and ping on discord if any answer

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

🔭 Outside diff range comments (1)
src/constants/zerodev.consts.ts (1)

Environment variables documentation is missing

The environment variables are properly used in the code, but there's a critical documentation gap:

  • README mentions copying .env.example, but the file is missing from the repository
  • ZeroDev environment variables are not documented anywhere in the codebase
  • No setup instructions for these required environment variables

Please:

  1. Create an .env.example file documenting all required environment variables
  2. Add setup instructions for ZeroDev-specific variables in the README or documentation
  3. Include the source/documentation for obtaining these values from the ZeroDev dashboard
🔗 Analysis chain

Line range hint 4-11: Verify environment variables are properly configured.

The configuration follows security best practices by using environment variables. Please ensure these environment variables are properly set in your deployment environment:

  • NEXT_PUBLIC_ZERO_DEV_BUNDLER_URL
  • NEXT_PUBLIC_ZERO_DEV_PAYMASTER_URL
  • NEXT_PUBLIC_ZERO_DEV_PASSKEY_SERVER_URL
  • NEXT_PUBLIC_ZERO_DEV_PASSKEY_PROJECT_ID
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if environment variables are documented in README or .env.example

echo "Checking for environment variables documentation..."
rg -l "NEXT_PUBLIC_ZERO_DEV_(BUNDLER|PAYMASTER|PASSKEY)" --type md
fd -e example -e sample -x rg "NEXT_PUBLIC_ZERO_DEV_(BUNDLER|PAYMASTER|PASSKEY)"

Length of output: 264


Script:

#!/bin/bash
# Search for all occurrences of ZeroDev environment variables
echo "Searching for ZeroDev environment variables usage..."
rg "NEXT_PUBLIC_ZERO_DEV_(BUNDLER|PAYMASTER|PASSKEY)" -l

echo -e "\nChecking for .env files..."
fd -H "^\.env" --type f

echo -e "\nChecking for configuration files..."
fd -e json -e js -e ts -e yaml -e yml --type f -d 1

Length of output: 730


Script:

#!/bin/bash
echo "Checking next.config.js for environment configuration..."
cat next.config.js

echo -e "\nChecking README.md for setup instructions..."
if [ -f README.md ]; then
    cat README.md
fi

echo -e "\nChecking for documentation in docs directory..."
fd -t d "^docs$"

Length of output: 8202


Script:

#!/bin/bash
echo "Searching for environment example files (case insensitive)..."
fd -I "env.example|env.sample" --type f

echo -e "\nChecking docs directory for environment setup..."
fd . docs/ -t f -e md -e mdx | xargs cat

echo -e "\nChecking for any env-related files..."
fd -I "env" --type f

Length of output: 7770

🧹 Nitpick comments (1)
src/constants/zerodev.consts.ts (1)

16-16: Maintain consistent comment style.

For consistency with other comments in the file, add a space after //:

-export const PEANUT_WALLET_TOKEN_DECIMALS = 6 //USDC decimals
+export const PEANUT_WALLET_TOKEN_DECIMALS = 6 // USDC decimals
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e6ac588 and ea1acfc.

📒 Files selected for processing (2)
  • src/app/(mobile-ui)/wallet/page.tsx (3 hunks)
  • src/constants/zerodev.consts.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/(mobile-ui)/wallet/page.tsx
🧰 Additional context used
🪛 Gitleaks (8.21.2)
src/constants/zerodev.consts.ts

17-17: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (2)
src/constants/zerodev.consts.ts (2)

1-2: LGTM! Import statements are correctly defined.


16-18: Verify USDC contract address and decimals.

Please verify:

  1. The USDC contract address is correct for Arbitrum mainnet
  2. The decimals value matches the token's configuration
✅ Verification successful

✅ USDC configuration verified

The token configuration is correct and consistent:

  • Contract address matches Arbitrum USDC across multiple files
  • Decimals value of 6 is correct for USDC
  • Token name is consistently referenced
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify USDC contract details on Arbitrum

# Fetch contract details from Arbiscan API
curl -s "https://api.arbiscan.io/api?module=token&action=tokeninfo&contractaddress=0xaf88d065e77c8cc2239327c5edb3a432268e5831&apikey=YourApiKey" | jq '.result | {name, symbol, decimals}'

Length of output: 253


Script:

#!/bin/bash
# Search for USDC contract address usage
echo "=== Searching for USDC contract address ==="
rg -i "0xaf88d065e77c8cc2239327c5edb3a432268e5831" -A 2 -B 2

echo -e "\n=== Searching for USDC decimals configuration ==="
rg -i "decimals.*=.*6.*usdc" -A 2 -B 2

echo -e "\n=== Searching for USDC token configurations ==="
rg -i "usdc.*contract|contract.*usdc" -A 2 -B 2

Length of output: 1572

🧰 Tools
🪛 Gitleaks (8.21.2)

17-17: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

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