Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add ignoreCache option to modal #583

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Message = function({ markup, meta, parentStyles, warnings }) {
amount: window.xprops.amount ?? null,
currency: window.xprops.currency ?? null,
buyerCountry: window.xprops.buyerCountry ?? null,
ignoreCache: window.xprops.ignoreCache ?? null,
style: JSON.stringify(window.xprops.style),
offer: window.xprops.offer ?? null,
payerId: window.xprops.payerId ?? null,
Expand Down Expand Up @@ -77,6 +78,7 @@ const Message = function({ markup, meta, parentStyles, warnings }) {
amount,
currency,
buyerCountry,
ignoreCache,
offer,
payerId,
clientId,
Expand All @@ -92,6 +94,7 @@ const Message = function({ markup, meta, parentStyles, warnings }) {
amount,
currency,
buyerCountry,
ignoreCache,
style: JSON.stringify(style),
offer,
payerId,
Expand All @@ -104,6 +107,7 @@ const Message = function({ markup, meta, parentStyles, warnings }) {
amount,
currency,
buyer_country: buyerCountry,
ignore_cache: ignoreCache,
style,
credit_type: offer,
payer_id: payerId,
Expand Down
16 changes: 14 additions & 2 deletions src/components/modal/lib/hooks/calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ const localize = (country, amount) => {
export default function useCalculator({ autoSubmit = false } = {}) {
const calculateRef = useRef();
const { terms: initialTerms, country, setServerData } = useServerData();
const { currency, payerId, clientId, merchantId, onCalculate, buyerCountry, amount } = useXProps();
const {
currency,
payerId,
clientId,
merchantId,
onCalculate,
buyerCountry,
ignoreCache,
amount,
stageTag
} = useXProps();
const [state, dispatch] = useReducer(reducer, {
inputValue: localize(country, initialTerms.amount),
prevValue: localize(country, initialTerms.amount),
Expand All @@ -77,7 +87,9 @@ export default function useCalculator({ autoSubmit = false } = {}) {
payerId,
clientId,
merchantId,
buyerCountry
buyerCountry,
ignoreCache,
stageTag
})
.then(data => {
setServerData(data);
Expand Down
50 changes: 27 additions & 23 deletions src/components/modal/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import objectEntries from 'core-js-pure/stable/object/entries';
import { request, memoize, ppDebug } from '../../../utils';

export const getContent = memoize(({ currency, amount, payerId, clientId, merchantId, buyerCountry, version, env }) => {
const query = objectEntries({
currency,
amount,
payer_id: payerId,
client_id: clientId,
merchant_id: merchantId,
buyer_country: buyerCountry,
version,
env
})
.filter(([, val]) => Boolean(val))
.reduce(
(acc, [key, val]) =>
`${acc}&${key}=${encodeURIComponent(typeof val === 'object' ? JSON.stringify(val) : val)}`,
''
)
.slice(1);
export const getContent = memoize(
({ currency, amount, payerId, clientId, merchantId, buyerCountry, ignoreCache, version, env, stageTag }) => {
const query = objectEntries({
currency,
amount,
payer_id: payerId,
client_id: clientId,
merchant_id: merchantId,
buyer_country: buyerCountry,
ignore_cache: ignoreCache,
version,
env,
stageTag
})
.filter(([, val]) => Boolean(val))
.reduce(
(acc, [key, val]) =>
`${acc}&${key}=${encodeURIComponent(typeof val === 'object' ? JSON.stringify(val) : val)}`,
''
)
.slice(1);

ppDebug('Updating modal with new props...', { inZoid: true });
ppDebug('Updating modal with new props...', { inZoid: true });

return request('GET', `${window.location.origin}/credit-presentment/modalContent?${query}`).then(
({ data }) => data
);
});
return request('GET', `${window.location.origin}/credit-presentment/modalContent?${query}`).then(
({ data }) => data
);
}
);
18 changes: 16 additions & 2 deletions src/components/modal/parts/Container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import Overlay from './Overlay';

const Container = ({ children, contentWrapper, contentMaxWidth, contentMaxHeight }) => {
const { type, products, meta, setServerData } = useServerData();
const { onReady, currency, amount, payerId, clientId, merchantId, buyerCountry, version, env } = useXProps();
const {
onReady,
currency,
amount,
payerId,
clientId,
merchantId,
buyerCountry,
ignoreCache,
version,
env,
stageTag
} = useXProps();
const [transitionState] = useTransitionState();
const [loading, setLoading] = useState(false);

Expand Down Expand Up @@ -42,8 +54,10 @@ const Container = ({ children, contentWrapper, contentMaxWidth, contentMaxHeight
clientId,
merchantId,
buyerCountry,
ignoreCache,
version,
env
env,
stageTag
}).then(data => {
setServerData(data);
setLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/message/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export default (options = {}) => ({
merchantId,
currency,
amount,
buyerCountry
buyerCountry,
ignoreCache
};
const modalProps = {
...commonProps,
Expand All @@ -103,7 +104,6 @@ export default (options = {}) => ({
style,
offer,
onClick,
ignoreCache,
onReady: (...args) => {
if (typeof onRender === 'function') {
onRender(...args);
Expand Down
15 changes: 14 additions & 1 deletion src/controllers/modal/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ import {
import { getModalComponent } from '../../zoid/modal';

const memoizedModal = memoizeOnProps(
({ account, merchantId, currency, amount, buyerCountry, offer, onReady, onCalculate, onApply, onClose }) => {
({
account,
merchantId,
currency,
amount,
buyerCountry,
ignoreCache,
offer,
onReady,
onCalculate,
onApply,
onClose
}) => {
addPerformanceMeasure('firstModalRenderDelay');

const { render, hide, updateProps, state, event } = getModalComponent()({
Expand All @@ -26,6 +38,7 @@ const memoizedModal = memoizeOnProps(
currency,
amount,
buyerCountry,
ignoreCache,
offer,
onReady,
onCalculate,
Expand Down
6 changes: 6 additions & 0 deletions src/zoid/modal/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export default createGlobalVariableGetter('__paypal_credit_modal__', () =>
queryParam: false,
required: false
},
ignoreCache: {
type: 'boolean',
queryParam: 'ignore_cache',
required: false,
value: validate.ignoreCache
},

// Callbacks
onClick: {
Expand Down