Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add in-app browser check for mobile #2219

Closed
wants to merge 11 commits into from
18 changes: 17 additions & 1 deletion packages/core/src/utils/CoreHelperUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { ConstantsUtil } from './ConstantsUtil.js'
import type { CaipAddress, LinkingRecord, CaipNetwork } from './TypeUtil.js'

export const CoreHelperUtil = {
isMobile() {
isInAppBrowser() {
if (typeof window !== 'undefined') {
return Boolean(/WebKit|wv|MetaMaskMobile|Phantom/u.test(navigator.userAgent))
}

return false
},

isMobileDevice() {
if (typeof window !== 'undefined') {
return Boolean(
window.matchMedia('(pointer:coarse)').matches ||
Expand All @@ -14,6 +22,14 @@ export const CoreHelperUtil = {
return false
},

isMobile() {
if (typeof window !== 'undefined') {
return this.isInAppBrowser() || this.isMobileDevice()
}

return false
},

checkCaipNetwork(network: CaipNetwork | undefined, networkName = '') {
return network?.id.toLocaleLowerCase().includes(networkName.toLowerCase())
},
Expand Down