Skip to content

Commit

Permalink
Merge pull request #172 from chain4travel/fix-network
Browse files Browse the repository at this point in the history
fix switching to logged in network
  • Loading branch information
aeddaqqa authored Dec 29, 2023
2 parents 1748af5 + f37dcb3 commit 6ccb8e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
24 changes: 18 additions & 6 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@ Cypress.Commands.add('changeNetwork', (network: string = 'Kopernikus') => {
cy.get('@txtSelectedNetwork')
.invoke('text')
.then(currentNetwork => {
cy.get('@btnNetworkSwitcher').click({ force: true }) // Network Switcher
cy.get(`[data-value="${network}"]`).click() // Select Network

// Waiting 'info.networkID', and 'info.getTxFee'
cy.wait('@getNetworkID').then(interceptNetworkInfo)
cy.wait('@getTxFee').then(interceptNetworkInfo)
if (currentNetwork !== network) {
// Only perform the switch if the current network is different
cy.get('@btnNetworkSwitcher').click({ force: true })
cy.get(`[data-value="${network}"]`).click()

// After switching, wait for the network requests
cy.wait('@getNetworkID').then(interceptNetworkInfo)
cy.wait('@getTxFee').then(interceptNetworkInfo)
} else {
cy.get('body').then($body => {
if ($body.find(`[data-value="${network}"]`).length > 0) {
cy.get(`[data-value="${network}"]`).click()
} else {
cy.log(`Network option '${network}' not found.`)
}
})
cy.log(`Already on the '${network}' network, no switch needed.`)
}

// increasing timeout to make sure the network is selected, especially on slowly local dev env
cy.get('@txtSelectedNetwork', { timeout: 15000 }).should('have.text', network)
Expand Down
13 changes: 11 additions & 2 deletions src/components/Navbar/NetworkSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ export default function NetworkSwitcher({ handleCloseSidebar }: NetworkSwitcherP
flexDirection: 'column',
alignItems: 'baseline',
color: theme.palette.text.primary,
...(network.name === activeNetwork.name && { cursor: 'auto' }),
}}
onClick={() => {
if (network.name === activeNetwork.name) return
changeNetwork(network.name)
}}
onClick={() => changeNetwork(network.name)}
>
<Stack
direction="row"
Expand Down Expand Up @@ -194,9 +198,14 @@ export default function NetworkSwitcher({ handleCloseSidebar }: NetworkSwitcherP
value={network.name}
divider
onClick={() => {
if (network.name === activeNetwork.name) return
handleChangeNetwork(network.name)
}}
sx={{ gap: '.6rem', justifyContent: 'space-between' }}
sx={{
gap: '.6rem',
justifyContent: 'space-between',
...(network.name === activeNetwork.name && { cursor: 'auto' }),
}}
data-cy={`network-name-${network.name}`}
>
<Typography variant="body2" component="span" noWrap>
Expand Down

0 comments on commit 6ccb8e9

Please sign in to comment.