OpChan/dist/assets/email-OHUMhOV6.js
2025-09-11 14:29:55 +05:30

238 lines
20 KiB
JavaScript

import{i as b,a3 as U,a4 as M,a5 as I,c as d,a as v,x as u,aa as m,a7 as P,d3 as R,T as l,O as h,L as C,R as f,K as V,$ as N,aj as y,a0 as c,ap as L,ay as B,aA as H,aw as q,Q as K}from"./index-Cr5N_0pd.js";const G=b`
:host {
position: relative;
display: inline-block;
}
input {
width: 50px;
height: 50px;
background: var(--wui-color-gray-glass-010);
border-radius: var(--wui-border-radius-xs);
border: 1px solid var(--wui-color-gray-glass-005);
font-family: var(--wui-font-family);
font-size: var(--wui-font-size-large);
font-weight: var(--wui-font-weight-regular);
letter-spacing: var(--wui-letter-spacing-large);
text-align: center;
color: var(--wui-color-fg-100);
caret-color: var(--wui-color-accent-100);
transition:
background-color var(--wui-ease-inout-power-1) var(--wui-duration-md),
border-color var(--wui-ease-inout-power-1) var(--wui-duration-md),
box-shadow var(--wui-ease-inout-power-1) var(--wui-duration-md);
will-change: background-color, border-color, box-shadow;
box-sizing: border-box;
-webkit-appearance: none;
-moz-appearance: textfield;
padding: 0px;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type='number'] {
-moz-appearance: textfield;
}
input:disabled {
cursor: not-allowed;
border: 1px solid var(--wui-color-gray-glass-010);
background: var(--wui-color-gray-glass-005);
}
input:focus:enabled {
background-color: var(--wui-color-gray-glass-015);
border: 1px solid var(--wui-color-accent-100);
-webkit-box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
-moz-box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
}
@media (hover: hover) and (pointer: fine) {
input:hover:enabled {
background-color: var(--wui-color-gray-glass-015);
}
}
`;var S=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let g=class extends v{constructor(){super(...arguments),this.disabled=!1,this.value=""}render(){return u`<input
type="number"
maxlength="1"
inputmode="numeric"
autofocus
?disabled=${this.disabled}
value=${this.value}
/> `}};g.styles=[U,M,G];S([I({type:Boolean})],g.prototype,"disabled",void 0);S([I({type:String})],g.prototype,"value",void 0);g=S([d("wui-input-numeric")],g);const Y=b`
:host {
position: relative;
display: block;
}
`;var O=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let w=class extends v{constructor(){super(...arguments),this.length=6,this.otp="",this.values=Array.from({length:this.length}).map(()=>""),this.numerics=[],this.shouldInputBeEnabled=e=>this.values.slice(0,e).every(n=>n!==""),this.handleKeyDown=(e,t)=>{const n=e.target,o=this.getInputElement(n),i=["ArrowLeft","ArrowRight","Shift","Delete"];if(!o)return;i.includes(e.key)&&e.preventDefault();const r=o.selectionStart;switch(e.key){case"ArrowLeft":r&&o.setSelectionRange(r+1,r+1),this.focusInputField("prev",t);break;case"ArrowRight":this.focusInputField("next",t);break;case"Shift":this.focusInputField("next",t);break;case"Delete":o.value===""?this.focusInputField("prev",t):this.updateInput(o,t,"");break;case"Backspace":o.value===""?this.focusInputField("prev",t):this.updateInput(o,t,"");break}},this.focusInputField=(e,t)=>{if(e==="next"){const n=t+1;if(!this.shouldInputBeEnabled(n))return;const o=this.numerics[n<this.length?n:t],i=o?this.getInputElement(o):void 0;i&&(i.disabled=!1,i.focus())}if(e==="prev"){const n=t-1,o=this.numerics[n>-1?n:t],i=o?this.getInputElement(o):void 0;i&&i.focus()}}}firstUpdated(){this.otp&&(this.values=this.otp.split(""));const e=this.shadowRoot?.querySelectorAll("wui-input-numeric");e&&(this.numerics=Array.from(e)),this.numerics[0]?.focus()}render(){return u`
<wui-flex gap="xxs" data-testid="wui-otp-input">
${Array.from({length:this.length}).map((e,t)=>u`
<wui-input-numeric
@input=${n=>this.handleInput(n,t)}
@click=${n=>this.selectInput(n)}
@keydown=${n=>this.handleKeyDown(n,t)}
.disabled=${!this.shouldInputBeEnabled(t)}
.value=${this.values[t]||""}
>
</wui-input-numeric>
`)}
</wui-flex>
`}updateInput(e,t,n){const o=this.numerics[t],i=e||(o?this.getInputElement(o):void 0);i&&(i.value=n,this.values=this.values.map((r,s)=>s===t?n:r))}selectInput(e){const t=e.target;t&&this.getInputElement(t)?.select()}handleInput(e,t){const n=e.target,o=this.getInputElement(n);if(o){const i=o.value;e.inputType==="insertFromPaste"?this.handlePaste(o,i,t):P.isNumber(i)&&e.data?(this.updateInput(o,t,e.data),this.focusInputField("next",t)):this.updateInput(o,t,"")}this.dispatchInputChangeEvent()}handlePaste(e,t,n){const o=t[0];if(o&&P.isNumber(o)){this.updateInput(e,n,o);const r=t.substring(1);if(n+1<this.length&&r.length){const s=this.numerics[n+1],D=s?this.getInputElement(s):void 0;D&&this.handlePaste(D,r,n+1)}else this.focusInputField("next",n)}else this.updateInput(e,n,"")}getInputElement(e){return e.shadowRoot?.querySelector("input")?e.shadowRoot.querySelector("input"):null}dispatchInputChangeEvent(){const e=this.values.join("");this.dispatchEvent(new CustomEvent("inputChange",{detail:e,bubbles:!0,composed:!0}))}};w.styles=[U,Y];O([I({type:Number})],w.prototype,"length",void 0);O([I({type:String})],w.prototype,"otp",void 0);O([m()],w.prototype,"values",void 0);w=O([d("wui-otp")],w);const Q=b`
wui-loading-spinner {
margin: 9px auto;
}
.email-display,
.email-display wui-text {
max-width: 100%;
}
`;var _=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i},T;let p=T=class extends v{firstUpdated(){this.startOTPTimeout()}disconnectedCallback(){clearTimeout(this.OTPTimeout)}constructor(){super(),this.loading=!1,this.timeoutTimeLeft=R.getTimeToNextEmailLogin(),this.error="",this.otp="",this.email=l.state.data?.email,this.authConnector=h.getAuthConnector()}render(){if(!this.email)throw new Error("w3m-email-otp-widget: No email provided");const e=!!this.timeoutTimeLeft,t=this.getFooterLabels(e);return u`
<wui-flex
flexDirection="column"
alignItems="center"
.padding=${["l","0","l","0"]}
gap="l"
>
<wui-flex
class="email-display"
flexDirection="column"
alignItems="center"
.padding=${["0","xl","0","xl"]}
>
<wui-text variant="paragraph-400" color="fg-100" align="center">
Enter the code we sent to
</wui-text>
<wui-text variant="paragraph-500" color="fg-100" lineClamp="1" align="center">
${this.email}
</wui-text>
</wui-flex>
<wui-text variant="small-400" color="fg-200">The code expires in 20 minutes</wui-text>
${this.loading?u`<wui-loading-spinner size="xl" color="accent-100"></wui-loading-spinner>`:u` <wui-flex flexDirection="column" alignItems="center" gap="xs">
<wui-otp
dissabled
length="6"
@inputChange=${this.onOtpInputChange.bind(this)}
.otp=${this.otp}
></wui-otp>
${this.error?u`
<wui-text variant="small-400" align="center" color="error-100">
${this.error}. Try Again
</wui-text>
`:null}
</wui-flex>`}
<wui-flex alignItems="center" gap="xs">
<wui-text variant="small-400" color="fg-200">${t.title}</wui-text>
<wui-link @click=${this.onResendCode.bind(this)} .disabled=${e}>
${t.action}
</wui-link>
</wui-flex>
</wui-flex>
`}startOTPTimeout(){this.timeoutTimeLeft=R.getTimeToNextEmailLogin(),this.OTPTimeout=setInterval(()=>{this.timeoutTimeLeft>0?this.timeoutTimeLeft=R.getTimeToNextEmailLogin():clearInterval(this.OTPTimeout)},1e3)}async onOtpInputChange(e){try{this.loading||(this.otp=e.detail,this.shouldSubmitOnOtpChange()&&(this.loading=!0,await this.onOtpSubmit?.(this.otp)))}catch(t){this.error=C.parseError(t),this.loading=!1}}async onResendCode(){try{if(this.onOtpResend){if(!this.loading&&!this.timeoutTimeLeft){if(this.error="",this.otp="",!h.getAuthConnector()||!this.email)throw new Error("w3m-email-otp-widget: Unable to resend email");this.loading=!0,await this.onOtpResend(this.email),this.startOTPTimeout(),f.showSuccess("Code email resent")}}else this.onStartOver&&this.onStartOver()}catch(e){f.showError(e)}finally{this.loading=!1}}getFooterLabels(e){return this.onStartOver?{title:"Something wrong?",action:`Try again ${e?`in ${this.timeoutTimeLeft}s`:""}`}:{title:"Didn't receive it?",action:`Resend ${e?`in ${this.timeoutTimeLeft}s`:"Code"}`}}shouldSubmitOnOtpChange(){return this.authConnector&&this.otp.length===T.OTP_LENGTH}};p.OTP_LENGTH=6;p.styles=Q;_([m()],p.prototype,"loading",void 0);_([m()],p.prototype,"timeoutTimeLeft",void 0);_([m()],p.prototype,"error",void 0);p=T=_([d("w3m-email-otp-widget")],p);var J=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let W=class extends p{constructor(){super(...arguments),this.onOtpSubmit=async e=>{try{if(this.authConnector){const t=V.state.activeChain,n=N.getConnections(t),o=y.state.remoteFeatures?.multiWallet,i=n.length>0;if(await this.authConnector.provider.connectOtp({otp:e}),c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_PASS"}),t)await N.connectExternal(this.authConnector,t);else throw new Error("Active chain is not set on ChainControll");if(c.sendEvent({type:"track",event:"CONNECT_SUCCESS",properties:{method:"email",name:this.authConnector.name||"Unknown",caipNetworkId:V.getActiveCaipNetwork()?.caipNetworkId}}),y.state.remoteFeatures?.emailCapture)return;if(y.state.siwx){L.close();return}if(i&&o){l.replace("ProfileWallets"),f.showSuccess("New Wallet Added");return}L.close()}}catch(t){throw c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_FAIL",properties:{message:C.parseError(t)}}),t}},this.onOtpResend=async e=>{this.authConnector&&(await this.authConnector.provider.connectEmail({email:e}),c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_SENT"}))}}};W=J([d("w3m-email-verify-otp-view")],W);const X=b`
wui-icon-box {
height: var(--wui-icon-box-size-xl);
width: var(--wui-icon-box-size-xl);
}
`;var k=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let x=class extends v{constructor(){super(),this.email=l.state.data?.email,this.authConnector=h.getAuthConnector(),this.loading=!1,this.listenForDeviceApproval()}render(){if(!this.email)throw new Error("w3m-email-verify-device-view: No email provided");if(!this.authConnector)throw new Error("w3m-email-verify-device-view: No auth connector provided");return u`
<wui-flex
flexDirection="column"
alignItems="center"
.padding=${["xxl","s","xxl","s"]}
gap="l"
>
<wui-icon-box
size="xl"
iconcolor="accent-100"
backgroundcolor="accent-100"
icon="verify"
background="opaque"
></wui-icon-box>
<wui-flex flexDirection="column" alignItems="center" gap="s">
<wui-flex flexDirection="column" alignItems="center">
<wui-text variant="paragraph-400" color="fg-100">
Approve the login link we sent to
</wui-text>
<wui-text variant="paragraph-400" color="fg-100"><b>${this.email}</b></wui-text>
</wui-flex>
<wui-text variant="small-400" color="fg-200" align="center">
The code expires in 20 minutes
</wui-text>
<wui-flex alignItems="center" id="w3m-resend-section" gap="xs">
<wui-text variant="small-400" color="fg-100" align="center">
Didn't receive it?
</wui-text>
<wui-link @click=${this.onResendCode.bind(this)} .disabled=${this.loading}>
Resend email
</wui-link>
</wui-flex>
</wui-flex>
</wui-flex>
`}async listenForDeviceApproval(){if(this.authConnector)try{await this.authConnector.provider.connectDevice(),c.sendEvent({type:"track",event:"DEVICE_REGISTERED_FOR_EMAIL"}),c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_SENT"}),l.replace("EmailVerifyOtp",{email:this.email})}catch{l.goBack()}}async onResendCode(){try{if(!this.loading){if(!this.authConnector||!this.email)throw new Error("w3m-email-login-widget: Unable to resend email");this.loading=!0,await this.authConnector.provider.connectEmail({email:this.email}),this.listenForDeviceApproval(),f.showSuccess("Code email resent")}}catch(e){f.showError(e)}finally{this.loading=!1}}};x.styles=X;k([m()],x.prototype,"loading",void 0);x=k([d("w3m-email-verify-device-view")],x);const Z=b`
wui-email-input {
width: 100%;
}
form {
width: 100%;
display: block;
position: relative;
}
`;var $=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let E=class extends v{constructor(){super(...arguments),this.formRef=B(),this.initialEmail=l.state.data?.email??"",this.redirectView=l.state.data?.redirectView,this.email="",this.loading=!1}firstUpdated(){this.formRef.value?.addEventListener("keydown",e=>{e.key==="Enter"&&this.onSubmitEmail(e)})}render(){return u`
<wui-flex flexDirection="column" padding="m" gap="m">
<form ${H(this.formRef)} @submit=${this.onSubmitEmail.bind(this)}>
<wui-email-input
value=${this.initialEmail}
.disabled=${this.loading}
@inputChange=${this.onEmailInputChange.bind(this)}
>
</wui-email-input>
<input type="submit" hidden />
</form>
${this.buttonsTemplate()}
</wui-flex>
`}onEmailInputChange(e){this.email=e.detail}async onSubmitEmail(e){try{if(this.loading)return;this.loading=!0,e.preventDefault();const t=h.getAuthConnector();if(!t)throw new Error("w3m-update-email-wallet: Auth connector not found");const n=await t.provider.updateEmail({email:this.email});c.sendEvent({type:"track",event:"EMAIL_EDIT"}),n.action==="VERIFY_SECONDARY_OTP"?l.push("UpdateEmailSecondaryOtp",{email:this.initialEmail,newEmail:this.email,redirectView:this.redirectView}):l.push("UpdateEmailPrimaryOtp",{email:this.initialEmail,newEmail:this.email,redirectView:this.redirectView})}catch(t){f.showError(t),this.loading=!1}}buttonsTemplate(){const e=!this.loading&&this.email.length>3&&this.email!==this.initialEmail;return this.redirectView?u`
<wui-flex gap="s">
<wui-button size="md" variant="neutral" fullWidth @click=${l.goBack}>
Cancel
</wui-button>
<wui-button
size="md"
variant="main"
fullWidth
@click=${this.onSubmitEmail.bind(this)}
.disabled=${!e}
.loading=${this.loading}
>
Save
</wui-button>
</wui-flex>
`:u`
<wui-button
size="md"
variant="main"
fullWidth
@click=${this.onSubmitEmail.bind(this)}
.disabled=${!e}
.loading=${this.loading}
>
Save
</wui-button>
`}};E.styles=Z;$([m()],E.prototype,"email",void 0);$([m()],E.prototype,"loading",void 0);E=$([d("w3m-update-email-wallet-view")],E);var ee=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let F=class extends p{constructor(){super(),this.email=l.state.data?.email,this.onOtpSubmit=async e=>{try{this.authConnector&&(await this.authConnector.provider.updateEmailPrimaryOtp({otp:e}),c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_PASS"}),l.replace("UpdateEmailSecondaryOtp",l.state.data))}catch(t){throw c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_FAIL",properties:{message:C.parseError(t)}}),t}},this.onStartOver=()=>{l.replace("UpdateEmailWallet",l.state.data)}}};F=ee([d("w3m-update-email-primary-otp-view")],F);var te=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let j=class extends p{constructor(){super(),this.email=l.state.data?.newEmail,this.redirectView=l.state.data?.redirectView,this.onOtpSubmit=async e=>{try{this.authConnector&&(await this.authConnector.provider.updateEmailSecondaryOtp({otp:e}),c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_PASS"}),this.redirectView&&l.reset(this.redirectView))}catch(t){throw c.sendEvent({type:"track",event:"EMAIL_VERIFICATION_CODE_FAIL",properties:{message:C.parseError(t)}}),t}},this.onStartOver=()=>{l.replace("UpdateEmailWallet",l.state.data)}}};j=te([d("w3m-update-email-secondary-otp-view")],j);var z=function(a,e,t,n){var o=arguments.length,i=o<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,t):n,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(a,e,t,n);else for(var s=a.length-1;s>=0;s--)(r=a[s])&&(i=(o<3?r(i):o>3?r(e,t,i):r(e,t))||i);return o>3&&i&&Object.defineProperty(e,t,i),i};let A=class extends v{constructor(){super(),this.authConnector=h.getAuthConnector(),this.isEmailEnabled=y.state.remoteFeatures?.email,this.isAuthEnabled=this.checkIfAuthEnabled(h.state.connectors),this.connectors=h.state.connectors,h.subscribeKey("connectors",e=>{this.connectors=e,this.isAuthEnabled=this.checkIfAuthEnabled(this.connectors)})}render(){if(!this.isEmailEnabled)throw new Error("w3m-email-login-view: Email is not enabled");if(!this.isAuthEnabled)throw new Error("w3m-email-login-view: No auth connector provided");return u`<wui-flex
flexDirection="column"
.padding=${["3xs","m","m","m"]}
gap="l"
>
<w3m-email-login-widget></w3m-email-login-widget>
</wui-flex> `}checkIfAuthEnabled(e){const t=e.filter(o=>o.type===q.CONNECTOR_TYPE_AUTH).map(o=>o.chain);return K.AUTH_CONNECTOR_SUPPORTED_CHAINS.some(o=>t.includes(o))}};z([m()],A.prototype,"connectors",void 0);A=z([d("w3m-email-login-view")],A);export{A as W3mEmailLoginView,p as W3mEmailOtpWidget,x as W3mEmailVerifyDeviceView,W as W3mEmailVerifyOtpView,F as W3mUpdateEmailPrimaryOtpView,j as W3mUpdateEmailSecondaryOtpView,E as W3mUpdateEmailWalletView};