@@ -6,9 +6,7 @@ import type {
66 DeviceOS ,
77 DeviceType ,
88 ChainId ,
9- Chain ,
10- WalletInit ,
11- WalletModule
9+ Chain
1210} from '@web3-onboard/common'
1311
1412import ethereumIcon from './icons/ethereum'
@@ -23,18 +21,26 @@ import gnosisIcon from './icons/gnosis'
2321import harmonyOneIcon from './icons/harmony-one'
2422import arbitrumIcon from './icons/arbitrum'
2523
26- import type { ChainStyle , ConnectedChain } from './types'
24+ import type { ChainStyle , ConnectedChain , DeviceNotBrowser } from './types'
2725
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 ( )
26+ export function getDevice ( ) : Device | DeviceNotBrowser {
27+ if ( typeof window !== 'undefined' ) {
28+ const parsed = bowser . getParser ( window . navigator . userAgent )
29+ const os = parsed . getOS ( )
30+ const browser = parsed . getBrowser ( )
31+ const { type } = parsed . getPlatform ( )
3332
34- return {
35- type : type as DeviceType ,
36- os : os as DeviceOS ,
37- browser : browser as DeviceBrowser
33+ return {
34+ type : type as DeviceType ,
35+ os : os as DeviceOS ,
36+ browser : browser as DeviceBrowser
37+ }
38+ } else {
39+ return {
40+ type : null ,
41+ os : null ,
42+ browser : null
43+ }
3844 }
3945}
4046
@@ -157,30 +163,3 @@ export function connectedToValidAppChain(
157163 namespace === walletConnectedChain . namespace
158164 )
159165}
160-
161- export function initializeWalletModules (
162- modules : WalletInit [ ] ,
163- device : Device
164- ) : WalletModule [ ] {
165- return modules . reduce ( ( acc , walletInit ) => {
166- const initialized = walletInit ( { device } )
167-
168- if ( initialized ) {
169- // injected wallets is an array of wallets
170- acc . push ( ...( Array . isArray ( initialized ) ? initialized : [ initialized ] ) )
171- }
172-
173- return acc
174- } , [ ] as WalletModule [ ] )
175- }
176-
177- export function uniqueWalletsByLabel (
178- walletModuleList : WalletModule [ ]
179- ) : WalletModule [ ] {
180- return walletModuleList . filter (
181- ( wallet , i ) =>
182- walletModuleList . findIndex (
183- ( innerWallet : WalletModule ) => innerWallet . label === wallet . label
184- ) === i
185- )
186- }
0 commit comments