@particle-network/authkit
Version:
Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.
79 lines (78 loc) • 4.61 kB
JavaScript
"use client";
import{a as T}from"./chunk-37ISZE7G.mjs";import{c as A}from"./chunk-DLTLN62L.mjs";import{a as P}from"./chunk-PPJQVDG4.mjs";import{G as b,H as L,J as N,O as C,h as d,qa as p,ta as E,wa as O}from"./chunk-WAC3ZEJ3.mjs";import"./chunk-2FKLQE76.mjs";import{isConnected as y,isSocialAuthType as Y}from"@particle-network/auth-core";import Z from"antd/es/message";import z from"base64url";import $ from"qs";import g,{useEffect as R,useState as I}from"react";import o from"react";var _=`.social-loading-content {
text-align: center;
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
padding: 0;
padding-bottom: 40px;
}
.social-loading-content .wrap {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.social-loading-content .wrap .social-logo-content {
width: 105px;
height: 105px;
border-radius: 100%;
position: relative;
}
.social-loading-content .wrap .social-logo-content.failed {
cursor: pointer;
}
.social-loading-content .wrap .social-logo-content .logo {
width: 100%;
height: 100%;
}
.social-loading-content .wrap .social-logo-content .logo img {
width: 100%;
height: auto;
}
.social-loading-content .wrap .social-logo-content .spin {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
animation: social-loading-spin 1.4s linear infinite;
}
.social-loading-content .wrap .social-logo-content .spin img {
width: 100%;
height: 100%;
}
.social-loading-content .wrap .social-logo-content .refresh-btn {
font-size: 19px;
position: absolute;
bottom: 10px;
right: 27px;
}
.social-loading-content .wrap .title {
margin-top: 10px;
margin-bottom: 10px;
}
.social-loading-content .wrap .desc {
width: 70%;
line-height: 1.2;
color: var(--secondary-text-color);
}
@keyframes social-loading-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
`;var W=({authType:a,isFailed:e=!0})=>{let{t:n}=O(),[i,m]=o.useState(!e),{socialAuthLogin:f}=N(),{modalOptions:s}=p();return o.createElement("div",{className:"social-loading-content"},o.createElement("style",null,d(_)),o.createElement("div",{className:"wrap"},o.createElement("div",{className:`social-logo-content ${e?"failed":""}`,onClick:()=>{!e||i||(m(!0),f({socialType:a}))}},o.createElement("div",{className:"logo"},o.createElement("img",{src:L(s.themeType)[a]||"",alt:"logo"})),i&&o.createElement("div",{className:"spin"},o.createElement("img",{src:T,alt:"loading"})),e&&!i&&o.createElement("div",{className:"refresh-btn"},o.createElement(A,{className:"refresh-icon",name:"refresh_icon"}))),o.createElement("div",{className:"title"},n(e?"login.request_failed":"login.logging_you_in")),e&&o.createElement("div",{className:"desc"},n("login.something_wrong"))),o.createElement(P,{className:"footer-box-v2"}))},j=W;var k=`.index-container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: var(--text-color);
}
`;var oo=()=>{let{connect:a}=C(),e=E(),{setConnectionStatus:n,socialConnectCallback:i,setAuthCoreModal:m}=p(),[f,s]=g.useState(!1),[J,M]=I(""),[V,q]=I(!1),G=l=>{var t,r;(t=window.particle)!=null&&t.ethereum&&(window.particle.ethereum.isSocialConnecting=!1),(r=window.particle)!=null&&r.solana&&(window.particle.solana.isSocialConnecting=!1),window.dispatchEvent(new CustomEvent("particle:socialConnectCompleted",{detail:l}))},Q=async()=>{var l;try{let t=$.parse(b()?"":window.location.search,{ignoreQueryPrefix:!0}),r=t==null?void 0:t.particleThirdpartyParams;if(!r){y()||n("disconnected");return}delete t.particleThirdpartyParams;let v=(window.location.origin+window.location.pathname+"?"+$.stringify(t)).replace(/\?$/,"");window.history.replaceState({},document.title,v),document.title=document.title||v;let U=JSON.parse(z.decode(r)),{code:x,nonce:u,appState:S,error:h}=U,B=S?JSON.parse(z.decode(S)):{},{authorization:D,chain:F,purpose:w,verifyToken:H}=B;if(h){y()||n("disconnected"),w?Z.error(h):(l=i==null?void 0:i.onError)==null||l.call(i,new Error(h)),w!=="bindLoginAccount"&&q(!0);return}let c=u.split("@")[0];M(c),w==="bindLoginAccount"?e("/login-account/bind-loading",{state:{authType:c,verifyToken:H,code:x,nonce:u},replace:!0}):(Y(c)&&(s(!0),m({particleModalVisible:!0})),await a({socialType:c,code:x,nonce:u,authorization:D,chain:F}))}catch(t){y()||n("disconnected"),G({result:Object.freeze(t)})}s(!1)};return R(()=>{Q()},[]),g.createElement("div",{className:"index-container"},g.createElement("style",null,d(k)),f&&g.createElement(j,{authType:J,isFailed:V}))},No=oo;export{No as default};