Skip to content

Commit

Permalink
fix: various email issues from w3i testing (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvoskamp authored Feb 19, 2024
1 parent 0c3510d commit 033bbf1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/scaffold/src/utils/w3m-email-otp-widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class W3mEmailOtpWidget extends LitElement {
></wui-otp>
${this.error
? html`
<wui-text variant="small-400" color="error-100">
<wui-text variant="small-400" align="center" color="error-100">
${this.error}. Try Again
</wui-text>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ export class W3mEmailVerifyDeviceView extends LitElement {
// -- Private ------------------------------------------- //
private async listenForDeviceApproval() {
if (this.emailConnector) {
await this.emailConnector.provider.connectDevice()
EventsController.sendEvent({ type: 'track', event: 'DEVICE_REGISTERED_FOR_EMAIL' })
EventsController.sendEvent({ type: 'track', event: 'EMAIL_VERIFICATION_CODE_SENT' })
RouterController.replace('EmailVerifyOtp', { email: this.email })
try {
await this.emailConnector.provider.connectDevice()
EventsController.sendEvent({ type: 'track', event: 'DEVICE_REGISTERED_FOR_EMAIL' })
EventsController.sendEvent({ type: 'track', event: 'EMAIL_VERIFICATION_CODE_SENT' })
RouterController.replace('EmailVerifyOtp', { email: this.email })
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
RouterController.goBack()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class W3mUpdateEmailSecondaryOtpView extends W3mEmailOtpWidget {
if (this.emailConnector) {
await this.emailConnector.provider.updateEmailSecondaryOtp({ otp })
EventsController.sendEvent({ type: 'track', event: 'EMAIL_VERIFICATION_CODE_PASS' })
RouterController.replace('Account', { email: this.email })
RouterController.reset('Account')
}
} catch (error) {
EventsController.sendEvent({ type: 'track', event: 'EMAIL_VERIFICATION_CODE_FAIL' })
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/src/composites/wui-list-accordion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export class WuiListAccordion extends LitElement {
public override firstUpdated() {
setTimeout(() => {
const heightElement = this.shadowRoot?.querySelector('.heightContent')
const textElement = this.shadowRoot?.querySelector('.textContent')

if (heightElement) {
if (heightElement && textElement) {
this.scrollElement = heightElement
const scrollHeight = heightElement?.scrollHeight
const scrollHeight = textElement?.scrollHeight

if (scrollHeight && scrollHeight > MAX_HEIGHT) {
this.enableAccordion = true
this.scrollHeightElement = scrollHeight
Expand All @@ -55,7 +57,7 @@ export class WuiListAccordion extends LitElement {
class="overflowedContent"
>
<div class="heightContent">
<wui-text variant="paragraph-400" color="fg-200">
<wui-text class="textContent" variant="paragraph-400" color="fg-200">
<pre>${this.overflowedContent}</pre>
</wui-text>
</div>
Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/composites/wui-otp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class WuiOtp extends LitElement {
(_, index: number) => html`
<wui-input-numeric
@input=${(e: InputEvent) => this.handleInput(e, index)}
@click=${(e: MouseEvent) => this.selectInput(e)}
@keydown=${(e: KeyboardEvent) => this.handleKeyDown(e, index)}
.disabled=${!this.shouldInputBeEnabled(index)}
.value=${this.values[index] || ''}
Expand All @@ -57,11 +58,20 @@ export class WuiOtp extends LitElement {
const input = element || (numeric ? this.getInputElement(numeric) : undefined)
if (input) {
input.value = value

// Need to update the whole reference else lit-html won't re-render
this.values = this.values.map((val, i) => (i === index ? value : val))
}
}

private selectInput(e: MouseEvent) {
const targetElement = e.target as HTMLElement
if (targetElement) {
const inputElement = this.getInputElement(targetElement)
inputElement?.select()
}
}

private handleInput(e: InputEvent, index: number) {
const inputElement = e.target as HTMLElement
const input = this.getInputElement(inputElement)
Expand Down Expand Up @@ -136,6 +146,7 @@ export class WuiOtp extends LitElement {

private handlePaste(input: HTMLInputElement, inputValue: string, index: number) {
const value = inputValue[0]

const isValid = value && UiHelperUtil.isNumber(value)
if (isValid) {
this.updateInput(input, index, value)
Expand Down

0 comments on commit 033bbf1

Please sign in to comment.