import{j as e,a7 as P,al as E}from"./vendor-mui-core-D7t4vMS5.js";import{r as T,u as j}from"./vendor-react-DX7tU9aY.js";import{o as k}from"./vendor-arcblock-ivFYo5vP.js";import{W,Q as d,b2 as C}from"./vendor-ux-Dl3wVbv_.js";import{w as I,c as R,l as S,b,e as v}from"./index-Ca33rdd_.js";import{K as U}from"./landing-page-BJAji-kI.js";import{w as L}from"./wrap-locale-BJF_SaOe.js";import{g as N}from"./get-safe-url-D4zRnTpF.js";import"./vendor-hooks-DAZ1H6Va.js";import"./vendor-utils-BzQg432x.js";import"./use-blocklet-logo-BWPJOOVd.js";import"./index-BoJbHOhC.js";function _({SessionContext:n,webWalletUrl:a,onSuccess:o}){const{api:t,session:i}=T.useContext(n),{t:s,locale:h}=W(),f=j(),{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=N(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(k,{children:e.jsx(P,{})}):e.jsx(U,{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:600*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=L(_);function z(){const n=C(),a=(o,t)=>{o.sessionToken&&(b(t(o.sessionToken)),v(t(o.refreshToken)))};return e.jsx(B,{SessionContext:S,webWalletUrl:n,onSuccess:a})}export{z as default};
