♻️ Improve code style and readability

This commit is contained in:
Philipp Stracker 2025-03-17 14:45:37 +01:00
parent b5faa08bfd
commit f5194c0be4
No known key found for this signature in database

View file

@ -54,7 +54,7 @@ class Renderer {
const enabledSeparateGateways = Object.fromEntries( const enabledSeparateGateways = Object.fromEntries(
Object.entries( settings.separate_buttons ).filter( Object.entries( settings.separate_buttons ).filter(
( [ s, data ] ) => document.querySelector( data.wrapper ) ( [ , data ] ) => document.querySelector( data.wrapper )
) )
); );
const hasEnabledSeparateGateways = const hasEnabledSeparateGateways =
@ -70,10 +70,12 @@ class Renderer {
); );
} }
} else { } else {
const allFundingSources = paypal.getFundingSources();
const separateFunding = allFundingSources.filter(
( s ) => ! ( s in enabledSeparateGateways )
);
// render each button separately // render each button separately
for ( const fundingSource of paypal for ( const fundingSource of separateFunding ) {
.getFundingSources()
.filter( ( s ) => ! ( s in enabledSeparateGateways ) ) ) {
const style = normalizeStyleForFundingSource( const style = normalizeStyleForFundingSource(
settings.button.style, settings.button.style,
fundingSource fundingSource
@ -161,29 +163,29 @@ class Renderer {
if ( this.shouldEnableShippingCallback() ) { if ( this.shouldEnableShippingCallback() ) {
options.onShippingOptionsChange = ( data, actions ) => { options.onShippingOptionsChange = ( data, actions ) => {
const shippingOptionsChange = const shippingOptionsChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled( ! this.isVenmoButtonClickedWhenVaultingIsEnabled(
venmoButtonClicked venmoButtonClicked
) )
? handleShippingOptionsChange( ? handleShippingOptionsChange(
data, data,
actions, actions,
this.defaultSettings this.defaultSettings
) )
: null; : null;
return shippingOptionsChange; return shippingOptionsChange;
}; };
options.onShippingAddressChange = ( data, actions ) => { options.onShippingAddressChange = ( data, actions ) => {
const shippingAddressChange = const shippingAddressChange =
! this.isVenmoButtonClickedWhenVaultingIsEnabled( ! this.isVenmoButtonClickedWhenVaultingIsEnabled(
venmoButtonClicked venmoButtonClicked
) )
? handleShippingAddressChange( ? handleShippingAddressChange(
data, data,
actions, actions,
this.defaultSettings this.defaultSettings
) )
: null; : null;
return shippingAddressChange; return shippingAddressChange;
}; };
@ -246,7 +248,7 @@ class Renderer {
return venmoButtonClicked && this.defaultSettings.vaultingEnabled; return venmoButtonClicked && this.defaultSettings.vaultingEnabled;
}; };
shouldEnableShippingCallback = () => { shouldEnableShippingCallback = () => {
const needShipping = const needShipping =
this.defaultSettings.needShipping || this.defaultSettings.needShipping ||
this.defaultSettings.context === 'product'; this.defaultSettings.context === 'product';
@ -254,7 +256,7 @@ class Renderer {
this.defaultSettings.should_handle_shipping_in_paypal && this.defaultSettings.should_handle_shipping_in_paypal &&
needShipping needShipping
); );
}; };
isAlreadyRendered( wrapper, fundingSource ) { isAlreadyRendered( wrapper, fundingSource ) {
return this.renderedSources.has( wrapper + ( fundingSource ?? '' ) ); return this.renderedSources.has( wrapper + ( fundingSource ?? '' ) );