Conversation
WalkthroughDependency updated for @etherspot/intent-sdk. Address normalization via viem’s getAddress applied to asset fields. UserIntent shape changed: removed constraints.maxGas/permittedChains and core.permittedAccounts; added top-level account. BuyButton now accepts an error object in expressIntentResponse and adjusts disabled logic accordingly. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
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:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
package.json (1)
23-23: Bump to intent-sdk alpha.9 looks good, but consider pinning pre-release versions.Caret ranges on pre-releases can float to newer alpha builds unexpectedly. If you want deterministic builds, prefer an exact version for alpha releases.
Apply this diff if you want to pin the version:
- "@etherspot/intent-sdk": "^1.0.0-alpha.9", + "@etherspot/intent-sdk": "1.0.0-alpha.9",src/apps/pulse/components/Buy/BuyButton.tsx (1)
52-52: Prop type widened to include error object — ensure the parent actually passes it.BuyButton now accepts
{ error: string }, but in Buy.tsx the state is stillExpressIntentResponse | nulland errors are only logged. If you intend to use this branch, propagate the error up so the disabled logic and UX benefit from it.I can provide a follow-up diff in Buy.tsx to widen the state and set the error on failure if you confirm that’s desired.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these settings in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
package.json(1 hunks)src/apps/pulse/components/Buy/Buy.tsx(3 hunks)src/apps/pulse/components/Buy/BuyButton.tsx(2 hunks)src/apps/pulse/utils/intent.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T07:42:24.646Z
Learnt from: IAmKio
PR: pillarwallet/x#351
File: src/apps/pulse/utils/intent.ts:44-53
Timestamp: 2025-08-12T07:42:24.646Z
Learning: In the Pulse app's intent utilities (src/apps/pulse/utils/intent.ts), the team has chosen to use floating-point arithmetic for token amount calculations despite potential precision issues, accepting JavaScript's decimal place limitations as a valid trade-off for their use case.
Applied to files:
src/apps/pulse/utils/intent.ts
🔇 Additional comments (1)
src/apps/pulse/components/Buy/Buy.tsx (1)
7-7: Normalize addresses safely and confirm the UserIntent field name (accountvsaccountAddress)getAddress throws on invalid input — guard with isAddress to avoid crashes. Also confirm the top-level UserIntent field name is
accountfor alpha.9 (notaccountAddress). I couldn't verify SDK/types from the provided snippet; please confirm or I can run a repo grep.Files to check
- src/apps/pulse/components/Buy/Buy.tsx — import (line 7) and the asset/account assignments
- Also applies to: lines 138 and 153
Apply these minimal diffs:
-import { Hex, getAddress } from 'viem'; +import { Hex, getAddress, isAddress } from 'viem';- asset: getAddress(token.address) as Hex, + asset: (isAddress(token.address) + ? getAddress(token.address) + : (token.address as Hex)) as Hex,- account: accountAddress as Hex, + account: (isAddress(accountAddress) + ? (getAddress(accountAddress) as Hex) + : (accountAddress as Hex)),Follow-up (make BuyButton error-aware so disabled state can act on expressIntent failures):
- const [expressIntentResponse, setExpressIntentResponse] = - useState<ExpressIntentResponse | null>(null); + type IntentResult = ExpressIntentResponse | { error: string } | null; + const [expressIntentResponse, setExpressIntentResponse] = + useState<IntentResult>(null);- } catch (error) { - console.error('express intent failed:: ', error); + } catch (error) { + const message = + error instanceof Error ? error.message : 'Unknown error'; + setExpressIntentResponse({ error: message });Rendering hint for warnings (surface errors alongside "Not enough liquidity"):
const hasError = expressIntentResponse && typeof expressIntentResponse === 'object' && 'error' in expressIntentResponse; {(notEnoughLiquidity || (!isLoading && expressIntentResponse && !hasError && (expressIntentResponse as ExpressIntentResponse).bids?.length === 0) || hasError) && ( // render "Not enough liquidity" or an error message accordingly )}Please confirm the SDK UserIntent field name (
accountvsaccountAddress). I can run a repo-wide grep or inspect SDK types if you want me to verify.
| !!(expressIntentResponse as { error: string }).error || | ||
| (expressIntentResponse as ExpressIntentResponse)?.bids?.length === 0 || | ||
| notEnoughLiquidity |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Safer error detection without type assertion.
The current check uses a forced cast which can mask mistakes. Use an in-operator guard to avoid misreads and keep type safety.
Apply this diff:
- !!(expressIntentResponse as { error: string }).error ||
- (expressIntentResponse as ExpressIntentResponse)?.bids?.length === 0 ||
+ (expressIntentResponse !== null &&
+ typeof expressIntentResponse === 'object' &&
+ 'error' in expressIntentResponse) ||
+ (expressIntentResponse as ExpressIntentResponse)?.bids?.length === 0 ||📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| !!(expressIntentResponse as { error: string }).error || | |
| (expressIntentResponse as ExpressIntentResponse)?.bids?.length === 0 || | |
| notEnoughLiquidity | |
| (expressIntentResponse !== null && | |
| typeof expressIntentResponse === 'object' && | |
| 'error' in expressIntentResponse) || | |
| (expressIntentResponse as ExpressIntentResponse)?.bids?.length === 0 || | |
| notEnoughLiquidity |
🤖 Prompt for AI Agents
In src/apps/pulse/components/Buy/BuyButton.tsx around lines 84-86, the
expression uses a forced cast (expressIntentResponse as { error: string }).error
which can mask incorrect types; replace this with a safe type-guard using the in
operator to check for the error property before reading it (e.g., ensure
expressIntentResponse is an object and 'error' in expressIntentResponse, then
coerce/check its truthiness), or extract a small type-guard helper that returns
boolean if the response has an error property, and then keep the rest of the OR
conditions unchanged.
| /* eslint-disable no-restricted-syntax */ | ||
| import { DispensableAsset } from '@etherspot/intent-sdk/dist/cjs/sdk/types/user-intent-types'; | ||
| import { Hex } from 'viem'; | ||
| import { getAddress, Hex } from 'viem'; |
There was a problem hiding this comment.
Guard getAddress to avoid runtime throws on invalid addresses.
viem’s getAddress throws on invalid input. Since this runs during effects, an invalid address would crash the component. Guard with isAddress to keep this path resilient.
Apply this minimal diff:
-import { getAddress, Hex } from 'viem';
+import { getAddress, isAddress, Hex } from 'viem';- asset: getAddress(tokenItem.address) as Hex,
+ asset: (isAddress(tokenItem.address)
+ ? getAddress(tokenItem.address)
+ : (tokenItem.address as Hex)) as Hex,Optionally, if you prefer to skip invalid assets entirely (recommended), I can provide a slightly larger refactor that continues the loop when the address is invalid.
Also applies to: 49-49
🤖 Prompt for AI Agents
In src/apps/pulse/utils/intent.ts around lines 3 and 49, calling viem's
getAddress directly can throw on invalid input; guard calls with viem's
isAddress before invoking getAddress (or skip/continue when invalid) to prevent
runtime exceptions during effects — check isAddress(address) first, only call
getAddress(address) if true, and handle the invalid case by logging/ignoring
that asset or continuing the loop so the component does not crash.
Description
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Summary by CodeRabbit
Bug Fixes
Chores