mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +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 {
|
||||
persist,
|
||||
sandboxOnboardingUrl,
|
||||
productionOnboardingUrl,
|
||||
authenticateWithCredentials,
|
||||
authenticateWithOAuth,
|
||||
startWebhookSimulation,
|
||||
|
@ -55,7 +53,6 @@ const useHooks = () => {
|
|||
useTransient( 'activeHighlight' );
|
||||
|
||||
// Persistent accessors.
|
||||
const [ isSandboxMode, setSandboxMode ] = usePersistent( 'useSandbox' );
|
||||
const [ isManualConnectionMode, setManualConnectionMode ] = usePersistent(
|
||||
'useManualConnection'
|
||||
);
|
||||
|
@ -75,16 +72,10 @@ const useHooks = () => {
|
|||
setActiveModal,
|
||||
activeHighlight,
|
||||
setActiveHighlight,
|
||||
isSandboxMode,
|
||||
setSandboxMode: ( state ) => {
|
||||
return savePersistent( setSandboxMode, state );
|
||||
},
|
||||
isManualConnectionMode,
|
||||
setManualConnectionMode: ( state ) => {
|
||||
return savePersistent( setManualConnectionMode, state );
|
||||
},
|
||||
sandboxOnboardingUrl,
|
||||
productionOnboardingUrl,
|
||||
authenticateWithCredentials,
|
||||
authenticateWithOAuth,
|
||||
wooSettings,
|
||||
|
@ -109,13 +100,23 @@ export const useStore = () => {
|
|||
};
|
||||
|
||||
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 = () => {
|
||||
const { productionOnboardingUrl } = useHooks();
|
||||
const { dispatch } = useStoreData();
|
||||
const { productionOnboardingUrl } = dispatch;
|
||||
|
||||
return { productionOnboardingUrl };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue