import{j as e,a6 as P,ak as E}from"./vendor-mui-core-DnR6WYuU.js";import{r as j,u as k}from"./vendor-react-CTtPmzVP.js";import{o as T}from"./vendor-arcblock-CPCSE54a.js";import{V as C,H as d,ar as W}from"./vendor-ux-DfSgTRg5.js";import{l as I,c as R,j as S,a as v,d as U}from"./index-BHa1_Bjz.js";import{K as L}from"./landing-page-Cv6belCa.js";import{w as N}from"./wrap-locale-DtcRIeKF.js";import{g as b}from"./get-safe-url-CqAaHb9L.js";import"./vendor-utils-drLlzTVq.js";import"./vendor-hooks-cYMUGE4V.js";import"./lottie-web-4koyQiv_.js";import"./index-BNeXCm1B.js";function _({SessionContext:n,webWalletUrl:a,onSuccess:o}){const{api:t,session:i}=j.useContext(n),{t:s,locale:h}=C(),f=k(),{searchParams:p}=new URL(window.location.href),l=p.get("redirect"),g=async(r,w)=>{o(r,w),await i.refresh(),d.success(s("exchangePassport.success")),setTimeout(()=>{if(l){const c=decodeURIComponent(l);c.startsWith(R.WELLKNOWN_SERVICE_PATH_PREFIX)?f(c,{replace:!0}):window.location.href=b(c)}else window.location.href=window.env.pathPrefix||window.env.apiPrefix||"/"},3e3)},u=r=>{d.error(r.message)},m={},x=p.get("componentId");return x&&(m.componentId=x),i.loading?e.jsx(T,{children:e.jsx(P,{})}):e.jsx(L,{did:window?.blocklet?.appPid||window?.env?.appPid,children:e.jsx(E,{sx:{maxWidth:"100%",height:"100%"},children:e.jsx(I,{popup:!0,open:!0,className:"connect",action:"exchange-passport",checkFn:t.get,checkTimeout:10*60*1e3,webWalletUrl:a,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=N(_);function G(){const n=W(),a=(o,t)=>{o.sessionToken&&(v(t(o.sessionToken)),U(t(o.refreshToken)))};return e.jsx(B,{SessionContext:S,webWalletUrl:n,onSuccess:a})}export{G as default};
