Skip to content

Commit

Permalink
Fix offline for users that dont have cards inserted (#792)
Browse files Browse the repository at this point in the history
* Update index.js

* Update index.js

* more generic

* test id

---------

Co-authored-by: EliFrankel <[email protected]>
  • Loading branch information
OmerGery and EliFrankel authored Nov 16, 2023
1 parent f97bf8e commit a842539
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions examples/client/Locomotion/src/Components/CardRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { View, Text } from 'react-native';
import moment from 'moment';
import styled, { ThemeContext } from 'styled-components';
import { PaymentIcon } from 'react-native-payment-icons';
import { paymentMethodToIconMap } from '../../pages/Payments/consts';
import { PAYMENT_METHODS, paymentMethodToIconMap } from '../../pages/Payments/consts';
import Button from '../Button';
import { capitalizeFirstLetter, getLastFourForamttedShort } from '../../pages/Payments/cardDetailUtils';
import i18n from '../../I18n';
Expand Down Expand Up @@ -106,7 +106,9 @@ const CardRow = (paymentMethod: any) => {
setIsCardExpired(isExpired);
}, 100);
}, [paymentMethod]);
const testID = paymentMethod.addNew ? `${paymentMethod.testIdPrefix || ''}AddPaymentMethod` : (`${paymentMethod.testIdPrefix || ''}ChoosePaymentMethod`);
const testID = paymentMethod.addNew
? `${paymentMethod.testIdPrefix || ''}AddPaymentMethod`
: (`${paymentMethod.testIdPrefix || ''}ChoosePaymentMethod${paymentMethod.id === PAYMENT_METHODS.OFFLINE || paymentMethod.id === PAYMENT_METHODS.CASH ? `_${paymentMethod.id}` : ''}`);

const getPaymentMethodIcon = () => {
const { brand, id, lastFour } = paymentMethod;
Expand Down
4 changes: 3 additions & 1 deletion examples/client/Locomotion/src/pages/ActiveRide/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Portal } from '@gorhom/portal';
import Config from 'react-native-config';
import { distance, point } from '@turf/turf';
import { isCardPaymentMethod } from '../../lib/ride/utils';
import networkInfo from '../../services/networkInfo';
import AFToast from '../../Components/Toast';
import * as navigationService from '../../services/navigation';
Expand Down Expand Up @@ -242,7 +243,8 @@ const RidePage = ({ mapSettings, navigation }) => {
isConfirmPickup
initialLocation={requestStopPoints[0]}
onButtonPress={(pickupLocation) => {
if (clientHasValidPaymentMethods() || ride.paymentMethodId === PAYMENT_METHODS.CASH) {
const { paymentMethodId } = ride;
if (clientHasValidPaymentMethods() || !isCardPaymentMethod({ id: paymentMethodId })) {
requestRide(pickupLocation);
} else {
changeBsPage(BS_PAGES.NO_PAYMENT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { isCardPaymentMethod } from '../../lib/ride/utils';
import { PAYMENT_METHODS } from '../../lib/commonTypes';

export const capitalizeFirstLetter = (string: string) => string?.charAt(0).toUpperCase() + string?.slice(1);
export const getLastFourForamttedShort = (lastFour: string) => `**** ${capitalizeFirstLetter(lastFour)}`;
export const getLastFourForamttedLong = (lastFour: string) => `**** **** **** ${capitalizeFirstLetter(lastFour)}`;

export const getPaymentMethod = (paymentMethodId: string) => {
if ([PAYMENT_METHODS.CASH, PAYMENT_METHODS.OFFLINE].includes(paymentMethodId)) {
if (!isCardPaymentMethod({ id: paymentMethodId })) {
return paymentMethodId;
}
return PAYMENT_METHODS.CARD;
Expand Down

0 comments on commit a842539

Please sign in to comment.