mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
♻️ Convert payment-store hooks to new code pattern
This commit is contained in:
parent
10527e507a
commit
b2b0bb8d7a
1 changed files with 25 additions and 84 deletions
|
@ -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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue