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

22875 Add API Calls when clicking “Reveal details” buttons #29017

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f73d601
first commit
lukemorawski Oct 6, 2023
5985ec1
move to reducer and error handling
lukemorawski Oct 6, 2023
df10ff7
removed unnecessary helper function
lukemorawski Oct 9, 2023
36fb11a
formatting
lukemorawski Oct 9, 2023
bfdb546
var name change to isLoading
lukemorawski Oct 9, 2023
9a8962c
better linting
lukemorawski Oct 9, 2023
c7dd8fa
moved action types to const
lukemorawski Oct 9, 2023
ccf8f4e
action types fix and cardID added to api call
lukemorawski Oct 9, 2023
ef623a4
address refactoring
lukemorawski Oct 10, 2023
f7ba68a
refactoring
lukemorawski Oct 11, 2023
9f173af
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski Oct 11, 2023
8361350
removed comment
lukemorawski Oct 12, 2023
36a6d4e
revealCardDetails move
lukemorawski Oct 13, 2023
28ca868
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski Oct 17, 2023
a7bcbb6
added offline disabling
lukemorawski Oct 17, 2023
f1aad79
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski Oct 17, 2023
42cb473
reject with generic error message
lukemorawski Oct 18, 2023
6dac4ca
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski Oct 19, 2023
dcb188b
Update src/libs/actions/Card.js
lukemorawski Oct 20, 2023
8254860
linting
lukemorawski Oct 20, 2023
586f20e
Merge branch 'main' into 22875-api_call_on_reveal_card_details
lukemorawski Oct 23, 2023
aaa7042
merging with latest changes
lukemorawski Oct 23, 2023
95d4a43
Update src/languages/en.ts
lukemorawski Oct 24, 2023
934344a
removed error handling
lukemorawski Oct 25, 2023
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 @@ -843,6 +843,7 @@ export default {
revealDetails: 'Reveal details',
copyCardNumber: 'Copy card number',
},
cardDetailsLoadingFailure: 'An error occurred loading card details, please try again.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this reads better

Suggested change
cardDetailsLoadingFailure: 'An error occurred loading card details, please try again.',
cardDetailsLoadingFailure: 'An error occurred while loading the card details. Please try again.',

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed this copy was already approved by marketing.

@lukemorawski @MrMuzyk @grgia is this wrong?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no error message copy for this in the Design Doc @marcaaron

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think we need to get the copy looked at. All copy needs to be approved. 🙃

Where did this error message come from?

},
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 @@ -839,6 +839,7 @@ export default {
revealDetails: 'Revelar detalles',
copyCardNumber: 'Copiar número de la tarjeta',
},
cardDetailsLoadingFailure: 'Ocurrió un error al cargar los detalles de la tarjeta. Por favor, inténtalo de nuevo.',
},
reportFraudPage: {
title: 'Reportar fraude con la tarjeta virtual',
Expand Down
23 changes: 23 additions & 0 deletions src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as API from '../API';
import CONST from '../../CONST';
import {TCardDetails} from '../../types/onyx/Card';
import * as Localize from '../Localize';

function revealVirtualCardDetails(cardID: string): Promise<TCardDetails> {
return new Promise((resolve, reject) => {
// eslint-disable-next-line rulesdir/no-api-side-effects-method
API.makeRequestWithSideEffects('RevealVirtualCardDetails', {cardID})
.then((response) => {
if (response.jsonCode !== CONST.JSON_CODE.SUCCESS) {
reject(response.message || Localize.translateLocal('cardPage.cardDetailsLoadingFailure'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not return the response.message error. It could be anything. Same with the catch below. Just return the default translated error in either case since the user will end up seeing this.

return;
}
resolve(response);
})
.catch((err) => {
reject(err.message);
});
});
}

export default {revealVirtualCardDetails};
28 changes: 21 additions & 7 deletions src/pages/settings/Wallet/ExpensifyCardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as Expensicons from '../../../components/Icon/Expensicons';
import * as CardUtils from '../../../libs/CardUtils';
import Button from '../../../components/Button';
import CardDetails from './WalletPage/CardDetails';
import Card from '../../../libs/actions/Card';
import CONST from '../../../CONST';
import assignedCardPropTypes from './assignedCardPropTypes';

Expand Down Expand Up @@ -50,7 +51,9 @@ function ExpensifyCardPage({
const virtualCard = _.find(domainCards, (card) => card.isVirtual) || {};
const physicalCard = _.find(domainCards, (card) => !card.isVirtual) || {};

const [shouldShowCardDetails, setShouldShowCardDetails] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [details, setDetails] = useState({});
const [errorMessage, setErrorMessage] = useState('');

if (_.isEmpty(virtualCard) && _.isEmpty(physicalCard)) {
return <NotFoundPage />;
Expand All @@ -59,7 +62,15 @@ function ExpensifyCardPage({
const formattedAvailableSpendAmount = CurrencyUtils.convertToDisplayString(physicalCard.availableSpend || virtualCard.availableSpend || 0);

const handleRevealDetails = () => {
setShouldShowCardDetails(true);
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.
// eslint-disable-next-line rulesdir/no-thenable-actions-in-views
Card.revealVirtualCardDetails(virtualCard.cardID)
.then(setDetails)
.catch(setErrorMessage)
.finally(() => setIsLoading(false));
};

return (
Expand All @@ -86,12 +97,12 @@ function ExpensifyCardPage({
/>
{!_.isEmpty(virtualCard) && (
<>
{shouldShowCardDetails ? (
{details.pan ? (
<CardDetails
// This is just a temporary mock, it will be replaced in this issue https://github.com/orgs/Expensify/projects/58?pane=issue&itemId=33286617
pan="1234123412341234"
expiration="11/02/2024"
cvv="321"
pan={details.pan}
expiration={details.expiration}
cvv={details.cvv}
privatePersonalDetails={{address: details.address}}
/>
) : (
<MenuItemWithTopDescription
Expand All @@ -100,11 +111,14 @@ function ExpensifyCardPage({
interactive={false}
titleStyle={styles.walletCardNumber}
shouldShowRightComponent
error={errorMessage}
rightComponent={
<Button
medium
text={translate('cardPage.cardDetails.revealDetails')}
onPress={handleRevealDetails}
isDisabled={isLoading}
isLoading={isLoading}
/>
}
/>
Expand Down
15 changes: 15 additions & 0 deletions src/types/onyx/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ type Card = {
isLoading?: boolean;
};

type TCardDetails = {
pan: string;
expiration: string;
cvv: string;
address: {
street: string;
street2: string;
city: string;
state: string;
zip: string;
country: string;
};
};

export default Card;
export type {TCardDetails};
Loading