@privy-io/cross-app-connect
Version:
Privy cross app wallet connectors for wagmi and RainbowKit
2 lines (1 loc) • 1.37 kB
JavaScript
function e({w:e,h:t}){let n=void 0!==window.screenLeft?window.screenLeft:window.screenX,o=void 0!==window.screenTop?window.screenTop:window.screenY,i=window.innerWidth?window.innerWidth:document.documentElement.clientWidth?document.documentElement.clientWidth:screen.width,r=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:screen.height;return`toolbar=0,location=0,menubar=0,height=${t},width=${e},popup=1,left=${(i-e)/2/(i/window.screen.availWidth)+n},top=${(r-t)/2/(r/window.screen.availHeight)+o}`}exports.getPopupOptions=e,exports.triggerPopup=async function(t){let n=window.open(void 0,void 0,e({w:440,h:680}));if(!n)throw Error("");return n.location=t.href,new Promise(((e,t)=>{let o,i=setTimeout((()=>{t(Error("Authorization request timed out after 2 minutes.")),r()}),12e4);function r(){n?.close(),window.removeEventListener("message",c)}let d=setInterval((()=>{n?.closed&&!o&&(r(),clearInterval(d),clearTimeout(i),t(Error("User rejected request")))}),300);function c(d){d.data&&("PRIVY_CROSS_APP_CONNECT_RESPONSE"===d.data.type&&(e(d.data),n?.close()),"PRIVY_OAUTH_ERROR"===d.data.type&&(clearTimeout(i),t(Error(d.data.error)),r()),"PRIVY_OAUTH_USE_BROADCAST_CHANNEL"===d.data.type&&((o=new BroadcastChannel("popup-privy-oauth")).onmessage=c))}window.addEventListener("message",c)}))};
;