Skip to content

Commit

Permalink
chore: test new regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hasan-deriv committed Apr 15, 2024
1 parent 2a49e8b commit fba5af8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/cfd/src/Containers/mt5-mobile-redirect-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ const MT5MobileRedirectOption = ({ mt5_trade_account }: TMT5MobileRedirectOption

useEffect(() => {
async function fetchData() {
const os = await mobileOSDetectAsync();
// eslint-disable-next-line no-console
console.log('==>', os);
await mobileOSDetectAsync();
}
fetchData();
}, []);
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/src/utils/os/os_detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export const mobileOSDetectAsync = async () => {
const huaweiDevicesRegex =
/\b(ALP-|AMN-|ANA-|ANE-|ANG-|AQM-|ARS-|ART-|ATU-|BAC-|BLA-|BRQ-|CAG-|CAM-|CAN-|CAZ-|CDL-|CDY-|CLT-|CRO-|CUN-|DIG-|DRA-|DUA-|DUB-|DVC-|ELE-|ELS-|EML-|EVA-|EVR-|FIG-|FLA-|FRL-|GLK-|HMA-|HW-|HWI-|INE-|JAT-|JEF-|JER-|JKM-|JNY-|JSC-|LDN-|LIO-|LON-|LUA-|LYA-|LYO-|MAR-|MED-|MHA-|MLA-|MRD-|MYA-|NCE-|NEO-|NOH-|NOP-|OCE-|PAR-|PIC-|POT-|PPA-|PRA-|RNE-|SEA-|SLA-|SNE-|SPN-|STK-|TAH-|TAS-|TET-|TRT-|VCE-|VIE-|VKY-|VNS-|VOG-|VTR-|WAS-|WKG-|WLZ-|JAD-|MLD-|RTE-|NAM-|NEN-|BAL-|JLN-|YAL|MGA-|FGD-|XYAO-|BON-|ALN-|ALT-|BRA-|DBY2-|STG-|MAO-|LEM-|GOA-|FOA-|MNA-|LNA-)\b/i;

const regex = /\b((?:ag[rs][23]?|bah2?|sht?|btv)-a?[lw]\d{2})\b(?!.+d\/s)/i;
const regex2 = /(?:huawei|honor)([-\w ]+)[;\)]/i;
const regex3 = /\b(nexus 6p|\w{2,4}e?-[atu]?[ln][\dx][012359c][adn]?)\b(?!.+d\/s)/i;

// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return 'Windows Phone';
Expand All @@ -120,7 +124,9 @@ export const mobileOSDetectAsync = async () => {
// Check if navigator.userAgentData is available for modern browsers
if (navigator?.userAgentData) {
const ua = await navigator.userAgentData.getHighEntropyValues(['model']);
if (huaweiDevicesRegex.test(ua?.model || '')) {
// eslint-disable-next-line no-console
console.log('==>', ua?.model && regex.test(ua.model) && regex2.test(ua.model) && regex3.test(ua.model));
if (ua?.model && regex.test(ua.model) && regex2.test(ua.model) && regex3.test(ua.model)) {
return 'huawei';
}
} else if (huaweiDevicesRegex.test(userAgent) || /huawei/i.test(userAgent)) {
Expand Down

0 comments on commit fba5af8

Please sign in to comment.