diff --git a/packages/scaffold/src/partials/w3m-account-default-widget/index.ts b/packages/scaffold/src/partials/w3m-account-default-widget/index.ts index 8703f0af4b..2fa3411267 100644 --- a/packages/scaffold/src/partials/w3m-account-default-widget/index.ts +++ b/packages/scaffold/src/partials/w3m-account-default-widget/index.ts @@ -232,6 +232,7 @@ export class W3mAccountDefaultWidget extends LitElement { iconVariant="overlay" icon="mail" iconSize="sm" + data-testid="w3m-account-email-update" ?chevron=${true} @click=${() => this.onGoToUpdateEmail(email)} > diff --git a/packages/scaffold/src/views/w3m-update-email-wallet-view/index.ts b/packages/scaffold/src/views/w3m-update-email-wallet-view/index.ts index 22ab43a531..079ee62fe9 100644 --- a/packages/scaffold/src/views/w3m-update-email-wallet-view/index.ts +++ b/packages/scaffold/src/views/w3m-update-email-wallet-view/index.ts @@ -84,12 +84,20 @@ export class W3mUpdateEmailWalletView extends LitElement { throw new Error('w3m-update-email-wallet: Email connector not found') } - await emailConnector.provider.updateEmail({ email: this.email }) + const response = await emailConnector.provider.updateEmail({ email: this.email }) EventsController.sendEvent({ type: 'track', event: 'EMAIL_EDIT' }) - RouterController.replace('UpdateEmailPrimaryOtp', { - email: this.initialEmail, - newEmail: this.email - }) + + if (response.action === 'VERIFY_SECONDARY_OTP') { + RouterController.push('UpdateEmailSecondaryOtp', { + email: this.initialEmail, + newEmail: this.email + }) + } else { + RouterController.push('UpdateEmailPrimaryOtp', { + email: this.initialEmail, + newEmail: this.email + }) + } } catch (error) { SnackController.showError(error) this.loading = false diff --git a/packages/wallet/src/W3mFrameProvider.ts b/packages/wallet/src/W3mFrameProvider.ts index 1736274217..b1aad9055c 100644 --- a/packages/wallet/src/W3mFrameProvider.ts +++ b/packages/wallet/src/W3mFrameProvider.ts @@ -15,7 +15,7 @@ type IsConnectedResolver = Resolver type SwitchChainResolver = Resolver type RpcRequestResolver = Resolver -type UpdateEmailResolver = Resolver +type UpdateEmailResolver = Resolver type UpdateEmailPrimaryOtpResolver = Resolver type UpdateEmailSecondaryOtpResolver = Resolver< W3mFrameTypes.Responses['FrameUpdateEmailSecondaryOtpResolver'] @@ -109,7 +109,7 @@ export class W3mFrameProvider { case W3mFrameConstants.FRAME_SESSION_UPDATE: return this.onSessionUpdate(event) case W3mFrameConstants.FRAME_UPDATE_EMAIL_SUCCESS: - return this.onUpdateEmailSuccess() + return this.onUpdateEmailSuccess(event) case W3mFrameConstants.FRAME_UPDATE_EMAIL_ERROR: return this.onUpdateEmailError(event) case W3mFrameConstants.FRAME_UPDATE_EMAIL_PRIMARY_OTP_SUCCESS: @@ -210,7 +210,7 @@ export class W3mFrameProvider { W3mFrameHelpers.checkIfAllowedToTriggerEmail() this.w3mFrame.events.postAppEvent({ type: W3mFrameConstants.APP_UPDATE_EMAIL, payload }) - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { this.updateEmailResolver = { resolve, reject } }) } @@ -523,8 +523,10 @@ export class W3mFrameProvider { } } - private onUpdateEmailSuccess() { - this.updateEmailResolver?.resolve(undefined) + private onUpdateEmailSuccess( + event: Extract + ) { + this.updateEmailResolver?.resolve(event.payload) this.setNewLastEmailLoginTime() } diff --git a/packages/wallet/src/W3mFrameSchema.ts b/packages/wallet/src/W3mFrameSchema.ts index 0d17180af4..bb50391ae3 100644 --- a/packages/wallet/src/W3mFrameSchema.ts +++ b/packages/wallet/src/W3mFrameSchema.ts @@ -65,6 +65,9 @@ export const AppSetPreferredAccountRequest = z.object({ type: z.string() }) export const FrameConnectEmailResponse = z.object({ action: z.enum(['VERIFY_DEVICE', 'VERIFY_OTP']) }) +export const FrameUpdateEmailResponse = z.object({ + action: z.enum(['VERIFY_PRIMARY_OTP', 'VERIFY_SECONDARY_OTP']) +}) export const FrameGetUserResponse = z.object({ email: z.string().email(), address: z.string(), @@ -406,7 +409,7 @@ export const W3mFrameSchema = { .or(z.object({ type: zType('FRAME_UPDATE_EMAIL_ERROR'), payload: zError })) - .or(z.object({ type: zType('FRAME_UPDATE_EMAIL_SUCCESS') })) + .or(z.object({ type: zType('FRAME_UPDATE_EMAIL_SUCCESS'), payload: FrameUpdateEmailResponse })) .or(z.object({ type: zType('FRAME_UPDATE_EMAIL_PRIMARY_OTP_ERROR'), payload: zError })) diff --git a/packages/wallet/src/W3mFrameTypes.ts b/packages/wallet/src/W3mFrameTypes.ts index d3483d68f1..70082342f3 100644 --- a/packages/wallet/src/W3mFrameTypes.ts +++ b/packages/wallet/src/W3mFrameTypes.ts @@ -55,7 +55,8 @@ import { RpcEthChainId, FrameSwitchNetworkResponse, AppSyncDappDataRequest, - FrameGetSmartAccountEnabledNetworksResponse + FrameGetSmartAccountEnabledNetworksResponse, + FrameUpdateEmailResponse } from './W3mFrameSchema.js' import type { W3mFrameRpcConstants } from './W3mFrameConstants.js' @@ -86,6 +87,7 @@ export namespace W3mFrameTypes { FrameGetSmartAccountEnabledNetworksResponse: z.infer< typeof FrameGetSmartAccountEnabledNetworksResponse > + FrameUpdateEmailResponse: z.infer } export interface Network {