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

Commit 0f29710

Browse files
committed
Add check for when express payment methods have updated too
1 parent 5ebe7fb commit 0f29710

File tree

1 file changed

+20
-4
lines changed
  • assets/js/base/context/providers/cart-checkout/checkout-events

1 file changed

+20
-4
lines changed

assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ import { STATUS } from '../../../../../data/checkout/constants';
3434
import { useStoreEvents } from '../../../hooks/use-store-events';
3535
import { useCheckoutNotices } from '../../../hooks/use-checkout-notices';
3636
import { CheckoutState } from '../../../../../data/checkout/default-state';
37-
import { getPaymentMethods } from '../../../../../blocks-registry/payment-methods/registry';
37+
import {
38+
getExpressPaymentMethods,
39+
getPaymentMethods,
40+
} from '../../../../../blocks-registry/payment-methods/registry';
3841

3942
type CheckoutEventsContextType = {
4043
// Submits the checkout and begins processing.
@@ -77,19 +80,32 @@ export const CheckoutEventsProvider = ( {
7780
redirectUrl: string;
7881
} ): JSX.Element => {
7982
const paymentMethods = getPaymentMethods();
83+
const expressPaymentMethods = getExpressPaymentMethods();
8084

8185
// Go into useState as once this is set it won't change.
8286
const [ isEditor ] = useState( !! wpDataSelect( 'core/editor' ) );
8387

84-
const { __internalInitializePaymentStore } =
88+
const { __internalUpdateAvailablePaymentMethods } =
8589
useDispatch( PAYMENT_STORE_KEY );
8690

91+
// Update the payment method store when paymentMethods or expressPaymentMethods changes.
92+
// Ensure this happens in the editor even if paymentMethods is empty. This won't happen instantly when the objects
93+
// are updated, but on the next re-render.
8794
useEffect( () => {
88-
if ( ! isEditor && Object.keys( paymentMethods ).length === 0 ) {
95+
if (
96+
! isEditor &&
97+
Object.keys( paymentMethods ).length === 0 &&
98+
Object.keys( expressPaymentMethods ).length === 0
99+
) {
89100
return;
90101
}
91102
__internalUpdateAvailablePaymentMethods();
92-
}, [ isEditor, paymentMethods, __internalInitializePaymentStore ] );
103+
}, [
104+
isEditor,
105+
paymentMethods,
106+
expressPaymentMethods,
107+
__internalUpdateAvailablePaymentMethods,
108+
] );
93109

94110
const checkoutActions = useDispatch( CHECKOUT_STORE_KEY );
95111
const checkoutState: CheckoutState = useSelect( ( select ) =>

0 commit comments

Comments
 (0)