mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-09 13:38:01 -05:00
* [INJIMOB-2670]: Enable Auto Vc Activation (#1) * [INJIMOB-2670]: Enable Auto Vc Activation (#1759) * [INJIMOB-2670]: Hide Success Banner during Auto Activation. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Locales for Auto Activation Error message Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Enable Auto Vc Activation and handle error scenarios Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Remove activation sections from Help content Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Update Event name to be generic Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Remove communication details and add default OTP into constants Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Removing Mosip specific condition for mosipInidividualId Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * add spanish language (#2) Signed-off-by: Sk Mijan Hossain <skmijanhossain@gmail.com> Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Individual Id fix and add prefix to face image (#4) * [INJIMOB-2670]: Individual Id fix and appending image format for face image. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Add Utils to append Png Base64 Prefix to faceImage. Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Update artifact Id and App name in fastlane scripts and build.gradle. (#3) Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Add enable_auth and remove lilveness_detection in internal-build yml (#5) Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Spanish locale updates. (#6) Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> * [INJIMOB-2670]: Liveness detection flag type changed to string Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> --------- Signed-off-by: BalachandarG <balachandar.g@thoughtworks.com> Signed-off-by: Sk Mijan Hossain <skmijanhossain@gmail.com> Co-authored-by: mijan32 <74153970+mijan32@users.noreply.github.com>
330 lines
10 KiB
TypeScript
330 lines
10 KiB
TypeScript
import React, {useLayoutEffect, useState} from 'react';
|
|
import {useTranslation} from 'react-i18next';
|
|
import {FlatList, Pressable} from 'react-native';
|
|
import {Issuer} from '../../components/openId4VCI/Issuer';
|
|
import {Error} from '../../components/ui/Error';
|
|
import {Header} from '../../components/ui/Header';
|
|
import {Button, Column, Row, Text} from '../../components/ui';
|
|
import {Theme} from '../../components/ui/styleUtils';
|
|
import {RootRouteProps} from '../../routes';
|
|
import {HomeRouteProps} from '../../routes/routeTypes';
|
|
import {useIssuerScreenController} from './IssuerScreenController';
|
|
import {Loader} from '../../components/ui/Loader';
|
|
import {isTranslationKeyFound, removeWhiteSpace} from '../../shared/commonUtil';
|
|
import {
|
|
ErrorMessage,
|
|
getDisplayObjectForCurrentLanguage,
|
|
Protocols,
|
|
} from '../../shared/openId4VCI/Utils';
|
|
import {
|
|
getInteractEventData,
|
|
getStartEventData,
|
|
sendInteractEvent,
|
|
sendStartEvent,
|
|
} from '../../shared/telemetry/TelemetryUtils';
|
|
import {TelemetryConstants} from '../../shared/telemetry/TelemetryConstants';
|
|
import {MessageOverlay} from '../../components/MessageOverlay';
|
|
import {SearchBar} from '../../components/ui/SearchBar';
|
|
import {SvgImage} from '../../components/ui/svg';
|
|
import {Icon} from 'react-native-elements';
|
|
import {BannerNotificationContainer} from '../../components/BannerNotificationContainer';
|
|
import {CredentialTypeSelectionScreen} from './CredentialTypeSelectionScreen';
|
|
|
|
export const IssuersScreen: React.FC<
|
|
HomeRouteProps | RootRouteProps
|
|
> = props => {
|
|
const controller = useIssuerScreenController(props);
|
|
const {t} = useTranslation('IssuersScreen');
|
|
|
|
const issuers = controller.issuers;
|
|
let [filteredSearchData, setFilteredSearchData] = useState(issuers);
|
|
const [search, setSearch] = useState('');
|
|
const [tapToSearch, setTapToSearch] = useState(false);
|
|
const [clearSearchIcon, setClearSearchIcon] = useState(false);
|
|
const showFullScreenError = controller.isError && controller.errorMessageType;
|
|
|
|
const isVerificationFailed = controller.verificationErrorMessage !== '';
|
|
|
|
const translationKey = `errors.verificationFailed.${controller.verificationErrorMessage}`;
|
|
|
|
const verificationErrorMessage = isTranslationKeyFound(translationKey, t)
|
|
? t(translationKey)
|
|
: t(`errors.verificationFailed.ERR_GENERIC`);
|
|
|
|
const isAutoWalletBindingFailed = controller.isAutoWalletBindingFailed;
|
|
|
|
useLayoutEffect(() => {
|
|
if (controller.loadingReason || showFullScreenError) {
|
|
props.navigation.setOptions({
|
|
headerShown: false,
|
|
});
|
|
} else {
|
|
props.navigation.setOptions({
|
|
headerShown: true,
|
|
header: props => (
|
|
<Header
|
|
goBack={props.navigation.goBack}
|
|
title={t('title')}
|
|
testID="issuersScreenHeader"
|
|
/>
|
|
),
|
|
});
|
|
}
|
|
|
|
if (controller.isStoring) {
|
|
props.navigation.goBack();
|
|
}
|
|
}, [
|
|
controller.loadingReason,
|
|
controller.errorMessageType,
|
|
controller.isStoring,
|
|
]);
|
|
|
|
const onPressHandler = (id: string, protocol: string) => {
|
|
sendStartEvent(
|
|
getStartEventData(TelemetryConstants.FlowType.vcDownload, {id: id}),
|
|
);
|
|
sendInteractEvent(
|
|
getInteractEventData(
|
|
TelemetryConstants.FlowType.vcDownload,
|
|
TelemetryConstants.InteractEventSubtype.click,
|
|
`IssuerType: ${id}`,
|
|
),
|
|
);
|
|
protocol === Protocols.OTP
|
|
? controller.DOWNLOAD_ID()
|
|
: controller.SELECTED_ISSUER(id);
|
|
};
|
|
|
|
const isGenericError = () => {
|
|
return controller.errorMessageType === ErrorMessage.GENERIC;
|
|
};
|
|
|
|
function isBackendError(): boolean {
|
|
return (
|
|
controller.errorMessageType === ErrorMessage.TECHNICAL_DIFFICULTIES ||
|
|
controller.errorMessageType ===
|
|
ErrorMessage.CREDENTIAL_TYPE_DOWNLOAD_FAILURE ||
|
|
controller.errorMessageType ===
|
|
ErrorMessage.AUTHORIZATION_GRANT_TYPE_NOT_SUPPORTED
|
|
);
|
|
}
|
|
|
|
const onFocusSearch = () => {
|
|
setTapToSearch(true);
|
|
};
|
|
|
|
const clearSearchText = () => {
|
|
filterIssuers('');
|
|
setClearSearchIcon(false);
|
|
};
|
|
|
|
const goBack = () => {
|
|
if (
|
|
controller.errorMessageType &&
|
|
controller.loadingReason === 'displayIssuers'
|
|
) {
|
|
props.navigation.goBack();
|
|
} else {
|
|
controller.RESET_ERROR();
|
|
}
|
|
};
|
|
|
|
const getImage = () => {
|
|
if (isGenericError()) {
|
|
return SvgImage.SomethingWentWrong();
|
|
}
|
|
if (isBackendError()) return SvgImage.ErrorOccurred();
|
|
return SvgImage.NoInternetConnection();
|
|
};
|
|
|
|
const filterIssuers = (searchText: string) => {
|
|
const filteredData = issuers.filter(item => {
|
|
if (
|
|
getDisplayObjectForCurrentLanguage(item.display)
|
|
?.title.toLowerCase()
|
|
.includes(searchText.toLowerCase())
|
|
) {
|
|
return getDisplayObjectForCurrentLanguage(item.display);
|
|
}
|
|
});
|
|
setFilteredSearchData(filteredData);
|
|
setSearch(searchText);
|
|
if (searchText !== '') {
|
|
setClearSearchIcon(true);
|
|
} else {
|
|
setClearSearchIcon(false);
|
|
}
|
|
};
|
|
if (controller.isSelectingCredentialType) {
|
|
return <CredentialTypeSelectionScreen {...props} />;
|
|
}
|
|
|
|
if (isVerificationFailed) {
|
|
return (
|
|
<Error
|
|
testID="verificationError"
|
|
isVisible={isVerificationFailed}
|
|
isModal={true}
|
|
alignActionsOnEnd
|
|
title={t('MyVcsTab:errors.verificationFailed.title')}
|
|
message={verificationErrorMessage}
|
|
image={SvgImage.PermissionDenied()}
|
|
showClose={false}
|
|
primaryButtonText="goBack"
|
|
primaryButtonEvent={controller.RESET_ERROR_SCREEN}
|
|
primaryButtonTestID="goBack"
|
|
customStyles={{marginTop: '30%'}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (isAutoWalletBindingFailed) {
|
|
return (
|
|
<Error
|
|
testID="autoWalletBindingError"
|
|
isVisible={isAutoWalletBindingFailed}
|
|
isModal={true}
|
|
alignActionsOnEnd
|
|
title={t('MyVcsTab:errors.autoWalletBindingError.title')}
|
|
message={t(`MyVcsTab:errors.autoWalletBindingError.message`)}
|
|
image={SvgImage.PermissionDenied()}
|
|
showClose={false}
|
|
primaryButtonText="goBack"
|
|
primaryButtonEvent={controller.RESET_ERROR_SCREEN}
|
|
primaryButtonTestID="goBack"
|
|
customStyles={{marginTop: '30%'}}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (controller.isBiometricsCancelled) {
|
|
return (
|
|
<MessageOverlay
|
|
isVisible={controller.isBiometricsCancelled}
|
|
minHeight={'auto'}
|
|
title={t('errors.biometricsCancelled.title')}
|
|
message={t('errors.biometricsCancelled.message')}
|
|
onBackdropPress={controller.RESET_ERROR}>
|
|
<Row>
|
|
<Button
|
|
fill
|
|
type="clear"
|
|
title={t('common:cancel')}
|
|
onPress={controller.RESET_ERROR}
|
|
margin={[0, 8, 0, 0]}
|
|
/>
|
|
<Button
|
|
testID="tryAgain"
|
|
fill
|
|
title={t('common:tryAgain')}
|
|
onPress={controller.TRY_AGAIN}
|
|
/>
|
|
</Row>
|
|
</MessageOverlay>
|
|
);
|
|
}
|
|
if (showFullScreenError) {
|
|
return (
|
|
<Error
|
|
testID={`${controller.errorMessageType}Error`}
|
|
isVisible={controller.errorMessageType !== ''}
|
|
title={t(`errors.${controller.errorMessageType}.title`)}
|
|
message={t(`errors.${controller.errorMessageType}.message`)}
|
|
goBack={goBack}
|
|
tryAgain={controller.TRY_AGAIN}
|
|
image={getImage()}
|
|
showClose
|
|
primaryButtonTestID="tryAgain"
|
|
primaryButtonText={
|
|
controller.errorMessageType != ErrorMessage.TECHNICAL_DIFFICULTIES &&
|
|
controller.errorMessageType !=
|
|
ErrorMessage.AUTHORIZATION_GRANT_TYPE_NOT_SUPPORTED
|
|
? 'tryAgain'
|
|
: undefined
|
|
}
|
|
primaryButtonEvent={controller.TRY_AGAIN}
|
|
onDismiss={goBack}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (controller.loadingReason) {
|
|
return (
|
|
<Loader
|
|
title={t('loaders.loading')}
|
|
subTitle={t(`loaders.subTitle.${controller.loadingReason}`)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<React.Fragment>
|
|
<BannerNotificationContainer />
|
|
{controller.issuers.length > 0 && (
|
|
<Column style={Theme.IssuersScreenStyles.issuerListOuterContainer}>
|
|
<Row
|
|
style={
|
|
tapToSearch
|
|
? Theme.SearchBarStyles.searchBarContainer
|
|
: Theme.SearchBarStyles.idleSearchBarBottomLine
|
|
}>
|
|
<SearchBar
|
|
searchIconTestID="searchIssuerIcon"
|
|
searchBarTestID="issuerSearchBar"
|
|
search={search}
|
|
placeholder={t('searchByIssuersName')}
|
|
onFocus={onFocusSearch}
|
|
onChangeText={filterIssuers}
|
|
onLayout={() => filterIssuers('')}
|
|
/>
|
|
{clearSearchIcon && (
|
|
<Pressable
|
|
onPress={clearSearchText}
|
|
style={Theme.SearchBarStyles.clearSearch}>
|
|
<Icon
|
|
testID="clearingIssuerSearchIcon"
|
|
name="circle-with-cross"
|
|
type="entypo"
|
|
size={18}
|
|
color={Theme.Colors.DetailsLabel}
|
|
/>
|
|
</Pressable>
|
|
)}
|
|
</Row>
|
|
<Text
|
|
testID="issuersScreenDescription"
|
|
style={{
|
|
...Theme.TextStyles.regularGrey,
|
|
...Theme.IssuersScreenStyles.issuersSearchSubText,
|
|
}}>
|
|
{t('description')}
|
|
</Text>
|
|
<Column scroll style={Theme.IssuersScreenStyles.issuersContainer}>
|
|
{controller.issuers.length > 0 && (
|
|
<FlatList
|
|
data={filteredSearchData}
|
|
renderItem={({item}) => (
|
|
<Issuer
|
|
testID={removeWhiteSpace(item.credential_issuer)}
|
|
key={item.credential_issuer}
|
|
displayDetails={getDisplayObjectForCurrentLanguage(
|
|
item.display,
|
|
)}
|
|
onPress={() =>
|
|
onPressHandler(item.credential_issuer, item.protocol)
|
|
}
|
|
{...props}
|
|
/>
|
|
)}
|
|
numColumns={1}
|
|
keyExtractor={item => item.credential_issuer}
|
|
/>
|
|
)}
|
|
</Column>
|
|
</Column>
|
|
)}
|
|
</React.Fragment>
|
|
);
|
|
};
|