Skip to content

Commit

Permalink
chore: abstract OTP callback
Browse files Browse the repository at this point in the history
  • Loading branch information
tomiir committed Dec 29, 2023
1 parent 33fec88 commit 96301b1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ export class W3mEmailVerifyOtpView extends LitElement {
private OTPTimeout: NodeJS.Timeout | undefined

public override firstUpdated() {
this.OTPTimeout = setInterval(() => {
if (this.timeoutTimeLeft > 0) {
this.timeoutTimeLeft -= 1
} else {
clearInterval(this.OTPTimeout)
}
}, 1000)
this.startOTPTimeout()
}

public override disconnectedCallback() {
Expand Down Expand Up @@ -85,6 +79,16 @@ export class W3mEmailVerifyOtpView extends LitElement {
}

// -- Private ------------------------------------------- //
private startOTPTimeout() {
this.OTPTimeout = setInterval(() => {
if (this.timeoutTimeLeft > 0) {
this.timeoutTimeLeft -= 1
} else {
clearInterval(this.OTPTimeout)
}
}, 1000)
}

private async onOtpInputChange(event: CustomEvent<string>) {
try {
if (!this.loading) {
Expand Down Expand Up @@ -117,6 +121,7 @@ export class W3mEmailVerifyOtpView extends LitElement {
this.loading = true
await emailConnector.provider.connectEmail({ email: this.email })
SnackController.showSuccess('Code email resent')
this.startOTPTimeout()
}
} catch (error) {
SnackController.showError(error)
Expand Down

0 comments on commit 96301b1

Please sign in to comment.