Skip to content

Commit 6b543c3

Browse files
authored
Fix: Cross-Namespace Wallet Switching (#5228)
1 parent 3e09219 commit 6b543c3

4 files changed

Lines changed: 60 additions & 2 deletions

File tree

.changeset/cool-comics-buy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@reown/appkit-scaffold-ui': patch
3+
'@reown/appkit-ui': patch
4+
---
5+
6+
Fixes an issue where the UI would show incorrect possibility to switch wallet in profile wallets view

apps/laboratory/tests/multichain-extension.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,48 @@ extensionTest(
152152
}
153153
)
154154

155+
extensionTest(
156+
'it should connect with email on Ethereum, switch to a different chain and be able to switch account type on Ethereum',
157+
async () => {
158+
const mailsacApiKey = process.env['MAILSAC_API_KEY']
159+
if (!mailsacApiKey) {
160+
throw new Error('MAILSAC_API_KEY is not set')
161+
}
162+
163+
const email = new Email(mailsacApiKey)
164+
await modalPage.emailFlow({
165+
emailAddress: await email.getEmailAddressToUse(),
166+
context: modalPage.page.context(),
167+
mailsacApiKey,
168+
clickConnectButton: true
169+
})
170+
await modalValidator.expectConnected()
171+
172+
const emailEthAddress = (await modalPage.page
173+
.getByTestId('w3m-address')
174+
.textContent()) as string
175+
176+
await modalPage.switchNetwork('Solana', true)
177+
await modalPage.closeModal()
178+
await modalValidator.expectConnected()
179+
await modalValidator.expectNetworkButton('Solana')
180+
await modalPage.openProfileWalletsView()
181+
await modalPage.clickTab('evm')
182+
await modalPage.switchAccount()
183+
await modalPage.closeModal()
184+
await modalValidator.expectConnected()
185+
await modalValidator.expectNetworkButton('Ethereum')
186+
await modalPage.openProfileWalletsView()
187+
await modalPage.clickTab('evm')
188+
await modalPage.switchAccount()
189+
await modalPage.closeModal()
190+
await modalValidator.expectAccountButtonAddress(emailEthAddress)
191+
await modalPage.openProfileWalletsView()
192+
await modalPage.clickProfileWalletsMoreButton()
193+
await modalPage.disconnect(false)
194+
}
195+
)
196+
155197
extensionTest('it should be disconnected after page refresh', async () => {
156198
await modalPage.page.reload()
157199
await modalValidator.expectDisconnected()

packages/scaffold-ui/src/views/w3m-profile-wallets-view/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,13 @@ export class W3mProfileWalletsView extends LitElement {
513513
this.lastSelectedConnectorId = connection.connectorId
514514
this.lastSelectedAddress = address
515515

516+
const isDifferentNamespace = this.caipNetwork?.chainNamespace !== namespace
517+
518+
if (isDifferentNamespace && connection?.caipNetwork) {
519+
ConnectorController.setFilterByNamespace(namespace)
520+
await ChainController.switchActiveNetwork(connection?.caipNetwork)
521+
}
522+
516523
await ConnectionController.switchConnection({
517524
connection,
518525
address,

packages/scaffold-ui/test/views/w3m-profile-wallets-view.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const mockEthereumNetwork = {
3737
id: 1,
3838
name: 'Ethereum',
3939
namespace: ConstantsUtil.CHAIN.EVM,
40+
chainNamespace: ConstantsUtil.CHAIN.EVM,
4041
blockExplorers: {
4142
default: { url: 'https://etherscan.io' }
4243
}
@@ -45,13 +46,15 @@ const mockEthereumNetwork = {
4546
const mockSolanaNetwork = {
4647
id: 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp',
4748
name: 'Solana',
48-
namespace: ConstantsUtil.CHAIN.SOLANA
49+
namespace: ConstantsUtil.CHAIN.SOLANA,
50+
chainNamespace: ConstantsUtil.CHAIN.SOLANA
4951
} as unknown as CaipNetwork
5052

5153
const mockBitcoinNetwork = {
5254
id: 'bitcoin:000000000019d6689c085ae165831e93',
5355
name: 'Bitcoin',
54-
namespace: ConstantsUtil.CHAIN.BITCOIN
56+
namespace: ConstantsUtil.CHAIN.BITCOIN,
57+
chainNamespace: ConstantsUtil.CHAIN.BITCOIN
5558
} as unknown as CaipNetwork
5659

5760
const mockMetaMaskConnector = {

0 commit comments

Comments
 (0)