mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Move api requests to controls
This commit is contained in:
parent
f0a09ba83b
commit
da0a81036a
5 changed files with 44 additions and 28 deletions
|
@ -9,8 +9,7 @@
|
|||
|
||||
import { useDispatch, useSelect } from '@wordpress/data';
|
||||
import { useCallback } from '@wordpress/element';
|
||||
import { REST_WEBHOOKS, STORE_NAME } from './constants';
|
||||
import apiFetch from '@wordpress/api-fetch';
|
||||
import { STORE_NAME } from './constants';
|
||||
|
||||
const useTransient = ( key ) =>
|
||||
useSelect(
|
||||
|
@ -31,10 +30,11 @@ const useHooks = () => {
|
|||
setManualConnectionMode,
|
||||
setClientId,
|
||||
setClientSecret,
|
||||
setWebhooks,
|
||||
connectToSandbox,
|
||||
connectToProduction,
|
||||
connectViaIdAndSecret,
|
||||
startWebhookSimulation,
|
||||
checkWebhookSimulationState,
|
||||
} = useDispatch( STORE_NAME );
|
||||
|
||||
// Transient accessors.
|
||||
|
@ -78,19 +78,14 @@ const useHooks = () => {
|
|||
setClientSecret: ( value ) => {
|
||||
return savePersistent( setClientSecret, value );
|
||||
},
|
||||
setWebhooks: async () => {
|
||||
const response = await apiFetch( {
|
||||
method: 'GET',
|
||||
path: REST_WEBHOOKS,
|
||||
} );
|
||||
setWebhooks( response?.data?.webhooks );
|
||||
},
|
||||
connectToSandbox,
|
||||
connectToProduction,
|
||||
connectViaIdAndSecret,
|
||||
merchant,
|
||||
wooSettings,
|
||||
webhooks,
|
||||
startWebhookSimulation,
|
||||
checkWebhookSimulationState,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue