feat(#305): Extract use ble enabled to a constant instead of env check

This commit is contained in:
Tilak Puli
2023-01-16 15:29:33 +05:30
parent 759295ac05
commit bbea73fd38
4 changed files with 8 additions and 6 deletions

View File

@@ -9,7 +9,9 @@ const { Openid4vpBle } = OpenIdBle;
type ShareProtocol = OpenIDBLEShare | IdpassSmartshareType;
let ShareLib: ShareProtocol;
if (USE_BLE_SHARE === 'true') {
export const isBLEEnabled = USE_BLE_SHARE === 'true';
if (isBLEEnabled) {
ShareLib = Openid4vpBle;
} else {
ShareLib = IdpassSmartshare;

View File

@@ -22,6 +22,7 @@ import { pure, respond } from 'xstate/lib/actions';
import { AppServices } from '../shared/GlobalContext';
import { request } from '../shared/request';
import { USE_BLE_SHARE } from 'react-native-dotenv';
import { isBLEEnabled } from '../lib/smartshare';
const model = createModel(
{
@@ -197,14 +198,14 @@ export const appMachine = model.createMachine(
activityLogMachine.id
);
serviceRefs.scan = USE_BLE_SHARE
serviceRefs.scan = isBLEEnabled
? spawn(
BLEScan.createScanMachine(serviceRefs),
BLEScan.scanMachine.id
)
: spawn(createScanMachine(serviceRefs), scanMachine.id);
serviceRefs.request = USE_BLE_SHARE
serviceRefs.request = isBLEEnabled
? spawn(
BLERequest.createRequestMachine(serviceRefs),
BLERequest.requestMachine.id

View File

@@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next';
import { LanguageSelector } from '../../components/LanguageSelector';
import i18next, { SUPPORTED_LANGUAGES } from '../../i18n';
import { USE_BLE_SHARE } from 'react-native-dotenv';
import { isBLEEnabled } from '../../lib/smartshare';
const LanguageSetting: React.FC = () => {
const { t } = useTranslation('ProfileScreen');
@@ -86,7 +87,7 @@ export const ProfileScreen: React.FC<MainRouteProps> = (props) => {
<ListItem.Content>
<ListItem.Title>
<Text color={Theme.Colors.profileLabel}>
{USE_BLE_SHARE === 'true' ? t('useBle') : t('useGoogleNearby')}
{isBLEEnabled ? t('useBle') : t('useGoogleNearby')}
</Text>
</ListItem.Title>
</ListItem.Content>

View File

@@ -50,8 +50,6 @@ export function offlineSubscribe<T extends SmartshareEventType>(
callback: (data: SmartshareEventData<T>) => void
) {
return IdpassSmartshare.handleNearbyEvents(({ type, data }) => {
console.log({ type, data });
console.log('{type, data}');
if (type !== 'msg') return;
const response = SmartshareEvent.fromString<T>(data);