Skip to content

Commit

Permalink
feat(mosip#695): show error code in ble error popup
Browse files Browse the repository at this point in the history
  • Loading branch information
tilak-puli committed Apr 27, 2023
1 parent 087b26a commit ec8692a
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 15 deletions.
6 changes: 6 additions & 0 deletions lib/smartshare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import OpenIdBle from 'react-native-openid4vp-ble';
import { OpenIDBLEShare } from 'react-native-openid4vp-ble/lib/typescript/types/bleshare';
import { IdpassSmartshare as IdpassSmartshareType } from '@idpass/smartshare-react-native/lib/typescript/IdpassSmartshare';
import { USE_BLE_SHARE } from 'react-native-dotenv';

const { IdpassSmartshare } = SmartshareReactNative;
const { Openid4vpBle } = OpenIdBle;

Expand All @@ -19,3 +20,8 @@ if (isBLEEnabled) {
}

export default ShareLib;

export interface BLEError {
message?: string;
code?: number;
}
8 changes: 5 additions & 3 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@
"message": "Please connect to the internet to enable Online sharing mode"
},
"bleError": {
"title": "Failed to transfer!",
"message": "Something went wrong while transferring {{vcLabel}}. Please try again."
"title": "Failed to transfer",
"message": "Something went wrong while transferring {{vcLabel}}. Please try again.",
"hint": "Error: {{code}}"
}
},
"online": "Online",
Expand Down Expand Up @@ -342,7 +343,8 @@
},
"bleError": {
"title": "Failed to transfer",
"message": "Something went wrong while transferring {{vcLabel}}. Please try again."
"message": "Something went wrong while transferring {{vcLabel}}. Please try again.",
"hint": "Error: {{code}}"
}
}
},
Expand Down
24 changes: 19 additions & 5 deletions machines/openIdBle/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import { VcEvents } from '../vc';
import { ConnectionParams } from '@idpass/smartshare-react-native/lib/typescript/IdpassSmartshare';
import {
ExchangeReceiverInfoEvent,
onlineSubscribe,
offlineSend,
offlineSubscribe,
PairingResponseEvent,
onlineSend,
offlineSend,
onlineSubscribe,
PairingResponseEvent,
SendVcResponseEvent,
} from '../../shared/openIdBLE/smartshare';
import { log } from 'xstate/lib/actions';
import { BLEError } from '../../lib/smartshare';
// import { verifyPresentation } from '../shared/vcjs/verifyPresentation';

const { GoogleNearbyMessages } = SmartshareReactNative;
Expand All @@ -41,6 +42,7 @@ const model = createModel(
receiverInfo: {} as DeviceInfo,
incomingVc: {} as VC,
storeError: null as Error,
bleError: {} as BLEError,
connectionParams: '',
loggers: [] as EmitterSubscription[],
sharingProtocol: (Platform.OS === 'ios'
Expand All @@ -61,7 +63,7 @@ const model = createModel(
CONNECTION_DESTROYED: () => ({}),
CONNECTED: () => ({}),
DISCONNECT: () => ({}),
BLE_ERROR: () => ({}),
BLE_ERROR: (bleError: BLEError) => ({ bleError }),
EXCHANGE_DONE: (senderInfo: DeviceInfo) => ({ senderInfo }),
SCREEN_FOCUS: () => ({}),
SCREEN_BLUR: () => ({}),
Expand Down Expand Up @@ -119,6 +121,7 @@ export const requestMachine =
},
BLE_ERROR: {
target: '.handlingBleError',
actions: 'setBleError',
},
RESET: {
target: '.checkingBluetoothService',
Expand Down Expand Up @@ -548,6 +551,10 @@ export const requestMachine =
storeError: (_context, event) => event.error,
}),

setBleError: assign({
bleError: (_context, event) => event.bleError,
}),

registerLoggers: assign({
loggers: () => {
if (__DEV__) {
Expand Down Expand Up @@ -747,7 +754,10 @@ export const requestMachine =
}

if (event.type === 'onError') {
callback({ type: 'BLE_ERROR' });
callback({
type: 'BLE_ERROR',
bleError: { message: event.message, code: event.code },
});
console.log('BLE Exception: ' + event.message);
}
});
Expand Down Expand Up @@ -927,6 +937,10 @@ export function selectStoreError(state: State) {
return state.context.storeError;
}

export function selectBleError(state: State) {
return state.context.bleError;
}

export function selectIsRejected(state: State) {
return state.matches('reviewing.rejected');
}
Expand Down
1 change: 1 addition & 0 deletions machines/openIdBle/request.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface Typegen0 {
| 'done.invoke.request.reviewing.verifyingVp:invocation[0]';
requestReceiverInfo: 'CONNECTED';
sendVcReceived: 'STORE_RESPONSE';
setBleError: 'BLE_ERROR';
setIncomingVc: 'VC_RECEIVED';
setReceiveLogTypeDiscarded: 'CANCEL' | 'REJECT' | 'STORE_ERROR';
setReceiveLogTypeRegular: 'ACCEPT' | 'STORE_RESPONSE';
Expand Down
18 changes: 13 additions & 5 deletions machines/openIdBle/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ import {
check,
PERMISSIONS,
PermissionStatus,
request,
RESULTS,
} from 'react-native-permissions';
import { checkLocation, requestLocation } from '../../shared/location';
import { CameraCapturedPicture } from 'expo-camera';
import { log } from 'xstate/lib/actions';
import { isBLEEnabled } from '../../lib/smartshare';
import { BLEError, isBLEEnabled } from '../../lib/smartshare';
import { createQrLoginMachine, qrLoginMachine } from '../QrLoginMachine';
import { StoreEvents } from '../store';

Expand All @@ -63,6 +62,7 @@ const model = createModel(
senderInfo: {} as DeviceInfo,
receiverInfo: {} as DeviceInfo,
selectedVc: {} as VC,
bleError: {} as BLEError,
createdVp: null as VC,
reason: '',
loggers: [] as EmitterSubscription[],
Expand All @@ -89,7 +89,7 @@ const model = createModel(
DISMISS: () => ({}),
CONNECTED: () => ({}),
DISCONNECT: () => ({}),
BLE_ERROR: () => ({}),
BLE_ERROR: (bleError: BLEError) => ({ bleError }),
CONNECTION_DESTROYED: () => ({}),
SCREEN_BLUR: () => ({}),
SCREEN_FOCUS: () => ({}),
Expand Down Expand Up @@ -147,6 +147,7 @@ export const scanMachine =
},
BLE_ERROR: {
target: '.handlingBleError',
actions: 'setBleError',
},
},
states: {
Expand Down Expand Up @@ -636,6 +637,10 @@ export const scanMachine =
createdVp: () => null,
}),

setBleError: assign({
bleError: (_context, event) => event.bleError,
}),

registerLoggers: assign({
loggers: (context) => {
if (context.sharingProtocol === 'OFFLINE' && __DEV__) {
Expand Down Expand Up @@ -810,8 +815,11 @@ export const scanMachine =
callback({ type: 'DISCONNECT' });
}
if (event.type === 'onError') {
callback({ type: 'BLE_ERROR' });
console.log('BLE Exception: ' + event.message);
callback({
type: 'BLE_ERROR',
bleError: { message: event.message, code: event.code },
});
console.log(`BLE Exception:${event.code} ${event.message}`);
}
});

Expand Down
Loading

0 comments on commit ec8692a

Please sign in to comment.