Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Ensure shopper saved card is used as default payment method (default was being overwritten in some circumstances) #3131

Merged
merged 3 commits into from
Sep 10, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,21 +341,23 @@ export const PaymentMethodDataProvider = ( { children } ) => {
return;
}

// If there's no active payment method, or the active payment method has
// been removed (e.g. COD vs shipping methods), set one as active.
if (
! activePaymentMethod ||
! paymentMethodKeys.includes( activePaymentMethod )
) {
setActivePaymentMethod(
Object.keys( paymentData.paymentMethods )[ 0 ]
);
}
setActive( ( currentActivePaymentMethod ) => {
// If there's no active payment method, or the active payment method has
// been removed (e.g. COD vs shipping methods), set one as active.
if (
! currentActivePaymentMethod ||
! paymentMethodKeys.includes( currentActivePaymentMethod )
) {
dispatch( statusOnly( PRISTINE ) );
return Object.keys( paymentData.paymentMethods )[ 0 ];
}
return currentActivePaymentMethod;
} );
}, [
activePaymentMethod,
paymentMethodsInitialized,
paymentData.paymentMethods,
setActivePaymentMethod,
setActive,
customerPaymentMethods,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this dependency needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, and it looks like it hasn't been needed for a while! Removed it and retested (just in case) 👍

] );

// emit events.
Expand Down