fix: add modal abstraction, platform detection and onboarding#1325
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1325 +/- ##
=======================================
Coverage 74.93% 74.93%
=======================================
Files 184 184
Lines 4513 4513
Branches 1105 1105
=======================================
Hits 3382 3382
Misses 1131 1131 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Bug: Callback Context Issue and Global Variable Conflict
The onTransportNotification method is passed as a callback to __transport.onNotification without binding its this context, causing this.emit() to fail when invoked. Additionally, the SDK uses global __provider and __transport variables, which breaks encapsulation. A disconnect() call from one SDK instance will clear these globals, inadvertently breaking other active SDK instances.
packages/sdk-multichain/src/multichain/index.ts#L33-L337
metamask-sdk/packages/sdk-multichain/src/multichain/index.ts
Lines 33 to 337 in 8bb171f
Bug: SDK Instances Share Global Variables
The global variables __provider and __transport are shared across all MultichainSDK instances. This causes multiple SDK instances to interfere, leading to race conditions and unexpected behavior, as connect and disconnect operations from one instance can overwrite the connection state of others.
packages/sdk-multichain/src/multichain/index.ts#L33-L35
metamask-sdk/packages/sdk-multichain/src/multichain/index.ts
Lines 33 to 35 in 8bb171f
Was this report helpful? Give feedback by reacting with 👍 or 👎
|
| } | ||
| if (__transport) { | ||
| const listener = __transport.onNotification(this.onTransportNotification); | ||
| if (!__transport.isConnected()) { |
There was a problem hiding this comment.
Bug: Callback Context Error in SDK Method
The onTransportNotification method is passed as a callback to __transport.onNotification without binding its this context. When the callback is invoked, this does not refer to the MultichainSDK instance, causing this.emit to fail.
| enabled: options.analytics?.enabled !== undefined ? options.analytics.enabled : true, | ||
| integrationType: 'unknown', | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Bug: SDK Overwrites User Integration Type
The MultichainSDK constructor unconditionally sets integrationType to 'unknown', overwriting any user-provided value in options.analytics. This prevents users from customizing the integration type. The implementation should prioritize the user's integrationType and default to 'unknown' only if not provided.
| return { | ||
| mount: () => { | ||
| parentElement?.appendChild(modal); | ||
| setTimeout(() => this.updateQRCode(link), 100); |
There was a problem hiding this comment.
Bug: Modal Initialization Timing Issue
A race condition exists in the modal mount logic due to a fragile 100ms setTimeout delay for the updateQRCode call. This timing-dependent approach can cause updateQRCode to execute before the modal element is fully initialized in the DOM or after the modal has been unmounted, potentially leading to display issues.
Locations (1)
| } | ||
| if (__transport) { | ||
| const listener = __transport.onNotification(this.onTransportNotification); | ||
| if (!__transport.isConnected()) { |
There was a problem hiding this comment.
Bug: Callback Method Fails Without Proper Binding
The onTransportNotification method is passed as a callback to __transport.onNotification() without binding its this context. This will cause this.emit() calls within the method to fail when invoked by the transport. The method should be bound (e.g., this.onTransportNotification.bind(this)) or defined as an arrow function.
Duplicate RPC stuff has been removed. |
| */ | ||
| export const isEnabled = async (namespace: LoggerNameSpaces, storage: StoreClient) => { | ||
| if (process?.env?.DEBUG) { | ||
| if ('process' in globalThis && process?.env?.DEBUG) { |
There was a problem hiding this comment.
Bug: Unnecessary process Check Causes Compatibility Issues
The condition if ('process' in globalThis && process?.env?.DEBUG) is less robust than the original process?.env?.DEBUG. It introduces an unnecessary check that can cause issues in environments where the process object exists but is not directly accessible via globalThis (e.g., certain bundled environments). The original optional chaining was more broadly compatible and sufficient.
|



Explanation
PR is introducing:
Checklist