-
Notifications
You must be signed in to change notification settings - Fork 14
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
[TASK-6288] refactor(request): avoid multiple calls to getLinkDetails #454
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 WalkthroughWalkthroughThe pull request introduces updates to the Changes
Possibly related PRs
Suggested reviewers
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: 0
🧹 Outside diff range and nitpick comments (2)
src/components/Request/Pay/Views/Initial.view.tsx (2)
Line range hint
24-29
: Remove unused dependencyisLoading
fromisButtonDisabled
In the
isButtonDisabled
useMemo
, the dependency array includesisLoading
, which is not used within the function. Removing it will prevent unnecessary re-computations and optimize performance.Apply this diff to fix the dependency array:
const isButtonDisabled = useMemo(() => { return ( viewState === ViewState.LOADING || viewState === ViewState.ERROR || (viewState === ViewState.READY_TO_PAY && !calculatedFee) ) -}, [viewState, isLoading, calculatedFee]) +}, [viewState, calculatedFee])
Line range hint
75-78
: Add error handling tofetchTokenSymbol
functionThe
fetchTokenSymbol
function lacks error handling for cases where the token contract details cannot be retrieved (e.g., network errors or invalid token addresses). Implementing error handling will enhance the application's robustness and prevent potential crashes.Consider modifying the function as follows:
const fetchTokenSymbol = async (chainId: string, address: string) => { const provider = await peanut.getDefaultProvider(chainId) - const tokenContract = await peanut.getTokenContractDetails({ - address, - provider, - }) + try { + const tokenContract = await peanut.getTokenContractDetails({ + address, + provider, + }) + setTokenRequestedSymbol(tokenContract?.symbol ?? '') + } catch (error) { + console.error('Failed to fetch token symbol:', error) + setTokenRequestedSymbol('') + } - setTokenRequestedSymbol(tokenContract?.symbol ?? '') }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
- package.json (1 hunks)
- src/components/Request/Pay/Views/Initial.view.tsx (1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Request/Pay/Views/Initial.view.tsx (6)
Learnt from: jjramirezn PR: peanutprotocol/peanut-ui#422 File: src/components/Request/Pay/Views/Initial.view.tsx:76-78 Timestamp: 2024-10-08T20:13:44.480Z 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: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-08T20:13:42.967Z 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-08T20:13:44.480Z 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: 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: jjramirezn PR: peanutprotocol/peanut-ui#422 File: src/components/Request/Pay/Views/Initial.view.tsx:76-78 Timestamp: 2024-10-08T20:13:42.967Z 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.
🔇 Additional comments (3)
package.json (1)
25-25
: LGTM! Verify SDK compatibility.The update of
@squirrel-labs/peanut-sdk
to version^0.5.5
aligns with the PR objective of utilizing the latest SDK version. This change should help in preventing multiple calls togetLinkDetails
as mentioned in the PR summary.To ensure a smooth transition, please verify the following:
Check the changelog or release notes for
@squirrel-labs/peanut-sdk
version 0.5.5 for any breaking changes or new features that may affect the current implementation.Run the following command to check for any peer dependency conflicts:
After verifying, ensure that all tests pass and the application builds successfully with the new SDK version.
src/components/Request/Pay/Views/Initial.view.tsx (2)
46-46
: Properly updatedlinkDetails
parameter in function callThe addition of
linkDetails: requestLink
correctly passes the entirerequestLink
object topeanut.prepareXchainRequestFulfillmentTransaction
. This aligns with the updated SDK usage and helps prevent multiple calls togetLinkDetails
, thereby enhancing performance as per the PR objectives.
Line range hint
130-134
: Ensure consistent typing incalculatedFee
In the
calculatedFee
useMemo
, bothtxFee
andutils.formatTokenAmount(estimatedGasCost, 3)
return strings. This ensures thatcalculatedFee
consistently returns a string without the need for additional type conversion, aligning with previous learnings.Learning applied from past experiences to maintain consistent return types in
calculatedFee
.
This PR uses newest sdk version that reuses previously fetched linkDetails when preparing xchain transactions on request