Skip to content

Commit 391c920

Browse files
authored
Merge pull request #151 from blocknative/enhancement/detect-os
Added feature to set os exclusions for wallets. Closes #149
2 parents b7606c1 + b24660b commit 391c920

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

src/interfaces.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface WalletModule {
8282
preferred?: boolean
8383
desktop?: boolean
8484
mobile?: boolean
85+
osExclusions?: Array<string>
8586
}
8687

8788
export interface Helpers {
@@ -209,6 +210,7 @@ export interface AppState {
209210
networkId: number
210211
version: string
211212
mobileDevice: boolean
213+
os: string
212214
darkMode: boolean
213215
autoSelectWallet: string
214216
walletSelectInProgress: boolean

src/modules/select/wallets/opera-touch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function operaTouch(
3737
link: 'https://www.opera.com/mobile/touch',
3838
installMessage: extensionInstallMessage,
3939
mobile: true,
40-
preferred
40+
preferred,
41+
osExclusions: ['Android']
4142
}
4243
}
4344

src/modules/select/wallets/opera.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ function opera(
3737
link: 'https://www.opera.com/',
3838
installMessage: extensionInstallMessage,
3939
desktop: true,
40-
preferred
40+
mobile: true,
41+
preferred,
42+
osExclusions: ['iOS']
4143
}
4244
}
4345

src/onboard.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
walletInterface
1515
} from './stores'
1616

17-
import { isMobileDevice } from './utilities'
17+
import { getDeviceInfo } from './utilities'
1818
import { initializeBlocknative } from './services'
1919
import { validateInit, validateConfig } from './validation'
2020

@@ -45,12 +45,15 @@ function init(initialization: Initialization): API {
4545

4646
initializeBlocknative(dappId, networkId)
4747

48+
const { os, isMobile } = getDeviceInfo()
49+
4850
app.update((store: AppState) => ({
4951
...store,
5052
dappId,
5153
networkId,
5254
version,
53-
mobileDevice: isMobileDevice(),
55+
mobileDevice: isMobile,
56+
os,
5457
darkMode
5558
}))
5659

src/stores.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const app: WritableStore = writable({
1818
networkId: 1,
1919
version: '',
2020
mobileDevice: false,
21+
os: '',
2122
darkMode: false,
2223
walletSelectInProgress: false,
2324
walletSelectCompleted: false,

src/utilities.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,15 @@ export function getProviderName(provider: any): string | undefined {
161161
}
162162
}
163163

164-
export function isMobileDevice() {
164+
export function getDeviceInfo() {
165165
const browser = bowser.getParser(window.navigator.userAgent)
166+
const { name } = browser.getOS()
166167
const { type } = browser.getPlatform()
167168

168-
return type !== 'desktop'
169+
return {
170+
isMobile: type !== 'desktop',
171+
os: name
172+
}
169173
}
170174

171175
export function networkName(id: number): string {

src/views/WalletSelect.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
4545
let selectedWalletModule: WalletModule
4646
47-
const { mobileDevice } = get(app)
47+
const { mobileDevice, os } = get(app)
4848
let { heading, description, wallets } = module
4949
5050
let primaryWallets: WalletModule[]
@@ -59,9 +59,12 @@
5959
6060
wallets = await wallets
6161
62-
const deviceWallets = (wallets as WalletModule[]).filter(
63-
wallet => wallet[mobileDevice ? 'mobile' : 'desktop']
64-
)
62+
const deviceWallets = (wallets as WalletModule[])
63+
.filter(wallet => wallet[mobileDevice ? 'mobile' : 'desktop'])
64+
.filter(wallet => {
65+
const { osExclusions = [] } = wallet
66+
return !osExclusions.includes(os)
67+
})
6568
6669
if (appState.autoSelectWallet) {
6770
const module = deviceWallets.find(

0 commit comments

Comments
 (0)