Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only request WooPay session once on Blocks pages #7393

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-7357-multiple-woopay-session-requests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Only request WooPay session data once on blocks pages.
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* External dependencies
*/
import { useCallback } from 'react';
cesarcosta99 marked this conversation as resolved.
Show resolved Hide resolved
import ReactDOM from 'react-dom';

/**
* Internal dependencies
*/
Expand All @@ -18,15 +24,27 @@ const api = new WCPayAPI(
request
);

const WooPayExpressCheckoutButtonContainer = () => {
const onRefChange = useCallback( ( node ) => {
if ( node ) {
cesarcosta99 marked this conversation as resolved.
Show resolved Hide resolved
const root = ReactDOM.createRoot( node );

root.render(
<WoopayExpressCheckoutButton
buttonSettings={ getConfig( 'woopayButton' ) }
api={ api }
emailSelector="#email"
/>
);
}
}, [] );

return <span ref={ onRefChange } />;
};

const wooPayExpressCheckoutPaymentMethod = () => ( {
name: PAYMENT_METHOD_NAME_WOOPAY_EXPRESS_CHECKOUT,
content: (
<WoopayExpressCheckoutButton
buttonSettings={ getConfig( 'woopayButton' ) }
api={ api }
emailSelector="#email"
/>
),
content: <WooPayExpressCheckoutButtonContainer />,
edit: (
<WoopayExpressCheckoutButton
buttonSettings={ getConfig( 'woopayButton' ) }
Expand Down
Loading