Skip to content

Commit

Permalink
feat[INJI-403]: Add events in the VC download flow for success scenar…
Browse files Browse the repository at this point in the history
…io (#908)

* feat(INJI-403): add events in the VC download flow for success scenario

* refactor(INJI-403): updates logic to capture preferred language in telemetry

Signed-off-by: Alka <[email protected]>

* fix(INJI-403): revert changes of google services and env added by mistake

Signed-off-by: Alka <[email protected]>

* refactor(INJI-403): extracts some methods of telemetry to a util file

Signed-off-by: Alka <[email protected]>

* fix(INJI-403): fetch selected issuer's id from context instead of event

Signed-off-by: Alka <[email protected]>

* feat(INJI-403): update telemetry package link to mosip org

Signed-off-by: Alka <[email protected]>

* feat(INJI-403): making language code mapping fail safe and removing unwanted code

Signed-off-by: Alka <[email protected]>

---------

Signed-off-by: Alka Prasad <[email protected]>
Signed-off-by: Alka <[email protected]>
  • Loading branch information
Alka1703 authored Oct 13, 2023
1 parent 74212e3 commit c7a557c
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 55 deletions.
12 changes: 1 addition & 11 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import {
import {DualMessageOverlay} from './components/DualMessageOverlay';
import {useApp} from './screens/AppController';
import {Alert} from 'react-native';
import {
getAppInfoData,
getTelemetryConfigData,
initializeTelemetry,
sendAppInfoEvent,
} from './shared/telemetry/TelemetryUtils';
import {configureTelemetry} from './shared/telemetry/TelemetryUtils';
import {MessageOverlay} from './components/MessageOverlay';
import SecureKeystore from 'react-native-secure-keystore';
import {isCustomSecureKeystore} from './shared/cryptoutil/cryptoUtil';
Expand All @@ -42,11 +37,6 @@ const DecryptErrorAlert = (controller, t) => {
},
]);
};
function configureTelemetry() {
const config = getTelemetryConfigData();
initializeTelemetry(config);
sendAppInfoEvent(getAppInfoData());
}

const AppLayoutWrapper: React.FC = () => {
const {appService} = useContext(GlobalContext);
Expand Down
2 changes: 0 additions & 2 deletions components/LanguageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Storage from '../shared/storage';
import {useTranslation} from 'react-i18next';
import i18next from 'i18next';
import RNRestart from 'react-native-restart';
import {__SelectedLanguage} from '../shared/GlobalVariables';

export const LanguageSelector: React.FC<LanguageSelectorProps> = props => {
const {i18n} = useTranslation();
Expand All @@ -17,7 +16,6 @@ export const LanguageSelector: React.FC<LanguageSelectorProps> = props => {
const changeLanguage = async (language: string) => {
if (language !== i18n.language) {
await i18n.changeLanguage(language).then(async () => {
__SelectedLanguage.setValue(language);
await Storage.setItem('language', i18n.language);
const isRTL = i18next.dir(language) === 'rtl' ? true : false;
if (isRTL !== I18nManager.isRTL) {
Expand Down
7 changes: 5 additions & 2 deletions machines/QrLoginMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
} from '../shared/keystore/SecureKeystore';
import i18n from '../i18n';
import {parseMetadatas, VCMetadata} from '../shared/VCMetadata';
import {getEndData, sendEndEvent} from '../shared/telemetry/TelemetryUtils';
import {
getEndEventData,
sendEndEvent,
} from '../shared/telemetry/TelemetryUtils';

const model = createModel(
{
Expand Down Expand Up @@ -224,7 +227,7 @@ export const qrLoginMachine =
},
},
success: {
entry: [() => sendEndEvent(getEndData('QR login'))],
entry: [() => sendEndEvent(getEndEventData('QR login'))],
on: {
CONFIRM: {
target: 'done',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import SecureKeystore from 'react-native-secure-keystore';
import {VCMetadata} from '../../../shared/VCMetadata';
import {
sendStartEvent,
getData,
getEndData,
getStartEventData,
getEndEventData,
sendEndEvent,
} from '../../../shared/telemetry/TelemetryUtils';

Expand Down Expand Up @@ -216,6 +216,7 @@ export const ExistingMosipVCItemMachine =
'setVerifiableCredential',
'updateVc',
'logDownloaded',
'sendTelemetryEvents',
'removeVcFromInProgressDownloads',
],
target: '#vc-item.checkingVerificationStatus',
Expand Down Expand Up @@ -301,7 +302,9 @@ export const ExistingMosipVCItemMachine =
showBindingWarning: {
on: {
CONFIRM: {
actions: [() => sendStartEvent(getData('VC activation'))],
actions: [
() => sendStartEvent(getStartEventData('VC activation')),
],
target: '#vc-item.kebabPopUp.requestingBindingOtp',
},
CANCEL: {
Expand Down Expand Up @@ -416,7 +419,7 @@ export const ExistingMosipVCItemMachine =
'setWalletBindingErrorEmpty',
'sendWalletBindingSuccess',
'logWalletBindingSuccess',
() => sendEndEvent(getEndData('VC activation')),
() => sendEndEvent(getEndEventData('VC activation')),
],
target: '#vc-item.kebabPopUp',
},
Expand Down Expand Up @@ -633,7 +636,7 @@ export const ExistingMosipVCItemMachine =
showBindingWarning: {
on: {
CONFIRM: {
actions: () => sendStartEvent(getData('VC activation')),
actions: () => sendStartEvent(getStartEventData('VC activation')),
target: 'requestingBindingOtp',
},
CANCEL: {
Expand Down Expand Up @@ -743,7 +746,7 @@ export const ExistingMosipVCItemMachine =
'setWalletBindingErrorEmpty',
'setWalletBindingSuccess',
'logWalletBindingSuccess',
() => sendEndEvent(getEndData('VC activation')),
() => sendEndEvent(getEndEventData('VC activation')),
],
target: 'idle',
},
Expand Down Expand Up @@ -1019,6 +1022,9 @@ export const ExistingMosipVCItemMachine =
to: context => context.serviceRefs.activityLog,
},
),
sendTelemetryEvents: () => {
sendEndEvent({type: 'VC Download', status: 'SUCCESS'});
},

logWalletBindingSuccess: send(
context =>
Expand Down
16 changes: 11 additions & 5 deletions machines/bleShare/scan/scanMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import Storage from '../../../shared/storage';
import {logState} from '../../app';
import {VCMetadata} from '../../../shared/VCMetadata';
import {
getData,
getEndData,
getStartEventData,
getEndEventData,
sendStartEvent,
sendEndEvent,
} from '../../../shared/telemetry/TelemetryUtils';
Expand Down Expand Up @@ -432,7 +432,10 @@ export const scanMachine =
},
navigatingToHistory: {},
},
entry: ['sendScanData', () => sendStartEvent(getData('QR login'))],
entry: [
'sendScanData',
() => sendStartEvent(getStartEventData('QR login')),
],
},
connecting: {
invoke: {
Expand Down Expand Up @@ -567,7 +570,10 @@ export const scanMachine =
},
},
accepted: {
entry: ['logShared', () => sendEndEvent(getEndData('VC share'))],
entry: [
'logShared',
() => sendEndEvent(getEndEventData('VC share')),
],
on: {
DISMISS: {
target: 'navigatingToHome',
Expand Down Expand Up @@ -1006,7 +1012,7 @@ export const scanMachine =
},

startConnection: context => callback => {
sendStartEvent(getData('VC share'));
sendStartEvent(getStartEventData('VC share'));
wallet.startConnection(context.openId4VpUri);
const statusCallback = (event: WalletDataEvent) => {
if (event.type === EventTypes.onSecureChannelEstablished) {
Expand Down
39 changes: 38 additions & 1 deletion machines/issuersMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ import {
} from '../shared/openId4VCI/Utils';
import {NETWORK_REQUEST_FAILED, REQUEST_TIMEOUT} from '../shared/constants';
import {VCMetadata} from '../shared/VCMetadata';
import {
getImpressionEventData,
getInteractEventData,
getStartEventData,
sendEndEvent,
sendImpressionEvent,
sendInteractEvent,
sendStartEvent,
} from '../shared/telemetry/TelemetryUtils';
import {
CredentialWrapper,
VerifiableCredential,
Expand Down Expand Up @@ -272,12 +281,16 @@ export const IssuersMachine = model.createMachine(
src: 'verifyCredential',
onDone: [
{
actions: ['sendSuccessEndEvent'],
target: 'storing',
},
],
onError: [
{
actions: log((_, event) => (event.data as Error).message),
actions: [
log((_, event) => (event.data as Error).message),
'sendErrorEndEvent',
],
//TODO: Move to state according to the required flow when verification of VC fails
target: 'idle',
},
Expand Down Expand Up @@ -460,13 +473,31 @@ export const IssuersMachine = model.createMachine(
to: context => context.serviceRefs.activityLog,
},
),
sendSuccessEndEvent: () => {
sendEndEvent({
type: 'VC Download',
status: 'SUCCESS',
});
},
sendErrorEndEvent: () => {
sendEndEvent({
type: 'VC Download',
status: 'FAILURE',
});
},
},
services: {
downloadIssuersList: async () => {
return await CACHED_API.fetchIssuers();
},
checkInternet: async () => await NetInfo.fetch(),
downloadIssuerConfig: async (context, _) => {
sendStartEvent(
getStartEventData('VC Download', {id: context.selectedIssuerId}),
);
sendInteractEvent(
getInteractEventData('VC Download', 'CLICK', 'Issuer Type'),
);
return await CACHED_API.fetchIssuerConfig(context.selectedIssuerId);
},
downloadCredential: async context => {
Expand All @@ -490,6 +521,12 @@ export const IssuersMachine = model.createMachine(
return credential;
},
invokeAuthorization: async context => {
sendImpressionEvent(
getImpressionEventData(
'VC Download',
context.selectedIssuer.id + ' Web View Page',
),
);
return await authorize(context.selectedIssuer);
},
generateKeyPair: async context => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"react-native-vector-icons": "^10.0.0",
"short-unique-id": "^4.4.4",
"simple-pem2jwk": "^0.2.4",
"telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#develop",
"telemetry-sdk": "git://github.com/mosip/sunbird-telemetry-sdk.git#develop",
"xstate": "^4.35.0"
},
"devDependencies": {
Expand Down
14 changes: 14 additions & 0 deletions screens/Home/MyVcsTabMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import {GetVcModalMachine} from './MyVcs/GetVcModalMachine';
import Storage from '../../shared/storage';
import {VCMetadata} from '../../shared/VCMetadata';
import {EsignetMosipVCItemMachine} from '../../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine';
import {
getInteractEventData,
getStartEventData,
sendInteractEvent,
sendStartEvent,
} from '../../shared/telemetry/TelemetryUtils';
import NetInfo from '@react-native-community/netinfo';

const model = createModel(
Expand Down Expand Up @@ -93,6 +99,7 @@ export const MyVcsTabMachine = model.createMachine(
target: 'storageLimitReached',
},
{
actions: ['registerEvent'],
target: '#MyVcsTab.addingVc',
},
],
Expand Down Expand Up @@ -200,6 +207,13 @@ export const MyVcsTabMachine = model.createMachine(
},

actions: {
registerEvent: () => {
sendStartEvent(getStartEventData('VC Download', {id: 'UIN, VID, AID'}));
sendInteractEvent(
getInteractEventData('VC Download', 'CLICK', 'Download VC button'),
);
},

viewVcFromParent: sendParent((_context, event: ViewVcEvent) =>
model.events.VIEW_VC(event.vcItemActor),
),
Expand Down
2 changes: 0 additions & 2 deletions screens/SetupLanguageScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {Theme} from '../components/ui/styleUtils';
import {Icon} from 'react-native-elements';
import {RootRouteProps} from '../routes';
import {useWelcomeScreen} from './WelcomeScreenController';
import {__SelectedLanguage} from '../shared/GlobalVariables';

export const SetupLanguageScreen: React.FC<RootRouteProps> = props => {
const {t} = useTranslation('SetupLanguage');
Expand All @@ -23,7 +22,6 @@ export const SetupLanguageScreen: React.FC<RootRouteProps> = props => {
const changeLanguage = async (language: string) => {
if (language !== i18n.language) {
await i18n.changeLanguage(language).then(async () => {
__SelectedLanguage.setValue(language);
await Storage.setItem('language', i18n.language);
const isRTL = i18next.dir(language) === 'rtl' ? true : false;
if (isRTL !== I18nManager.isRTL) {
Expand Down
12 changes: 0 additions & 12 deletions shared/GlobalVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ export class __SessionId {
}
}

export class __SelectedLanguage {
private static language = '';

public static getValue(): string {
return __SelectedLanguage.language;
}

public static setValue(currentLangauge: string) {
this.language = currentLangauge;
}
}

function generateSessionId() {
const shortUUID = new ShortUniqueId({
length: APP_ID_LENGTH,
Expand Down
Loading

0 comments on commit c7a557c

Please sign in to comment.