From bec1560eed968bd3ee9adce453700a157273c9dd Mon Sep 17 00:00:00 2001 From: tomiir Date: Mon, 13 May 2024 18:08:21 +0200 Subject: [PATCH] fix: siwe tests by moving logm essages to ui component. Add replace for email account signatures flow --- .../views/w3m-connecting-siwe-view/index.ts | 9 +++- packages/siwe/src/client.ts | 52 ++++++------------- 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/packages/siwe/scaffold/views/w3m-connecting-siwe-view/index.ts b/packages/siwe/scaffold/views/w3m-connecting-siwe-view/index.ts index a5f99db431..d207661922 100644 --- a/packages/siwe/scaffold/views/w3m-connecting-siwe-view/index.ts +++ b/packages/siwe/scaffold/views/w3m-connecting-siwe-view/index.ts @@ -11,6 +11,7 @@ import { customElement } from '@web3modal/ui' import { LitElement, html } from 'lit' import { state } from 'lit/decorators.js' import { SIWEController } from '../../../core/controller/SIWEController.js' +import { W3mFrameRpcConstants } from '@web3modal/wallet' @customElement('w3m-connecting-siwe-view') export class W3mConnectingSiweView extends LitElement { @@ -95,8 +96,12 @@ export class W3mConnectingSiweView extends LitElement { return session } catch (error) { - SnackController.showError('Signature declined') - + const preferredAccountType = AccountController.state.preferredAccountType + if (preferredAccountType === W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT) { + SnackController.showError('This application might not support Smart Accounts') + } else { + SnackController.showError('Signature declined') + } SIWEController.setStatus('error') return EventsController.sendEvent({ diff --git a/packages/siwe/src/client.ts b/packages/siwe/src/client.ts index 45f1e58657..6c3bb7724f 100644 --- a/packages/siwe/src/client.ts +++ b/packages/siwe/src/client.ts @@ -13,14 +13,11 @@ import { ConnectionController, RouterUtil, RouterController, - StorageUtil, - ModalController, - SnackController + StorageUtil } from '@web3modal/core' import { NetworkUtil } from '@web3modal/common' import { ConstantsUtil } from '../core/utils/ConstantsUtil.js' -import { W3mFrameRpcConstants } from '@web3modal/wallet' // -- Client -------------------------------------------------------------------- // export class Web3ModalSIWEClient { @@ -117,42 +114,27 @@ export class Web3ModalSIWEClient { goBack: false, replace: true, onCancel() { - ConnectionController.disconnect().then(() => ModalController.close()) + RouterController.replace('ConnectingSiwe') } }) } - try { - const signature = await ConnectionController.signMessage(message) - const isValid = await this.methods.verifyMessage({ message, signature }) - if (!isValid) { - let errorMessage = 'Error verifying SIWE signature' - if ( - AccountController.state.preferredAccountType === - W3mFrameRpcConstants.ACCOUNT_TYPES.SMART_ACCOUNT - ) { - errorMessage = 'This application might not support Smart Account connections' - } + const signature = await ConnectionController.signMessage(message) + const isValid = await this.methods.verifyMessage({ message, signature }) + if (!isValid) { + throw new Error('Error verifying SIWE signature') + } - throw new Error(errorMessage) - } - - const session = await this.methods.getSession() - if (!session) { - throw new Error('Error verifying SIWE signature') - } - if (this.methods.onSignIn) { - this.methods.onSignIn(session) - } - - RouterUtil.navigateAfterNetworkSwitch() - - return session - } catch (error) { - SnackController.showError((error as Error).message) - await ConnectionController.disconnect() - ModalController.close() - throw error + const session = await this.methods.getSession() + if (!session) { + throw new Error('Error verifying SIWE signature') } + if (this.methods.onSignIn) { + this.methods.onSignIn(session) + } + + RouterUtil.navigateAfterNetworkSwitch() + + return session } async signOut() {