import{j as e,a6 as P,ak as E}from"./vendor-mui-core-CnXrAOs3.js";import{r as k,i as T}from"./vendor-react-Dvs43sk9.js";import{o as j}from"./vendor-arcblock-CuFtPveO.js";import{V as C,H as d,s as S}from"./vendor-ux-IiQnod3w.js";import{v as W,c as v,S as I,s as R,b as U}from"./index-sNHCLgAE.js";import{K as b}from"./landing-page-sUHYSREd.js";import{w as L}from"./wrap-locale-fIPwg8LW.js";import{g as N}from"./get-safe-url-DpalOXcM.js";import"./vendor-utils-cJEl_UEd.js";import"./vendor-hooks-CjESGRlR.js";import"./lottie-web-4koyQiv_.js";import"./index-x4Yvq15-.js";function _({SessionContext:n,webWalletUrl:r,onSuccess:o}){const{api:t,session:i}=k.useContext(n),{t:s,locale:h}=C(),f=T(),{searchParams:p}=new URL(window.location.href),l=p.get("redirect"),g=async(a,w)=>{o(a,w),await i.refresh(),d.success(s("exchangePassport.success")),setTimeout(()=>{if(l){const c=decodeURIComponent(l);c.startsWith(v.WELLKNOWN_SERVICE_PATH_PREFIX)?f(c,{replace:!0}):window.location.href=N(c)}else window.location.href=window.env.pathPrefix||window.env.apiPrefix||"/"},3e3)},u=a=>{d.error(a.message)},m={},x=p.get("componentId");return x&&(m.componentId=x),i.loading?e.jsx(j,{children:e.jsx(P,{})}):e.jsx(b,{did:window?.blocklet?.appPid||window?.env?.appPid,children:e.jsx(E,{sx:{maxWidth:"100%",height:"100%"},children:e.jsx(W,{popup:!0,open:!0,className:"connect",action:"exchange-passport",checkFn:t.get,checkTimeout:10*60*1e3,webWalletUrl:r,onSuccess:g,onError:u,locale:h,messages:{title:s("exchangePassport.dialog.title"),scan:s("exchangePassport.dialog.scan"),confirm:s("exchangePassport.dialog.confirm"),success:s("exchangePassport.dialog.success")},extraParams:m,extraContent:null,hideCloseButton:!0})})})}const B=L(_);function G(){const n=S(),r=(o,t)=>{o.sessionToken&&(R(t(o.sessionToken)),U(t(o.refreshToken)))};return e.jsx(B,{SessionContext:I,webWalletUrl:n,onSuccess:r})}export{G as default};
