mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
♻️ Refactor hooks without changing their response
This commit is contained in:
parent
0f5f571f98
commit
c0dbcf6884
1 changed files with 13 additions and 12 deletions
|
@ -41,8 +41,6 @@ const useHooks = () => {
|
||||||
const { useTransient, usePersistent, dispatch, select } = useStoreData();
|
const { useTransient, usePersistent, dispatch, select } = useStoreData();
|
||||||
const {
|
const {
|
||||||
persist,
|
persist,
|
||||||
sandboxOnboardingUrl,
|
|
||||||
productionOnboardingUrl,
|
|
||||||
authenticateWithCredentials,
|
authenticateWithCredentials,
|
||||||
authenticateWithOAuth,
|
authenticateWithOAuth,
|
||||||
startWebhookSimulation,
|
startWebhookSimulation,
|
||||||
|
@ -55,7 +53,6 @@ const useHooks = () => {
|
||||||
useTransient( 'activeHighlight' );
|
useTransient( 'activeHighlight' );
|
||||||
|
|
||||||
// Persistent accessors.
|
// Persistent accessors.
|
||||||
const [ isSandboxMode, setSandboxMode ] = usePersistent( 'useSandbox' );
|
|
||||||
const [ isManualConnectionMode, setManualConnectionMode ] = usePersistent(
|
const [ isManualConnectionMode, setManualConnectionMode ] = usePersistent(
|
||||||
'useManualConnection'
|
'useManualConnection'
|
||||||
);
|
);
|
||||||
|
@ -75,16 +72,10 @@ const useHooks = () => {
|
||||||
setActiveModal,
|
setActiveModal,
|
||||||
activeHighlight,
|
activeHighlight,
|
||||||
setActiveHighlight,
|
setActiveHighlight,
|
||||||
isSandboxMode,
|
|
||||||
setSandboxMode: ( state ) => {
|
|
||||||
return savePersistent( setSandboxMode, state );
|
|
||||||
},
|
|
||||||
isManualConnectionMode,
|
isManualConnectionMode,
|
||||||
setManualConnectionMode: ( state ) => {
|
setManualConnectionMode: ( state ) => {
|
||||||
return savePersistent( setManualConnectionMode, state );
|
return savePersistent( setManualConnectionMode, state );
|
||||||
},
|
},
|
||||||
sandboxOnboardingUrl,
|
|
||||||
productionOnboardingUrl,
|
|
||||||
authenticateWithCredentials,
|
authenticateWithCredentials,
|
||||||
authenticateWithOAuth,
|
authenticateWithOAuth,
|
||||||
wooSettings,
|
wooSettings,
|
||||||
|
@ -109,13 +100,23 @@ export const useStore = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSandbox = () => {
|
export const useSandbox = () => {
|
||||||
const { isSandboxMode, setSandboxMode, sandboxOnboardingUrl } = useHooks();
|
const { dispatch, usePersistent } = useStoreData();
|
||||||
|
const [ isSandboxMode, setSandboxMode ] = usePersistent( 'useSandbox' );
|
||||||
|
const { sandboxOnboardingUrl, persist } = dispatch;
|
||||||
|
|
||||||
return { isSandboxMode, setSandboxMode, sandboxOnboardingUrl };
|
return {
|
||||||
|
isSandboxMode,
|
||||||
|
setSandboxMode: ( state ) => {
|
||||||
|
setSandboxMode( state );
|
||||||
|
return persist();
|
||||||
|
},
|
||||||
|
sandboxOnboardingUrl,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useProduction = () => {
|
export const useProduction = () => {
|
||||||
const { productionOnboardingUrl } = useHooks();
|
const { dispatch } = useStoreData();
|
||||||
|
const { productionOnboardingUrl } = dispatch;
|
||||||
|
|
||||||
return { productionOnboardingUrl };
|
return { productionOnboardingUrl };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue