Skip to content

Commit c3635ba

Browse files
authored
Fix scenario where window is not available (#931)
1 parent 56623ac commit c3635ba

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

packages/core/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import initI18N from './i18n'
1414

1515
import App from './views/Index.svelte'
1616
import type { InitOptions, OnboardAPI } from './types'
17-
import { device } from './utils'
17+
import { getDevice } from './utils'
1818

1919
const API = {
2020
connectWallet,
@@ -58,6 +58,8 @@ function init(options: InitOptions): OnboardAPI {
5858

5959
let accountCenterUpdate
6060

61+
const device = getDevice()
62+
6163
if (device.type === 'mobile') {
6264
accountCenterUpdate = {
6365
enabled: false

packages/core/src/utils.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ import arbitrumIcon from './icons/arbitrum'
2525

2626
import type { ChainStyle, ConnectedChain } from './types'
2727

28-
const parsed = bowser.getParser(window.navigator.userAgent)
29-
const os = parsed.getOS()
30-
const browser = parsed.getBrowser()
31-
const { type } = parsed.getPlatform()
32-
33-
export const device: Device = {
34-
type: type as DeviceType,
35-
os: os as DeviceOS,
36-
browser: browser as DeviceBrowser
28+
export function getDevice(): Device {
29+
const parsed = bowser.getParser(window.navigator.userAgent)
30+
const os = parsed.getOS()
31+
const browser = parsed.getBrowser()
32+
const { type } = parsed.getPlatform()
33+
34+
return {
35+
type: type as DeviceType,
36+
os: os as DeviceOS,
37+
browser: browser as DeviceBrowser
38+
}
3739
}
3840

3941
export const notNullish = <T>(value: T | null | undefined): value is T =>

0 commit comments

Comments
 (0)