Skip to content

Commit bc6ef9d

Browse files
fix: try fixing X deeplinks by adding $deeplink_path
1 parent f9325e3 commit bc6ef9d

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

app/core/AppConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default {
9393
},
9494
},
9595
MM_UNIVERSAL_LINK_HOST: 'metamask.app.link',
96+
MM_UNIVERSAL_LINK_HOST_ALTERNATE: 'metamask-alternate.app.link',
9697
MM_IO_UNIVERSAL_LINK_HOST: 'link.metamask.io',
9798
MM_IO_UNIVERSAL_LINK_TEST_HOST: 'link-test.metamask.io',
9899
MM_DEEP_ITMS_APP_LINK: 'https://metamask.app.link/skAH3BaF99',

app/core/DeeplinkManager/DeeplinkManager.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ export class DeeplinkManager {
6666

6767
try {
6868
const latestParams = await branch.getLatestReferringParams();
69-
const deeplink = latestParams?.['+non_branch_link'] as string;
69+
const deeplink = latestParams?.$deeplink_path
70+
? `metamask://${latestParams.$deeplink_path}`
71+
: (latestParams?.['+non_branch_link'] as string);
72+
Logger.log(`getBranchDeeplink - deeplink: ${deeplink}`);
7073
if (deeplink) {
7174
handleDeeplink({ uri: deeplink });
7275
}
@@ -117,12 +120,30 @@ export class DeeplinkManager {
117120
const branchError = new Error(error);
118121
Logger.error(branchError, 'Error subscribing to branch.');
119122
}
120-
getBranchDeeplink(opts.uri);
121-
//TODO: that async call in the subscribe doesn't look good to me
122-
branch.getLatestReferringParams().then((val) => {
123-
const deeplink = opts.uri || (val['+non_branch_link'] as string);
124-
handleDeeplink({ uri: deeplink });
125-
});
123+
const uri = opts.uri;
124+
125+
// If uri is a raw Branch URL (not a resolved deeplink),
126+
// try to get routing from Branch params instead
127+
const isBranchUrl = uri && /\.(app|test-app)\.link\//.test(uri);
128+
129+
Logger.log(`Received deeplink: ${uri}, isBranchUrl: ${isBranchUrl}`);
130+
131+
if (uri && !isBranchUrl) {
132+
handleDeeplink({ uri });
133+
} else {
134+
branch.getLatestReferringParams().then((params) => {
135+
Logger.log(
136+
`branch.getLatestReferringParams: ${JSON.stringify(params)}`,
137+
);
138+
const deeplink = params?.$deeplink_path
139+
? `metamask://${params.$deeplink_path}`
140+
: (params?.['+non_branch_link'] as string);
141+
Logger.log(`branch.subscribe - deeplink: ${deeplink}`);
142+
if (deeplink) {
143+
handleDeeplink({ uri: deeplink });
144+
}
145+
});
146+
}
126147
});
127148
}
128149
}

app/core/DeeplinkManager/handlers/legacy/handleUniversalLink.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import Logger from '../../../../util/Logger';
5757

5858
const {
5959
MM_UNIVERSAL_LINK_HOST,
60+
MM_UNIVERSAL_LINK_HOST_ALTERNATE,
6061
MM_IO_UNIVERSAL_LINK_HOST,
6162
MM_IO_UNIVERSAL_LINK_TEST_HOST,
6263
} = AppConstants;
@@ -216,6 +217,7 @@ async function handleUniversalLink({
216217

217218
const isSupportedDomain =
218219
urlObj.hostname === MM_UNIVERSAL_LINK_HOST ||
220+
urlObj.hostname === MM_UNIVERSAL_LINK_HOST_ALTERNATE ||
219221
urlObj.hostname === MM_IO_UNIVERSAL_LINK_HOST ||
220222
urlObj.hostname === MM_IO_UNIVERSAL_LINK_TEST_HOST;
221223

app/core/DeeplinkManager/util/deeplinks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import AppConstants from '../../../AppConstants';
22

33
const {
44
MM_UNIVERSAL_LINK_HOST,
5+
MM_UNIVERSAL_LINK_HOST_ALTERNATE,
56
MM_IO_UNIVERSAL_LINK_HOST,
67
MM_IO_UNIVERSAL_LINK_TEST_HOST,
78
} = AppConstants;
@@ -10,6 +11,7 @@ const METAMASK_HOSTS = [
1011
...new Set(
1112
[
1213
MM_UNIVERSAL_LINK_HOST || 'link.metamask.io',
14+
MM_UNIVERSAL_LINK_HOST_ALTERNATE || 'metamask-alternate.app.link',
1315
MM_IO_UNIVERSAL_LINK_HOST || 'link.metamask.io',
1416
MM_IO_UNIVERSAL_LINK_TEST_HOST || 'link-test.metamask.io',
1517
'metamask.app.link',

0 commit comments

Comments
 (0)