-
Notifications
You must be signed in to change notification settings - Fork 544
[SDK] Fix: Token price cache to use proper address #7230
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
🦋 Changeset detectedLatest commit: 1c43eab The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
WalkthroughThis change modifies the cache key logic in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PayEmbed
participant convertCryptoToFiat
participant Cache
User->>PayEmbed: Request token price conversion
PayEmbed->>convertCryptoToFiat: Call with fromTokenAddress, chainId, to
convertCryptoToFiat->>Cache: Check cache (fromTokenAddress + chainId)
alt Cache hit
Cache-->>convertCryptoToFiat: Return cached result
else Cache miss
convertCryptoToFiat->>PayEmbed: Fetch and compute price
convertCryptoToFiat->>Cache: Store result with new key
end
convertCryptoToFiat-->>PayEmbed: Return conversion result
PayEmbed-->>User: Show converted price
Possibly related PRs
Suggested reviewers
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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
🧹 Nitpick comments (1)
packages/thirdweb/src/pay/convert/cryptoToFiat.ts (1)
110-110
: Excellent fix! Cache key now correctly reflects the cached data.The change from using
to
(fiat currency) tofromTokenAddress
in the cache key is correct because:
- The cached result depends on the token address and chain, not the target fiat currency
- The function always returns USD price (line 128:
firstResult.price_usd * fromAmount
) regardless of theto
parameter- The API query parameters match this cache key structure
Consider renaming the cache key to be more descriptive:
- cacheKey: `convert-fiat-to-crypto-${fromTokenAddress}-${chain.id}`, + cacheKey: `token-price-usd-${fromTokenAddress}-${chain.id}`,This would better reflect that it's caching USD token prices rather than suggesting a fiat-to-crypto conversion.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/loose-tools-move.md
(1 hunks)packages/thirdweb/src/pay/convert/cryptoToFiat.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: Unit Tests
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: Size
- GitHub Check: Build Packages
- GitHub Check: Lint Packages
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/thirdweb/src/pay/convert/cryptoToFiat.ts (1)
128-128
: Note: Function only supports USD despiteto
parameter.The function always returns USD price regardless of the
to
parameter value. This aligns with the comment on line 36 stating "Only USD is supported at the moment."Consider either:
- Removing the
to
parameter entirely since it's not used- Adding validation to ensure
to === "USD"
- Adding a TODO comment to implement multi-currency support in the future
The current implementation might be confusing to developers who expect different results when passing different
to
values..changeset/loose-tools-move.md (1)
1-6
: Changeset documentation looks good.The changeset properly documents this as a patch-level fix with an appropriate description that matches the PR objective.
size-limit report 📦
|
PR-Codex overview
This PR addresses a bug related to token pricing in the
PayEmbed
component by updating the cache key used in the conversion function.Detailed summary
cacheKey
inpackages/thirdweb/src/pay/convert/cryptoToFiat.ts
fromconvert-fiat-to-crypto-${to}-${chain.id}
toconvert-fiat-to-crypto-${fromTokenAddress}-${chain.id}
.Summary by CodeRabbit