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

fix: update isMobile function #240

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/dapp-toolkit/src/helpers/is-mobile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, it, expect } from 'vitest'
import { isMobile } from './is-mobile'

describe('isMobile', () => {
it('should return true if userAgent is mobile', () => {
;[
'Mozilla/5.0 (iPad; CPU OS 13_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/126.0.0.0 Mobile/15E148 Safari/604.1',
].forEach((userAgent) => {
expect(isMobile(userAgent)).toBe(true)
})
})
})
6 changes: 3 additions & 3 deletions packages/dapp-toolkit/src/helpers/is-mobile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Bowser from 'bowser'

export const isMobile = () => {
const userAgent = Bowser.parse(window.navigator.userAgent)
return userAgent.platform.type === 'mobile'
export const isMobile = (userAgent: string = window.navigator.userAgent) => {
const parsed = Bowser.parse(userAgent)
return parsed.platform.type === 'mobile' || parsed.platform.type === 'tablet'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ResultAsync } from 'neverthrow'
import { errAsync, okAsync } from 'neverthrow'
import { Logger } from '../../../../helpers'
import { Logger, isMobile } from '../../../../helpers'
import Bowser from 'bowser'
import { SdkError } from '../../../../error'

Expand Down Expand Up @@ -34,7 +34,7 @@ export const DeepLinkModule = (input: {
data: { ...values },
})

if (platform.type === 'mobile' && globalThis.location?.href) {
if (isMobile() && globalThis.location?.href) {
globalThis.location.href = outboundUrl.toString()

return okAsync(undefined)
Expand Down
Loading