Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
e.preventDefault();
e.stopPropagation();
if (isIos()) {
// eslint-disable-next-line no-alert
window.alert('Please switch tabs to reactivate the PayPal window');
} else {
focus();
}
}
const { style = {} } = props;
const content = containerContent[lang];
const onDisplay = new ZalgoPromise(resolve => {
event.on(EVENT.DISPLAY, resolve);
});
const onClose = new ZalgoPromise(resolve => {
event.on(EVENT.CLOSE, resolve);
});
const setupAnimations = (name) => {
return (el) => {
onDisplay.then(() => animate(el, `show-${ name }`, noop));
onClose.then(() => animate(el, `hide-${ name }`, noop));
};
};
let outlet;
function awaitPaymentTokenAndUrl() : { url : ZalgoPromise, paymentToken : ZalgoPromise } {
let paymentTokenAndUrl = new ZalgoPromise((resolve) => {
checkout.initXO = () => {
warn(`gettoken_initxo`);
};
// startFlow is our 'success' case - we get a token, and we can pass it back to the caller
checkout.startFlow = once((item) => {
debug(`gettoken_startflow`, { item });
let { url, paymentToken } = matchUrlAndPaymentToken(item);
checkUrlAgainstEnv(url);
return resolve({ url, paymentToken });
});
}
}
export function getElement(id : ElementRefType) : HTMLElement {
let element = getElementSafe(id);
if (element) {
return element;
}
throw new Error(`Can not find element: ${ stringify(id) }`);
}
export let documentReady = new ZalgoPromise(resolve => {
if (window.document.readyState === 'complete') {
return resolve(window.document);
}
let interval = setInterval(() => {
if (window.document.readyState === 'complete') {
clearInterval(interval);
return resolve(window.document);
}
}, 10);
});
export function isDocumentReady() : boolean {
return window.document.readyState === 'complete';
}
export function delay(time : number = 1) : ZalgoPromise {
return new ZalgoPromise(resolve => {
setTimeout(resolve, time);
});
}
return ZalgoPromise.try(() => {
this.onInit = this.onInit || new ZalgoPromise();
this.onInit.reject(err);
return this.destroy();
}).then(() => {
if (props.onError) {
return documentBodyReady.then(body => {
body.appendChild(iframe);
const bridge = iframe.contentWindow;
return new ZalgoPromise((resolve, reject) => {
iframe.addEventListener('load', resolve);
iframe.addEventListener('error', reject);
}).then(() => {
return awaitWindowHello(bridge, BRIDGE_TIMEOUT, `Bridge ${ url }`);
}).then(() => {
return bridge;
});
});
}));
export function deserializePromise(source : CrossDomainWindowType | ProxyWindow, origin : string, { then } : { then : Function }) : ZalgoPromise {
return new ZalgoPromise(then);
}
export function getHttpType(contentType, url) {
return new ZalgoPromise(function (resolve, reject) {
var req = new window.XMLHttpRequest();
req.open('GET', url);
req.setRequestHeader('Accept', contentType);
req.send(null);
req.onload = function () {
resolve(req.responseText);
};
req.onerror = function () {
return reject(new Error('prefetch failed'));
};
});
}
export function awaitFrameLoad(frame) {
if (awaitFrameLoadPromises.has(frame)) {
var _promise = awaitFrameLoadPromises.get(frame);
if (_promise) {
return _promise;
}
}
var promise = new ZalgoPromise(function (resolve, reject) {
frame.addEventListener('load', function () {
linkFrameWindow(frame);
resolve(frame);
});
frame.addEventListener('error', function (err) {
if (frame.contentWindow) {
resolve(frame);
} else {
reject(err);
}
});
});
awaitFrameLoadPromises.set(frame, promise);