Skip to content

Commit 99928ea

Browse files
author
Timur Karimov
committed
simplify the structure of duplicates received by the front end
1 parent d0756e2 commit 99928ea

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

client/components/payment-methods-list/payment-method.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface PaymentMethodProps {
4646
locked: boolean;
4747
isPoEnabled: boolean;
4848
isPoComplete: boolean;
49-
duplicatesData: Record< string, string[] >;
49+
duplicatesData: string[];
5050
}
5151

5252
const PaymentMethodLabel = ( {
@@ -148,7 +148,7 @@ const PaymentMethod = ( {
148148
isPoInProgress ||
149149
upeCapabilityStatuses.REJECTED === status;
150150
const shouldDisplayNotice = id === 'sofort';
151-
const isDuplicate = duplicatesData[ id ]?.length > 0;
151+
const isDuplicate = duplicatesData.includes( id );
152152

153153
const needsOverlay =
154154
( isManualCaptureEnabled && ! isAllowingManualCapture ) ||

client/components/payment-methods-list/test/payment-method.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe( 'PaymentMethod', () => {
4343
locked={ false }
4444
isPoEnabled={ false }
4545
isPoComplete={ false }
46-
duplicatesData={ {} as Record< string, string[] > }
46+
duplicatesData={ {} as string[] }
4747
/>
4848
);
4949
};
@@ -102,7 +102,7 @@ describe( 'PaymentMethod', () => {
102102
required={ false }
103103
isPoEnabled={ false }
104104
isPoComplete={ false }
105-
duplicatesData={ {} as Record< string, string[] > }
105+
duplicatesData={ {} as string[] }
106106
/>
107107
);
108108
};

client/settings/express-checkout/apple-google-pay-item.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,10 @@ const AppleGooglePayExpressCheckoutItem = (): React.ReactElement => {
2727
] = usePaymentRequestEnabledSettings() as PaymentRequestEnabledSettingsHook;
2828

2929
const showIncompatibilityNotice = useExpressCheckoutShowIncompatibilityNotice();
30-
const duplicatedPaymentMethods = useGetDuplicatedPaymentMethodIds() as Record<
31-
string,
32-
string[]
33-
>;
34-
const isDuplicate =
35-
duplicatedPaymentMethods?.apple_pay_google_pay?.length > 0;
30+
const duplicatedPaymentMethods = useGetDuplicatedPaymentMethodIds() as string[];
31+
const isDuplicate = duplicatedPaymentMethods.includes(
32+
'apple_pay_google_pay'
33+
);
3634

3735
return (
3836
<li

includes/class-duplicates-detection-service.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function find_duplicates() {
5858
->keep_woopayments_enabled_gateways_only()
5959
->keep_duplicates_only();
6060

61-
return $this->gateways_qualified_by_duplicates_detector;
61+
// Return payment method IDs list so that front-end can successfully compare with its own list.
62+
return array_keys( $this->gateways_qualified_by_duplicates_detector );
6263
}
6364

6465
/**

0 commit comments

Comments
 (0)