Skip to content

Commit

Permalink
feat(INJI-433): add events for VC share success and failure scenario …
Browse files Browse the repository at this point in the history
…for sender

Signed-off-by: Alka <[email protected]>
  • Loading branch information
Alka1703 committed Oct 30, 2023
1 parent e82599f commit c75501d
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 20 deletions.
5 changes: 4 additions & 1 deletion machines/bleShare/request/requestMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,10 @@ export const requestMachine =
callback({type: 'DISCONNECT'});
}

if (event.type === EventTypes.onError) {
if (
event.type === EventTypes.onError &&
event.code.includes('TVV')
) {
callback({
type: 'BLE_ERROR',
bleError: {message: event.message, code: event.code},
Expand Down
103 changes: 84 additions & 19 deletions machines/bleShare/scan/scanMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ import {
sendStartEvent,
sendEndEvent,
TelemetryConstants,
sendImpressionEvent,
getImpressionEventData,
sendErrorEvent,
getErrorEventData,
} from '../../../shared/telemetry/TelemetryUtils';
import {logState} from '../../../shared/commonUtil';

Expand Down Expand Up @@ -145,7 +149,7 @@ export const scanMachine =
},
BLE_ERROR: {
target: '.handlingBleError',
actions: 'setBleError',
actions: ['sendBLEConnectionErrorEvent', 'setBleError'],
},
RESET: {
target: '.checkStorage',
Expand Down Expand Up @@ -397,12 +401,12 @@ export const scanMachine =
{
target: 'connecting',
cond: 'isOpenIdQr',
actions: 'setUri',
actions: ['sendTelemetryStartEvent', 'setUri'],
},
{
target: 'showQrLogin',
cond: 'isQrLogin',
actions: 'setLinkCode',
actions: ['sendTelemetryStartEvent', 'setLinkCode'],
},
{
target: 'invalid',
Expand Down Expand Up @@ -504,6 +508,7 @@ export const scanMachine =
},
CANCEL: {
target: 'cancelling',
actions: 'sendVCShareFlowCancelEndEvent',
},
TOGGLE_USER_CONSENT: {
actions: 'toggleShouldVerifyPresence',
Expand Down Expand Up @@ -537,11 +542,17 @@ export const scanMachine =
},
CANCEL: {
target: '#scan.reviewing.cancelling',
actions: 'setPromptHint',
actions: [
'setPromptHint',
'sendVCShareFlowTimeoutEndEvent',
],
},
RETRY: {
target: '#scan.reviewing.cancelling',
actions: 'setPromptHint',
actions: [
'setPromptHint',
'sendVCShareFlowTimeoutEndEvent',
],
},
},
},
Expand Down Expand Up @@ -574,16 +585,7 @@ export const scanMachine =
},
},
accepted: {
entry: [
'logShared',
() =>
sendEndEvent(
getEndEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.EndEventStatus.success,
),
),
],
entry: ['logShared', 'sendVcShareSuccessEvent'],
on: {
DISMISS: {
target: 'navigatingToHome',
Expand Down Expand Up @@ -905,6 +907,69 @@ export const scanMachine =
to: context => context.serviceRefs.activityLog,
},
),

sendVcShareSuccessEvent: () => {
sendImpressionEvent(
getImpressionEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.Screens.vcShareSuccessPage,
),
);
sendEndEvent(
getEndEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.EndEventStatus.success,
),
);
},

sendBLEConnectionErrorEvent: (context, event) => {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.vcShare,
event.bleError.code,
event.bleError.message,
),
);
sendEndEvent(
getEndEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.EndEventStatus.failure,
),
);
},

sendTelemetryStartEvent: () => {
sendStartEvent(
getStartEventData(TelemetryConstants.FlowType.vcShare),
);
sendImpressionEvent(
getImpressionEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.Screens.scanScreen,
),
);
},

sendVCShareFlowCancelEndEvent: () => {
sendEndEvent(
getEndEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.EndEventStatus.cancel,
{comment: 'User cancelled VC share'},
),
);
},

sendVCShareFlowTimeoutEndEvent: () => {
sendEndEvent(
getEndEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.EndEventStatus.failure,
{comment: 'VC sharing timeout'},
),
);
},
},

services: {
Expand Down Expand Up @@ -958,7 +1023,10 @@ export const scanMachine =
if (event.type === EventTypes.onDisconnected) {
callback({type: 'DISCONNECT'});
}
if (event.type === EventTypes.onError) {
if (
event.type === EventTypes.onError &&
event.code.includes('TVW')
) {
callback({
type: 'BLE_ERROR',
bleError: {message: event.message, code: event.code},
Expand Down Expand Up @@ -1022,9 +1090,6 @@ export const scanMachine =
},

startConnection: context => callback => {
sendStartEvent(
getStartEventData(TelemetryConstants.FlowType.vcShare),
);
wallet.startConnection(context.openId4VpUri);
const statusCallback = (event: WalletDataEvent) => {
if (event.type === EventTypes.onSecureChannelEstablished) {
Expand Down
13 changes: 13 additions & 0 deletions screens/Scan/SendVcScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {useFocusEffect} from '@react-navigation/native';
import {VcItemContainer} from '../../components/VC/VcItemContainer';
import {VCMetadata} from '../../shared/VCMetadata';
import {createEsignetMosipVCItemMachine} from '../../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine';
import {
TelemetryConstants,
getImpressionEventData,
sendImpressionEvent,
} from '../../shared/telemetry/TelemetryUtils';

export const SendVcScreen: React.FC = () => {
const {t} = useTranslation('SendVcScreen');
Expand Down Expand Up @@ -43,6 +48,14 @@ export const SendVcScreen: React.FC = () => {
controller.SELECT_VC_ITEM(0)(service);
}
}, []);
useEffect(() => {
sendImpressionEvent(
getImpressionEventData(
TelemetryConstants.FlowType.vcShare,
TelemetryConstants.Screens.vcList,
),
);
}, []);

useFocusEffect(
React.useCallback(() => {
Expand Down
4 changes: 4 additions & 0 deletions shared/telemetry/TelemetryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const TelemetryConstants = {

EndEventStatus: Object.freeze({
success: 'SUCCESS',
cancel: 'CANCEL',
failure: 'FAILURE',
}),

Expand Down Expand Up @@ -225,5 +226,8 @@ export const TelemetryConstants = {
webViewPage: 'Web View Page',
otpVerificationModal: 'Otp Verification Modal',
issuerList: 'Issuer List',
scanScreen: 'Scan Screen',
vcList: 'VC List',
vcShareSuccessPage: 'VC Successfully Shared Page',
}),
};

0 comments on commit c75501d

Please sign in to comment.