Skip to content

Commit

Permalink
simplify the structure of duplicates received by the front end
Browse files Browse the repository at this point in the history
  • Loading branch information
Timur Karimov committed Apr 11, 2024
1 parent d0756e2 commit 99928ea
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions client/components/payment-methods-list/payment-method.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface PaymentMethodProps {
locked: boolean;
isPoEnabled: boolean;
isPoComplete: boolean;
duplicatesData: Record< string, string[] >;
duplicatesData: string[];
}

const PaymentMethodLabel = ( {
Expand Down Expand Up @@ -148,7 +148,7 @@ const PaymentMethod = ( {
isPoInProgress ||
upeCapabilityStatuses.REJECTED === status;
const shouldDisplayNotice = id === 'sofort';
const isDuplicate = duplicatesData[ id ]?.length > 0;
const isDuplicate = duplicatesData.includes( id );

const needsOverlay =
( isManualCaptureEnabled && ! isAllowingManualCapture ) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe( 'PaymentMethod', () => {
locked={ false }
isPoEnabled={ false }
isPoComplete={ false }
duplicatesData={ {} as Record< string, string[] > }
duplicatesData={ {} as string[] }
/>
);
};
Expand Down Expand Up @@ -102,7 +102,7 @@ describe( 'PaymentMethod', () => {
required={ false }
isPoEnabled={ false }
isPoComplete={ false }
duplicatesData={ {} as Record< string, string[] > }
duplicatesData={ {} as string[] }
/>
);
};
Expand Down
10 changes: 4 additions & 6 deletions client/settings/express-checkout/apple-google-pay-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ const AppleGooglePayExpressCheckoutItem = (): React.ReactElement => {
] = usePaymentRequestEnabledSettings() as PaymentRequestEnabledSettingsHook;

const showIncompatibilityNotice = useExpressCheckoutShowIncompatibilityNotice();
const duplicatedPaymentMethods = useGetDuplicatedPaymentMethodIds() as Record<
string,
string[]
>;
const isDuplicate =
duplicatedPaymentMethods?.apple_pay_google_pay?.length > 0;
const duplicatedPaymentMethods = useGetDuplicatedPaymentMethodIds() as string[];
const isDuplicate = duplicatedPaymentMethods.includes(
'apple_pay_google_pay'
);

return (
<li
Expand Down
3 changes: 2 additions & 1 deletion includes/class-duplicates-detection-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function find_duplicates() {
->keep_woopayments_enabled_gateways_only()
->keep_duplicates_only();

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

/**
Expand Down

0 comments on commit 99928ea

Please sign in to comment.