From 9f8c778ff45a4053f462172e950866973545062f Mon Sep 17 00:00:00 2001 From: Kiruthika Jeyashankar <81218987+KiruthikaJeyashankar@users.noreply.github.com> Date: Mon, 9 Oct 2023 11:57:27 +0530 Subject: [PATCH] refactor(INJI-205): rename variable and remove redundant comments --- machines/issuersMachine.ts | 14 +- machines/issuersMachine.typegen.ts | 224 ++++++++++++++++++----------- 2 files changed, 150 insertions(+), 88 deletions(-) diff --git a/machines/issuersMachine.ts b/machines/issuersMachine.ts index e8f19ae1cd..1d5a08e667 100644 --- a/machines/issuersMachine.ts +++ b/machines/issuersMachine.ts @@ -35,7 +35,7 @@ enum OIDCErrors { const model = createModel( { issuers: [] as issuerType[], - tempSelectedIssuer: '' as string, + selectedIssuerId: '' as string, selectedIssuer: {} as issuerType, tokenResponse: {} as AuthorizeResult, errorMessage: '' as string, @@ -122,8 +122,7 @@ export const IssuersMachine = model.createMachine( actions: sendParent('DOWNLOAD_ID'), }, SELECTED_ISSUER: { - // set the issuer obj from the issuerStore - actions: 'updateTmpSelectedIssuer', + actions: 'updateSelectedIssuerId', target: 'downloadIssuerConfig', }, }, @@ -134,7 +133,6 @@ export const IssuersMachine = model.createMachine( src: 'downloadIssuerConfig', onDone: { actions: 'setSelectedIssuers', - // TODO: move checkInternet before downloadIssuerConfig target: 'checkInternet', }, onError: { @@ -300,7 +298,7 @@ export const IssuersMachine = model.createMachine( }), setError: model.assign({ errorMessage: (_, event) => { - console.log('Error while fetching issuers ', event.data.message); + console.log('Error occured ', event.data.message); return event.data.message === 'Network request failed' ? 'noInternetConnection' : 'generic'; @@ -380,8 +378,8 @@ export const IssuersMachine = model.createMachine( setSelectedIssuers: model.assign({ selectedIssuer: (_, event) => event.data, }), - updateTmpSelectedIssuer: model.assign({ - tempSelectedIssuer: (_, event) => event.id, + updateSelectedIssuerId: model.assign({ + selectedIssuerId: (_, event) => event.id, }), setTokenResponse: model.assign({ tokenResponse: (_, event) => event.data, @@ -432,7 +430,7 @@ export const IssuersMachine = model.createMachine( }, checkInternet: async () => await NetInfo.fetch(), downloadIssuerConfig: async (context, _) => { - return await CACHED_API.fetchIssuerConfig(context.tempSelectedIssuer); + return await CACHED_API.fetchIssuerConfig(context.selectedIssuerId); }, downloadCredential: async context => { const body = await getBody(context); diff --git a/machines/issuersMachine.typegen.ts b/machines/issuersMachine.typegen.ts index 8ef6eb4992..9243b16463 100644 --- a/machines/issuersMachine.typegen.ts +++ b/machines/issuersMachine.typegen.ts @@ -1,81 +1,145 @@ +// This file was automatically generated. Edits will be overwritten - // This file was automatically generated. Edits will be overwritten - - export interface Typegen0 { - '@@xstate/typegen': true; - internalEvents: { - "done.invoke.checkInternet": { type: "done.invoke.checkInternet"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"done.invoke.issuersMachine.displayIssuers:invocation[0]": { type: "done.invoke.issuersMachine.displayIssuers:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"done.invoke.issuersMachine.downloadCredentials:invocation[0]": { type: "done.invoke.issuersMachine.downloadCredentials:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]": { type: "done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"done.invoke.issuersMachine.generateKeyPair:invocation[0]": { type: "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"done.invoke.issuersMachine.performAuthorization:invocation[0]": { type: "done.invoke.issuersMachine.performAuthorization:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"done.invoke.issuersMachine.verifyingCredential:invocation[0]": { type: "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; data: unknown; __tip: "See the XState TS docs to learn how to strongly type this." }; -"error.platform.checkInternet": { type: "error.platform.checkInternet"; data: unknown }; -"error.platform.issuersMachine.displayIssuers:invocation[0]": { type: "error.platform.issuersMachine.displayIssuers:invocation[0]"; data: unknown }; -"error.platform.issuersMachine.downloadCredentials:invocation[0]": { type: "error.platform.issuersMachine.downloadCredentials:invocation[0]"; data: unknown }; -"error.platform.issuersMachine.downloadIssuerConfig:invocation[0]": { type: "error.platform.issuersMachine.downloadIssuerConfig:invocation[0]"; data: unknown }; -"error.platform.issuersMachine.performAuthorization:invocation[0]": { type: "error.platform.issuersMachine.performAuthorization:invocation[0]"; data: unknown }; -"xstate.init": { type: "xstate.init" }; - }; - invokeSrcNameMap: { - "checkInternet": "done.invoke.checkInternet"; -"downloadCredential": "done.invoke.issuersMachine.downloadCredentials:invocation[0]"; -"downloadIssuerConfig": "done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]"; -"downloadIssuersList": "done.invoke.issuersMachine.displayIssuers:invocation[0]"; -"generateKeyPair": "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; -"invokeAuthorization": "done.invoke.issuersMachine.performAuthorization:invocation[0]"; -"verifyCredential": "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; - }; - missingImplementations: { - actions: never; - delays: never; - guards: never; - services: never; - }; - eventsCausingActions: { - "getKeyPairFromStore": "done.invoke.issuersMachine.performAuthorization:invocation[0]"; -"loadKeyPair": "done.invoke.issuersMachine.performAuthorization:invocation[0]"; -"logDownloaded": "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; -"resetError": "RESET_ERROR" | "TRY_AGAIN" | "error.platform.issuersMachine.performAuthorization:invocation[0]"; -"setCredentialWrapper": "done.invoke.issuersMachine.downloadCredentials:invocation[0]"; -"setError": "error.platform.issuersMachine.displayIssuers:invocation[0]" | "error.platform.issuersMachine.downloadCredentials:invocation[0]" | "error.platform.issuersMachine.downloadIssuerConfig:invocation[0]" | "error.platform.issuersMachine.performAuthorization:invocation[0]"; -"setIssuers": "done.invoke.issuersMachine.displayIssuers:invocation[0]"; -"setLoadingIssuer": "TRY_AGAIN"; -"setNoInternet": "done.invoke.checkInternet"; -"setPrivateKey": "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; -"setPublicKey": "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; -"setSelectedIssuers": "done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]"; -"setTokenResponse": "done.invoke.issuersMachine.performAuthorization:invocation[0]"; -"setVerifiableCredential": "done.invoke.issuersMachine.downloadCredentials:invocation[0]"; -"storeKeyPair": "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; -"storeVcMetaContext": "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; -"storeVcsContext": "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; -"storeVerifiableCredentialData": "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; -"storeVerifiableCredentialMeta": "done.invoke.issuersMachine.verifyingCredential:invocation[0]"; -"unsetLoadingReason": "done.invoke.checkInternet" | "done.invoke.issuersMachine.displayIssuers:invocation[0]" | "error.platform.issuersMachine.performAuthorization:invocation[0]"; -"updateTmpSelectedIssuer": "SELECTED_ISSUER"; - }; - eventsCausingDelays: { - - }; - eventsCausingGuards: { - "hasKeyPair": "CHECK_KEY_PAIR"; -"isCustomSecureKeystore": "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; -"isInternetConnected": "done.invoke.checkInternet"; -"isOIDCflowCancelled": "error.platform.issuersMachine.performAuthorization:invocation[0]"; -"shouldFetchIssuersAgain": "TRY_AGAIN"; - }; - eventsCausingServices: { - "checkInternet": "done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]"; -"downloadCredential": "CHECK_KEY_PAIR" | "done.invoke.issuersMachine.generateKeyPair:invocation[0]"; -"downloadIssuerConfig": "SELECTED_ISSUER" | "TRY_AGAIN"; -"downloadIssuersList": "TRY_AGAIN" | "xstate.init"; -"generateKeyPair": "CHECK_KEY_PAIR"; -"invokeAuthorization": "done.invoke.checkInternet"; -"verifyCredential": "done.invoke.issuersMachine.downloadCredentials:invocation[0]"; - }; - matchesStates: "checkInternet" | "checkKeyPair" | "displayIssuers" | "done" | "downloadCredentials" | "downloadIssuerConfig" | "error" | "generateKeyPair" | "idle" | "performAuthorization" | "selectingIssuer" | "storing" | "verifyingCredential"; - tags: never; - } - \ No newline at end of file +export interface Typegen0 { + '@@xstate/typegen': true; + internalEvents: { + 'done.invoke.checkInternet': { + type: 'done.invoke.checkInternet'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'done.invoke.issuersMachine.displayIssuers:invocation[0]': { + type: 'done.invoke.issuersMachine.displayIssuers:invocation[0]'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'done.invoke.issuersMachine.downloadCredentials:invocation[0]': { + type: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]': { + type: 'done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'done.invoke.issuersMachine.generateKeyPair:invocation[0]': { + type: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'done.invoke.issuersMachine.performAuthorization:invocation[0]': { + type: 'done.invoke.issuersMachine.performAuthorization:invocation[0]'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'done.invoke.issuersMachine.verifyingCredential:invocation[0]': { + type: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + data: unknown; + __tip: 'See the XState TS docs to learn how to strongly type this.'; + }; + 'error.platform.checkInternet': { + type: 'error.platform.checkInternet'; + data: unknown; + }; + 'error.platform.issuersMachine.displayIssuers:invocation[0]': { + type: 'error.platform.issuersMachine.displayIssuers:invocation[0]'; + data: unknown; + }; + 'error.platform.issuersMachine.downloadCredentials:invocation[0]': { + type: 'error.platform.issuersMachine.downloadCredentials:invocation[0]'; + data: unknown; + }; + 'error.platform.issuersMachine.downloadIssuerConfig:invocation[0]': { + type: 'error.platform.issuersMachine.downloadIssuerConfig:invocation[0]'; + data: unknown; + }; + 'error.platform.issuersMachine.performAuthorization:invocation[0]': { + type: 'error.platform.issuersMachine.performAuthorization:invocation[0]'; + data: unknown; + }; + 'xstate.init': {type: 'xstate.init'}; + }; + invokeSrcNameMap: { + checkInternet: 'done.invoke.checkInternet'; + downloadCredential: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]'; + downloadIssuerConfig: 'done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]'; + downloadIssuersList: 'done.invoke.issuersMachine.displayIssuers:invocation[0]'; + generateKeyPair: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + invokeAuthorization: 'done.invoke.issuersMachine.performAuthorization:invocation[0]'; + verifyCredential: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + }; + missingImplementations: { + actions: never; + delays: never; + guards: never; + services: never; + }; + eventsCausingActions: { + getKeyPairFromStore: 'done.invoke.issuersMachine.performAuthorization:invocation[0]'; + loadKeyPair: 'done.invoke.issuersMachine.performAuthorization:invocation[0]'; + logDownloaded: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + resetError: + | 'RESET_ERROR' + | 'TRY_AGAIN' + | 'error.platform.issuersMachine.performAuthorization:invocation[0]'; + setCredentialWrapper: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]'; + setError: + | 'error.platform.issuersMachine.displayIssuers:invocation[0]' + | 'error.platform.issuersMachine.downloadCredentials:invocation[0]' + | 'error.platform.issuersMachine.downloadIssuerConfig:invocation[0]' + | 'error.platform.issuersMachine.performAuthorization:invocation[0]'; + setIssuers: 'done.invoke.issuersMachine.displayIssuers:invocation[0]'; + setLoadingIssuer: 'TRY_AGAIN'; + setNoInternet: 'done.invoke.checkInternet'; + setPrivateKey: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + setPublicKey: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + setSelectedIssuers: 'done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]'; + setTokenResponse: 'done.invoke.issuersMachine.performAuthorization:invocation[0]'; + setVerifiableCredential: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]'; + storeKeyPair: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + storeVcMetaContext: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + storeVcsContext: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + storeVerifiableCredentialData: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + storeVerifiableCredentialMeta: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'; + unsetLoadingReason: + | 'done.invoke.checkInternet' + | 'done.invoke.issuersMachine.displayIssuers:invocation[0]' + | 'error.platform.issuersMachine.performAuthorization:invocation[0]'; + updateSelectedIssuerId: 'SELECTED_ISSUER'; + }; + eventsCausingDelays: {}; + eventsCausingGuards: { + hasKeyPair: 'CHECK_KEY_PAIR'; + isCustomSecureKeystore: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + isInternetConnected: 'done.invoke.checkInternet'; + isOIDCflowCancelled: 'error.platform.issuersMachine.performAuthorization:invocation[0]'; + shouldFetchIssuersAgain: 'TRY_AGAIN'; + }; + eventsCausingServices: { + checkInternet: 'done.invoke.issuersMachine.downloadIssuerConfig:invocation[0]'; + downloadCredential: + | 'CHECK_KEY_PAIR' + | 'done.invoke.issuersMachine.generateKeyPair:invocation[0]'; + downloadIssuerConfig: 'SELECTED_ISSUER' | 'TRY_AGAIN'; + downloadIssuersList: 'TRY_AGAIN' | 'xstate.init'; + generateKeyPair: 'CHECK_KEY_PAIR'; + invokeAuthorization: 'done.invoke.checkInternet'; + verifyCredential: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]'; + }; + matchesStates: + | 'checkInternet' + | 'checkKeyPair' + | 'displayIssuers' + | 'done' + | 'downloadCredentials' + | 'downloadIssuerConfig' + | 'error' + | 'generateKeyPair' + | 'idle' + | 'performAuthorization' + | 'selectingIssuer' + | 'storing' + | 'verifyingCredential'; + tags: never; +}