Skip to content
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

[5.2][IMPROVEMENT] Adds support for 'dapp/' urls support on 'metamask://' and fixes DL opening to Apple Store #4167

Merged
merged 7 commits into from
May 13, 2022
1 change: 1 addition & 0 deletions app/core/AppConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default {
SUPPORTED_NETWORKS: [MAINNET, RINKEBY],
},
MM_UNIVERSAL_LINK_HOST: 'metamask.app.link',
MM_DEEP_ITMS_APP_LINK: 'https://metamask.app.link/skAH3BaF99',
SAI_ADDRESS: '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359',
HOMEPAGE_URL: 'https://home.metamask.io/',
SHORT_HOMEPAGE_URL: 'MetaMask.io',
Expand Down
33 changes: 29 additions & 4 deletions app/core/DeeplinkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ class DeeplinkManager {

const handled = () => (onHandled ? onHandled() : false);

const { MM_UNIVERSAL_LINK_HOST } = AppConstants;
const { MM_UNIVERSAL_LINK_HOST, MM_DEEP_ITMS_APP_LINK } = AppConstants;
const DEEP_LINK_BASE = `${PROTOCOLS.HTTPS}://${MM_UNIVERSAL_LINK_HOST}`;

switch (urlObj.protocol.replace(':', '')) {
case PROTOCOLS.HTTP:
Expand All @@ -250,16 +251,34 @@ class DeeplinkManager {
return;
} else if (PREFIXES[action]) {
const url = urlObj.href.replace(
`https://${MM_UNIVERSAL_LINK_HOST}/${action}/`,
`${DEEP_LINK_BASE}/${action}/`,
PREFIXES[action],
);
// loops back to open the link with the right protocol
this.parse(url, { browserCallBack });
} else {
// If it's our universal link don't open it in the browser
if (!action && urlObj.href === `https://${MM_UNIVERSAL_LINK_HOST}/`)
// If it's our universal link or Apple store deep link don't open it in the browser
if (
(!action &&
(urlObj.href === `${DEEP_LINK_BASE}/` ||
urlObj.href === DEEP_LINK_BASE)) ||
urlObj.href === MM_DEEP_ITMS_APP_LINK
)
return;

// Fix for Apple Store redirect even when app is installed
if (urlObj.href.startsWith(`${DEEP_LINK_BASE}/`)) {
this._handleBrowserUrl(
`${PROTOCOLS.HTTPS}://${urlObj.href.replace(
`${DEEP_LINK_BASE}/`,
'',
)}`,
browserCallBack,
);

return;
}

// Normal links (same as dapp)
this._handleBrowserUrl(urlObj.href, browserCallBack);
}
Expand Down Expand Up @@ -315,6 +334,12 @@ class DeeplinkManager {
params?.autosign,
origin,
);
} else if (url.startsWith('metamask://dapp/')) {
try {
this._handleBrowserUrl(urlObj.href.split('metamask://dapp/')[1]);
} catch (e) {
if (e) Alert.alert(strings('deeplink.invalid'), e.toString());
}
}
break;
default:
Expand Down
1 change: 1 addition & 0 deletions ios/MetaMask/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitter</string>
<string>itms-apps</string>
</array>
</dict>
</plist>