Skip to content

Commit 63532fb

Browse files
authored
Hirad: adding deep-linking (#12840)
* feat: adding deep-linking * fix: added android to the condition as well * fix: removed the redundant re-renders * fix: improved the code * fix: fixed the issue of the mt5 for desktop * fix: changed the inconsistency of the is_mobile * fix: fixing the sonarCloud issues * fix: trying the onBlur * fix: fixing the sonar cloud issue * fix: changing the onClick component * fix: fixing the sonar cloud issue * fix: fixed the type of the window.location * fix: added comment to get the type fixed * fix: made the code more consistent * fix: improved the quality of the code * fix: improved the quality of the code * fix: changed the namings * fix: made is_mobile condition more readable * fix: fixing the issue of the iOS users
1 parent d1738a6 commit 63532fb

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

packages/cfd/src/Containers/dmt5-trade-modal.tsx

+31-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getPlatformSettings,
1010
getUrlBase,
1111
MT5_ACCOUNT_STATUS,
12+
mobileOSDetect,
1213
} from '@deriv/shared';
1314
import { observer, useStore } from '@deriv/stores';
1415
import { Localize, localize } from '@deriv/translations';
@@ -61,6 +62,28 @@ const DMT5TradeModal = observer(
6162
return undefined;
6263
};
6364

65+
const getMobileAppInstallerURL = () => {
66+
if (mobileOSDetect() === 'iOS') {
67+
return getPlatformMt5DownloadLink('ios');
68+
} else if (/huawei/i.test(navigator.userAgent)) {
69+
return getPlatformMt5DownloadLink('huawei');
70+
}
71+
return getPlatformMt5DownloadLink('android');
72+
};
73+
74+
let mobile_url;
75+
const mobileURLSet = () => {
76+
mobile_url = window.location.replace(deepLink);
77+
const timeout = setTimeout(() => {
78+
mobile_url = window.location.replace(getMobileAppInstallerURL());
79+
}, 3000);
80+
if (!/safari/i.test(navigator.userAgent)) {
81+
window.onblur = () => {
82+
clearTimeout(timeout);
83+
};
84+
}
85+
};
86+
6487
const getHeadingTitle = () =>
6588
getCFDAccountDisplay({
6689
market_type: mt5_trade_account.market_type,
@@ -93,6 +116,10 @@ const DMT5TradeModal = observer(
93116
MT5_ACCOUNT_STATUS.MIGRATED_WITHOUT_POSITION,
94117
].includes(mt5_trade_account?.status);
95118

119+
const deepLink = `metatrader5://account?login=${
120+
(mt5_trade_account as TTradingPlatformAccounts)?.display_login
121+
}&server=${(mt5_trade_account as DetailsOfEachMT5Loginid)?.server_info?.environment}`;
122+
96123
return (
97124
<div className='cfd-trade-modal-container'>
98125
<div className='cfd-trade-modal'>
@@ -193,9 +220,10 @@ const DMT5TradeModal = observer(
193220
<a
194221
className='dc-btn cfd-trade-modal__download-center-app--option-link'
195222
type='button'
196-
href={mt5_trade_account.webtrader_url}
197-
target='_blank'
198-
rel='noopener noreferrer'
223+
onClick={is_mobile ? mobileURLSet : undefined}
224+
href={is_mobile ? mobile_url : mt5_trade_account.webtrader_url}
225+
target={is_mobile ? '' : '_blank'}
226+
rel={is_mobile ? '' : 'noopener noreferrer'}
199227
>
200228
<Text size='xxs' weight='bold' color='prominent'>
201229
{localize('Open')}

0 commit comments

Comments
 (0)