UNPKG

@particle-network/authkit

Version:

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

294 lines (293 loc) 14.7 kB
"use client"; import{a as X,b as Y}from"./chunk-UD6Q2AOH.mjs";import{a as Q}from"./chunk-Z4EUAXHR.mjs";import{b as _}from"./chunk-GKIRU5P2.mjs";import{a as U}from"./chunk-CHA6AH7V.mjs";import{F as L,I as M,qa as $,sa as q,u as W,va as D,w as J}from"./chunk-45SUOK7A.mjs";import"./chunk-2FKLQE76.mjs";import{DownOutlined as be}from"@ant-design/icons";import{getBindSecurityAccounCaptcha as he,getCloudflareTurnstileResponse as xe}from"@particle-network/auth-core";import{useRequest as ye}from"ahooks";import{Button as ve}from"antd";import ne from"country-flag-icons/unicode";import n,{useEffect as V,useRef as oe,useState as x}from"react";import{ApiError as Z,bindSecurityAccount as ae,getBindSecurityAccounCaptcha as re,getCloudflareTurnstileResponse as ce,syncUserInfo as se}from"@particle-network/auth-core";import{useInterval as le,useRequest as R}from"ahooks";import{Button as ee}from"antd";import ue from"lodash/throttle.js";import pe from"qs";import a,{useCallback as me,useEffect as de,useRef as ge,useState as N}from"react";var F=`.set-email-container { position: relative; display: flex; flex-direction: column; align-items: center; height: 100%; overflow: auto; color: var(--text-color); } .set-email-container .footer-box { position: absolute; bottom: 10px; margin: 0; } @media (max-height: 500px) { .set-email-container .footer-box { display: none; } } .set-email-container .display-none { display: none; } .set-email-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-email-container .error-tip.show { height: 30px; opacity: 1; } .set-email-container .set-email-title { margin-top: 60px; font-size: 22px; color: var(--text-color); } .set-email-container .patment-tips1 { width: 80vw; margin-top: 30px; font-size: 14px; text-align: center; color: var(--text-color); } @media (min-width: 600px) { .set-email-container .patment-tips1 { width: calc(80 * var(--vw)); } } .set-email-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-email-container .success-icon { width: 50px; height: 50px; margin-top: 60px; } .set-email-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-email-container .account-input-box { position: relative; z-index: 3; width: 90%; height: 47px; margin-top: 28px; border-radius: var(--primary-btn-border-radius); line-height: 47px; color: var(--text-color); background-color: var(--input-background-color); opacity: 1; } .set-email-container .account-input-box .account-select-country { position: absolute; z-index: 2; top: 54px; left: 2%; width: 96%; height: 210px; border-radius: var(--card-border-radius) !important; overflow-y: auto; background-color: var(--input-background-color); } .set-email-container .account-input-box .account-select-country::-webkit-scrollbar { display: none; width: 0; } .set-email-container .account-input-box .account-select-country .account-select-country-item { display: flex; justify-content: space-between; align-items: center; box-sizing: border-box; width: 100%; height: 47px; padding: 5px 0 5px 13px; margin: 0; border-bottom: 1px solid var(--card-unclickable-background-color); font-size: 14px; color: var(--text-color); cursor: pointer; } .set-email-container .account-input-box .account-select-country .account-select-country-item:hover { background-color: var(--card-unclickable-background-color); } .set-email-container .account-input-box .account-select-country .account-select-country-item div { display: flex; margin-right: 13px; } .set-email-container .account-input-box .account-select-country .account-select-country-item div .country-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .set-email-container .account-input-box input[type='number']::-webkit-inner-spin-button, .set-email-container .account-input-box input[type='number']::-webkit-outer-spin-button { appearance: none; margin: 0; } .set-email-container .account-input-box.phone { display: flex; align-items: center; border: 1px solid var(--input-background-color); border-radius: var(--primary-btn-border-radius); } .set-email-container .account-input-box.phone[data-focus='true'] { border: 1px solid var(--accent-color) !important; } .set-email-container .account-input-box.phone input { border: none !important; } .set-email-container .account-input-box.phone input:focus { border: none !important; } .set-email-container .account-input-box .account-select-opt { display: flex; flex-shrink: 0; justify-content: center; align-items: center; width: 60px; height: 100%; padding-left: 8px; cursor: pointer; } .set-email-container .account-input-box .account-select-opt .account-select-icon { display: flex; justify-content: center; align-items: center; overflow: hidden; font-size: 15px; } .set-email-container .account-input-box .account-select-opt .down-more { margin-left: 8px; font-size: 10px; } .set-email-container .account-input-box span { flex-shrink: 0; margin: 0; font-size: 15px; } .set-email-container .account-input-box input { flex-shrink: 1; box-sizing: border-box; width: 100%; height: 100%; padding: 0 15px; outline: none; font-weight: 400; font-size: 15px; color: var(--text-color); background-color: transparent; } .set-email-container .send-code-btn { margin-bottom: 0 !important; } .set-email-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-email-container .account-submit-btn.bottom-margin { margin-bottom: 100px; } .set-email-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-email-container .account-switch-item { margin-top: 40px; font-weight: 500; font-size: 13px; line-height: 19px; color: var(--accent-color); cursor: pointer; } .set-email-container .set-email-desc-2 { min-width: 116px; height: 23px; padding: 0 15px; 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-email-container .code-error { position: absolute; left: calc((100vw - 316px) / 2); margin-top: 220px; font-weight: 400; font-size: 12px; color: var(--error-color); } @media (min-width: 600px) { .set-email-container .code-error { left: calc((var(--vw) * 100 - 316px) / 2); } } .set-email-container .back { display: flex; align-items: center; height: 19px; margin-top: 90px; margin-bottom: 20px; font-weight: 400; font-size: 16px; line-height: 19px; color: var(--accent-color); opacity: 1; cursor: pointer; gap: 8px; } .set-email-container .back svg { position: relative; top: 0; color: var(--accent-color); } .set-email-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-email-container .send-again:hover { color: var(--text-color); background-color: transparent !important; } .set-email-container .send-again:disabled { opacity: 0.5; } `;var fe=j=>{let{bindAccount:s,backToInputAccount:i,redirectUrl:o="",verifyToken:T=""}=j,G=L(),{t:l}=D(),{themeType:z,language:y}=M(),d=q(),[u,E]=N(""),[S,g]=N(1e3),[r,f]=N(60),[p,b]=N(),P=ge(null),{authCoreModal:H}=$(),[m,v]=N(!1);le(()=>{if(r>0){let t=r-1;f(t),t===0&&g(void 0)}},S);let{run:h}=R(ae,{manual:!0,onBefore:()=>{v(!0)},onSuccess:t=>{se(),o?d(o.split("?")[0],{replace:!0,back:!0,state:{...pe.parse(o.split("?")[1]),verifyToken:t==null?void 0:t.token,account:s}}):t.has_set_payment_password?d("/account/security",{replace:!0}):d("/account/set-password")},onError:t=>{(t==null?void 0:t.error_code)===Z.InvalidCode?b(l("login.invalid_code")):(t==null?void 0:t.error_code)===Z.ResendCode&&b(l("login.please_send_again"))},onFinally:()=>{setTimeout(()=>{v(!1)},2e3)}}),{loading:w,run:k}=R(re,{manual:!0,onSuccess:(t,c)=>{S||(f(60),g(1e3))},onError:t=>{f(0),g(void 0)}}),A=t=>{let c;s.includes("@")?c={email:s,code:t||u}:c={phone:s,code:t||u},T&&(c.token=T),h(c)},B=()=>{b(""),s.includes("@")?k({email:s}):ce({theme:z,language:y,getContainer:()=>H.rootBody}).then(t=>{k({phone:s,cf_turnstile_response:t})}).catch(t=>{G.error(l("error.server_20112"))})},C=t=>{E(t),b(""),t.length===6&&K(t)},K=me(ue(t=>{A(t)},1e3,{leading:!0,trailing:!1}),[]);de(()=>{var O;let t=document.getElementsByClassName("react-input-code"),c=I=>I.preventDefault();return(O=t[0])==null||O.addEventListener("contextmenu",c),()=>{var I;(I=t[0])==null||I.removeEventListener("contextmenu",c)}},[]);let e=()=>{var c;(c=document.getElementsByClassName("input-code-item")[Math.min(u.length,5)])==null||c.focus()};return a.createElement("div",{className:"set-email-container"},a.createElement("style",null,F),a.createElement(_,{className:"icon-navigation-back",name:"circle_back",onClick:i}),a.createElement("h2",{className:"set-email-title"},l("account.enter_code")),a.createElement("p",{className:"set-email-desc-2",style:{margin:20}},s),a.createElement("div",{onClick:e},a.createElement(Q,{containerClassName:"react-input-code",inputClassName:"input-code-item",allowedCharacters:"numeric",length:6,ref:P,placeholder:" ",onChange:C})),p&&a.createElement("div",{className:"code-error"},p),a.createElement(ee,{disabled:u.length!==6,className:"account-submit-btn",loading:m,onClick:()=>A()},l("common.confirm")),a.createElement(ee,{className:"send-again",onClick:B,disabled:r>0||w},r>0?`${l("login.send_again")} (${r}s)`:l("login.send_again")),a.createElement("div",{className:"back",onClick:i},a.createElement(_,{className:"arrow1-icon",name:"arrow1_icon"}),a.createElement("span",null,l("login.back"))),a.createElement(U,null))},te=fe;var we=j=>{let s=q(),{t:i}=D(),o=j,T=o==null?void 0:o.redirectUrl,G=o==null?void 0:o.verifyToken,l=L(),z=oe(),[y,d]=x(""),[u,E]=x(["United States","us","1"]),[S,g]=x(!1),r=oe(null),[f,p]=x(""),{themeType:b,language:P}=M(),{authCoreModal:H}=$(),[m,v]=x("email");V(()=>{if(m==="phone"||(o==null?void 0:o.showSwitch)){let e=Y();e&&E(e)}},[m,o==null?void 0:o.showSwitch]);let[h,w]=x(!1);V(()=>{if(h)return document.addEventListener("click",k,!0),()=>{document.removeEventListener("click",k,!0)}},[h]);let k=e=>{setTimeout(()=>{var t;(t=z.current)!=null&&t.contains(e.target)||w(!1)})};V(()=>{let e=o==null?void 0:o.accountType;e&&v(e)},[o]);let{loading:A,run:B}=ye(he,{manual:!0,onSuccess:(e,t)=>{g(e)},onError:e=>{let t=(e==null?void 0:e.error_code)||0;(t===50003||t===50004)&&(d(""),r.current.value="")}}),C=()=>{let e=r.current.value;if(m==="email")if(e){if(!W.test(e))return p(i("login.email_format_error"))}else return p(i("account.input_vaild_email"));else{let t=u[1].toUpperCase();if(!e&&e!=="0")return p(i("account.input_vaild_mobile"));if(J(e,t))e=`+${u[2]}${e}`;else return p(i("login.phone_format_error"))}d(e),e.includes("@")?B({email:e}):xe({theme:b,language:P,getContainer:()=>H.rootBody}).then(t=>{B({phone:e,cf_turnstile_response:t})}).catch(t=>{l.error(i("error.server_20112"))})},K=()=>{p(""),v(m==="email"?"phone":"email"),d("")};return V(()=>{setTimeout(()=>{var e;(e=r.current)==null||e.focus()})},[]),S?n.createElement(te,{bindAccount:y,redirectUrl:T||"",verifyToken:G,backToInputAccount:()=>{g(!1)}}):n.createElement("div",{className:"set-email-container"},n.createElement("style",null,F),n.createElement(_,{className:"icon-navigation-back",name:"circle_back",onClick:()=>s(-1)}),n.createElement("h2",{className:"set-email-title"},i(m==="email"?"account.set_your_email":"account.set_your_mobile")),n.createElement("p",{className:"set-email-desc-1"},i(m==="email"?"account.set_your_email_tip":"account.set_your_mobile_tip")),m==="email"?n.createElement(n.Fragment,null,n.createElement("div",{className:"account-input-box"},n.createElement("input",{onInput:()=>p(""),className:"input_email",type:"email",placeholder:i("account.place_email_address"),ref:r,defaultValue:y,onKeyDown:e=>{e.key==="Enter"&&C()}}))):n.createElement(n.Fragment,null,n.createElement("div",{className:"account-input-box phone",ref:z},h&&n.createElement("div",{className:"account-select-country"},X.map((e,t)=>n.createElement("p",{key:t,className:"account-select-country-item",onClick:()=>{E(e),w(!1)}},n.createElement("div",{className:"country-box"},n.createElement("div",{className:"country-flag"},ne(`${e[1]}`)),n.createElement("span",{className:"country-name"},e[0])),n.createElement("div",{className:"country-code"},"+"+e[2])))),n.createElement("div",{className:"account-select-opt",onClick:()=>w(!h)},n.createElement("div",{className:"account-select-icon"},ne(`${u[1]}`)),n.createElement(be,{className:"down-more"})),n.createElement("span",null,"+",u[2]),n.createElement("input",{onInput:()=>{var e;p(""),r.current.value=((e=r.current.value.match(/^\d+/))==null?void 0:e[0])||""},type:"text",className:"no-number dd",placeholder:i("account.mobile"),ref:r,onWheel:e=>e.target.blur(),defaultValue:y.replace(`+${u[2]}`,""),onKeyDown:e=>{e.key==="Enter"&&C()},onFocus:()=>{var e;(e=document.querySelector(".account-input-box.phone"))==null||e.setAttribute("data-focus","true")},onBlur:()=>{var e;(e=document.querySelector(".account-input-box.phone"))==null||e.setAttribute("data-focus","false")}}))),n.createElement("p",{className:`error-tip ${f?"show":""}`},f),n.createElement(ve,{className:"send-code-btn account-submit-btn bottom-margin",loading:A,onClick:C},i("login.get_captcha")),(o==null?void 0:o.showSwitch)&&n.createElement("div",{className:"account-switch-item",onClick:K},i(m==="email"?"account.switch_text_mobile":"account.switch_text_email")),n.createElement(U,null))},Ze=we;export{Ze as default};