mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 21:48:04 -05:00
* feat(INJI-245): dowload and view card via issuers Co-authored-by: Harsh Vardhan <harsh59v@gmail.com> * fix(INJI-245): remove vc from wallet Co-authored-by: Harsh Vardhan <harsh59v@gmail.com> * feat(INJI-245): pin card downloaded via eSignet * refactor(INJI-245): remove debug logs * refactor(INJI-245): rename vcItem related component to ExistingVcItem * refactor(INJI-245): add lock file modifications * refactor(INJI-245): add styles in purple theme for issuer related components * refactor(INJI-245): update VID for wallet binding usecase and issuer logo display in vc * refactor(INJI-245): remove duplicate loader component * refactor(INJI-245): remove unused props in vc details container --------- Co-authored-by: Harsh Vardhan <harsh59v@gmail.com> Co-authored-by: Vijay <94220135+vijay151096@users.noreply.github.com>
133 lines
4.7 KiB
TypeScript
133 lines
4.7 KiB
TypeScript
import React, {useContext, useEffect, useRef} from 'react';
|
|
import {useInterpret, useSelector} from '@xstate/react';
|
|
import {View, Pressable} from 'react-native';
|
|
import {ActorRefFrom} from 'xstate';
|
|
import {
|
|
createExistingMosipVCItemMachine,
|
|
selectVerifiableCredential,
|
|
selectGeneratedOn,
|
|
ExistingMosipVCItemMachine,
|
|
selectContext,
|
|
selectTag,
|
|
selectEmptyWalletBindingId,
|
|
selectIsSavingFailedInIdle,
|
|
selectKebabPopUp,
|
|
} from '../../../machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine';
|
|
import {ExistingMosipVCItemEvents} from '../../../machines/VCItemMachine/ExistingMosipVCItem/ExistingMosipVCItemMachine';
|
|
import {ErrorMessageOverlay} from '../../MessageOverlay';
|
|
import {Theme} from '../../ui/styleUtils';
|
|
import {GlobalContext} from '../../../shared/GlobalContext';
|
|
import {ExistingMosipVCItemContent} from './ExistingMosipVCItemContent';
|
|
import {ExistingMosipVCItemActivationStatus} from './ExistingMosipVCItemActivationStatus';
|
|
import {Row} from '../../ui';
|
|
import {KebabPopUp} from '../../KebabPopUp';
|
|
import {logState} from '../../../machines/app';
|
|
import {VCMetadata} from '../../../shared/VCMetadata';
|
|
import {format} from 'date-fns';
|
|
|
|
export const ExistingMosipVCItem: React.FC<
|
|
ExistingMosipVCItemProps
|
|
> = props => {
|
|
const {appService} = useContext(GlobalContext);
|
|
const machine = useRef(
|
|
createExistingMosipVCItemMachine(
|
|
appService.getSnapshot().context.serviceRefs,
|
|
props.vcMetadata,
|
|
),
|
|
);
|
|
|
|
const service = useInterpret(machine.current, {devTools: __DEV__});
|
|
|
|
useEffect(() => {
|
|
service.subscribe(logState);
|
|
}, [service]);
|
|
|
|
const context = useSelector(service, selectContext);
|
|
const verifiableCredential = useSelector(service, selectVerifiableCredential);
|
|
const emptyWalletBindingId = useSelector(service, selectEmptyWalletBindingId);
|
|
const isKebabPopUp = useSelector(service, selectKebabPopUp);
|
|
const DISMISS = () => service.send(ExistingMosipVCItemEvents.DISMISS());
|
|
const KEBAB_POPUP = () =>
|
|
service.send(ExistingMosipVCItemEvents.KEBAB_POPUP());
|
|
const isSavingFailedInIdle = useSelector(service, selectIsSavingFailedInIdle);
|
|
|
|
const storeErrorTranslationPath = 'errors.savingFailed';
|
|
|
|
const generatedOn = useSelector(service, selectGeneratedOn);
|
|
const formattedDate = format(new Date(generatedOn), 'MM/dd/yyyy');
|
|
const tag = useSelector(service, selectTag);
|
|
|
|
return (
|
|
<React.Fragment>
|
|
<Pressable
|
|
onPress={() => props.onPress(service)}
|
|
disabled={!verifiableCredential}
|
|
style={
|
|
props.selected
|
|
? Theme.Styles.selectedBindedVc
|
|
: Theme.Styles.closeCardBgContainer
|
|
}>
|
|
<ExistingMosipVCItemContent
|
|
context={context}
|
|
verifiableCredential={verifiableCredential}
|
|
generatedOn={formattedDate}
|
|
tag={tag}
|
|
selectable={props.selectable}
|
|
selected={props.selected}
|
|
service={service}
|
|
iconName={props.iconName}
|
|
iconType={props.iconType}
|
|
onPress={() => props.onPress(service)}
|
|
/>
|
|
<View style={Theme.Styles.horizontalLine} />
|
|
{props.isSharingVc ? null : (
|
|
<Row style={Theme.Styles.activationTab}>
|
|
{props.activeTab !== 'receivedVcsTab' &&
|
|
props.activeTab != 'sharingVcScreen' && (
|
|
<ExistingMosipVCItemActivationStatus
|
|
verifiableCredential={verifiableCredential}
|
|
emptyWalletBindingId={emptyWalletBindingId}
|
|
onPress={() => props.onPress(service)}
|
|
showOnlyBindedVc={props.showOnlyBindedVc}
|
|
/>
|
|
)}
|
|
<View style={Theme.Styles.verticalLine} />
|
|
<Row style={Theme.Styles.kebabIcon}>
|
|
<Pressable onPress={KEBAB_POPUP}>
|
|
<KebabPopUp
|
|
vcMetadata={props.vcMetadata}
|
|
iconName="dots-three-horizontal"
|
|
iconType="entypo"
|
|
isVisible={isKebabPopUp}
|
|
onDismiss={DISMISS}
|
|
service={service}
|
|
/>
|
|
</Pressable>
|
|
</Row>
|
|
</Row>
|
|
)}
|
|
</Pressable>
|
|
<ErrorMessageOverlay
|
|
isVisible={isSavingFailedInIdle}
|
|
error={storeErrorTranslationPath}
|
|
onDismiss={DISMISS}
|
|
translationPath={'VcDetails'}
|
|
/>
|
|
</React.Fragment>
|
|
);
|
|
};
|
|
|
|
export interface ExistingMosipVCItemProps {
|
|
vcMetadata: VCMetadata;
|
|
margin?: string;
|
|
selectable?: boolean;
|
|
selected?: boolean;
|
|
showOnlyBindedVc?: boolean;
|
|
onPress?: (vcRef?: ActorRefFrom<typeof ExistingMosipVCItemMachine>) => void;
|
|
onShow?: (vcRef?: ActorRefFrom<typeof ExistingMosipVCItemMachine>) => void;
|
|
activeTab?: string;
|
|
iconName?: string;
|
|
iconType?: string;
|
|
isSharingVc?: boolean;
|
|
}
|