Skip to content

Commit 1dd9186

Browse files
committed
fix: improve tests + code
1 parent 95a8734 commit 1dd9186

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

  • packages/sdk-multichain/src/domain/platform

packages/sdk-multichain/src/domain/platform/index.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,38 @@ export enum PlatformType {
1313
ReactNative = 'react-native',
1414
}
1515

16-
1716
function isNotBrowser() {
18-
return (
19-
typeof window === 'undefined' ||
20-
!window?.navigator ||
21-
(typeof global !== 'undefined' &&
22-
global?.navigator?.product === 'ReactNative') ||
23-
navigator?.product === 'ReactNative'
24-
);
17+
if (typeof window === 'undefined') {
18+
return true;
19+
}
20+
if (!window?.navigator) {
21+
return true
22+
}
23+
if (typeof global !== 'undefined' &&
24+
global?.navigator?.product === 'ReactNative') {
25+
return true;
26+
}
27+
return navigator?.product === 'ReactNative'
2528
}
2629

2730
function isReactNative() {
28-
return (
29-
typeof window !== 'undefined' &&
30-
window?.navigator &&
31-
window.navigator?.product === 'ReactNative'
32-
) ?? false;
31+
const hasWindowNavigator = typeof window !== 'undefined' && window.navigator !== undefined;
32+
const navigator = hasWindowNavigator ?
33+
window.navigator :
34+
undefined;
35+
36+
if (!navigator) {
37+
return false;
38+
}
39+
40+
return hasWindowNavigator && window.navigator?.product === 'ReactNative'
3341
}
3442

3543
function isMetaMaskMobileWebView() {
3644
return (
3745
typeof window !== 'undefined' &&
3846
Boolean(window.ReactNativeWebView) &&
39-
Boolean(navigator.userAgent.endsWith('MetaMaskMobile'))
47+
Boolean(window.navigator.userAgent.endsWith('MetaMaskMobile'))
4048
);
4149
}
4250

0 commit comments

Comments
 (0)