Skip to content

Commit

Permalink
refactor(INJI-435): extract esignetMosipVcItem and existingMosipVcIte…
Browse files Browse the repository at this point in the history
…m machines common functions into separate file

Signed-off-by: PuBHARGAVI <[email protected]>
  • Loading branch information
PuBHARGAVI committed Oct 25, 2023
1 parent 4147c0b commit 3c049bc
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 254 deletions.
6 changes: 5 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fileignoreconfig:
- filename: package.json
checksum: fdd5905228a1afbfb004c710fd6c61adf073a12840200327c0592b76bea5e7e3
- filename: package-lock.json
checksum: fc26d97edecbacd0b7507032c6fc1acfcea9f01f5dbe66a2a0341506e2f0daca
checksum: 4515c3d663d9435eab0f56b75480c93c5209aa59befb2b71f2b3fe7c9051d80a
- filename: components/PasscodeVerify.tsx
checksum: 14654c0f038979fcd0d260170a45894a072f81e0767ca9a0e66935d33b5cc703
- filename: i18n.ts
Expand Down Expand Up @@ -58,3 +58,7 @@ fileignoreconfig:
checksum: 237a2640b7db70770d65da67c79f2929581e32f1162517e50b8d37e409f3387d
- filename: shared/cryptoutil/cryptoUtil.ts
checksum: b785ff3f01ab9530119072c4d38195048bfeee6155c54ea7dd031559acb722f3
- filename: machines/store.typegen.ts
checksum: 6d22bc5c77398316b943c512c208ce0846a9fff674c1ccac79e07f21962acd5f
- filename: machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine.typegen.ts
checksum: 533785a3c8096ea93afc59c65025679c24d379e824e784e745ab298a0978cd2a
77 changes: 19 additions & 58 deletions components/KebabPopUpController.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {useSelector} from '@xstate/react';
import {ActorRefFrom} from 'xstate';
import {
ExistingMosipVCItemEvents,
ExistingMosipVCItemMachine,
selectBindingAuthFailedError,
selectEmptyWalletBindingId,
selectIsPinned,
Expand All @@ -15,22 +13,14 @@ import {
selectShowActivities,
selectShowWalletBindingError,
selectWalletBindingError,
} from '../machines/VCItemMachine/commonSelectors';
import {
ExistingMosipVCItemEvents,
ExistingMosipVCItemMachine,
} from '../machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine';

import {
EsignetMosipVCItemEvents,
EsignetMosipVCItemMachine,
selectEmptyWalletBindingId as esignetSelectEmptyWalletBindingId,
selectIsPinned as esignetSelectIsPinned,
selectKebabPopUp as esignetSelectKebabPopUp,
selectKebabPopUpAcceptingBindingOtp as esignetSelectKebabPopUpAcceptingBindingOtp,
selectKebabPopUpBindingWarning as esignetSelectKebabPopUpBindingWarning,
selectKebabPopUpWalletBindingInProgress as esignetSelectKebabPopUpWalletBindingInProgress,
selectOtpError as esignetSelectOtpError,
selectRemoveWalletWarning as esignetSelectRemoveWalletWarning,
selectShowActivities as esignetSelectShowActivities,
selectShowWalletBindingError as esignetSelectShowWalletBindingError,
selectWalletBindingError as esignetSelectWalletBindingError,
} from '../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine';
import {selectActivities} from '../machines/activityLog';
import {GlobalContext} from '../shared/GlobalContext';
Expand All @@ -57,60 +47,31 @@ export function useKebabPopUp(props) {
const SHOW_ACTIVITY = () => service.send(vcEvents.SHOW_ACTIVITY());
const INPUT_OTP = (otp: string) => service.send(vcEvents.INPUT_OTP(otp));
const RESEND_OTP = () => service.send(vcEvents.RESEND_OTP());
let isPinned = useSelector(service, selectIsPinned);
let isBindingWarning = useSelector(service, selectKebabPopUpBindingWarning);
let isRemoveWalletWarning = useSelector(service, selectRemoveWalletWarning);
let isAcceptingOtpInput = useSelector(
const isPinned = useSelector(service, selectIsPinned);
const isBindingWarning = useSelector(service, selectKebabPopUpBindingWarning);
const isRemoveWalletWarning = useSelector(service, selectRemoveWalletWarning);
const isAcceptingOtpInput = useSelector(
service,
selectKebabPopUpAcceptingBindingOtp,
);
let isWalletBindingError = useSelector(service, selectShowWalletBindingError);
let otpError = useSelector(service, selectOtpError);
let walletBindingError = useSelector(service, selectWalletBindingError);
let bindingAuthFailedError = useSelector(
const isWalletBindingError = useSelector(
service,
selectShowWalletBindingError,
);
const otpError = useSelector(service, selectOtpError);
const walletBindingError = useSelector(service, selectWalletBindingError);
const bindingAuthFailedError = useSelector(
service,
selectBindingAuthFailedError,
);
let WalletBindingInProgress = useSelector(
const WalletBindingInProgress = useSelector(
service,
selectKebabPopUpWalletBindingInProgress,
);
let emptyWalletBindingId = useSelector(service, selectEmptyWalletBindingId);
let isKebabPopUp = useSelector(service, selectKebabPopUp);
let isShowActivities = useSelector(service, selectShowActivities);
const emptyWalletBindingId = useSelector(service, selectEmptyWalletBindingId);
const isKebabPopUp = useSelector(service, selectKebabPopUp);
const isShowActivities = useSelector(service, selectShowActivities);

if (props.vcMetadata.isFromOpenId4VCI()) {
isPinned = useSelector(service, esignetSelectIsPinned);
isBindingWarning = useSelector(
service,
esignetSelectKebabPopUpBindingWarning,
);
isRemoveWalletWarning = useSelector(
service,
esignetSelectRemoveWalletWarning,
);
isAcceptingOtpInput = useSelector(
service,
esignetSelectKebabPopUpAcceptingBindingOtp,
);
isWalletBindingError = useSelector(
service,
esignetSelectShowWalletBindingError,
);
otpError = useSelector(service, esignetSelectOtpError);
walletBindingError = useSelector(service, esignetSelectWalletBindingError);
bindingAuthFailedError = useSelector(service, selectBindingAuthFailedError);
WalletBindingInProgress = useSelector(
service,
esignetSelectKebabPopUpWalletBindingInProgress,
);
emptyWalletBindingId = useSelector(
service,
esignetSelectEmptyWalletBindingId,
);
isKebabPopUp = useSelector(service, esignetSelectKebabPopUp);
isShowActivities = useSelector(service, esignetSelectShowActivities);
}
const {appService} = useContext(GlobalContext);
const activityLogService = appService.children.get('activityLog');

Expand Down
29 changes: 10 additions & 19 deletions components/VC/MosipVCItem/VcItemController.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import {useContext, useRef} from 'react';
import {GlobalContext} from '../../../shared/GlobalContext';
import {
createExistingMosipVCItemMachine,
ExistingMosipVCItemEvents,
selectContext,
selectEmptyWalletBindingId,
selectGeneratedOn,
selectIsSavingFailedInIdle,
selectKebabPopUp,
selectVerifiableCredential,
} from '../../../machines/VCItemMachine/commonSelectors';
import {
createExistingMosipVCItemMachine,
ExistingMosipVCItemEvents,
selectIsSavingFailedInIdle,
} from '../../../machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine';
import {
createEsignetMosipVCItemMachine,
EsignetMosipVCItemEvents,
selectContext as esignetSelectContext,
selectEmptyWalletBindingId as esignetSelectEmptyWalletBindingId,
selectGeneratedOn as esignetSelectGeneratedOn,
selectKebabPopUp as esignetSelectKebabPopUp,
selectVerifiableCredentials as esignetSelectVerifiableCredentials,
} from '../../../machines/VCItemMachine/EsignetMosipVCItem/EsignetMosipVCItemMachine';
import {useInterpret, useSelector} from '@xstate/react';
import {EsignetMosipVCItemProps, ExistingMosipVCItemProps} from './MosipVCItem';
Expand Down Expand Up @@ -50,19 +47,13 @@ export function useVcItemController(
const storeErrorTranslationPath = 'errors.savingFailed';
let generatedOn = useSelector(service, selectGeneratedOn);
if (props.vcMetadata.isFromOpenId4VCI()) {
context = useSelector(service, esignetSelectContext);
isKebabPopUp = useSelector(service, esignetSelectKebabPopUp);
generatedOn = useSelector(service, esignetSelectGeneratedOn);
emptyWalletBindingId = useSelector(
service,
esignetSelectEmptyWalletBindingId,
);
context = useSelector(service, selectContext);
isKebabPopUp = useSelector(service, selectKebabPopUp);
generatedOn = useSelector(service, selectGeneratedOn);
emptyWalletBindingId = useSelector(service, selectEmptyWalletBindingId);
DISMISS = () => service.send(EsignetMosipVCItemEvents.DISMISS());
KEBAB_POPUP = () => service.send(EsignetMosipVCItemEvents.KEBAB_POPUP());
verifiableCredential = useSelector(
service,
esignetSelectVerifiableCredentials,
);
verifiableCredential = useSelector(service, selectVerifiableCredential);
}
return {
service,
Expand Down
4 changes: 3 additions & 1 deletion components/VidItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {CheckBox} from 'react-native-elements';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {ActorRefFrom} from 'xstate';
import {
createExistingMosipVCItemMachine,
selectVerifiableCredential,
selectGeneratedOn,
} from '../machines/VCItemMachine/commonSelectors';
import {
createExistingMosipVCItemMachine,
selectId,
ExistingMosipVCItemMachine,
} from '../machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,88 +924,3 @@ export const createEsignetMosipVCItemMachine = (
vcMetadata,
});
};

type State = StateFrom<typeof EsignetMosipVCItemMachine>;

export function selectVerifiableCredentials(state: State) {
return state.context.verifiableCredential;
}

export function selectKebabPopUp(state: State) {
return state.matches('kebabPopUp');
}

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

export function selectGeneratedOn(state: State) {
return state.context.generatedOn;
}

export function selectWalletBindingSuccess(state: State) {
return state.context.walletBindingSuccess;
}

export function selectEmptyWalletBindingId(state: State) {
var val = state.context.walletBindingResponse
? state.context.walletBindingResponse.walletBindingId
: undefined;
return val == undefined || val == null || val.length <= 0 ? true : false;
}

export function selectWalletBindingError(state: State) {
return state.context.walletBindingError;
}

export function selectBindingAuthFailedError(state: State) {
return state.context.bindingAuthFailedMessage;
}

export function selectKebabPopUpAcceptingBindingOtp(state: State) {
return state.matches('kebabPopUp.acceptingBindingOtp');
}

export function selectKebabPopUpShowWalletBindingError(state: State) {
return state.matches('kebabPopUp.showingWalletBindingError');
}

export function selectKebabPopUpWalletBindingInProgress(state: State) {
return state.matches('kebabPopUp.requestingBindingOtp') ||
state.matches('kebabPopUp.addingWalletBindingId') ||
state.matches('kebabPopUp.addKeyPair') ||
state.matches('kebabPopUp.updatingPrivateKey')
? true
: false;
}

export function selectKebabPopUpBindingWarning(state: State) {
return state.matches('kebabPopUp.showBindingWarning');
}

export function selectRemoveWalletWarning(state: State) {
return state.matches('kebabPopUp.removeWallet');
}

export function selectIsPinned(state: State) {
return state.context.isPinned;
}

export function selectOtpError(state: State) {
return state.context.otpError;
}

export function selectShowActivities(state: State) {
return state.matches('kebabPopUp.showActivities');
}

export function selectShowWalletBindingError(state: State) {
return (
state.matches('showingWalletBindingError') ||
state.matches('kebabPopUp.showingWalletBindingError')
);
}

export function selectLogoUrl(state: State) {
return state.context.logoUrl;
}
Loading

0 comments on commit 3c049bc

Please sign in to comment.