-
Notifications
You must be signed in to change notification settings - Fork 13
fix: fixes and refactor in request #422
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
Conversation
Load logo and symbol correctly from mobula if not found in sdk, also added some type safety to the tokenPriceData. Refs: #79
Avoid "A component is changing an uncontrolled input to be controlled" error
Go into initial view immediately after the request link data is fetched. Then fetch the price, gas and points as the necessary data is available. Parallel when possible.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces several enhancements to various components and hooks within the application. Key changes include improved error handling in the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🔇 Additional comments (2)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 12
🧹 Outside diff range and nitpick comments (5)
src/components/Request/Pay/Pay.consts.ts (1)
Line range hint
1-58
: Summary: Improved token price data handlingThe changes in this file represent a positive step towards more detailed and flexible token price data handling. The shift from a simple
number
type to a more complexITokenPriceData
type aligns well with the PR objectives and should allow for better handling of token symbols and logos.Key points:
- The new import and interface change maintain type safety and follow TypeScript best practices.
- The
tokenPriceData
property is now optional, which provides more flexibility but may require additional null checks in component logic.- These changes may necessitate updates in components that use the
IPayScreenProps
interface.Consider adding a brief comment above the
IPayScreenProps
interface to explain the purpose oftokenPriceData
and why it's optional. This would help other developers understand the design decision and how to properly use this property.src/components/Request/Create/Views/Initial.view.tsx (1)
36-37
: Consider using a more descriptive name for_tokenValue
While the changes effectively address the PR objectives and improve the component's robustness, consider using a more descriptive name for the
_tokenValue
state variable. A name likeinputTokenValue
orcurrentTokenValue
might better convey its purpose and relationship to the input field.This is a minor suggestion for improved code readability and doesn't affect the functionality of the changes.
Also applies to: 160-160
src/interfaces/interfaces.ts (1)
66-69
: LGTM with a minor suggestion.The new
ITokenPriceData
type effectively combines token information with chain-specific price data, which aligns with the PR objective of fetching symbol and logo from price data.However, there's a potential property duplication. The
IToken
interface already includes achainId
property, so extending it and addingchainId
again might be redundant.Consider modifying the type definition to avoid duplication:
export type ITokenPriceData = IToken & { price: number }This change ensures that
chainId
is only defined once, reducing the risk of inconsistencies.src/utils/fetch.utils.ts (1)
Line range hint
95-97
: Include error details in the catch block loggingCurrently, the catch block logs a generic message without the error details. Including the error object can provide more context for debugging.
Consider updating the log statement:
} catch (error) { - console.log('error fetching token price for token ' + tokenAddress + ' on chain ' + chainId) + console.error('Error fetching token price for token ' + tokenAddress + ' on chain ' + chainId + ':', error) return undefined }src/components/Request/Pay/Pay.tsx (1)
134-142
: Improve error handling when estimating gas feesIn the
estimateGasFee
call, errors are only logged to the console. This might not provide sufficient feedback to the user if gas estimation fails.Consider handling the error more proactively by setting an error state or informing the user about the failure to estimate gas fees. This will improve the user experience by providing meaningful feedback.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
- src/components/Create/useCreateLink.tsx (2 hunks)
- src/components/Request/Create/Views/Initial.view.tsx (2 hunks)
- src/components/Request/Pay/Pay.consts.ts (2 hunks)
- src/components/Request/Pay/Pay.tsx (4 hunks)
- src/components/Request/Pay/Views/Initial.view.tsx (12 hunks)
- src/context/tokenSelector.context.tsx (4 hunks)
- src/interfaces/interfaces.ts (1 hunks)
- src/utils/fetch.utils.ts (2 hunks)
🧰 Additional context used
📓 Learnings (3)
src/components/Request/Create/Views/Initial.view.tsx (1)
Learnt from: Hugo0 PR: peanutprotocol/peanut-ui#413 File: src/components/Request/Pay/Views/Initial.view.tsx:71-72 Timestamp: 2024-10-04T13:10:49.199Z Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, it's acceptable to use the `!` operator in TypeScript to assert that `selectedTokenData` is not `null` or `undefined`, and potential runtime errors from accessing its properties without checks can be disregarded.
src/components/Request/Pay/Views/Initial.view.tsx (2)
Learnt from: Hugo0 PR: peanutprotocol/peanut-ui#413 File: src/components/Request/Pay/Views/Initial.view.tsx:71-72 Timestamp: 2024-10-04T13:10:49.199Z Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, it's acceptable to use the `!` operator in TypeScript to assert that `selectedTokenData` is not `null` or `undefined`, and potential runtime errors from accessing its properties without checks can be disregarded.
Learnt from: jjramirezn PR: peanutprotocol/peanut-ui#410 File: src/components/Request/Pay/Views/Initial.view.tsx:87-93 Timestamp: 2024-10-03T14:57:44.520Z 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.
src/context/tokenSelector.context.tsx (2)
Learnt from: jjramirezn PR: peanutprotocol/peanut-ui#413 File: src/context/tokenSelector.context.tsx:118-123 Timestamp: 2024-10-04T13:40:16.067Z Learning: In the `TokenContextProvider` component within `src/context/tokenSelector.context.tsx`, in the TypeScript React application, when data changes and before calling `fetchAndSetTokenPrice`, it is necessary to reset `selectedTokenData`, `selectedTokenPrice`, `selectedTokenDecimals`, and `inputDenomination` to discard stale data.
Learnt from: jjramirezn PR: peanutprotocol/peanut-ui#404 File: src/context/tokenSelector.context.tsx:121-121 Timestamp: 2024-10-03T09:57:43.885Z Learning: In `TokenContextProvider` within `tokenSelector.context.tsx`, when token data is loaded from preferences, it's acceptable to set `isTokenPriceFetchingComplete` to `true` because the token data is already available.
🔇 Additional comments (10)
src/components/Request/Pay/Pay.consts.ts (1)
3-3
: LGTM: New import for ITokenPriceDataThe new import statement is correctly formatted and follows TypeScript best practices. It's a necessary addition to support the changes in the
IPayScreenProps
interface.src/context/tokenSelector.context.tsx (5)
7-7
: LGTM: New import for ITokenPriceDataThe addition of this import is consistent with the changes in the component's state management. It's good practice to import only what's necessary.
42-42
: LGTM: Consistent state type for selectedTokenDataThe update of the
selectedTokenData
state type toITokenPriceData | undefined
is consistent with the earlier context type change. This maintains type consistency between the state and the context.
Line range hint
146-146
: LGTM: Added selectedTokenData to context valueThe addition of
selectedTokenData
to the context provider value is consistent with the earlier changes and makes this data available to consuming components. This change completes the integration of the newITokenPriceData
type throughout the component.
27-27
: Verify consistency of ITokenPriceData usageThe type change for
selectedTokenData
toITokenPriceData | undefined
is appropriate given the new import. This change suggests a shift in the data structure being used for token information.Please ensure this type change is consistently applied throughout the component. Run the following script to verify:
✅ Verification successful
Consistent Update of ITokenPriceData Verified
The type change for
selectedTokenData
toITokenPriceData | undefined
is appropriately reflected throughout the codebase. No remaining usages ofITokenData
were found.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for consistent usage of ITokenPriceData # Test: Search for occurrences of ITokenPriceData rg --type typescript 'ITokenPriceData' # Test: Search for any remaining occurrences of ITokenData rg --type typescript 'ITokenData'Length of output: 142
Script:
#!/bin/bash # Description: Check for consistent usage of ITokenPriceData # Test: Search for occurrences of ITokenPriceData in TypeScript files rg --type ts 'ITokenPriceData' rg --type tsx 'ITokenPriceData' # Test: Search for any remaining occurrences of ITokenData in TypeScript files rg --type ts 'ITokenData' rg --type tsx 'ITokenData'Length of output: 1190
Script:
#!/bin/bash # Description: Check for consistent usage of ITokenPriceData and ITokenData in .ts and .tsx files # Find all .ts and .tsx files and search for ITokenPriceData fd -e ts -e tsx | xargs rg 'ITokenPriceData' # Find all .ts and .tsx files and search for ITokenData fd -e ts -e tsx | xargs rg 'ITokenData'Length of output: 1103
82-82
: Verify tokenPriceResponse structureThe direct assignment of
tokenPriceResponse
toselectedTokenData
simplifies the code and aligns with the newITokenPriceData
type. This change is good for maintaining data consistency.To ensure robustness, please verify that
tokenPriceResponse
always conforms to theITokenPriceData
interface. Consider adding a type check or using a type guard. Run the following script to check the structure oftokenPriceResponse
:src/components/Request/Create/Views/Initial.view.tsx (2)
36-37
: Improved state initialization for_tokenValue
This change enhances the robustness of the component by ensuring that
_tokenValue
is always initialized as a string. By providing a default empty string when the computed value is undefined, it prevents potential type-related issues and aligns with TypeScript best practices.This modification also addresses the PR objective of reinstating the functionality to disable the confirm button when the value is deleted from the input field, as an empty string will be falsy in the button's disabled condition.
160-160
: Updated disabled condition for confirm buttonThis change successfully implements the PR objective of disabling the confirm button when the value is deleted from the input field. By using
_tokenValue
in the disabled condition, it correctly reflects the current state of the input, including when it's an empty string.The modification maintains the existing checks for valid recipient, input changing state, and loading state, ensuring that all necessary conditions are met before enabling the button.
src/interfaces/interfaces.ts (1)
Line range hint
1-70
: File structure and organization look good.The addition of the
ITokenPriceData
type is well-placed within the file, maintaining a logical organization of related interfaces and types. The new type doesn't introduce any breaking changes to existing interfaces, and the overall file structure remains consistent and organized.src/components/Create/useCreateLink.tsx (1)
250-253
: ValidatenativeTokenPrice.price
before using itThis issue is the same as described in lines 227-230. Ensure that
nativeTokenPrice.price
is validated before performing calculations to prevent potential errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve all the comments - otherwise looks good
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this 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 (2)
src/components/Request/Pay/Views/Initial.view.tsx (2)
4-4
: LGTM! Minor suggestion for prop naming consistency.The addition of
useMemo
and the renaming oftokenPrice
totokenPriceData
are good improvements. They suggest performance optimization and better data structure representation.Consider updating other occurrences of
tokenPrice
totokenPriceData
throughout the codebase for consistency, if not already done.Also applies to: 24-24
125-145
: LGTM! Improved token info handling. Minor safety suggestion.The new logic for setting
tokenRequestedLogoURI
andtokenRequestedSymbol
enhances the UI's ability to display accurate token information. The fallback tofetchTokenSymbol
ensures that the symbol is always available.Consider adding a null check before calling
toUpperCase()
to prevent potential runtime errors:- ?.symbol.toUpperCase() ?? + ?.symbol?.toUpperCase() ??
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- src/components/Request/Pay/Views/Initial.view.tsx (12 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Request/Pay/Views/Initial.view.tsx (1)
Learnt from: Hugo0 PR: peanutprotocol/peanut-ui#413 File: src/components/Request/Pay/Views/Initial.view.tsx:71-72 Timestamp: 2024-10-04T13:10:49.199Z Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, it's acceptable to use the `!` operator in TypeScript to assert that `selectedTokenData` is not `null` or `undefined`, and potential runtime errors from accessing its properties without checks can be disregarded.
🔇 Additional comments (5)
src/components/Request/Pay/Views/Initial.view.tsx (5)
76-78
: LGTM! Good use of useMemo for performance optimization.The memoization of
calculatedFee
is a smart performance optimization. It ensures that the fee is only recalculated when its dependencies change.
Line range hint
114-124
: LGTM! Improved cross-chain detection and optimization.The updates to the
isXChain
logic and the early return condition in theuseEffect
hook enhance the accuracy of cross-chain transaction detection and prevent unnecessary calculations.
170-170
: LGTM! Consistent use of renamed prop.The replacement of
tokenPrice
withtokenPriceData
in thehandleOnNext
function maintains consistency with the earlier prop renaming.
296-302
: LGTM! Improved consistency and UI responsiveness.The updates in the JSX return statement, including the use of
tokenPriceData
,tokenRequestedSymbol
, and the additional check forcalculatedFee
in the button's disabled state, enhance the overall consistency and responsiveness of the component.Also applies to: 319-319, 338-342, 364-368, 387-392
Line range hint
1-424
: Overall, excellent improvements to the InitialView component.The changes in this file significantly enhance token handling, error management, and UI responsiveness. The introduction of new state variables, memoization for performance, and improved logic for cross-chain detection are all positive additions. The code is well-structured and follows good practices.
A few minor suggestions were made:
- Add error handling to the
fetchTokenSymbol
function.- Add a null check before calling
toUpperCase()
on the token symbol.- Ensure consistency in prop naming across the codebase.
Great work on these improvements!
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (1)
src/components/Request/Pay/Views/Initial.view.tsx (1)
296-302
: LGTM: Improved token display and button state handlingThe updates to the JSX improve the consistency of token price and symbol display. The use of
tokenRequestedSymbol
andtokenPriceData
aligns with the earlier changes. The enhanced button disabled state logic is a good improvement.Consider extracting the complex disabled state logic into a separate variable for improved readability:
+ const isButtonDisabled = linkState === RequestStatus.LOADING || + linkState === RequestStatus.NOT_FOUND || + isLoading || + (linkState === RequestStatus.CLAIM && !calculatedFee); <button className="wc-disable-mf btn-purple btn-xl " - disabled={ - linkState === RequestStatus.LOADING || - linkState === RequestStatus.NOT_FOUND || - isLoading || - (linkState === RequestStatus.CLAIM && !calculatedFee) - } + disabled={isButtonDisabled} onClick={() => { if (!isConnected) handleConnectWallet() else if (RequestStatus.CLAIM === linkState) handleOnNext() }} >This change would make the JSX more readable and the disabled state logic easier to understand at a glance.
Also applies to: 319-319, 338-342, 387-392
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- src/components/Request/Pay/Views/Initial.view.tsx (12 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Request/Pay/Views/Initial.view.tsx (1)
Learnt from: Hugo0 PR: peanutprotocol/peanut-ui#413 File: src/components/Request/Pay/Views/Initial.view.tsx:71-72 Timestamp: 2024-10-04T13:10:49.199Z Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, it's acceptable to use the `!` operator in TypeScript to assert that `selectedTokenData` is not `null` or `undefined`, and potential runtime errors from accessing its properties without checks can be disregarded.
🔇 Additional comments (4)
src/components/Request/Pay/Views/Initial.view.tsx (4)
4-4
: LGTM: Import and prop updates enhance functionalityThe addition of
useMemo
and the renaming oftokenPrice
totokenPriceData
are good improvements. These changes suggest better performance optimization and more comprehensive token price handling.Also applies to: 24-24
Line range hint
79-124
: LGTM: Improved error handling and state managementThe updates to the
useEffect
hook enhance the component's ability to handle cross-chain transactions and various error scenarios. The state updates and error handling are comprehensive, improving the overall robustness of the component.
170-170
: LGTM: Consistent renaming oftokenPrice
totokenPriceData
The change from
tokenPrice
totokenPriceData
in thehandleOnNext
function is consistent with the earlier prop renaming. The overall logic for handling transactions remains intact and appears to be functioning correctly.
Line range hint
1-420
: Overall assessment: Good improvements with minor suggestionsThe changes to the
InitialView
component significantly enhance its functionality, particularly in terms of token information handling, fee calculation, and error management. The use ofuseMemo
for performance optimization and the improved state management are commendable.Key improvements:
- Better handling of token symbol and logo URI
- Enhanced fee calculation with cross-chain support
- Improved error handling and state management
- Consistent updates to use
tokenPriceData
instead oftokenPrice
The suggested changes in the review comments, such as adding error handling to
fetchTokenSymbol
and ensuring consistent return types incalculatedFee
, will further improve the robustness of the component.Overall, these changes represent a solid improvement to the codebase. Once the minor suggestions are addressed, this PR will be ready for merge.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (4)
src/components/Request/Pay/Views/GeneralViews/Error.view.tsx (1)
35-35
: Update the default export name if you rename the component.If you rename the component as suggested earlier, make sure to update the default export as well.
Here's the change you should make if you rename the component:
-export default Error +export default ErrorViewsrc/components/Request/Pay/Views/Initial.view.tsx (1)
125-145
: Updated useEffect for token dataThis useEffect hook has been significantly modified to handle setting the
tokenRequestedLogoURI
andtokenRequestedSymbol
. It now includes fallback logic and uses the newfetchTokenSymbol
function when necessary.However, there's a potential improvement:
Consider extracting the logic for setting
tokenRequestedLogoURI
andtokenRequestedSymbol
into separate functions to improve readability:const setTokenRequestedData = () => { const chainDetails = consts.peanutTokenDetails.find((chain) => chain.chainId === requestLinkData.chainId) const logoURI = chainDetails?.tokens.find((token) => utils.areTokenAddressesEqual(token.address, requestLinkData.tokenAddress) )?.logoURI ?? tokenPriceData?.logoURI setTokenRequestedLogoURI(logoURI) let tokenSymbol = requestLinkData.tokenSymbol ?? chainDetails?.tokens.find((token) => utils.areTokenAddressesEqual(token.address, requestLinkData.tokenAddress)) ?.symbol?.toUpperCase() ?? tokenPriceData?.symbol if (tokenSymbol) { setTokenRequestedSymbol(tokenSymbol) } else { fetchTokenSymbol(requestLinkData.chainId, requestLinkData.tokenAddress) } } useEffect(() => { setTokenRequestedData() }, [requestLinkData, tokenPriceData])src/components/Create/useCreateLink.tsx (2)
227-229
: Improved error handling, but consider using Number.isNaNThe changes improve error handling by checking if
nativeTokenPrice
is valid before using it. This addresses the PR objective of ensuring proper data fetching. However, consider usingNumber.isNaN
instead ofisNaN
for safer type checking.Consider updating the condition as follows:
- if (!nativeTokenPrice || typeof nativeTokenPrice.price !== 'number' || isNaN(nativeTokenPrice.price)) { + if (!nativeTokenPrice || typeof nativeTokenPrice.price !== 'number' || Number.isNaN(nativeTokenPrice.price)) { throw new Error('Failed to fetch token price') }This change will make the type checking more robust and avoid potential issues with type coercion.
🧰 Tools
🪛 Biome
[error] 227-227: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.(lint/suspicious/noGlobalIsNan)
250-253
: Consider adding additional checks for consistencyThe error handling improvements in the catch block are good, but they're not as comprehensive as the checks added earlier in the function. For consistency and robustness, consider adding the same level of checking here as well.
Consider updating the condition in the catch block as follows:
- if (!nativeTokenPrice) { + if (!nativeTokenPrice || typeof nativeTokenPrice.price !== 'number' || Number.isNaN(nativeTokenPrice.price)) { throw new Error('Failed to fetch token price') }This will ensure consistent error handling throughout the function.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- src/components/Create/useCreateLink.tsx (2 hunks)
- src/components/Request/Pay/Pay.consts.ts (3 hunks)
- src/components/Request/Pay/Pay.tsx (5 hunks)
- src/components/Request/Pay/Views/GeneralViews/Error.view.tsx (2 hunks)
- src/components/Request/Pay/Views/GeneralViews/index.ts (1 hunks)
- src/components/Request/Pay/Views/Initial.view.tsx (12 hunks)
✅ Files skipped from review due to trivial changes (1)
- src/components/Request/Pay/Views/GeneralViews/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/components/Request/Pay/Pay.consts.ts
- src/components/Request/Pay/Pay.tsx
🧰 Additional context used
📓 Learnings (1)
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:76-78 Timestamp: 2024-10-07T15:28:25.280Z 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`.
Learnt from: jjramirezn PR: peanutprotocol/peanut-ui#422 File: src/components/Request/Pay/Views/Initial.view.tsx:76-78 Timestamp: 2024-10-07T15:25:45.170Z Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, both `txFee` and `utils.formatTokenAmount(...)` return strings, ensuring that `calculatedFee` consistently returns a string without the need for additional type conversion.
Learnt from: Hugo0 PR: peanutprotocol/peanut-ui#413 File: src/components/Request/Pay/Views/Initial.view.tsx:71-72 Timestamp: 2024-10-04T13:10:49.199Z Learning: In `src/components/Request/Pay/Views/Initial.view.tsx`, it's acceptable to use the `!` operator in TypeScript to assert that `selectedTokenData` is not `null` or `undefined`, and potential runtime errors from accessing its properties without checks can be disregarded.
🪛 Biome
src/components/Create/useCreateLink.tsx
[error] 227-227: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.(lint/suspicious/noGlobalIsNan)
src/components/Request/Pay/Views/GeneralViews/Error.view.tsx
[error] 6-6: Do not shadow the global "Error" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
🔇 Additional comments (14)
src/components/Request/Pay/Views/GeneralViews/Error.view.tsx (2)
10-10
: Good job implementing dynamic error message display.The change from a static message to a dynamic one using the
errorMessage
prop improves the component's flexibility and reusability.
Line range hint
6-35
: Overall, good improvements to error handling and component flexibility.The changes in this file align well with the PR objectives of improving error handling. The new
Error
component (which I suggest renaming toErrorView
) provides more flexibility by accepting a dynamic error message. This enhancement improves the reusability of the component across different error scenarios.The structure and styling of the component have been maintained, ensuring consistency with the previous version. The addition of the dynamic error message display is a positive change that will make error reporting more informative and adaptable.
Once the naming issue is addressed, these changes will contribute to a more robust and maintainable codebase.
🧰 Tools
🪛 Biome
[error] 6-6: Do not shadow the global "Error" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
src/components/Request/Pay/Views/Initial.view.tsx (11)
4-4
: New import addedThe
useMemo
hook has been imported from 'react'. This is a good addition as it can help optimize performance by memoizing expensive computations.
24-24
: Prop name changeThe prop
tokenPrice
has been renamed totokenPriceData
. This change improves clarity by indicating that the prop contains more than just the price.
44-45
: New state variables addedTwo new state variables,
tokenRequestedLogoURI
andtokenRequestedSymbol
, have been introduced. These variables will help manage the logo URI and symbol of the requested token, improving the component's ability to display token information.
54-54
: Updated property accessThe
tokenAddress
property has been replaced withaddress
when accessingselectedTokenData
. This change aligns with the updated data structure and improves consistency.Also applies to: 61-61
76-78
: New memoized value:calculatedFee
The
calculatedFee
is now computed usinguseMemo
, which is a good optimization. It determines the fee based on whether the transaction is cross-chain or not.
170-170
: Updated USD amount calculationThe calculation of
amountUsd
now uses thetokenPriceData.price
instead oftokenPrice.price
. This change aligns with the renamed prop and ensures correct USD amount calculation.
296-302
: Updated token amount displayThe component now uses
tokenPriceData
instead oftokenPrice
for displaying the token amount in USD. IftokenPriceData
is not available, it falls back to displaying the amount in the requested token's symbol.
319-319
: Updated token symbol displayThe component now uses
tokenRequestedSymbol
for displaying the token symbol, which is more accurate as it's derived from multiple sources including the contract itself if necessary.
338-342
: Improved fee displayThe component now uses the memoized
calculatedFee
for displaying the network cost. If the fee is not yet calculated, it shows a loading animation, which improves the user experience.
364-368
: Improved points displaySimilar to the fee display, the points display now shows a loading animation when the points are not yet calculated. This provides a consistent user experience across the component.
387-392
: Updated button disabled stateThe Pay button's disabled state now includes a check for
calculatedFee
. This ensures that the button is not clickable until all necessary data is available, preventing potential errors.src/components/Create/useCreateLink.tsx (1)
Line range hint
1-853
: Request for clarification on performance improvementsThe changes reviewed contribute to improved error handling and data fetching, which is great. However, the PR objectives mention performance improvements, particularly in handling requests in the Request Pay view. These improvements are not immediately apparent in the visible changes.
Could you please clarify where the performance improvements mentioned in the PR objectives are implemented? Are they in a different file or part of the code that's not visible in this diff?
To help locate these changes, you could run the following command:
This will search for relevant keywords in TypeScript and TSX files, which might help identify where the performance improvements have been implemented.
🧰 Tools
🪛 Biome
[error] 227-227: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.(lint/suspicious/noGlobalIsNan)
Fixes
Refactor
Did a performance focused refactor on the Request Pay view, instead of making all calls one after another and wait for all to be finished, now we do in parallel what doesn't depend on each other and render progressively