Skip to content

feat: add open link platform API - #41267

Open
mganchas wants to merge 7 commits into
mainfrom
feat/open-link-platform-api
Open

mganchas wants to merge 7 commits into
mainfrom
feat/open-link-platform-api

Conversation

@mganchas

@mganchas mganchas commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds openLink() and useOpenLink() under app/platform/links/ (spec-022). Mobile Platform owns the contract; feature teams own when to open a link, which origins they trust, and what they track.

  • mode is required: system uses Linking.openURL, sheet uses react-native-inappbrowser-reborn with one configurable fallback (webview default, system, none).
  • Fixed scheme allowlists (system: https: mailto: tel: itms-apps: market:; sheet: https:), MetaMask self-scheme and METAMASK_DEEPLINK_HOSTS rejection, original-string dispatch.
  • Shared sheet guard across imperative callers and hook instances; hook-level repeat-call lock; closeSheet only after native dismissal while mounted.
  • Sanitized logging: no URL, query, fragment, userinfo or raw native error reaches Logger.
  • Ships with no production consumers. No dependency, lint rule, SimpleWebview, native, auth or deeplink changes. Contract overview: app/platform/links/README.md, with API types and contract tests colocated.

Rollback: revert this PR as a unit.

Test layer placement

Unit (*.test.ts): capability with no UI, tested at the public entry point (.) with native, navigation and logger boundaries mocked.

Changelog

CHANGELOG entry: null

Related issues

Refs: .specs/spec-022-open-link-platform-api.md

Manual testing steps

Feature: Open link platform API (no production consumers)

  Scenario: Native behavior in a local-only harness
    Given a local-only harness screen calling openLink / useOpenLink (not committed)
    When the tester opens a system link, a sheet link, and a sheet link with the sheet stubbed unavailable
    Then system hands off to the OS, the sheet shows Safari View Controller / Custom Tab, and the fallback issues one OS or WebView open

Native QA (Android emulator, iOS simulator) has not been run for this PR; see Evidence.

Screenshots/Recordings

N/A — no UI change and no production consumer.

Evidence (spec Log)

  • Baseline: Mobile origin/main 98c38bc7d65e717d0481e15f597367d24e4f6583. Skills origin/main 885dd4def32b2000a2b7ee4d599da00bf09400d7 (skills PR not opened yet; waits for this PR on main).
  • Scoped diff / owner: 9 files: app/platform/links/** + one /app/platform/ CODEOWNERS entry → @MetaMask/mobile-platform. 997 lines added against the PR base. No other file changed.
  • Tests: yarn jest app/platform/links --coverage → 1 suite, 96 tests pass, 100% statements, branches, functions and lines for executable capability code. The consolidated suite tests both public entry points with shared mocks. It covers both scheme allowlists, MetaMask schemes and hosts, malformed and ambiguous URLs, the app URL polyfill, original-string handoff, synchronous OS dispatch, fallback routing, shared and hook-level guards, dismissal and unmount behavior, and sanitized errors and logging.
  • Lint/format/types: eslint, oxlint (existing warnings only), and prettier --check pass on app/platform/links. Full tsc --noEmit -p . passes after restoring the ignored, generated termsOfUseContent.ts from the local Mobile setup.
  • Reference inventory (pinned d1f6d744cc3d, independently reproduced with git grep, non-test files): Linking.openURL 117 (source-reported 112); native sheet InAppBrowser.open 6 (matches) plus 3 openAuth files (source: two auth flows); dapp browser (Routes.BROWSER.HOME|VIEW) 33 (source 24); SimpleWebview (WEBVIEW.SIMPLE|SimpleWebview) 71 (source 62). Different patterns, so counts are not a migration inventory.
  • Native QA: not run. Android emulator and iOS simulator checks from the spec's How to Test are still outstanding. Device-only universal-link behavior is not claimed.
  • Installer/audit: n/a here (Skills PR).
  • Knip (initial implementation): yarn knip:check fails on main baseline drift unrelated to this diff (2 unused Collectibles files, 1 stale baseline entry); app/platform/links has no new findings.

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Medium Risk
New shared link-opening path with URL validation and optional WebView fallback affects security posture once adopted; this PR adds no runtime consumers, so immediate production risk is low.

Overview
Introduces a new app/platform/links platform module with openLink and useOpenLink, plus a /app/platform/ CODEOWNERS entry for Mobile Platform. There are no production call sites in this PR; feature teams adopt the API later.

openLink validates URLs (mode-specific scheme allowlists, rejection of MetaMask self-schemes and deeplink hosts), then opens via system (Linking.openURL), sheet (native in-app browser), or webview fallback on SimpleWebview. Results are always opened / rejected / failed; errors and logs omit URL secrets and only expose a normalized hostname for onOpen / logContext.

useOpenLink adds per-hook repeat-tap gating, isOpening, optional closeSheet after native sheet dismiss (when still mounted), and shares a global sheet in-flight guard with imperative callers. Contract behavior is documented in README.md and covered by a large openLink.test.ts suite.

Reviewed by Cursor Bugbot for commit 922ea40. Configure here.

Add openLink() and useOpenLink() under app/platform/links with fixed scheme
allowlists, MetaMask link rejection, a shared sheet guard, a single fallback
and sanitized logging. No production consumers. Mobile Platform owns the
contract.
@mganchas mganchas added the no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed label Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@github-actions github-actions Bot added size-XL pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. labels Dec 3, 2026
@metamask-ci metamask-ci Bot added the team-mobile-platform Mobile Platform team label Dec 3, 2026
@metamask-ci

metamask-ci Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Pre-merge author checklist has only 5 of the required 8 items. Every checklist row must be present and consciously checked — do not delete rows.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

Comment thread .github/CODEOWNERS Resolved
Comment thread app/platform/links/openLink.ts Resolved
Comment thread app/platform/links/openLink.ts Resolved
Comment thread app/platform/links/openLink.ts Resolved
Comment thread app/platform/links/openLink.ts Resolved
Comment thread app/platform/links/openLink.ts Resolved
Comment thread app/platform/links/README.md Resolved
Comment thread app/platform/links/types.ts Resolved
Comment thread app/platform/links/types.ts Resolved
Comment thread app/platform/links/useOpenLink.ts Resolved
Comment thread app/platform/links/useOpenLink.ts Resolved
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.69%. Comparing base (4216b78) to head (cf9500f).
⚠️ Report is 76 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #41267      +/-   ##
==========================================
+ Coverage   88.67%   88.69%   +0.01%     
==========================================
  Files        8795     8859      +64     
  Lines      266024   268365    +2341     
  Branches    68391    69016     +625     
==========================================
+ Hits       235907   238020    +2113     
- Misses      16594    16708     +114     
- Partials    13523    13637     +114     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread app/platform/links/openLink.ts Resolved
Comment thread app/platform/links/openLink.ts Resolved
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added size-L and removed size-XL labels Dec 4, 2026
@mganchas
mganchas marked this pull request as ready for review December 4, 2026 12:00
@mganchas
mganchas requested a review from a team as a code owner December 4, 2026 12:00

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed pr-not-ready-for-e2e Skip E2E and block merging. Remove this label once the PR is ready to run the E2E tests. size-L team-mobile-platform Mobile Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants