Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing network not supported modal on wallet network switch #2565

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/laboratory/tests/shared/pages/WalletPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,29 @@ export class WalletPage {
await btn.focus()
await this.page.keyboard.press('Space')
}

/**
* Enables testnets in the wallet settings
*/
async enableTestnets() {
await this.page.waitForLoadState()
const settingsButton = this.page.getByTestId('settings')
await settingsButton.click()
const testnetSwitch = this.page.getByTestId('settings-toggle-testnets')
await testnetSwitch.click()
expect(testnetSwitch).toHaveAttribute('data-state', 'checked')
}

/**
* Switches the network in the wallet
* @param network the network id to switch (e.g. eip155:1 for Ethereum Mainnet)
*/
async switchNetwork(network: string) {
await this.page.waitForLoadState()
const networkButton = this.page.getByTestId('accounts')
await networkButton.click()
const switchNetworkButton = this.page.getByTestId(`chain-switch-button${network}`)
await switchNetworkButton.click()
await expect(switchNetworkButton).toHaveText('✅')
}
}
10 changes: 10 additions & 0 deletions apps/laboratory/tests/shared/validators/ModalValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ export class ModalValidator {

expect(accounts.length).toBeGreaterThan(1)
}

async expectNetworkNotSupportedVisible() {
const networkNotSupportedMessage = this.page.getByText(
'This app doesn’t support your current network. Switch to an available option to continue.'
)
await expect(
networkNotSupportedMessage,
'Network not supported message should be visible'
).toBeVisible()
}
}
13 changes: 13 additions & 0 deletions apps/laboratory/tests/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,16 @@ testConnectedMW('it should show multiple accounts', async ({ modalPage, modalVal
await modalValidator.expectMultipleAccounts()
await modalPage.closeModal()
})

testConnectedMW(
'it should show Switch Network modal if network is not supported',
async ({ modalPage, modalValidator, walletPage }) => {
if (modalPage.library === 'solana') {
return
}
Comment on lines +85 to +87
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ganchoradkov now that RPC supports solana testnet/devnet can we add them to react-wallet?

await walletPage.enableTestnets()
await walletPage.switchNetwork('eip155:5')
await modalValidator.expectNetworkNotSupportedVisible()
await modalPage.closeModal()
}
)
10 changes: 6 additions & 4 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export const NetworkController = {
PublicStateController.set({ activeChain: chain, selectedNetworkId: caipNetwork?.id })

if (!ChainController.state.chains.get(chain)?.networkState?.allowUnsupportedChain) {
this.checkIfSupportedNetwork()
const isSupported = this.checkIfSupportedNetwork()

if (!isSupported) {
this.showUnsupportedChainUI()
}
}
},

Expand Down Expand Up @@ -258,9 +262,7 @@ export const NetworkController = {
},

checkIfSupportedNetwork() {
const chain = ChainController.state.multiChainEnabled
? ChainController.state.activeChain
: ChainController.state.activeChain
const chain = ChainController.state.activeChain

if (!chain) {
return false
Expand Down
Loading