Skip to content

Commit

Permalink
fix: remove condition on SIWE sign out mapping (#3286)
Browse files Browse the repository at this point in the history
Co-authored-by: tomiir <rocchitomas@gmail.com>
  • Loading branch information
zoruka and tomiir authored Nov 21, 2024
1 parent 4417c7b commit 2c82245
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
24 changes: 24 additions & 0 deletions .changeset/itchy-onions-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@reown/appkit-siwe': patch
'@apps/demo': patch
'@apps/gallery': patch
'@apps/laboratory': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-polkadot': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
---

Remove condition from SIWE signOut returning false to keep backwards compatibility
33 changes: 23 additions & 10 deletions packages/siwe/src/mapToSIWX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ import type { AppKitSIWEClient } from '../exports/index.js'
import { NetworkUtil } from '@reown/appkit-common'

export function mapToSIWX(siwe: AppKitSIWEClient): SIWXConfig {
async function getSession() {
try {
return await siwe.methods.getSession()
} catch (error) {
console.warn('AppKit:SIWE:getSession - error:', error)

return undefined
}
}

ChainController.subscribeKey('activeCaipNetwork', async activeCaipNetwork => {
if (!siwe.options.signOutOnNetworkChange) {
return
}

const session = await siwe.methods.getSession().catch(() => undefined)
const session = await getSession()
const isDiffernetNetwork =
session &&
session.chainId !== NetworkUtil.caipNetworkIdToNumber(activeCaipNetwork?.caipNetworkId)
Expand All @@ -29,7 +39,7 @@ export function mapToSIWX(siwe: AppKitSIWEClient): SIWXConfig {
return
}

const session = await siwe.methods.getSession().catch(() => undefined)
const session = await getSession()
const isDifferentAddress =
session && session.address !== CoreHelperUtil.getPlainAddress(activeCaipAddress)

Expand Down Expand Up @@ -96,18 +106,21 @@ export function mapToSIWX(siwe: AppKitSIWEClient): SIWXConfig {
},

async revokeSession(_chainId, _address) {
if (await siwe.signOut()) {
try {
await siwe.methods.signOut()
siwe.methods.onSignOut?.()

return Promise.resolve()
} catch (error) {
console.warn('AppKit:SIWE:revokeSession - signOut error', error)
}

throw new Error('Failed to sign out')
},

async setSessions(sessions) {
if (sessions.length === 0) {
await siwe.methods.signOut()
try {
await siwe.methods.signOut()
} catch (error) {
console.warn('AppKit:SIWE:setSessions - signOut error', error)
}
} else {
const addingSessions = sessions.map(session => this.addSession(session))
await Promise.all(addingSessions)
Expand All @@ -130,7 +143,7 @@ export function mapToSIWX(siwe: AppKitSIWEClient): SIWXConfig {
]
}

const siweSession = await siwe.methods.getSession()
const siweSession = await getSession()

const siweCaipNetworkId = `eip155:${siweSession?.chainId}`
if (!siweSession || siweSession.address !== address || siweCaipNetworkId !== chainId) {
Expand All @@ -149,7 +162,7 @@ export function mapToSIWX(siwe: AppKitSIWEClient): SIWXConfig {
return [session]
} catch (error) {
// eslint-disable-next-line no-console
console.error('SIWE:getSessions - error:', error)
console.warn('AppKit:SIWE:getSessions - error:', error)

return []
}
Expand Down

0 comments on commit 2c82245

Please sign in to comment.