Skip to content

Commit 60c11b2

Browse files
author
lukaw3d
committed
Move detecting a mobile app into runtimeIs
1 parent 9ccea52 commit 60c11b2

5 files changed

Lines changed: 13 additions & 8 deletions

File tree

.changelog/2155.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Move detecting a mobile app into runtimeIs

src/app/components/Ionic/components/IonicNativePlatformProvider/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { FC, PropsWithChildren } from 'react'
2-
import { Capacitor } from '@capacitor/core'
2+
import { runtimeIs } from '../../../../../config'
33
import { IonicContextProvider } from '../../providers/IonicProvider'
44
import { UpdateGate } from '../UpdateGate'
55

66
export const IonicNativePlatformProvider: FC<PropsWithChildren> = ({ children }) => {
7-
if (Capacitor.isNativePlatform()) {
7+
if (runtimeIs === 'mobile-app') {
88
return (
99
<IonicContextProvider>
1010
<UpdateGate>{children}</UpdateGate>

src/app/lib/ledger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { hex2uint, publicKeyToAddress } from './helpers'
77
import type Transport from '@ledgerhq/hw-transport'
88
import { isSupported, requestLedgerDevice } from '@ledgerhq/hw-transport-webusb/lib-es/webusb'
99
import BleTransport from '@oasisprotocol/ionic-ledger-hw-transport-ble/lib'
10-
import { Capacitor } from '@capacitor/core'
10+
import { runtimeIs } from '../../config'
1111

1212
interface LedgerAccount {
1313
publicKey: Uint8Array
@@ -22,7 +22,7 @@ export async function canAccessNavigatorUsb(): Promise<boolean> {
2222
export async function canAccessBle(): Promise<boolean> {
2323
const hasBLE = await BleTransport.isEnabled().catch(() => false)
2424
// Scan depends on requestLEScan method, which is not available on the web(feature flag)
25-
const hasLEScan = Capacitor.isNativePlatform() || !!navigator?.bluetooth?.requestLEScan
25+
const hasLEScan = runtimeIs === 'mobile-app' || !!navigator?.bluetooth?.requestLEScan
2626
return hasBLE && hasLEScan
2727
}
2828

src/app/pages/OpenWalletPage/Features/FromLedger/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Button } from 'grommet/es6/components/Button'
66
import { Text } from 'grommet/es6/components/Text'
77
import { canAccessBle, canAccessNavigatorUsb } from '../../../../lib/ledger'
88
import { useTranslation } from 'react-i18next'
9-
import { Capacitor } from '@capacitor/core'
109
import TransportWebUSB from '@ledgerhq/hw-transport-webusb'
10+
import { runtimeIs } from '../../../../../config'
1111

1212
type SelectOpenMethodProps = {
1313
openLedgerAccessPopup?: () => void
@@ -23,8 +23,7 @@ export function FromLedger({ openLedgerAccessPopup }: SelectOpenMethodProps) {
2323
async function getLedgerSupport() {
2424
const usbLedgerSupported = await canAccessNavigatorUsb()
2525

26-
const isNativePlatform = Capacitor.isNativePlatform()
27-
const bleLedgerSupported = isNativePlatform && (await canAccessBle())
26+
const bleLedgerSupported = runtimeIs === 'mobile-app' && (await canAccessBle())
2827

2928
setSupportsUsbLedger(usbLedgerSupported)
3029
setSupportsBleLedger(bleLedgerSupported)

src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Capacitor } from '@capacitor/core'
12
import { NetworkType } from 'app/state/network/types'
23

34
export const TRANSACTIONS_LIMIT = 20
@@ -198,7 +199,11 @@ export const paraTimesConfig: ParaTimesConfig = {
198199
}
199200

200201
// https://github.com/mozilla/webextension-polyfill/blob/6e3e26c/src/browser-polyfill.js#L9
201-
export const runtimeIs = (globalThis as any).chrome?.runtime?.id ? 'extension' : 'webapp'
202+
export const runtimeIs = Capacitor.isNativePlatform()
203+
? 'mobile-app'
204+
: (globalThis as any).chrome?.runtime?.id
205+
? 'extension'
206+
: 'webapp'
202207

203208
const splitUrls = (input: string | undefined): string[] =>
204209
input

0 commit comments

Comments
 (0)