Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: email + UI responsive issues #1676

Merged
merged 31 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
28ab291
fix: button padding
tomiir Dec 27, 2023
8835552
chore: improve style by applying them to button directly
tomiir Dec 27, 2023
bca46e9
feat: add charsStart and charsEnd properties to wui-account-button
tomiir Dec 27, 2023
06dfae4
feat: add charStart and end to stories
tomiir Dec 27, 2023
c178406
feat: add properties through w3m-account-button and w3m-button
tomiir Dec 27, 2023
3f7ce48
fix: property forwarding
tomiir Dec 27, 2023
865c38a
fix: connect button responsive height and padding
tomiir Dec 28, 2023
2a833d8
fix: account button responsive height
tomiir Dec 28, 2023
856b39b
fix: remove button from email widget
tomiir Dec 28, 2023
2bc3dcf
fix: connect button font size in responsive
tomiir Dec 28, 2023
33bcdde
fix: local errors in email
tomiir Dec 28, 2023
08f0237
fix: made backdrop darker
tomiir Dec 28, 2023
9463dc1
fix: hover issue on wui-numeric-input
tomiir Dec 28, 2023
cfaa583
fix: disable input until previous ones are filled out
tomiir Dec 28, 2023
1be9a2d
feat: added countdown timer for OTP code
tomiir Dec 28, 2023
33fec88
fix: resend otp copy
tomiir Dec 28, 2023
96301b1
chore: abstract OTP callback
tomiir Dec 29, 2023
c35dafd
chore: made disabling reactive
tomiir Dec 29, 2023
ac293a4
fix: improved ux by pre-loading the timeout
tomiir Dec 29, 2023
7d8a34b
fix: rollback change. caused potential bug on button spam
tomiir Dec 29, 2023
b4faba2
chore: add email to title in case its single connector
tomiir Dec 29, 2023
9170833
chore: use W3mFrameHelpers to get localstorage stored las login attem…
tomiir Jan 2, 2024
dd5c129
chore: remove zod usage in scaffold. rely on upstream validation
tomiir Jan 2, 2024
1dc81a6
fix: disable error/any rule
tomiir Jan 2, 2024
af39081
fix: input email validation
tomiir Jan 2, 2024
0f17cde
fix: email input padding and icon size
tomiir Jan 2, 2024
ddb5bf4
fix: icon positioning
tomiir Jan 2, 2024
74b0701
fix: email otp autofocus
tomiir Jan 2, 2024
e10deb5
fix: use parseError to display error message instead of snackbar
tomiir Jan 2, 2024
4a99aa6
chore: abstract EMAIL_MINIMUM_TIMEOUT
tomiir Jan 3, 2024
f2d074a
Merge branch 'V3' into fix/email-ui-responsive-issues
tomiir Jan 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default {
avatarSrc: avatarImageSrc,
address,
balance: '0.527 ETH',
isProfileName: false
isProfileName: false,
charsStart: 4,
charsEnd: 6
},
argTypes: {
disabled: {
Expand All @@ -35,5 +37,7 @@ export const Default: Component = {
.avatarSrc=${args.avatarSrc}
.balance=${args.balance}
address=${args.address}
.charsStart=${args.charsStart}
.charsEnd=${args.charsEnd}
></wui-account-button>`
}
6 changes: 6 additions & 0 deletions packages/scaffold/src/modal/w3m-account-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class W3mAccountButton extends LitElement {

@property() public balance?: 'show' | 'hide' = 'show'

@property() public charsStart?: WuiAccountButton['charsStart'] = 4

@property() public charsEnd?: WuiAccountButton['charsEnd'] = 6

@state() private address = AccountController.state.address

@state() private balanceVal = AccountController.state.balance
Expand Down Expand Up @@ -79,6 +83,8 @@ export class W3mAccountButton extends LitElement {
: ''}
@click=${this.onClick.bind(this)}
data-testid="account-button"
.charsStart=${this.charsStart}
.charsEnd=${this.charsEnd}
>
</wui-account-button>
`
Expand Down
6 changes: 6 additions & 0 deletions packages/scaffold/src/modal/w3m-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class W3mButton extends LitElement {

@property() public loadingLabel?: W3mConnectButton['loadingLabel'] = undefined

@property() public charsStart?: W3mAccountButton['charsStart'] = 4

@property() public charsEnd?: W3mAccountButton['charsEnd'] = 6

@state() private isAccount = AccountController.state.isConnected

// -- Lifecycle ----------------------------------------- //
Expand All @@ -45,6 +49,8 @@ export class W3mButton extends LitElement {
<w3m-account-button
.disabled=${Boolean(this.disabled)}
balance=${ifDefined(this.balance)}
.charsStart=${ifDefined(this.charsStart)}
.charsEnd=${ifDefined(this.charsEnd)}
>
</w3m-account-button>
`
Expand Down
28 changes: 13 additions & 15 deletions packages/scaffold/src/partials/w3m-email-login-widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ref, createRef } from 'lit/directives/ref.js'
import type { Ref } from 'lit/directives/ref.js'
import styles from './styles.js'
import { SnackController, RouterController } from '@web3modal/core'
import { z } from 'zod'
tomiir marked this conversation as resolved.
Show resolved Hide resolved

@customElement('w3m-email-login-widget')
export class W3mEmailLoginWidget extends LitElement {
Expand All @@ -23,6 +24,8 @@ export class W3mEmailLoginWidget extends LitElement {

@state() private loading = false

@state() private error = ''

public constructor() {
super()
this.unsubscribe.push(
Expand Down Expand Up @@ -57,10 +60,11 @@ export class W3mEmailLoginWidget extends LitElement {
<wui-email-input
.disabled=${this.loading}
@inputChange=${this.onEmailInputChange.bind(this)}
.errorMessage=${this.error}
>
</wui-email-input>

${showSubmit && multipleConnectors
${showSubmit
? html`
<wui-icon-link
size="sm"
Expand All @@ -71,47 +75,41 @@ export class W3mEmailLoginWidget extends LitElement {
</wui-icon-link>
`
: null}
${this.loading && multipleConnectors
${this.loading
? html`<wui-loading-spinner size="md" color="accent-100"></wui-loading-spinner>`
: null}

<input type="submit" hidden />
</form>

${multipleConnectors
? html`<wui-separator text="or"></wui-separator>`
: html`<wui-button
size="md"
variant="fill"
fullWidth
@click=${this.onSubmitEmail.bind(this)}
.disabled=${!showSubmit}
.loading=${this.loading}
>
Continue
</wui-button>`}
${multipleConnectors ? html`<wui-separator text="or"></wui-separator>` : null}
`
}

// -- Private ------------------------------------------- //
private onEmailInputChange(event: CustomEvent<string>) {
this.email = event.detail
this.error = ''
}

private async onSubmitEmail(event: Event) {
try {
if (this.loading) {
return
}
const { success: isEmailValid } = z.string().email().safeParse(this.email)
tomiir marked this conversation as resolved.
Show resolved Hide resolved
if (!isEmailValid) {
this.error = 'Invalid email. Try again'

return
}
this.loading = true
event.preventDefault()
const emailConnector = ConnectorController.getEmailConnector()

if (!emailConnector) {
throw new Error('w3m-email-login-widget: Email connector not found')
}

const { action } = await emailConnector.provider.connectEmail({ email: this.email })
if (action === 'VERIFY_OTP') {
RouterController.push('EmailVerifyOtp', { email: this.email })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default css`
wui-icon-link,
wui-loading-spinner {
position: absolute;
top: 50%;
top: 26px;
tomiir marked this conversation as resolved.
Show resolved Hide resolved
transform: translateY(-50%);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class W3mEmailVerifyDeviceView extends LitElement {
}
this.loading = true
await this.emailConnector.provider.connectEmail({ email: this.email })
SnackController.showSuccess('New Email sent')
SnackController.showSuccess('Code email resent')
}
} catch (error) {
SnackController.showError(error)
Expand Down
34 changes: 31 additions & 3 deletions packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,26 @@ export class W3mEmailVerifyOtpView extends LitElement {
// -- State & Properties -------------------------------- //
@state() private loading = false

@state() private timeoutTimeLeft = 30
tomiir marked this conversation as resolved.
Show resolved Hide resolved

private OTPTimeout: NodeJS.Timeout | undefined

public override firstUpdated() {
this.startOTPTimeout()
}

public override disconnectedCallback() {
clearTimeout(this.OTPTimeout)
}

// -- Render -------------------------------------------- //
public override render() {
if (!this.email) {
throw new Error('w3m-email-verify-otp-view: No email provided')
}

const isResendDisabled = Boolean(this.timeoutTimeLeft)

return html`
<wui-flex
flexDirection="column"
Expand All @@ -56,13 +70,26 @@ export class W3mEmailVerifyOtpView extends LitElement {

<wui-flex alignItems="center">
<wui-text variant="small-400" color="fg-200">Didn't receive it?</wui-text>
<wui-link @click=${this.onResendCode.bind(this)}>Resend code</wui-link>
<wui-link @click=${this.onResendCode.bind(this)} .disabled=${isResendDisabled}>
Resend ${isResendDisabled ? `in ${this.timeoutTimeLeft}s` : 'Code'}
</wui-link>
</wui-flex>
</wui-flex>
`
}

// -- Private ------------------------------------------- //
private startOTPTimeout() {
this.timeoutTimeLeft = 30
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 All @@ -87,14 +114,15 @@ export class W3mEmailVerifyOtpView extends LitElement {

private async onResendCode() {
try {
if (!this.loading) {
if (!this.loading && !this.timeoutTimeLeft) {
const emailConnector = ConnectorController.getEmailConnector()
if (!emailConnector || !this.email) {
throw new Error('w3m-email-login-widget: Unable to resend email')
}
this.loading = true
await emailConnector.provider.connectEmail({ email: this.email })
SnackController.showSuccess('New Email sent')
this.startOTPTimeout()
SnackController.showSuccess('Code email resent')
}
} catch (error) {
SnackController.showError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class W3mUpdateEmailWalletWaitingView extends LitElement {
this.loading = true
await this.emailConnector.provider.updateEmail({ email: this.email })
this.listenForEmailUpdateApproval()
SnackController.showSuccess('New Email sent')
SnackController.showSuccess('Code email resent')
}
} catch (error) {
SnackController.showError(error)
Expand Down
19 changes: 11 additions & 8 deletions packages/ui/src/composites/wui-account-button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ export class WuiAccountButton extends LitElement {

@property() public address = ''

@property() public charsStart = 4

@property() public charsEnd = 6

// -- Render -------------------------------------------- //
public override render() {
return html`
<button ?disabled=${this.disabled}>
<button
?disabled=${this.disabled}
class=${ifDefined(this.balance ? undefined : 'local-no-balance')}
>
${this.balanceTemplate()}
<wui-flex
gap="xxs"
alignItems="center"
class=${ifDefined(this.balance ? undefined : 'local-no-balance')}
>
<wui-flex gap="xxs" alignItems="center">
<wui-avatar
.imageSrc=${this.avatarSrc}
alt=${this.address}
Expand All @@ -46,8 +49,8 @@ export class WuiAccountButton extends LitElement {
<wui-text variant="paragraph-600" color="inherit">
${UiHelperUtil.getTruncateString({
string: this.address,
charsStart: this.isProfileName ? 18 : 4,
charsEnd: this.isProfileName ? 0 : 6,
charsStart: this.isProfileName ? 18 : this.charsStart,
charsEnd: this.isProfileName ? 0 : this.charsEnd,
truncate: this.isProfileName ? 'end' : 'middle'
})}
</wui-text>
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/composites/wui-account-button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default css`
padding: 4px var(--wui-spacing-m) 4px var(--wui-spacing-xxs);
}

wui-flex.local-no-balance {
button.local-no-balance {
border-radius: 0px;
border: none;
background: transparent;
Expand All @@ -77,6 +77,8 @@ export default css`
@media (max-width: 500px) {
button {
gap: 0px;
padding: var(--wui-spacing-3xs) var(--wui-spacing-xs) !important;
height: 32px;
}
wui-image,
wui-icon-box,
Expand All @@ -85,10 +87,11 @@ export default css`
width: 0px;
height: 0px;
}
button > wui-flex {
button {
border-radius: 0px;
border: none;
background: transparent;
padding: 0px;
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/ui/src/composites/wui-connect-button/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ export default css`
padding-left: var(--wui-spacing-3xs);
}

@media (max-width: 500px) {
button[data-size='md'] {
height: 32px;
padding: 5px 12px;
}

button[data-size='md'] > wui-text > slot {
font-size: 14px !important;
}
}

wui-loading-spinner {
width: 14px;
height: 14px;
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/composites/wui-input-numeric/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export default css`
-moz-box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
box-shadow: 0px 0px 0px 4px var(--wui-box-shadow-blue);
}

input:hover:enabled {
background-color: var(--wui-gray-glass-010);
@media (hover: hover) and (pointer: fine) {
input:hover:enabled {
background-color: var(--wui-gray-glass-010);
}
}
`
Loading
Loading