Skip to content

Commit

Permalink
Show validateCode error in the valideCode modal
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-lr committed Oct 26, 2024
1 parent 00ae18e commit de7bf8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,11 @@ function reportVirtualExpensifyCardFraud(cardID: number, validateCode: string):
API.makeRequestWithSideEffects(SIDE_EFFECT_REQUEST_COMMANDS.REPORT_VIRTUAL_EXPENSIFY_CARD_FRAUD, parameters, {optimisticData, successData, failureData})
.then((response): string | undefined => {
if (response?.jsonCode !== CONST.JSON_CODE.SUCCESS) {
if (response?.jsonCode === CONST.JSON_CODE.INCORRECT_MAGIC_CODE) {
// eslint-disable-next-line prefer-promise-reject-errors
reject('validateCodeForm.error.incorrectMagicCode');
return;
}

// eslint-disable-next-line prefer-promise-reject-errors
reject();
return;
}
resolve((response as ExpensifyCardID).newCardID.toString());
})
// eslint-disable-next-line prefer-promise-reject-errors
.catch(() => reject('cardPage.cardDetailsLoadingFailure'));
.catch(() => reject());
});
}

Expand Down
21 changes: 19 additions & 2 deletions src/pages/settings/Wallet/ReportVirtualCardFraudPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Text from '@components/Text';
import ValidateCodeActionModal from '@components/ValidateCodeActionModal';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {requestValidateCodeAction} from '@libs/actions/User';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
Expand All @@ -27,13 +28,15 @@ function ReportVirtualCardFraudPage({
}: ReportVirtualCardFraudPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST);
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);
const [formData] = useOnyx(ONYXKEYS.FORMS.REPORT_VIRTUAL_CARD_FRAUD);
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(false);

const virtualCard = cardList?.[cardID];
const virtualCardError = ErrorUtils.getLatestErrorMessage(virtualCard);
const validateError = ErrorUtils.getLatestErrorMessageField(virtualCard);

if (isEmptyObject(virtualCard)) {
return;
Expand All @@ -48,9 +51,19 @@ function ReportVirtualCardFraudPage({
if (!newCardID) {
return;
}
setIsValidateCodeActionModalVisible(false);
Navigation.navigate(ROUTES.SETTINGS_WALLET_DOMAINCARD.getRoute(newCardID));
});
setIsValidateCodeActionModalVisible(false);
};

const sendValidateCode = () => {
const primaryLogin = account?.primaryLogin ?? '';

if (loginList?.[primaryLogin]?.validateCodeSent) {
return;
}

requestValidateCodeAction();
};

return (
Expand All @@ -72,7 +85,11 @@ function ReportVirtualCardFraudPage({
</View>
<ValidateCodeActionModal
handleSubmitForm={handleValidateCodeEntered}
clearError={() => {}}
sendValidateCode={sendValidateCode}
validateError={validateError}
clearError={() => {
Card.clearCardListErrors(virtualCard.cardID);
}}
onClose={() => setIsValidateCodeActionModalVisible(false)}
isVisible={isValidateCodeActionModalVisible}
title={translate('cardPage.validateCardTitle')}
Expand Down

0 comments on commit de7bf8a

Please sign in to comment.