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 29 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
35 changes: 16 additions & 19 deletions packages/scaffold/src/partials/w3m-email-login-widget/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectorController } from '@web3modal/core'
import { ConnectorController, CoreHelperUtil } from '@web3modal/core'
import { customElement } from '@web3modal/ui'
import { LitElement, html } from 'lit'
import { state } from 'lit/decorators.js'
Expand All @@ -23,6 +23,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 +59,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,55 +74,49 @@ 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
}

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 })
} else if (action === 'VERIFY_DEVICE') {
RouterController.push('EmailVerifyDevice', { email: this.email })
}
} catch (error) {
SnackController.showError(error)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
const parsedError = CoreHelperUtil.parseError(error)
if (parsedError?.includes('Invalid email')) {
this.error = 'Invalid email. Try again.'
} else {
SnackController.showError(error)
}
} finally {
this.loading = false
}
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: 20px;
transform: translateY(-50%);
}

Expand Down
5 changes: 4 additions & 1 deletion packages/scaffold/src/partials/w3m-header/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { RouterControllerState } from '@web3modal/core'
import {
ConnectionController,
ConnectorController,
EventsController,
ModalController,
RouterController,
Expand All @@ -17,9 +18,11 @@ function headings() {
const walletName = RouterController.state.data?.wallet?.name
const networkName = RouterController.state.data?.network?.name
const name = walletName ?? connectorName
const connectors = ConnectorController.getConnectors()
const isEmail = connectors.length === 1 && connectors[0]?.id === 'w3m-email'

return {
Connect: 'Connect Wallet',
Connect: `Connect ${isEmail ? 'Email' : ''} Wallet`,
Account: undefined,
ConnectingExternal: name ?? 'Connect Wallet',
ConnectingWalletConnect: name ?? 'WalletConnect',
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
58 changes: 48 additions & 10 deletions packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import {
ModalController,
EventsController,
ConnectionController,
ConnectorController
ConnectorController,
CoreHelperUtil
} from '@web3modal/core'
import { state } from 'lit/decorators.js'
import styles from './styles.js'
import { W3mFrameHelpers } from '@web3modal/wallet'

// -- Helpers ------------------------------------------- //
const OTP_LENGTH = 6
Expand All @@ -26,12 +28,28 @@ export class W3mEmailVerifyOtpView extends LitElement {
// -- State & Properties -------------------------------- //
@state() private loading = false

@state() private timeoutTimeLeft = W3mFrameHelpers.getTimeToNextEmailLogin()

@state() private error = ''

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 @@ -48,21 +66,40 @@ export class W3mEmailVerifyOtpView extends LitElement {

${this.loading
? html`<wui-loading-spinner size="xl" color="accent-100"></wui-loading-spinner>`
: html`<wui-otp
dissabled
length="6"
@inputChange=${this.onOtpInputChange.bind(this)}
></wui-otp>`}
: html` <wui-flex flexDirection="column" alignItems="center" gap="xs">
<wui-otp
dissabled
length="6"
@inputChange=${this.onOtpInputChange.bind(this)}
></wui-otp>
${this.error
? html`<wui-text variant="small-400" color="error-100"
>${this.error}. Try Again</wui-text
>`
: null}
</wui-flex>`}

<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.OTPTimeout = setInterval(() => {
if (this.timeoutTimeLeft > 0) {
this.timeoutTimeLeft = W3mFrameHelpers.getTimeToNextEmailLogin()
} else {
clearInterval(this.OTPTimeout)
}
}, 1000)
}

private async onOtpInputChange(event: CustomEvent<string>) {
try {
if (!this.loading) {
Expand All @@ -80,21 +117,22 @@ export class W3mEmailVerifyOtpView extends LitElement {
}
}
} catch (error) {
SnackController.showError(error)
this.error = CoreHelperUtil.parseError(error)
this.loading = false
}
}

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
Loading
Loading