Conversation
For getting contract abi and the link details
WalkthroughThe changes add two new functions to the module. The first function, ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/index.ts (3)
246-283: Duplicated contract ABI selection logic introduces maintenance risk.The
getContractAbifunction duplicates the switch statement logic that's already present in thegetContractfunction (lines 295-331). This duplication could lead to maintenance issues if one is updated but the other is not.Consider extracting the switch statement into a shared helper function that both
getContractAbiandgetContractcan use:+function getContractAbiForVersion(version: string): any { + let contractAbi: any + switch (version) { + case 'v4': + contractAbi = PEANUT_ABI_V4 + break + case 'v4.2': + contractAbi = PEANUT_ABI_V4_2 + break + // ... other cases + default: + throw new Error('Unable to find Peanut contract for this version, check for correct version or updated SDK') + } + return contractAbi +} function getContractAbi(version: string): any { - let contractAbi: any - switch (version) { - case 'v4': - contractAbi = PEANUT_ABI_V4 - break - // ... other cases - default: - throw new Error('Unable to find Peanut contract for this version, check for correct version or updated SDK') - } - return contractAbi + return getContractAbiForVersion(version) } // Later in getContract function -let CONTRACT_ABI: any -switch (version) { - case 'v4': - CONTRACT_ABI = PEANUT_ABI_V4 - break - // ... other cases -} +const CONTRACT_ABI = getContractAbiForVersion(version)
2053-2055: Function lacks proper type definitions and documentation.The function uses
anytype for its parameters and doesn't have JSDoc comments explaining what each parameter represents.Add appropriate type definitions and documentation:
/** + * Extracts details from a link based on deposit information and token details. + * + * @param params - The parameters extracted from the link URL + * @param deposit - The on-chain deposit data + * @param tokenDetails - The details of the token (symbol, name, decimals) + * @returns An object containing all extracted link details + */ -function extractLinkDetails({ params, deposit, tokenDetails }: any) { +function extractLinkDetails({ + params, + deposit, + tokenDetails +}: { + params: { + chainId: string; + contractVersion: string; + depositIdx: number; + }; + deposit: { + tokenAddress: string; + contractType: number; + senderAddress: string; + pubKey20?: string; + claimed?: boolean; + timestamp?: number; + amount: ethers.BigNumber; + tokenId: ethers.BigNumber; + recipient?: string; + reclaimableAfter?: number; + }; + tokenDetails: { + symbol: string; + name: string; + decimals: number; + tokenURI?: string; + metadata?: any; + }; +}) { // Function implementation
2086-2087: Useconstfor variables that aren't reassigned.The variables
tokenURIandmetadataare never reassigned after their initial declaration as null, so they should useconstinstead oflet.- let tokenURI = null - let metadata = null + const tokenURI = null + const metadata = null🧰 Tools
🪛 ESLint
[error] 2086-2086: 'tokenURI' is never reassigned. Use 'const' instead.
(prefer-const)
[error] 2087-2087: 'metadata' is never reassigned. Use 'const' instead.
(prefer-const)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (1)
src/index.ts(4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/index.ts (1)
src/data.ts (11)
PEANUT_ABI_V4(51-51)PEANUT_ABI_V4_2(52-52)PEANUT_ABI_V4_3(53-53)PEANUT_ABI_V4_4(54-54)PEANUT_BATCHER_ABI_V4(55-55)PEANUT_BATCHER_ABI_V4_3(57-57)PEANUT_BATCHER_ABI_V4_4(58-58)PEANUT_BATCHER_ABI_V4_2(56-56)PEANUT_ROUTER_ABI_V4_2(59-59)VAULT_CONTRACTS_V4_ANDUP(77-77)TOKEN_DETAILS(66-66)
🪛 ESLint
src/index.ts
[error] 2086-2086: 'tokenURI' is never reassigned. Use 'const' instead.
(prefer-const)
[error] 2087-2087: 'metadata' is never reassigned. Use 'const' instead.
(prefer-const)
For getting contract abi and the link details