Skip to content

Conversation

jjramirezn
Copy link
Contributor

@jjramirezn jjramirezn commented Nov 28, 2024

Main changes

  • Refactor in wallet context to correctly handle wallet state

Other changes

  • Added some packages previously removed because they are peerDependencies
  • Removed duplicated element (possibly from conflict resolving)
  • Renamed areTokenAddressesEqual to areAdressesEqual (not only token addresses are compared)

QA info

Right now it should be possible to generate a request link, fulfill it and then generate a claim link with that balance.
IMPORTANT: right now the token must be manually selected, in a (near)future PR we will hide the token selector. Select USDC in arbitrum as token.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new logging utility for better log readability.
    • Enhanced wallet management functionality, including improved wallet connection checks.
  • Improvements

    • Updated address comparison logic across multiple components for consistency and robustness.
    • Enhanced error handling and messaging in various components to provide clearer feedback to users.
    • Improved API interaction and validation checks for user accounts and liquidation addresses.

These updates aim to improve user experience and streamline interactions within the application.

Copy link

vercel bot commented Nov 28, 2024

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 Dec 2, 2024 3:08pm

Copy link

Copy link
Contributor

coderabbitai bot commented Nov 28, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request updates the package.json file for the peanut-ui project by adding a new dependency, pino-pretty, for enhanced logging capabilities, and introduces several new development dependencies for testing. Additionally, it modifies multiple components across the codebase, primarily replacing the areTokenAddressesEqual function with areEvmAddressesEqual to standardize address comparison. This change affects error handling, user feedback, and address validation logic in various components, improving the robustness of user interactions.

Changes

File Path Change Summary
package.json Added dependency: "pino-pretty": "^13.0.0"; added development dependencies and removed outdated ones.
src/components/Claim/Link/Initial.view.tsx Replaced areTokenAddressesEqual with areEvmAddressesEqual, enhanced error handling, and updated control flow.
src/components/Create/Create.utils.ts Updated import from areTokenAddressesEqual to areEvmAddressesEqual in getTokenDetails.
src/components/Create/Link/Confirm.view.tsx Replaced areTokenAddressesEqual with areEvmAddressesEqual for token address comparisons.
src/components/Global/ImageGeneration/LinkPreview.tsx Updated to use areEvmAddressesEqual instead of areTokenAddressesEqual.
src/components/Global/TokenSelector/TokenSelector.tsx Replaced areTokenAddressesEqual with areEvmAddressesEqual in multiple areas for token address comparisons.
src/components/Profile/index.tsx Updated address comparisons in handleSiwe and rendering logic using areEvmAddressesEqual.
src/components/Request/Pay/Views/Initial.view.tsx Replaced areTokenAddressesEqual with areEvmAddressesEqual in cross-chain checks and token fetching logic.
src/components/Request/Pay/Views/Success.view.tsx Updated token address comparison logic to use areEvmAddressesEqual.
src/context/walletContext/walletContext.tsx Changed isPeanut parameter type, updated selected wallet logic, and added new functions for wallet management.
src/hooks/useBalance.tsx Renamed areTokenAddressesEqual to areEvmAddressesEqual in balance checks.
src/utils/cashout.utils.ts Updated getBridgeTokenName to use areEvmAddressesEqual, enhanced error handling in account functions.
src/utils/general.utils.ts Renamed areTokenAddressesEqual to areEvmAddressesEqual, updated references in various functions.
src/utils/token.utils.ts Replaced areTokenAddressesEqual with areEvmAddressesEqual in checkTokenSupportsXChain.

Possibly related PRs

🐇 In the code, I hop and play,
With addresses bright as day.
From token checks to logs so neat,
My changes make the project sweet!
With every line, I dance and cheer,
For clarity and joy are here! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9135117 and 91cde2f.

📒 Files selected for processing (13)
  • src/components/Claim/Link/Initial.view.tsx (3 hunks)
  • src/components/Create/Create.utils.ts (2 hunks)
  • src/components/Create/Link/Confirm.view.tsx (2 hunks)
  • src/components/Global/ImageGeneration/LinkPreview.tsx (1 hunks)
  • src/components/Global/TokenSelector/TokenSelector.tsx (5 hunks)
  • src/components/Profile/index.tsx (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (3 hunks)
  • src/components/Request/Pay/Views/Success.view.tsx (1 hunks)
  • src/context/walletContext/walletContext.tsx (3 hunks)
  • src/hooks/useBalance.tsx (3 hunks)
  • src/utils/cashout.utils.ts (1 hunks)
  • src/utils/general.utils.ts (3 hunks)
  • src/utils/token.utils.ts (2 hunks)

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.

@jjramirezn jjramirezn requested a review from Hugo0 November 28, 2024 23:08
@jjramirezn jjramirezn changed the title [TASK-7192] feat: send money with peanut-wallet [TASK-7192] [TASK-7193] feat: send money with peanut-wallet Nov 29, 2024
Copy link

@jjramirezn jjramirezn changed the title [TASK-7192] [TASK-7193] feat: send money with peanut-wallet [TASK-7159] [TASK-7192] [TASK-7193] feat: send money with peanut-wallet Nov 29, 2024
Copy link

@Hugo0
Copy link
Contributor

Hugo0 commented Dec 2, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Outside diff range and nitpick comments (5)
src/context/walletContext/walletContext.tsx (2)

71-79: Optimize by caching the default wallet instance

Currently, createDefaultDBWallet(wagmiAddress) is called twice, which is redundant. Caching the result in a variable can improve efficiency.

Apply this diff to cache the default wallet:

return wagmiAddress
    ? [
+       (() => {
+           const defaultWallet = createDefaultDBWallet(wagmiAddress);
            return {
-               ...createDefaultDBWallet(wagmiAddress),
+               ...defaultWallet,
-               connected: isWalletConnected(createDefaultDBWallet(wagmiAddress)),
+               connected: isWalletConnected(defaultWallet),
                balance: BigInt(0),
            };
+       })(),
    ]
    : []

119-120: Use areAddressesEqual for address comparisons

Direct string comparison of Ethereum addresses can lead to issues due to case sensitivity. Using areAddressesEqual ensures accurate, case-insensitive comparisons.

For line 119:

- const wallet = wallets.find((w) => w.address === selectedAddress)
+ const wallet = wallets.find((w) => areAddressesEqual(w.address, selectedAddress))

For line 140:

- const walletExists = wallets.some((wallet) => wallet.address === wagmiAddress)
+ const walletExists = wallets.some((wallet) => areAddressesEqual(wallet.address, wagmiAddress))

Also applies to: 140-141

package.json (1)

58-58: Move pino-pretty to devDependencies

pino-pretty is primarily used for development logging. Placing it in devDependencies prevents it from being included in the production build, reducing bundle size.

Apply this diff to move pino-pretty:

 "dependencies": {
     // other dependencies
-    "pino-pretty": "^13.0.0",
 },
 "devDependencies": {
     // other devDependencies
+    "pino-pretty": "^13.0.0",
 },
src/components/Request/Pay/Views/Success.view.tsx (1)

Line range hint 3-3: Consider adding tests for address comparison changes

The switch from areTokenAddressesEqual to areAddressesEqual spans across UI components and core functionality. Consider:

  1. Adding unit tests specifically for cross-chain scenarios
  2. Documenting the address comparison behavior in the codebase
  3. Adding integration tests for the payment processing flow

Also applies to: 14-14, 35-35, 56-56, 180-180

src/components/Claim/Link/Initial.view.tsx (1)

334-334: Consider extracting the hardcoded address

While the function rename is correct, consider extracting the hardcoded address 0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C used in the route finding logic into a named constant.

+ const DEFAULT_ROUTE_ADDRESS = '0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C'
...
-                        ? '0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C'
-                        : recipient.address || '0x04B5f21facD2ef7c7dbdEe7EbCFBC68616adC45C',
+                        ? DEFAULT_ROUTE_ADDRESS
+                        : recipient.address || DEFAULT_ROUTE_ADDRESS,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7f839be and b3fee6b.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • package.json (1 hunks)
  • src/components/Claim/Link/Initial.view.tsx (3 hunks)
  • src/components/Create/Create.utils.ts (2 hunks)
  • src/components/Create/Link/Confirm.view.tsx (2 hunks)
  • src/components/Global/ImageGeneration/LinkPreview.tsx (1 hunks)
  • src/components/Global/TokenSelector/TokenSelector.tsx (5 hunks)
  • src/components/Profile/index.tsx (1 hunks)
  • src/components/Request/Pay/Views/Initial.view.tsx (3 hunks)
  • src/components/Request/Pay/Views/Success.view.tsx (1 hunks)
  • src/context/walletContext/walletContext.tsx (3 hunks)
  • src/hooks/useBalance.tsx (3 hunks)
  • src/utils/cashout.utils.ts (1 hunks)
  • src/utils/general.utils.ts (3 hunks)
  • src/utils/token.utils.ts (2 hunks)
🧰 Additional context used
📓 Learnings (3)
src/components/Global/ImageGeneration/LinkPreview.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#460
File: src/components/Global/ImageGeneration/LinkPreview.tsx:125-128
Timestamp: 2024-11-12T09:39:20.720Z
Learning: 'tokenPrice' is not used currently and will be removed in future PRs.
src/components/Request/Pay/Views/Success.view.tsx (1)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#409
File: src/components/Request/Pay/Views/Success.view.tsx:23-23
Timestamp: 2024-11-12T09:39:20.720Z
Learning: In the `SuccessView` component, `transactionHash` remains constant because we are in a success view, so it's unnecessary to include it in the dependency array of `useEffect` hooks.
src/components/Request/Pay/Views/Initial.view.tsx (3)
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#422
File: src/components/Request/Pay/Views/Initial.view.tsx:67-74
Timestamp: 2024-11-12T09:39:20.720Z
Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, the functions `getDefaultProvider` and `getTokenContractDetails` used in `fetchTokenSymbol` do not throw errors but can return `undefined`. Additional error handling is unnecessary since this is already handled in the code.
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#410
File: src/components/Request/Pay/Views/Initial.view.tsx:87-93
Timestamp: 2024-11-12T09:39:20.720Z
Learning: When refactoring to eliminate code duplication, prioritize readability and consider whether the change significantly improves the code. If it doesn't enhance readability or maintainability, it's acceptable to keep the existing code structure.
Learnt from: jjramirezn
PR: peanutprotocol/peanut-ui#422
File: src/components/Request/Pay/Views/Initial.view.tsx:76-78
Timestamp: 2024-11-12T09:39:20.720Z
Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, both `txFee` and `utils.formatTokenAmount(estimatedGasCost, 3)` return strings, ensuring consistent return types for `calculatedFee`.
🔇 Additional comments (16)
src/utils/cashout.utils.ts (1)

444-444: LGTM

The change to use utils.areAddressesEqual improves address comparison accuracy.

src/utils/token.utils.ts (1)

1-1: LGTM

Replacing areTokenAddressesEqual with areAddressesEqual ensures consistent and accurate address comparisons.

Also applies to: 12-12, 19-19

src/components/Create/Create.utils.ts (1)

5-5: LGTM

Updating to areAddressesEqual enhances the reliability of address comparisons throughout the utility functions.

Also applies to: 54-54, 58-58, 64-64

src/components/Global/ImageGeneration/LinkPreview.tsx (1)

35-35: LGTM: Address comparison method updated

The change from areTokenAddressesEqual to areAddressesEqual is appropriate here as the function is used for general address comparison to find token logos.

src/hooks/useBalance.tsx (2)

14-14: Good: Simplified wallet context usage

The destructuring has been simplified to use just address and isConnected, making the code cleaner and more maintainable.


180-180: LGTM: Updated address comparison in balance lookup

The change from areTokenAddressesEqual to areAddressesEqual maintains consistency with the codebase-wide update while preserving the balance lookup functionality.

src/components/Request/Pay/Views/Success.view.tsx (1)

56-56: Verify payment processing with new address comparison

While the change from areTokenAddressesEqual to areAddressesEqual aligns with the codebase update, let's verify it doesn't affect the payment processing logic.

✅ Verification successful

Address comparison change is safe and consistent

The verification shows that areAddressesEqual is used consistently throughout the codebase for token address comparisons:

  • It's the standard utility function for address comparison in both payment and claim flows
  • The implementation in general.utils.ts properly handles native token address normalization
  • The function is used in similar token address comparison contexts across multiple components

The change from areTokenAddressesEqual to areAddressesEqual aligns with the codebase's standard practice and maintains the same payment processing logic.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other payment processing flows that might be affected
rg -A 5 "submitRequestLinkFulfillment" --type tsx --type ts

# Check for any test cases covering this scenario
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts | xargs rg "areAddressesEqual.*tokenAddress"

Length of output: 183


Script:

#!/bin/bash
# Search for other payment processing flows that might be affected
rg -A 5 "submitRequestLinkFulfillment"

# Check for usage of areAddressesEqual with token addresses
rg -A 2 "areAddressesEqual.*token"

# Look for test files related to payment processing
fd "pay|payment" -e test.tsx -e test.ts -e spec.tsx -e spec.ts

# Check the utils file for areAddressesEqual implementation
rg -A 3 "areAddressesEqual.*=" 

Length of output: 8035

src/components/Profile/index.tsx (1)

190-190: LGTM! Function rename improves semantic clarity.

The change from areTokenAddressesEqual to areAddressesEqual better reflects that the function compares wallet addresses in the referral system, not specifically token addresses.

src/components/Create/Link/Confirm.view.tsx (1)

8-8: LGTM! Consistent address comparison in token lookup.

The change from areTokenAddressesEqual to areAddressesEqual maintains the same functionality while providing better semantic clarity. The function is correctly used to find tokens by their addresses in both Squid and Peanut supported chains.

Also applies to: 100-108

src/components/Global/TokenSelector/TokenSelector.tsx (1)

10-10: LGTM! Consistent address comparison across token selection logic.

The change from areTokenAddressesEqual to areAddressesEqual is consistently applied across all token comparison scenarios:

  • Token selection highlighting
  • Duplicate token filtering
  • Balance matching
  • Selected token lookup

The functionality remains the same while the naming better reflects the general-purpose address comparison.

Also applies to: 75-77, 197-197, 225-225, 233-233, 281-281

src/components/Request/Pay/Views/Initial.view.tsx (2)

210-210: LGTM: Consistent function usage

The function rename is consistently applied in the token logo lookup logic.


201-201: Function rename improves code clarity

The change from areTokenAddressesEqual to areAddressesEqual better reflects the function's general-purpose address comparison capability.

✅ Verification successful

Function rename is consistent across the codebase

The verification confirms that areAddressesEqual is the only version present in the codebase, defined in src/utils/general.utils.ts. The function properly handles address comparison with case normalization and special ETH address cases, making it suitable for both token and general address comparisons.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify consistent usage of the new function name
rg "areTokenAddressesEqual" --type ts --type tsx

Length of output: 76


Script:

#!/bin/bash
# Search for both old and new function names in all files
rg "areTokenAddressesEqual|areAddressesEqual" -t ts -t typescript -t jsx -t tsx

# Also search for function definitions using AST
ast-grep --pattern 'function areTokenAddressesEqual($_) { $$$ }'
ast-grep --pattern 'function areAddressesEqual($_) { $$$ }'
ast-grep --pattern 'const areTokenAddressesEqual = $_'
ast-grep --pattern 'const areAddressesEqual = $_'

Length of output: 1203

src/components/Claim/Link/Initial.view.tsx (1)

302-302: LGTM: Consistent function usage in cross-chain detection

The function rename is correctly applied in the cross-chain detection logic.

src/utils/general.utils.ts (3)

Line range hint 371-379: Well-implemented address comparison function

The implementation is robust:

  • Handles special cases for ETH addresses
  • Uses ethers.utils.getAddress for case-insensitive comparison
  • Maintains consistent behavior with the previous implementation

382-382: LGTM: Consistent usage in zero address check

The function is correctly used in the zero address check utility.


981-982: LGTM: Proper integration in token symbol lookup

The function is appropriately used in the token symbol lookup logic.

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 b3fee6b and 93fea06.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (4 hunks)
🔇 Additional comments (3)
package.json (3)

81-82: Testing setup looks complete and well-configured

The testing setup includes all necessary dependencies:

  • Jest and its environment
  • Testing Library
  • TypeScript support via ts-jest

The configuration in the jest section is also properly set up with the correct test environment and module mapping.

Also applies to: 84-84, 95-96, 105-105


Line range hint 5-7: Node.js engine requirements are well-defined

The engine requirements are specific and include the latest LTS versions:

"engines": {
    "node": ">=21.1.0 <22.0.0 || ^18.18.0 || ^20.9.0"
}

This ensures compatibility with both the current LTS versions (18.x and 20.x) and the latest stable version (21.x).


107-107: Verify TypeScript version compatibility

The TypeScript version has been updated to ^5.6.3. Ensure this version is compatible with all your type definitions and Next.js version.

✅ Verification successful

TypeScript version update appears compatible

The TypeScript version update to ^5.6.3 appears safe based on:

  • Next.js version (^14.2.18) is compatible with TypeScript 5.x
  • No experimental TypeScript features are used in tsconfig.json
  • Standard TypeScript configuration is used with common Next.js settings
  • Codebase shows typical Next.js TypeScript patterns without advanced type features
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for potential TypeScript compatibility issues
# Look for any TypeScript-related errors or warnings in package-lock.json
if [ -f package-lock.json ]; then
  echo "Checking package-lock.json for TypeScript compatibility warnings..."
  cat package-lock.json | jq -r '.packages | .[] | select(.name != null) | select(.name | contains("@types")) | {name: .name, version: .version}'
fi

# Check Next.js TypeScript template version
echo "Checking Next.js TypeScript template version..."
if [ -f tsconfig.json ]; then
  cat tsconfig.json
fi

Length of output: 1180


Script:

#!/bin/bash
# Check Next.js version and other TypeScript-related dependencies
cat package.json | jq -r '.dependencies["next"], .dependencies["@types/node"], .dependencies["@types/react"], .dependencies["@types/react-dom"]'

# Look for any TypeScript errors in the codebase
fd -e ts -e tsx --exec head -n 1 {} \;

# Check for any TypeScript experimental features usage
rg -l "experimental" tsconfig.json

Length of output: 11969

@Hugo0 Hugo0 force-pushed the feat/send-with-peanut-wallet branch from eec3bb9 to b3fee6b Compare December 2, 2024 08:49
Copy link
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.

Overall lgtm!

</div>
)}

<div className="flex w-full flex-row items-center justify-between px-2 text-h8 text-gray-1">
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: why are we removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was duplicated after merging

tokenDecimals =
peanutTokenDetails
.find((detail) => detail.chainId.toString() == chainId)
?.tokens.find((token) => areTokenAddressesEqual(token.address, tokenAddress))?.decimals ?? 18
Copy link
Contributor

Choose a reason for hiding this comment

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

.find((detail) => detail.chainId.toString() == chainId)
Nit Q: shouldn't this be triple equality?

userBalances.some(
(balance) => areTokenAddressesEqual(balance.address, tokenAddress) && balance.chainId == chainId
)
userBalances.some((balance) => areAddressesEqual(balance.address, tokenAddress) && balance.chainId == chainId)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: triple equality?

Comment on lines 30 to 31
return wallet?.walletProviderType === interfaces.WalletProviderType.PEANUT
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: function name seems quite short - I'd prefer overly long but descriptive names over too short generic ones that might cause confusion down the line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rely a lot in typing a function isPeanut that receives a Wallet object is self describing to me

@@ -1,16 +1,14 @@
'use client'
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: we expect this context to be available everywhere right? I find the organization of src > context > walletContext a bit confusing. Especially when we have components > Global too. It's a bit hard to navigate so many folders, I think we might want to dedicate some time to restructuring this

Copy link
Contributor

Choose a reason for hiding this comment

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

thought 2: I think it was nice to have a high level overview comment explaining the goal of this file / WalletProvider. Sad to see it gone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmmm I think the distintion between components and context is useful (even if in the end they are all components). I know that a context will have a state available everywhere and components will be reusable UI pieces. (I do agree that we have many folders and sometimes is hard to navigate, if you ask me to write a path to a component I am working on I wont be able to do it)

if (selectedWallet) {
updateSelectedWalletWithConnectionStatus(selectedWallet)
if (!selectedAddress && wallets.length > 0) {
const initialWallet = wallets.find(isPeanut) ?? wallets[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: its smart to use peanut wallet as the default wallet, i like it. Question, do we respect users preferences? Ie should we store their last used wallet and let them use that instead on the next session?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm I think that's a good Idea

// TODO: if active, default active -> PW if logged in, otherwise
// if another wallet is connected to the provider, make that active, otherwise
// no wallet active (have to review all props to ensure they are null)
}, [wagmiAddress, wallets, user, addAccount])
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: doesn't having addAccount in dep array make this circular?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addAccount should not change, is an util function, it should not be part of this depArray

})

const { data: wallets = [] } = useQuery<interfaces.IWallet[]>({
queryKey: ['wallets', user?.accounts, wagmiAddress],
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: queryKey should containt all dependencies of isWalletConnected

I added a dev dependency to detect this automatically

Copy link
Contributor

Choose a reason for hiding this comment

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

nvm the linter doesn't seeem to work

Copy link
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.

Overall lgtm!

@jjramirezn jjramirezn merged commit 2181c10 into peanut-wallet Dec 2, 2024
4 checks passed
@jjramirezn jjramirezn deleted the feat/send-with-peanut-wallet branch December 2, 2024 15:08
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