-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: detect SDKConnectV2 connections in useOriginSource via v2Connections store #28290
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
Merged
+101
−20
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,39 +11,59 @@ interface UseOriginSourceProps { | |
|
|
||
| type SourceTypeValue = (typeof SourceType)[keyof typeof SourceType]; | ||
|
|
||
| /** | ||
| * Determines the connection source type for analytics from a permission-request origin. | ||
| * | ||
| * The origin value varies by connection type: | ||
| * - SDK v2 (MWP): bare UUID (the connection/session ID) | ||
| * - SDK v1: bare UUID, or prefixed with "MMSDKREMOTE::" | ||
| * - WalletConnect: the dapp URL (no special prefix) | ||
| * - In-app browser: the dapp URL | ||
| * | ||
| * We check in priority order: SDK v2 → SDK v1 → WalletConnect → browser. | ||
| */ | ||
| export const useOriginSource = ({ | ||
| origin, | ||
| }: UseOriginSourceProps): SourceTypeValue | undefined => { | ||
| const { wc2Metadata } = useSelector((state: RootState) => state.sdk); | ||
| const { wc2Metadata, v2Connections } = useSelector( | ||
| (state: RootState) => state.sdk, | ||
| ); | ||
|
|
||
| // Return undefined if origin is undefined | ||
| if (!origin) { | ||
| return undefined; | ||
| } | ||
|
|
||
| // Check for V2 connections | ||
| if (origin.startsWith(AppConstants.MM_SDK.SDK_CONNECT_V2_ORIGIN)) { | ||
| // --- SDK v2 (MWP) --- | ||
| // V2 connections use the bare session UUID as the permission-system origin. | ||
| // Look it up in the v2Connections store (populated by | ||
| // HostApplicationAdapter.syncConnectionList, keyed by connection ID). | ||
| if (isUUID(origin) && v2Connections?.[origin]) { | ||
jiexi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return SourceType.SDK_CONNECT_V2; | ||
| } | ||
|
|
||
| // Check if origin is a UUID (SDK channel ID format) or starts with SDK_REMOTE_ORIGIN | ||
| const isChannelId = isUUID(origin); | ||
| const isSDKRemoteOrigin = origin.startsWith( | ||
| AppConstants.MM_SDK.SDK_REMOTE_ORIGIN, | ||
| ); | ||
|
|
||
| const sdkConnection = isChannelId | ||
| ? SDKConnect.getInstance().getConnection({ channelId: origin }) | ||
| : undefined; | ||
|
|
||
| // Check if it's SDK (either by UUID connection or remote origin) | ||
| if (sdkConnection || isSDKRemoteOrigin) { | ||
| // --- SDK v1 --- | ||
| // V1 origins are either a bare UUID (channel ID) found in the SDKConnect | ||
| // singleton, or prefixed with "MMSDKREMOTE::" (used as the connection host | ||
| // in approved-hosts, display logic, etc.). | ||
| if (origin.startsWith(AppConstants.MM_SDK.SDK_REMOTE_ORIGIN)) { | ||
| return SourceType.SDK; | ||
| } | ||
| if (isUUID(origin)) { | ||
| const sdkConnection = SDKConnect.getInstance().getConnection({ | ||
| channelId: origin, | ||
| }); | ||
| if (sdkConnection) { | ||
| return SourceType.SDK; | ||
| } | ||
| } | ||
|
|
||
| // Check if origin matches WalletConnect metadata | ||
| const isWalletConnect = wc2Metadata?.id && wc2Metadata.id.length > 0; | ||
| if (isWalletConnect) { | ||
| // --- WalletConnect --- | ||
| // wc2Metadata is a single Redux slot holding the *most recent* WC proposal | ||
| // metadata (set on session_proposal, cleared after approval/rejection). | ||
| // It is not keyed by origin — we rely on the WC proposal flow being | ||
| // serialized (via proposalLock in WalletConnectV2) so that during the | ||
| // approval window, a non-empty id implies *this* origin is from WC. | ||
|
Comment on lines
+61
to
+65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😭 😭 😭
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created a ticket to improve this here: https://consensyssoftware.atlassian.net/browse/WAPI-1383 |
||
| if (wc2Metadata?.id && wc2Metadata.id.length > 0) { | ||
| return SourceType.WALLET_CONNECT; | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.