Skip to content

Commit

Permalink
chore: console ua parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-deriv committed Apr 23, 2024
1 parent bf3b97f commit 6d3e714
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/cfd/src/Containers/mt5-mobile-redirect-option.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import React, { useEffect } from 'react';
import { DetailsOfEachMT5Loginid } from '@deriv/api-types';
import { Icon, Text } from '@deriv/components';
import { Localize } from '@deriv/translations';
import { DEEP_LINK, WEBTRADER_URL, getMobileAppInstallerURL } from '../Helpers/constants';
import './mt5-mobile-redirect-option.scss';
import { isSafariBrowser } from '@deriv/shared';
import { isSafariBrowser, mobileOSDetectAsync } from '@deriv/shared';

type TMT5MobileRedirectOptionProps = {
mt5_trade_account: DetailsOfEachMT5Loginid;
Expand All @@ -27,6 +27,13 @@ const MT5MobileRedirectOption = ({ mt5_trade_account }: TMT5MobileRedirectOption
}
};

useEffect(() => {
async function test() {
await mobileOSDetectAsync();
}
test();
}, []);

return (
<div className='mt5-download-container'>
<a
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"moment": "^2.29.2",
"object.fromentries": "^2.0.0",
"react": "^17.0.2",
"react-loadable": "^5.5.0"
"react-loadable": "^5.5.0",
"ua-parser-js": "^1.0.37"
}
}
7 changes: 7 additions & 0 deletions packages/shared/src/utils/os/os_detect.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import UAParser from 'ua-parser-js';

declare global {
interface Window {
opera?: string;
Expand Down Expand Up @@ -233,6 +235,11 @@ function validateHuaweiCodes(inputString: string) {

export const mobileOSDetectAsync = async () => {
const userAgent = navigator.userAgent ?? window.opera ?? '';
const parser = new UAParser(userAgent);

// eslint-disable-next-line no-console
console.log('==>', parser.getDevice());

// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return 'Windows Phone';
Expand Down

0 comments on commit 6d3e714

Please sign in to comment.