Skip to content

Commit 8b9607b

Browse files
authored
feat: Implement LegacyLinkAdapter between old and new 'core' links (#22202)
Part 2 of 4 to fix: MetaMask/mobile-planning#2343 https://consensyssoftware.atlassian.net/jira/polaris/projects/MWMR/ideas/view/8845676?selectedIssue=MWMR-10 Previous Part: #21869 ## Description This PR adds `LegacyLinkAdapter`, a bidirectional adapter that bridges the new `CoreUniversalLink` format (from PR #XXXX) with the existing legacy deep link handlers. This is the second PR in Phase 1 of the deep link consolidation project. ### Context The current deep link system has routing logic fragmented across multiple files with nested switch-case statements. This adapter enables gradual migration to a unified routing system while maintaining 100% backward compatibility with existing handlers. ### What Changed - **Created `LegacyLinkAdapter`** with bidirectional conversion methods: - `toLegacyFormat()` - Converts `CoreUniversalLink` to legacy `urlObj` + `params` format - `fromLegacyFormat()` - Creates `CoreUniversalLink` from legacy URL strings - `extractActionParams()` - Extracts action-specific paths and query parameters - `toProtocolUrl()` - Converts links between protocols (metamask://, https://, ethereum://, dapp://) - `shouldUseNewSystem()` - Feature flag system for gradual rollout (currently disabled for all actions) - `wrapHandler()` - Wraps legacy handlers to accept `CoreUniversalLink` - **Added comprehensive test coverage** (23 test cases): - Format conversion tests - Parameter handling (including SDK params) - Protocol conversions - Edge cases (null/undefined values, empty paths) ### Why This Approach - **Non-breaking**: No changes to existing deep link handlers in this PR - **Gradual migration**: `shouldUseNewSystem()` allows action-by-action rollout - **Type-safe**: Full TypeScript coverage with proper type guards - **Testable**: All adapter methods are pure functions with comprehensive tests ### Dependencies None ### How to Test - Only automated tests at this time since this functionality is not actually "enabled" in the app --- ## Changelog ### Added - Added `LegacyLinkAdapter` for bidirectional conversion between new `CoreUniversalLink` format and legacy deep link handlers - Added migration strategy with `shouldUseNewSystem()` feature flag for gradual rollout <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduce LegacyLinkAdapter for bidirectional conversion between new core links and legacy handlers, add protocol/path utilities and tests, and map `ACTIONS.PERPS_MARKETS` in the normalizer. > > - **Deeplink Adapter**: > - Implement `LegacyLinkAdapter` with: > - `toLegacyFormat` / `fromLegacyFormat` for bidirectional conversion between `CoreUniversalLink` and legacy `urlObj` + `params`. > - `wrapHandler` to adapt legacy handlers to core links. > - `extractActionParams` to derive action path/query params. > - `toProtocolUrl` to convert links across `metamask`, `https`, `ethereum`, and `dapp`. > - `shouldUseNewSystem` feature-flag list (currently empty). > - **Normalizer**: > - Add `ACTIONS.PERPS_MARKETS` → `perpsMarketsPath` to `ACTION_PATH_MAP` in `CoreLinkNormalizer`. > - **Tests**: > - Add `LegacyLinkAdapter.test.ts` covering conversions, param handling (incl. SDK and custom params), protocol conversions, empty/edge cases, and handler wrapping. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d81867b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 344f947 commit 8b9607b

File tree

3 files changed

+699
-0
lines changed

3 files changed

+699
-0
lines changed

app/core/DeeplinkManager/CoreLinkNormalizer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class CoreLinkNormalizer {
3232
[ACTIONS.ONBOARDING]: 'onboardingPath',
3333
[ACTIONS.CREATE_ACCOUNT]: 'createAccountPath',
3434
[ACTIONS.DEPOSIT]: 'depositCashPath',
35+
[ACTIONS.PERPS_MARKETS]: 'perpsMarketsPath',
3536
};
3637

3738
/**

0 commit comments

Comments
 (0)