Skip to content

Commit

Permalink
adds browser new prop event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
danzhaaspaypal committed Dec 10, 2024
1 parent 713635e commit ecf1a92
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/modal/v2/lib/zoid-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ const IOS_INTERFACE_NAME = 'paypalMessageModalCallbackHandler';
const ANDROID_INTERFACE_NAME = 'paypalMessageModalCallbackHandler';

const setupBrowser = props => {
const propListeners = new Set();

window.addEventListener(
'message',
newProps => {
if (newProps && typeof newProps === 'object') {
Array.from(propListeners.values()).forEach(listener => {
listener({ ...window.xprops, ...newProps });
});
Object.assign(window.xprops, newProps);
}
},
false
);

window.xprops = {
// We will never recieve new props via this integration style
onProps: () => {},
onProps: listener => propListeners.add(listener),
// TODO: Verify these callbacks are instrumented correctly
onReady: ({ products, meta }) => {
const { clientId, payerId, merchantId, offer, partnerAttributionId } = props;
Expand Down

0 comments on commit ecf1a92

Please sign in to comment.