Skip to content

Commit

Permalink
fix: siwe modal not opening for some wallets (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
magiziz authored Oct 7, 2024
1 parent 8b93b1c commit e1b8720
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
26 changes: 26 additions & 0 deletions .changeset/giant-moons-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@reown/appkit-scaffold-ui': patch
'@apps/laboratory': patch
'@apps/demo': patch
'@apps/gallery': 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-ethers': patch
'@reown/appkit-ethers5': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-siwe': patch
'@reown/appkit-solana': patch
'@reown/appkit-ui': patch
'@reown/appkit-wagmi': patch
'@reown/appkit-wallet': patch
---

Fixed an issue where SIWE modal wasn't showing up for some mobile wallets.
28 changes: 17 additions & 11 deletions packages/scaffold-ui/src/modal/w3m-modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,31 +189,37 @@ export class W3mModal extends LitElement {
}

private async onNewAddress(caipAddress?: CaipAddress) {
const prevConnected = this.caipAddress
? CoreHelperUtil.getPlainAddress(this.caipAddress)
const prevCaipAddress = this.caipAddress
const prevConnected = prevCaipAddress
? CoreHelperUtil.getPlainAddress(prevCaipAddress)
: undefined
const nextConnected = caipAddress ? CoreHelperUtil.getPlainAddress(caipAddress) : undefined
const isSameAddress = prevConnected === nextConnected

this.caipAddress = caipAddress

if (nextConnected && !isSameAddress && this.isSiweEnabled) {
const { SIWEController } = await import('@reown/appkit-siwe')
const signed = AccountController.state.siweStatus === 'success'
try {
const { SIWEController } = await import('@reown/appkit-siwe')
const signed = AccountController.state.siweStatus === 'success'

if (!prevConnected && nextConnected) {
this.onSiweNavigation()
} else if (signed && prevConnected && nextConnected && prevConnected !== nextConnected) {
if (SIWEController.state._client?.options.signOutOnAccountChange) {
await SIWEController.signOut()
if (!prevConnected && nextConnected) {
this.onSiweNavigation()
} else if (signed && prevConnected && nextConnected && prevConnected !== nextConnected) {
if (SIWEController.state._client?.options.signOutOnAccountChange) {
await SIWEController.signOut()
this.onSiweNavigation()
}
}
} catch (err) {
this.caipAddress = prevCaipAddress
throw err
}
}

if (!nextConnected) {
ModalController.close()
}

this.caipAddress = caipAddress
}

private async onNewNetwork(nextCaipNetwork: CaipNetwork | undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class W3mConnectingWcView extends LitElement {

@state() private platforms: Platform[] = []

@state() private isSiweEnabled = OptionsController.state.isSiweEnabled

public constructor() {
super()
this.determinePlatforms()
Expand Down Expand Up @@ -72,7 +74,7 @@ export class W3mConnectingWcView extends LitElement {
OptionsController.state.hasMultipleAddresses
) {
RouterController.push('SelectAddresses')
} else {
} else if (!this.isSiweEnabled) {
ModalController.close()
}
}
Expand Down

0 comments on commit e1b8720

Please sign in to comment.