Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reveal card details error handling #31067

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ export default {
copyCardNumber: 'Copy card number',
updateAddress: 'Update address',
},
cardDetailsLoadingFailure: 'An error occurred while loading the card details. Please check your internet connection and try again.',
},
reportFraudPage: {
title: 'Report virtual card fraud',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ export default {
copyCardNumber: 'Copiar número de la tarjeta',
updateAddress: 'Actualizar dirección',
},
cardDetailsLoadingFailure: 'Se ha producido un error al cargar los datos de la tarjeta. Comprueba tu conexión a Internet e inténtalo de nuevo.',
},
reportFraudPage: {
title: 'Reportar fraude con la tarjeta virtual',
Expand Down
5 changes: 3 additions & 2 deletions src/libs/actions/Card.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import * as Localize from '@libs/Localize';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

Expand Down Expand Up @@ -163,12 +164,12 @@ function revealVirtualCardDetails(cardID) {
API.makeRequestWithSideEffects('RevealExpensifyCardDetails', {cardID})
.then((response) => {
if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) {
reject();
reject(Localize.translateLocal('cardPage.cardDetailsLoadingFailure'));
return;
}
resolve(response);
})
.catch(reject);
.catch(() => reject(Localize.translateLocal('cardPage.cardDetailsLoadingFailure')));
});
}

Expand Down
77 changes: 32 additions & 45 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function ExpensifyCardPage({

const [isLoading, setIsLoading] = useState(false);
const [details, setDetails] = useState({});
const [cardDetailsError, setCardDetailsError] = useState('');

if (_.isEmpty(virtualCard) && _.isEmpty(physicalCard)) {
return <NotFoundPage />;
Expand All @@ -70,16 +71,21 @@ function ExpensifyCardPage({
const handleRevealDetails = () => {
setIsLoading(true);
// We can't store the response in Onyx for security reasons.
// That is this action is handled manually and the response is stored in a local state
// Hence the eslint disable here.
// That is why this action is handled manually and the response is stored in a local state
// Hence eslint disable here.
// eslint-disable-next-line rulesdir/no-thenable-actions-in-views
Card.revealVirtualCardDetails(virtualCard.cardID)
.then(setDetails)
.then((value) => {
setDetails(value);
setCardDetailsError('');
})
.catch(setCardDetailsError)
.finally(() => setIsLoading(false));
};

const hasDetectedDomainFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN);
const hasDetectedIndividualFraud = _.some(domainCards, (card) => card.fraud === CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL);
const cardDetailsErrorObject = cardDetailsError ? {error: cardDetailsError} : {};

return (
<ScreenWrapper
Expand Down Expand Up @@ -108,32 +114,6 @@ function ExpensifyCardPage({

{hasDetectedIndividualFraud && !hasDetectedDomainFraud ? (
<>
{details.pan ? (
<CardDetails
pan={details.pan}
expiration={details.expiration}
cvv={details.cvv}
privatePersonalDetails={{address: details.address}}
domain={domain}
/>
) : (
<MenuItemWithTopDescription
description={translate('cardPage.virtualCardNumber')}
title={CardUtils.maskCard(virtualCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardNumber}
shouldShowRightComponent
rightComponent={
<Button
medium
text={translate('cardPage.cardDetails.revealDetails')}
onPress={handleRevealDetails}
isDisabled={isLoading || isOffline}
isLoading={isLoading}
/>
}
/>
)}
<DangerCardSection
title={translate('cardPage.suspiciousBannerTitle')}
description={translate('cardPage.suspiciousBannerDescription')}
Expand Down Expand Up @@ -169,22 +149,29 @@ function ExpensifyCardPage({
domain={domain}
/>
) : (
<MenuItemWithTopDescription
description={translate('cardPage.virtualCardNumber')}
title={CardUtils.maskCard(virtualCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardNumber}
shouldShowRightComponent
rightComponent={
<Button
medium
text={translate('cardPage.cardDetails.revealDetails')}
onPress={handleRevealDetails}
isDisabled={isLoading || isOffline}
isLoading={isLoading}
/>
}
/>
<>
<MenuItemWithTopDescription
description={translate('cardPage.virtualCardNumber')}
title={CardUtils.maskCard(virtualCard.lastFourPAN)}
interactive={false}
titleStyle={styles.walletCardNumber}
shouldShowRightComponent
rightComponent={
<Button
medium
text={translate('cardPage.cardDetails.revealDetails')}
onPress={handleRevealDetails}
isDisabled={isLoading || isOffline}
isLoading={isLoading}
/>
}
/>
<DotIndicatorMessage
messages={cardDetailsErrorObject}
type="error"
style={[styles.ph5]}
/>
</>
)}
<MenuItemWithTopDescription
title={translate('cardPage.reportFraud')}
Expand Down
4 changes: 2 additions & 2 deletions src/styles/fontFamily/multiFontFamily.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getOperatingSystem from '@libs/getOperatingSystem';
import CONST from '@src/CONST';
import {multiBold} from './bold';
import FontFamilyStyles from './types';
import CONST from '../../CONST';
import getOperatingSystem from '../../libs/getOperatingSystem';

// In windows and ubuntu, we need some extra system fonts for emojis to work properly
// otherwise few of them will appear as black and white
Expand Down