♻️ Convert payment-store hooks to new code pattern

This commit is contained in:
Philipp Stracker 2025-02-14 17:49:35 +01:00
parent 10527e507a
commit b2b0bb8d7a
No known key found for this signature in database

View file

@ -37,7 +37,21 @@ const useStoreData = () => {
); );
}; };
const useHooks = () => { export const useStore = () => {
const { useTransient, dispatch } = useStoreData();
const { persist, refresh, setPersistent, changePaymentSettings } = dispatch;
const [ isReady ] = useTransient( 'isReady' );
return {
persist,
refresh,
setPersistent,
changePaymentSettings,
isReady,
};
};
export const usePaymentMethods = () => {
const { usePersistent } = useStoreData(); const { usePersistent } = useStoreData();
// PayPal checkout. // PayPal checkout.
@ -64,83 +78,6 @@ const useHooks = () => {
const [ pui ] = usePersistent( 'ppcp-pay-upon-invoice-gateway' ); const [ pui ] = usePersistent( 'ppcp-pay-upon-invoice-gateway' );
const [ oxxo ] = usePersistent( 'ppcp-oxxo-gateway' ); const [ oxxo ] = usePersistent( 'ppcp-oxxo-gateway' );
// Custom modal data.
const [ paypalShowLogo ] = usePersistent( 'paypalShowLogo' );
const [ threeDSecure ] = usePersistent( 'threeDSecure' );
const [ fastlaneCardholderName ] = usePersistent(
'fastlaneCardholderName'
);
const [ fastlaneDisplayWatermark ] = usePersistent(
'fastlaneDisplayWatermark'
);
return {
paypal,
venmo,
payLater,
creditCard,
advancedCreditCard,
fastlane,
applePay,
googlePay,
bancontact,
blik,
eps,
ideal,
mybank,
p24,
trustly,
multibanco,
pui,
oxxo,
paypalShowLogo,
threeDSecure,
fastlaneCardholderName,
fastlaneDisplayWatermark,
};
};
export const useStore = () => {
const { useTransient, dispatch } = useStoreData();
const { persist, refresh, setPersistent, changePaymentSettings } = dispatch;
const [ isReady ] = useTransient( 'isReady' );
return {
persist,
refresh,
setPersistent,
changePaymentSettings,
isReady,
};
};
export const usePaymentMethods = () => {
const {
// PayPal Checkout.
paypal,
venmo,
payLater,
creditCard,
// Online card payments.
advancedCreditCard,
fastlane,
applePay,
googlePay,
// Local APMs.
bancontact,
blik,
eps,
ideal,
mybank,
p24,
trustly,
multibanco,
pui,
oxxo,
} = useHooks();
const payPalCheckout = [ paypal, venmo, payLater, creditCard ]; const payPalCheckout = [ paypal, venmo, payLater, creditCard ];
const onlineCardPayments = [ const onlineCardPayments = [
advancedCreditCard, advancedCreditCard,
@ -190,12 +127,16 @@ export const usePaymentMethods = () => {
}; };
export const usePaymentMethodsModal = () => { export const usePaymentMethodsModal = () => {
const { const { usePersistent } = useStoreData();
paypalShowLogo,
threeDSecure, const [ paypalShowLogo ] = usePersistent( 'paypalShowLogo' );
fastlaneCardholderName, const [ threeDSecure ] = usePersistent( 'threeDSecure' );
fastlaneDisplayWatermark, const [ fastlaneCardholderName ] = usePersistent(
} = useHooks(); 'fastlaneCardholderName'
);
const [ fastlaneDisplayWatermark ] = usePersistent(
'fastlaneDisplayWatermark'
);
return { return {
paypalShowLogo, paypalShowLogo,