refactor djed-sdk\src\djed\tradeUtils.js#78
refactor djed-sdk\src\djed\tradeUtils.js#78aniket866 wants to merge 3 commits intoDjedAlliance:mainfrom
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdded a new exported constant FEE_UI_UNSCALED; changed Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@djed-sdk/src/djed/tradeUtils.js`:
- Around line 123-131: The exported function promiseTx changed its third
parameter from signer to web3 (signature now promiseTx(isWalletConnected, tx,
web3)), but the compiled bundles still export the old signature; rebuild the
compiled output so dist/ bundles reflect the new API, then run the build step
(e.g., npm/yarn build) to regenerate the ESM/UMD artifacts and verify the
generated bundles export promiseTx with the web3 parameter and the same runtime
behavior (ensure web3?.eth is checked and web3.eth.sendTransaction is used).
🧹 Nitpick comments (2)
djed-sdk/src/djed/tradeUtils.js (2)
137-153: Clarifyreceipt.statussemantics for callers.The function resolves with
receipt.status, which isfalsefor reverted transactions andtruefor successful ones. This means a resolved promise doesn't guarantee transaction success—callers must check the returned boolean.Consider either:
- Rejecting when
receipt.status === falseto make failure handling explicit- Documenting this behavior for callers
♻️ Option: Reject on failed transactions
const receipt = await web3.eth.getTransactionReceipt(hash); if (receipt) { - return resolve(receipt.status); + if (receipt.status) { + return resolve(receipt.status); + } + return reject(new Error("Transaction reverted")); }
134-135: Consider extracting timeout as a named constant.The 60-second timeout is reasonable for blockchain confirmation. For consistency with
CONFIRMATION_WAIT_PERIOD, consider defining this as a named constant (e.g.,CONFIRMATION_TIMEOUT) in the constants file.
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
djed-sdk/src/djed/tradeUtils.js (1)
123-130:⚠️ Potential issue | 🔴 CriticalFix
promiseTxparameter mismatch (ReferenceError).
Line 123 declaresSingerbut the body referencessigner, which throws before any Promise is returned.🐛 Proposed fix
-export const promiseTx = (isWalletConnected, tx, Singer) => { +export const promiseTx = (isWalletConnected, tx, signer) => { if (!isWalletConnected) { return Promise.reject(new Error("Metamask not connected!")); } if (!signer) { return Promise.reject(new Error("Couldn't get Signer")); } return signer.sendTransaction(tx); };
Fixed transaction sending to consistently use Web3.js instead of Ethers.js syntax.
Improved transaction verification by polling for the receipt with a timeout.
Corrected UI fee unscaling to prevent double division and wrong fee values.
No comment changes and minimal code modifications.
Improves reliability and correctness of trade execution.
@Zahnentferner Please review
Summary by CodeRabbit
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.