mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
✨ Add merchant details to “common” hydration path
This commit is contained in:
parent
0462905123
commit
c97464d7e2
4 changed files with 60 additions and 9 deletions
|
@ -8,7 +8,7 @@
|
|||
export const STORE_NAME = 'wc/paypal/common';
|
||||
|
||||
/**
|
||||
* REST path to hydrate data of this module by loading data from the WP DB..
|
||||
* REST path to hydrate data of this module by loading data from the WP DB.
|
||||
*
|
||||
* Used by resolvers.
|
||||
*
|
||||
|
|
|
@ -17,6 +17,13 @@ const defaultTransient = {
|
|||
activities: new Map(),
|
||||
|
||||
// Read only values, provided by the server via hydrate.
|
||||
merchant: {
|
||||
isConnected: false,
|
||||
isSandbox: false,
|
||||
id: '',
|
||||
email: '',
|
||||
},
|
||||
|
||||
wooSettings: {
|
||||
storeCountry: '',
|
||||
storeCurrency: '',
|
||||
|
@ -75,12 +82,17 @@ const commonReducer = createReducer( defaultTransient, defaultPersistent, {
|
|||
[ ACTION_TYPES.HYDRATE ]: ( state, payload ) => {
|
||||
const newState = setPersistent( state, payload.data );
|
||||
|
||||
if ( payload.wooSettings ) {
|
||||
newState.wooSettings = {
|
||||
...newState.wooSettings,
|
||||
...payload.wooSettings,
|
||||
};
|
||||
}
|
||||
// Populate read-only properties.
|
||||
[ 'wooSettings', 'merchant' ].forEach( ( key ) => {
|
||||
if ( ! payload[ key ] ) {
|
||||
return;
|
||||
}
|
||||
|
||||
newState[ key ] = Object.freeze( {
|
||||
...newState[ key ],
|
||||
...payload[ key ],
|
||||
} );
|
||||
} );
|
||||
|
||||
return newState;
|
||||
},
|
||||
|
|
|
@ -16,7 +16,8 @@ export const persistentData = ( state ) => {
|
|||
};
|
||||
|
||||
export const transientData = ( state ) => {
|
||||
const { data, wooSettings, ...transientState } = getState( state );
|
||||
const { data, merchant, wooSettings, ...transientState } =
|
||||
getState( state );
|
||||
return transientState || EMPTY_OBJ;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue