@particle-network/authkit
Version:
Auth Core provides MPC (Multi-Party Computation)-based threshold signatures.
178 lines (177 loc) • 9.55 kB
JavaScript
"use client";
import{a as O}from"./chunk-SAJER5IB.mjs";import{a as j}from"./chunk-75ZH6NQL.mjs";import"./chunk-OZGUXGJL.mjs";import{b as k}from"./chunk-IOEQ3TXF.mjs";import{a as F}from"./chunk-OVV6E33Q.mjs";import{F as z,I as V,P as q,Q as U,pa as D,qa as G,ra as H,sa as $,va as J}from"./chunk-6YEBFRI3.mjs";import"./chunk-2FKLQE76.mjs";import{ApiError as g,AuthType as m,bindLoginAccount as xe,getBindSecurityAccounCaptcha as be,getCloudflareTurnstileResponse as Ce,getSecurityAccountCaptcha as _e,getSecurityAccountToken as we,setPaymentPassword as Ae,syncUserInfo as Q,thirdpartyAuth as Te}from"@particle-network/auth-core";import{useInterval as ke,useRequest as h}from"ahooks";import{Button as R,Modal as Le}from"antd";import Be from"base64url";import Ne from"lodash/throttle.js";import o,{useCallback as Se,useEffect as W,useMemo as Ee,useRef as Me,useState as v}from"react";var K=`.set-viery-container {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
overflow: auto;
color: var(--text-color);
}
.set-viery-container .footer-box {
position: absolute;
bottom: 10px;
margin: 0;
}
@media only screen and (max-height: 520px) {
.set-viery-container .footer-box {
position: unset;
bottom: 0;
margin-top: 20px;
margin-bottom: 10px;
}
}
.set-viery-container .display-none {
display: none;
}
.set-viery-container .error-tip {
width: 90%;
height: 0;
padding-left: 10px;
margin-top: 6px;
margin-bottom: 0;
text-align: left;
color: red;
opacity: 0;
transition: all 0.3s;
}
.set-viery-container .error-tip.show {
height: 30px;
opacity: 1;
}
.set-viery-container .set-email-title {
margin-top: 60px;
font-size: 22px;
color: var(--text-color);
}
.set-viery-container .patment-tips1 {
width: 80vw;
margin-top: 30px;
font-size: 14px;
text-align: center;
color: var(--text-color);
}
@media (min-width: 600px) {
.set-viery-container .patment-tips1 {
width: calc(80 * var(--vw));
}
}
.set-viery-container .set-email-buttons {
position: absolute;
bottom: 0;
left: 0;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
width: 100%;
height: auto;
padding-bottom: 20px;
}
.set-viery-container .success-icon {
width: 50px;
height: 50px;
margin-top: 60px;
}
.set-viery-container .set-email-desc-1 {
box-sizing: border-box;
padding: 0 18px;
margin: 15px 0 25px;
font-weight: 400;
font-size: 14px;
line-height: 16px;
text-align: center;
color: var(--text-color);
}
.set-viery-container .account-submit-btn {
width: 90%;
height: 47px;
padding: 0;
margin-top: 38px;
border: none;
border-radius: var(--primary-btn-border-radius);
font-weight: 500;
font-size: var(--primary-btn-font-size);
line-height: 47px;
text-align: center;
color: var(--primary-btn-color);
background: var(--primary-btn-background-color);
opacity: 1;
}
.set-viery-container .account-submit-btn:hover {
border: none;
color: var(--primary-btn-color) !important;
background: var(--primary-btn-background-color) !important;
opacity: var(--hover-opacity);
}
.set-viery-container .account-switch-item {
margin-top: 40px;
font-weight: 500;
font-size: 13px;
line-height: 19px;
color: var(--accent-color);
cursor: pointer;
}
.set-viery-container .set-email-desc-2 {
min-width: 116px;
height: 23px;
padding: 0 15px;
margin: 20px 0 28px;
border-radius: var(--primary-btn-border-radius);
font-weight: 400;
font-size: 12px;
line-height: 23px;
text-align: center;
color: var(--secondary-text-color);
background: var(--tag-background-color);
opacity: 1;
}
.set-viery-container .back {
display: flex;
align-items: center;
margin-top: 90px;
font-weight: 400;
font-size: 16px;
line-height: 19px;
color: var(--accent-color);
opacity: 1;
cursor: pointer;
gap: 8px;
}
.set-viery-container .back svg {
position: relative;
top: -1px;
color: var(--accent-color);
}
.set-viery-container .code-error {
position: absolute;
left: calc((100vw - 316px) / 2);
margin-top: 224px;
font-weight: 400;
font-size: 12px;
color: var(--error-color);
}
@media (min-width: 600px) {
.set-viery-container .code-error {
left: calc((var(--vw) * 100 - 316px) / 2);
}
}
.set-viery-container .send-again {
margin-top: 20px;
border: none !important;
outline: none !important;
font-weight: 400;
font-size: 16px;
line-height: 19px;
color: var(--text-color);
background-color: transparent;
box-shadow: none;
}
.set-viery-container .send-again:hover {
color: var(--text-color) !important;
background-color: transparent !important;
}
.set-viery-container .send-again:disabled {
opacity: 0.5;
}
`;var Pe=X=>{let c=$(),{t:n}=J(),Y=X,x=z(),{customRouter:Z}=H(),{themeType:ee,language:te}=V(),{account:a,pageType:d,authType:s,verifyToken:ne,redirectUrl:oe,password:ie}=Y,[b,re]=v(""),[L,C]=v(1e3),[y,_]=v(60),[w,l]=v(),{authCoreModal:B}=G(),{userInfo:ae}=D(),[se,N]=v(!1),S=Me(null);ke(()=>{if(y>0){let e=y-1;_(e),e===0&&C(void 0)}},L);let{run:E}=h(async e=>d==="bind_login_account"?(e={[s]:a,cf_turnstile_response:e.cf_turnstile_response},be(e).then(t=>t)):_e(e.verifyCodeMethod),{manual:!0,onSuccess:(e,t)=>{L||(_(60),C(1e3))},onError:e=>{_(0),C(void 0)}}),{runAsync:M}=h(we,{manual:!0,onBefore:()=>{N(!0)},onError:e=>{(e==null?void 0:e.error_code)===g.InvalidCode?l(n("login.invalid_code")):(e==null?void 0:e.error_code)===g.ResendCode?l(n("login.please_send_again")):e.message&&x.error(e.message)},onFinally:()=>{setTimeout(()=>{N(!1)},2e3)}}),{loading:ce,runAsync:le}=h(async e=>xe(e).then(async()=>{await Q()}),{manual:!0,onSuccess:e=>{x.success(n("new.bind_login_account_success"))},onError:e=>{var i;let t=e.message;if((e==null?void 0:e.error_code)===g.InvalidCode){l(n("login.invalid_code"));return}else if((e==null?void 0:e.error_code)===g.ResendCode){l(n("login.please_send_again"));return}else e.error_code===20109?t=s==m.email?n("error.server_email_20109"):n("error.server_phone_20109"):t=((i=e==null?void 0:e.extra)==null?void 0:i[0])||e.message;Le.error({title:t,wrapClassName:"auth-core-modal-error",getContainer:()=>B.rootBody,onOk:()=>{var r;(r=S.current)==null||r.clear(),e.error_code===20109&&c(-1)}})}}),{loading:de,run:ue}=h(Ae,{manual:!0,onError:e=>{(e==null?void 0:e.error_code)===g.InvalidCode?l(n("login.invalid_code")):(e==null?void 0:e.error_code)===g.ResendCode&&l(n("login.please_send_again"))},onSuccess:(e,t)=>{Q();let i=["account/security","solana/sign","evm-chain/sign"],r=i.map(T=>{var u;return(u=Z.history)==null?void 0:u.findIndex(p=>p.path===T)}),A=r.indexOf(Math.max(...r));c(i[A],{replace:!0,back:!0})}}),{loading:pe,run:Ie}=h(()=>new Promise((e,t)=>{}),{manual:!0,onSuccess:e=>{}}),f=Ee(()=>a!=null&&a.includes("@")?m.email:m.phone,[a]);W(()=>{P()},[a]);let P=()=>{l(""),d==="bind_login_account"&&s===m.phone?Ce({theme:ee,language:te,getContainer:()=>B.rootBody}).then(e=>{E({verify_code_method:f,cf_turnstile_response:e})}).catch(()=>{x.error(n("error.server_20112")),c(-1)}):E({verifyCodeMethod:f})},ge=e=>{l(""),re(e),e.length===6&&me(e)},me=Se(Ne(e=>{I(e)},1e3,{leading:!0,trailing:!1}),[]),ye=e=>{ue({password:ie,verifyCodeMethod:f,code:e||b})},I=(e="")=>{if(w)return;let t={code:e};d==="reset_payment_password"?ye(e):d=="verify_security_account_set_security_account"?M({verifyCodeMethod:f,code:e}).then(i=>{c("/account/bind",{replace:!0,state:{accountType:s,verifyToken:i,redirectUrl:oe}})}):d==="verify_security_account_bind_login_account"?M({verifyCodeMethod:f,code:e}).then(i=>{let r=j({userInfo:ae,t:n}),{id:A,value:T}=r.find(u=>u.type===s)||{};if(s===m.phone||s===m.email||T||A)c("/login-account/bind",{state:{authType:s,verifyToken:i},replace:!0});else{let u=Be.encode(JSON.stringify({verifyToken:i,purpose:"bindLoginAccount"}));Te({authType:s,appState:u,prompt:"select_account"}).catch(p=>{x.error((p==null?void 0:p.message)||p)})}}):d==="bind_login_account"?(t={...t,security_account_verify_token:ne,[s]:a},le(t).then(i=>{c(-2)})):"unbind_login_account"},fe=()=>a.includes("@")?q(a):U(a);W(()=>{var i;let e=document.getElementsByClassName("react-input-code"),t=r=>r.preventDefault();return(i=e[0])==null||i.addEventListener("contextmenu",t),()=>{var r;(r=e[0])==null||r.removeEventListener("contextmenu",t)}},[]);let he=()=>{var t;(t=document.getElementsByClassName("input-code-item")[Math.min(b.length,5)])==null||t.focus()};return o.createElement("div",{className:"set-viery-container"},o.createElement("style",null,K),o.createElement("div",{className:"account-header"},o.createElement(k,{className:"icon-navigation-back",name:"circle_back",onClick:()=>{c(-1)}})),o.createElement("h2",{className:"set-email-title"},n("account.enter_code")),o.createElement("p",{className:"set-email-desc-2"},fe()),o.createElement("div",{onClick:he},o.createElement(O,{containerClassName:"react-input-code",inputClassName:"input-code-item",allowedCharacters:"numeric",length:6,ref:S,placeholder:" ",onChange:ge})),w&&o.createElement("div",{className:"code-error"},w),o.createElement(R,{className:"account-submit-btn",loading:de||se||ce||pe,onClick:()=>{setTimeout(()=>{I(b)})},disabled:b.length!==6},n("common.confirm")),o.createElement(R,{className:"send-again",onClick:P,disabled:y>0},y>0?`${n("login.send_again")} (${y}s)`:n("login.send_again")),o.createElement("div",{className:"back",onClick:()=>{c(-1)}},o.createElement(k,{className:"arrow1-icon",name:"arrow1_icon"}),o.createElement("span",null,n("login.back"))),o.createElement(F,null))},Xe=Pe;export{Xe as default};