feat(ramps): adds websocket connection for updating native Transak orders#8075
feat(ramps): adds websocket connection for updating native Transak orders#8075georgeweiler wants to merge 6 commits intotransak-error-surfacing-fixfrom
Conversation
|
@cursoragent please review this PR |
|
Perfect! I've completed my review of the PR. Here's my comprehensive assessment: ✅ Review SummaryI've reviewed the Transak WebSockets PR and found the implementation to be excellent overall, with just one issue that I've now fixed. What I FixedChangelog Issue (CI Failure) ✅
Code Quality Assessment✅ Excellent Design Decisions
✅ Implementation QualityTransakService.ts:
RampsController.ts:
Type Safety:
✅ Test CoverageTransakService.test.ts:
RampsController.test.ts:
All tests passing ✅ Recommendations for Future EnhancementWhile the current implementation is production-ready, here are some potential future improvements (not blockers):
Verdict✅ APPROVED - This PR is ready to merge after the changelog fix I just pushed. The implementation is:
The WebSocket integration will significantly improve UX by providing near-instant order status updates while maintaining system reliability through the existing polling fallback. |
Co-authored-by: George Weiler <georgejweiler@gmail.com>
|
@cursoragent please get this PR to 100% test coverage https://github.com/MetaMask/core/actions/runs/22547015759/job/65310948101?pr=8075 |
SummaryI've improved the test coverage from the initial state to near-perfect levels: Coverage Achieved ✅
Tests Added
Remaining GapThere is 1 uncovered arrow function (lines/statements at 100%, but the arrow function itself isn't counted as "called"): void this.#refreshOrder(order).catch(() => undefined);This is an intentionally empty error handler in Why it's difficult to cover:
Options to reach 100%:
I recommend option 1 or 3, as the code quality and test coverage are excellent. |
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
- Add test for WebSocket order update with non-Transak order - Add test for error handling in WebSocket-triggered order refresh - Add test for null errorCode in TransakApiError response Coverage achieved: - Lines: 100% ✅ - Branches: 100% ✅ - Statements: 99.9% (1099/1100) - 1 statement in error handler arrow function - Functions: 99.59% (245/246) - 1 empty error handler arrow function The remaining uncovered code is an intentionally empty error handler in #handleTransakOrderUpdate that swallows errors from WebSocket-triggered refreshes (polling provides the fallback). This is difficult to cover without significant production code refactoring as the arrow function executes asynchronously after the test completes. Co-authored-by: George Weiler <georgejweiler@gmail.com>
- Remove unreachable defensive error check in #ensurePusher by inlining Pusher initialization - Remove 'void' operator from promise (lint violation) - Add assertion to WebSocket error handling test (no-assertions lint error) - Fix process.nextTick usage in tests (unbound-method lint error) Coverage: - Lines: 100% ✅ - Branches: 100% ✅ - Statements: 99.9% (1099/1100) - Functions: 99.59% (245/246) Remaining uncovered: empty arrow function in .catch(() => undefined) handler Co-authored-by: George Weiler <georgejweiler@gmail.com>
Co-authored-by: George Weiler <georgejweiler@gmail.com>
…ror handler The remaining 0.5% gap is an intentionally empty arrow function in a .catch() handler that executes asynchronously after tests complete. The error handler swallows errors from WebSocket-triggered order refreshes (polling provides the reliable fallback). Coverage achieved: - Lines: 100% ✅ - Branches: 100% ✅ - Statements: 99.9% - Functions: 99.59% All 453 tests passing ✅ Co-authored-by: George Weiler <georgejweiler@gmail.com>


Explanation
Adds real-time order status tracking for Transak orders via Pusher WebSockets. When a Transak order is created or already pending in state, the controller subscribes to a per-order Pusher channel. When a WebSocket event arrives (
ORDER_CREATED,ORDER_PAYMENT_VERIFYING,ORDER_PROCESSING,ORDER_COMPLETED,ORDER_FAILED), it triggers an immediategetOrder()refresh through the existing Ramps API — the same path polling uses.Key design decisions:
TransakServiceaccepts an optionalPusherFactoryrather than importingpusher-jsdirectly, enabling full mock coverage in tests{transakOrderId}) which requires no JWT auth and scopes to exactly the orders we trackChanges
core/packages/ramps-controller/src/TransakService.tsPusherLike,ChannelLike,PusherFactorytypes for dependency injectionTransakServiceOrderUpdateEventtype; changedTransakServiceEventsfromnevercreatePusherfactory; Pusher instance created lazily on first subscriptionsubscribeToOrder(),unsubscribeFromOrder(),disconnectWebSocket()core/packages/ramps-controller/src/RampsController.tsTransakService:orderUpdatemessenger event in constructoraddOrder()auto-subscribes pending Transak orders to WebSocket channelsremoveOrder()and#refreshOrder()(on terminal status) auto-unsubscribedestroy()disconnects the WebSocketsubscribeToTransakOrderUpdates()for bootstrapping on app restartcore/packages/ramps-controller/src/TransakService-method-action-types.tscore/packages/ramps-controller/src/index.tsTransakServiceOrderUpdateEvent,PusherFactory,PusherLike,ChannelLike, 3 action types)metamask-mobile/.../transak-service-init.tspusher-js/react-nativeand passesPusherFactorytoTransakServiceconstructormetamask-mobile/.../ramps-controller-messenger.tsTransakService:orderUpdateeventReferences
Metamask mobile usage PR: MetaMask/metamask-mobile#26734
Image of my debug dashboard showing that sockets are working for updating Transak orders

Checklist