mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
✨ Add “Common” hook to access merchant data
This commit is contained in:
parent
b4d1596fd1
commit
82b364a0ac
2 changed files with 30 additions and 0 deletions
|
@ -45,6 +45,10 @@ const useHooks = () => {
|
||||||
const isSandboxMode = usePersistent( 'useSandbox' );
|
const isSandboxMode = usePersistent( 'useSandbox' );
|
||||||
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
const isManualConnectionMode = usePersistent( 'useManualConnection' );
|
||||||
|
|
||||||
|
const merchant = useSelect(
|
||||||
|
( select ) => select( STORE_NAME ).merchant(),
|
||||||
|
[]
|
||||||
|
);
|
||||||
const wooSettings = useSelect(
|
const wooSettings = useSelect(
|
||||||
( select ) => select( STORE_NAME ).wooSettings(),
|
( select ) => select( STORE_NAME ).wooSettings(),
|
||||||
[]
|
[]
|
||||||
|
@ -76,6 +80,7 @@ const useHooks = () => {
|
||||||
connectToSandbox,
|
connectToSandbox,
|
||||||
connectToProduction,
|
connectToProduction,
|
||||||
connectViaIdAndSecret,
|
connectViaIdAndSecret,
|
||||||
|
merchant,
|
||||||
wooSettings,
|
wooSettings,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -120,6 +125,27 @@ export const useWooSettings = () => {
|
||||||
return wooSettings;
|
return wooSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useMerchantInfo = () => {
|
||||||
|
const { merchant } = useHooks();
|
||||||
|
const { refreshMerchantData } = useDispatch( STORE_NAME );
|
||||||
|
|
||||||
|
const verifyLoginStatus = useCallback( async () => {
|
||||||
|
const result = await refreshMerchantData();
|
||||||
|
|
||||||
|
if ( ! result.success ) {
|
||||||
|
throw new Error( result?.message || result?.error?.message );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify if the server state is "connected" and we have a merchant ID.
|
||||||
|
return merchant?.isConnected && merchant?.id;
|
||||||
|
}, [ refreshMerchantData, merchant ] );
|
||||||
|
|
||||||
|
return {
|
||||||
|
merchant, // Merchant details
|
||||||
|
verifyLoginStatus, // Callback
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// -- Not using the `useHooks()` data provider --
|
// -- Not using the `useHooks()` data provider --
|
||||||
|
|
||||||
export const useBusyState = () => {
|
export const useBusyState = () => {
|
||||||
|
|
|
@ -26,6 +26,10 @@ export const getActivityList = ( state ) => {
|
||||||
return Object.fromEntries( activities );
|
return Object.fromEntries( activities );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const merchant = ( state ) => {
|
||||||
|
return getState( state ).merchant || EMPTY_OBJ;
|
||||||
|
};
|
||||||
|
|
||||||
export const wooSettings = ( state ) => {
|
export const wooSettings = ( state ) => {
|
||||||
return getState( state ).wooSettings || EMPTY_OBJ;
|
return getState( state ).wooSettings || EMPTY_OBJ;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue