mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 13:38:01 -05:00
* feat(inji-344): Use VC Key class instead of separate functions for managing vc key * feat(inji-344): Use properties from VcKey Class instead of reading from vckey string * feat(inji-344): Rename vcKey to vcMetadata * feat(inji-344): Use vc's unique id or vckey instead of joined string of vc metadata * feat(inji-344): Use vc key instead of unique id to avoid confusion. Fix issues reg parsing vc metadata * feat(inji-344):fix redownloading issue Co-authored-by: Tilak <tilakpuli15@gmail.com> * feat(inji-344): Remove vc getting stored on update of pin status * feat(inji-344): update other vc's pin status to false when any vc is pinned * feat(inji-344): remove hash ID for UIN * feat(inji-344): revert google services json * feat(inji-344): remove mmkv logs added for debugging * feat(inji-344): fix received vcs not getting displayed on reopen of app * feat(inji-344): fix id not shown in revoke component --------- Co-authored-by: Sri Kanth Kola <srikanthsri7447@gmail.com>
132 lines
3.9 KiB
TypeScript
132 lines
3.9 KiB
TypeScript
import { useSelector } from '@xstate/react';
|
|
import { useContext, useEffect, useState } from 'react';
|
|
import NetInfo from '@react-native-community/netinfo';
|
|
import { GlobalContext } from '../../shared/GlobalContext';
|
|
import {
|
|
selectIsRefreshingMyVcs,
|
|
selectMyVcsMetadata,
|
|
VcEvents,
|
|
} from '../../machines/vc';
|
|
import { vcItemMachine } from '../../machines/vcItem';
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import {
|
|
RevokeVidsEvents,
|
|
selectIsAcceptingOtpInput,
|
|
selectIsRevokingVc,
|
|
selectIsLoggingRevoke,
|
|
} from '../../machines/revoke';
|
|
|
|
import { ActorRefFrom } from 'xstate';
|
|
|
|
export function useRevoke() {
|
|
const { t } = useTranslation('ProfileScreen');
|
|
const { appService } = useContext(GlobalContext);
|
|
const vcService = appService.children.get('vc');
|
|
const revokeService = appService.children.get('RevokeVids');
|
|
const vcsMetadata = useSelector(vcService, selectMyVcsMetadata);
|
|
const isRevokingVc = useSelector(revokeService, selectIsRevokingVc);
|
|
const isLoggingRevoke = useSelector(revokeService, selectIsLoggingRevoke);
|
|
const isAcceptingOtpInput = useSelector(
|
|
revokeService,
|
|
selectIsAcceptingOtpInput
|
|
);
|
|
|
|
const [isRevoking, setRevoking] = useState(false);
|
|
const [isAuthenticating, setAuthenticating] = useState(false);
|
|
const [isViewing, setIsViewing] = useState(false);
|
|
const [toastVisible, setToastVisible] = useState(false);
|
|
const [message, setMessage] = useState('');
|
|
const [selectedIndex, setSelectedIndex] = useState<number>(null);
|
|
const [selectedVidUniqueIds, setSelectedVidUniqueIds] = useState<string[]>(
|
|
[]
|
|
);
|
|
|
|
const vidsMetadata = vcsMetadata.filter(
|
|
(vcMetadata) => vcMetadata.idType === 'VID'
|
|
);
|
|
|
|
const selectVcItem = (index: number, vcUniqueId: string) => {
|
|
return () => {
|
|
setSelectedIndex(index);
|
|
if (selectedVidUniqueIds.includes(vcUniqueId)) {
|
|
setSelectedVidUniqueIds(
|
|
selectedVidUniqueIds.filter((item) => item !== vcUniqueId)
|
|
);
|
|
} else {
|
|
setSelectedVidUniqueIds((prevArray) => [...prevArray, vcUniqueId]);
|
|
}
|
|
};
|
|
};
|
|
|
|
const showToast = (message: string) => {
|
|
setToastVisible(true);
|
|
setMessage(message);
|
|
setTimeout(() => {
|
|
setToastVisible(false);
|
|
setMessage('');
|
|
}, 3000);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (isRevokingVc) {
|
|
setSelectedVidUniqueIds([]);
|
|
showToast(t('revokeSuccessful'));
|
|
}
|
|
if (isLoggingRevoke) {
|
|
revokeService.send(RevokeVidsEvents.DISMISS());
|
|
vcService.send(VcEvents.REFRESH_MY_VCS());
|
|
}
|
|
}, [isRevokingVc, isLoggingRevoke]);
|
|
|
|
return {
|
|
error: '',
|
|
isAcceptingOtpInput,
|
|
isAuthenticating,
|
|
isRefreshingVcs: useSelector(vcService, selectIsRefreshingMyVcs),
|
|
isRevoking,
|
|
isViewing,
|
|
message,
|
|
selectedIndex,
|
|
selectedVidUniqueIds,
|
|
toastVisible,
|
|
uniqueVidsMetadata: vidsMetadata.filter(
|
|
(vcMetadata, index, vid) => vid.indexOf(vcMetadata) === index
|
|
),
|
|
|
|
CONFIRM_REVOKE_VC: () => {
|
|
setRevoking(true);
|
|
},
|
|
DISMISS: () => {
|
|
revokeService.send(RevokeVidsEvents.DISMISS());
|
|
},
|
|
INPUT_OTP: (otp: string) =>
|
|
revokeService.send(RevokeVidsEvents.INPUT_OTP(otp)),
|
|
REFRESH: () => vcService.send(VcEvents.REFRESH_MY_VCS()),
|
|
REVOKE_VC: () => {
|
|
revokeService.send(RevokeVidsEvents.REVOKE_VCS(selectedVidUniqueIds));
|
|
setRevoking(false);
|
|
//since nested modals/overlays don't work in ios, we need to toggle revoke screen
|
|
setIsViewing(false);
|
|
},
|
|
revokeVc: (otp: string) => {
|
|
NetInfo.fetch().then((state) => {
|
|
if (state.isConnected) {
|
|
revokeService.send(RevokeVidsEvents.INPUT_OTP(otp));
|
|
} else {
|
|
revokeService.send(RevokeVidsEvents.DISMISS());
|
|
showToast('Request network failed');
|
|
}
|
|
});
|
|
},
|
|
setAuthenticating,
|
|
selectVcItem,
|
|
setIsViewing,
|
|
setRevoking,
|
|
};
|
|
}
|
|
|
|
export interface RevokeProps {
|
|
service: ActorRefFrom<typeof vcItemMachine>;
|
|
}
|