UNPKG

@particle-network/authkit

Version:

Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.

79 lines (78 loc) 4.63 kB
"use client"; import{a as L}from"./chunk-37ISZE7G.mjs";import{a as C}from"./chunk-BM7ICTT2.mjs";import{a as O}from"./chunk-ZTTU2K7E.mjs";import"./chunk-GYYKKPHD.mjs";import"./chunk-3RRPQ2DX.mjs";import{N,Q as A,U as P,X as E,h as d,l as p,o as T,r as b}from"./chunk-H6TXMQRA.mjs";import"./chunk-C7OWFSST.mjs";import{isConnected as w,isSocialAuthType as X}from"@particle-network/auth-core";import z from"base64url";import g,{useEffect as Y,useState as U}from"react";import o from"react";var j=`.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 Q=({authType:a,isFailed:i=!0})=>{let{t:n}=b(),[e,m]=o.useState(!i),{socialAuthLogin:f}=P(),{modalOptions:s}=p();return o.createElement("div",{className:"social-loading-content"},o.createElement("style",null,d(j)),o.createElement("div",{className:"wrap"},o.createElement("div",{className:`social-logo-content ${i?"failed":""}`,onClick:()=>{!i||e||(m(!0),f({socialType:a}))}},o.createElement("div",{className:"logo"},o.createElement("img",{src:N(s.themeType)[a]||"",alt:"logo"})),e&&o.createElement("div",{className:"spin"},o.createElement("img",{src:L,alt:"loading"})),i&&!e&&o.createElement("div",{className:"refresh-btn"},o.createElement(C,{className:"refresh-icon",name:"refresh_icon"}))),o.createElement("div",{className:"title"},n(i?"login.request_failed":"login.logging_you_in")),i&&o.createElement("div",{className:"desc"},n("login.something_wrong"))),o.createElement(O,{className:"footer-box-v2"}))},_=Q;var k=`.index-container { display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; color: var(--text-color); } `;var Z=()=>{let{connect:a}=E(),i=T(),{setConnectionStatus:n,socialConnectCallback:e,setAuthCoreModal:m}=p(),[f,s]=g.useState(!1),[$,I]=U(""),[J,M]=U(!1),V=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}))},G=async()=>{var l;try{let t=Object.fromEntries(new URLSearchParams(A()?"":window.location.search)),r=t==null?void 0:t.particleThirdpartyParams;if(!r){w()||n("disconnected");return}delete t.particleThirdpartyParams;let y=(window.location.origin+window.location.pathname+"?"+new URLSearchParams(t).toString()).replace(/\?$/,"");window.history.replaceState({},document.title,y),document.title=document.title||y;let q=JSON.parse(z.decode(r)),{code:v,nonce:u,appState:S,error:x}=q,B=S?JSON.parse(z.decode(S)):{},{authorization:D,chain:F,purpose:h,verifyToken:H}=B;if(x){w()||n("disconnected"),h||(l=e==null?void 0:e.onError)==null||l.call(e,new Error(x)),h!=="bindLoginAccount"&&M(!0);return}let c=u.split("@")[0];I(c),h==="bindLoginAccount"?i("/login-account/bind-loading",{state:{authType:c,verifyToken:H,code:v,nonce:u},replace:!0}):(X(c)&&(s(!0),m({particleModalVisible:!0})),await a({socialType:c,code:v,nonce:u,authorization:D,chain:F}))}catch(t){w()||n("disconnected"),V({result:Object.freeze(t)})}s(!1)};return Y(()=>{G()},[]),g.createElement("div",{className:"index-container"},g.createElement("style",null,d(k)),f&&g.createElement(_,{authType:$,isFailed:J}))},xo=Z;export{xo as default};