♻️ Slightly improve code readability

This commit is contained in:
Philipp Stracker 2025-03-17 14:59:03 +01:00
parent 745c1cc88c
commit 3cfbd1002f
No known key found for this signature in database

View file

@ -133,10 +133,7 @@ class Renderer {
this.onSmartButtonClick( data, actions ); this.onSmartButtonClick( data, actions );
} }
venmoButtonClicked = false; venmoButtonClicked = data.fundingSource === 'venmo';
if ( data.fundingSource === 'venmo' ) {
venmoButtonClicked = true;
}
}, },
onInit: ( data, actions ) => { onInit: ( data, actions ) => {
if ( this.onSmartButtonsInit ) { if ( this.onSmartButtonsInit ) {
@ -219,10 +216,7 @@ class Renderer {
this.renderedSources.add( wrapper + ( fundingSource ?? '' ) ); this.renderedSources.add( wrapper + ( fundingSource ?? '' ) );
if ( if ( window.paypal?.Buttons ) {
typeof paypal !== 'undefined' &&
typeof paypal.Buttons !== 'undefined'
) {
widgetBuilder.registerButtons( widgetBuilder.registerButtons(
[ wrapper, fundingSource ], [ wrapper, fundingSource ],
buttonsOptions() buttonsOptions()
@ -239,6 +233,7 @@ class Renderer {
const needShipping = const needShipping =
this.defaultSettings.needShipping || this.defaultSettings.needShipping ||
this.defaultSettings.context === 'product'; this.defaultSettings.context === 'product';
return ( return (
this.defaultSettings.should_handle_shipping_in_paypal && this.defaultSettings.should_handle_shipping_in_paypal &&
needShipping needShipping
@ -261,6 +256,7 @@ class Renderer {
this.onButtonsInitListeners[ wrapper ] = reset this.onButtonsInitListeners[ wrapper ] = reset
? [] ? []
: this.onButtonsInitListeners[ wrapper ] || []; : this.onButtonsInitListeners[ wrapper ] || [];
this.onButtonsInitListeners[ wrapper ].push( handler ); this.onButtonsInitListeners[ wrapper ].push( handler );
} }
@ -272,12 +268,11 @@ class Renderer {
if ( this.onButtonsInitListeners[ wrapper ] ) { if ( this.onButtonsInitListeners[ wrapper ] ) {
for ( const handler of this.onButtonsInitListeners[ wrapper ] ) { for ( const handler of this.onButtonsInitListeners[ wrapper ] ) {
if ( typeof handler === 'function' ) { if ( typeof handler !== 'function' ) {
handler( { continue;
wrapper,
...this.buttonsOptions[ wrapper ],
} );
} }
handler( { wrapper, ...this.buttonsOptions[ wrapper ] } );
} }
} }
} }
@ -286,10 +281,11 @@ class Renderer {
if ( ! this.buttonsOptions[ wrapper ] ) { if ( ! this.buttonsOptions[ wrapper ] ) {
return; return;
} }
try { try {
this.buttonsOptions[ wrapper ].actions.disable(); this.buttonsOptions[ wrapper ].actions.disable();
} catch ( err ) { } catch ( err ) {
console.log( 'Failed to disable buttons: ' + err ); console.warn( 'Failed to disable buttons: ' + err );
} }
} }
@ -297,10 +293,11 @@ class Renderer {
if ( ! this.buttonsOptions[ wrapper ] ) { if ( ! this.buttonsOptions[ wrapper ] ) {
return; return;
} }
try { try {
this.buttonsOptions[ wrapper ].actions.enable(); this.buttonsOptions[ wrapper ].actions.enable();
} catch ( err ) { } catch ( err ) {
console.log( 'Failed to enable buttons: ' + err ); console.warn( 'Failed to enable buttons: ' + err );
} }
} }
} }