mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
🎨 Minor re-organization of code
This commit is contained in:
parent
67822b3b11
commit
a8f12c63fa
1 changed files with 18 additions and 17 deletions
|
@ -34,21 +34,6 @@ const handlePopupOpen = ( url, onError ) => {
|
|||
return true;
|
||||
};
|
||||
|
||||
const useConnectionAttempt = ( connectFn, errorMessage ) => {
|
||||
const { handleError, createErrorNotice } = useConnectionBase();
|
||||
|
||||
return async ( ...args ) => {
|
||||
const res = await connectFn( ...args );
|
||||
|
||||
if ( ! res.success || ! res.data ) {
|
||||
handleError( res, errorMessage );
|
||||
return false;
|
||||
}
|
||||
|
||||
return handlePopupOpen( res.data, createErrorNotice );
|
||||
};
|
||||
};
|
||||
|
||||
const useConnectionBase = () => {
|
||||
const { setCompleted } = OnboardingHooks.useSteps();
|
||||
const { createSuccessNotice, createErrorNotice } =
|
||||
|
@ -67,6 +52,21 @@ const useConnectionBase = () => {
|
|||
};
|
||||
};
|
||||
|
||||
const useConnectionAttempt = ( connectFn, errorMessage ) => {
|
||||
const { handleError, createErrorNotice } = useConnectionBase();
|
||||
|
||||
return async ( ...args ) => {
|
||||
const res = await connectFn( ...args );
|
||||
|
||||
if ( ! res.success || ! res.data ) {
|
||||
handleError( res, errorMessage );
|
||||
return false;
|
||||
}
|
||||
|
||||
return handlePopupOpen( res.data, createErrorNotice );
|
||||
};
|
||||
};
|
||||
|
||||
export const useSandboxConnection = () => {
|
||||
const { connectToSandbox, isSandboxMode, setSandboxMode } =
|
||||
CommonHooks.useSandbox();
|
||||
|
@ -83,6 +83,8 @@ export const useSandboxConnection = () => {
|
|||
};
|
||||
|
||||
export const useManualConnection = () => {
|
||||
const { handleError, handleSuccess, createErrorNotice } =
|
||||
useConnectionBase();
|
||||
const {
|
||||
connectViaIdAndSecret,
|
||||
isManualConnectionMode,
|
||||
|
@ -92,8 +94,6 @@ export const useManualConnection = () => {
|
|||
clientSecret,
|
||||
setClientSecret,
|
||||
} = CommonHooks.useManualConnection();
|
||||
const { handleError, handleSuccess, createErrorNotice } =
|
||||
useConnectionBase();
|
||||
|
||||
const handleConnectViaIdAndSecret = async ( { validation } = {} ) => {
|
||||
if ( 'function' === typeof validation ) {
|
||||
|
@ -104,6 +104,7 @@ export const useManualConnection = () => {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const res = await connectViaIdAndSecret();
|
||||
|
||||
if ( res.success ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue