fix: clearing input on connect wallet (#6928)
* fix: clearing input on connect wallet * update e2e tests
This commit is contained in:
parent
02883aca13
commit
3f812f4aee
@ -2,7 +2,7 @@ import { getTestSelector } from '../../utils'
|
|||||||
import { DISCONNECTED_WALLET_USER_STATE } from '../../utils/user-state'
|
import { DISCONNECTED_WALLET_USER_STATE } from '../../utils/user-state'
|
||||||
|
|
||||||
describe('disconnect wallet', () => {
|
describe('disconnect wallet', () => {
|
||||||
it('should clear state', () => {
|
it('should not clear state', () => {
|
||||||
cy.visit('/swap', { ethereum: 'hardhat' })
|
cy.visit('/swap', { ethereum: 'hardhat' })
|
||||||
cy.get('#swap-currency-input .token-amount-input').clear().type('1')
|
cy.get('#swap-currency-input .token-amount-input').clear().type('1')
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ describe('disconnect wallet', () => {
|
|||||||
cy.contains('Connect Wallet')
|
cy.contains('Connect Wallet')
|
||||||
|
|
||||||
// Verify swap input is cleared
|
// Verify swap input is cleared
|
||||||
cy.get('#swap-currency-input .token-amount-input').should('have.value', '')
|
cy.get('#swap-currency-input .token-amount-input').should('have.value', '1')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import { TraceJsonRpcVariant, useTraceJsonRpcFlag } from 'featureFlags/flags/tra
|
|||||||
import useEagerlyConnect from 'hooks/useEagerlyConnect'
|
import useEagerlyConnect from 'hooks/useEagerlyConnect'
|
||||||
import useOrderedConnections from 'hooks/useOrderedConnections'
|
import useOrderedConnections from 'hooks/useOrderedConnections'
|
||||||
import usePrevious from 'hooks/usePrevious'
|
import usePrevious from 'hooks/usePrevious'
|
||||||
import { ReactNode, useEffect, useMemo, useState } from 'react'
|
import { ReactNode, useEffect } from 'react'
|
||||||
import { useLocation } from 'react-router-dom'
|
import { useLocation } from 'react-router-dom'
|
||||||
import { useConnectedWallets } from 'state/wallets/hooks'
|
import { useConnectedWallets } from 'state/wallets/hooks'
|
||||||
import { getCurrentPageFromLocation } from 'utils/urlRoutes'
|
import { getCurrentPageFromLocation } from 'utils/urlRoutes'
|
||||||
@ -20,16 +20,8 @@ export default function Web3Provider({ children }: { children: ReactNode }) {
|
|||||||
const connections = useOrderedConnections()
|
const connections = useOrderedConnections()
|
||||||
const connectors: [Connector, Web3ReactHooks][] = connections.map(({ hooks, connector }) => [connector, hooks])
|
const connectors: [Connector, Web3ReactHooks][] = connections.map(({ hooks, connector }) => [connector, hooks])
|
||||||
|
|
||||||
// Force a re-render when our connection state changes.
|
|
||||||
const [index, setIndex] = useState(0)
|
|
||||||
useEffect(() => setIndex((index) => index + 1), [connections])
|
|
||||||
const key = useMemo(
|
|
||||||
() => connections.map((connection) => connection.getName()).join('-') + index,
|
|
||||||
[connections, index]
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Web3ReactProvider connectors={connectors} key={key}>
|
<Web3ReactProvider connectors={connectors}>
|
||||||
<Updater />
|
<Updater />
|
||||||
{children}
|
{children}
|
||||||
</Web3ReactProvider>
|
</Web3ReactProvider>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { getConnection } from 'connection'
|
import { getConnection } from 'connection'
|
||||||
import { ConnectionType } from 'connection/types'
|
import { ConnectionType } from 'connection/types'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useAppSelector } from 'state/hooks'
|
|
||||||
|
|
||||||
const SELECTABLE_WALLETS = [
|
const SELECTABLE_WALLETS = [
|
||||||
ConnectionType.UNISWAP_WALLET_V2,
|
ConnectionType.UNISWAP_WALLET_V2,
|
||||||
@ -11,23 +10,17 @@ const SELECTABLE_WALLETS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export default function useOrderedConnections() {
|
export default function useOrderedConnections() {
|
||||||
const selectedWallet = useAppSelector((state) => state.user.selectedWallet)
|
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const orderedConnectionTypes: ConnectionType[] = []
|
const orderedConnectionTypes: ConnectionType[] = []
|
||||||
|
|
||||||
// Always attempt to use to Gnosis Safe first, as we can't know if we're in a SafeContext.
|
// Always attempt to use to Gnosis Safe first, as we can't know if we're in a SafeContext.
|
||||||
orderedConnectionTypes.push(ConnectionType.GNOSIS_SAFE)
|
orderedConnectionTypes.push(ConnectionType.GNOSIS_SAFE)
|
||||||
|
|
||||||
// Add the `selectedWallet` to the top so it's prioritized, then add the other selectable wallets.
|
orderedConnectionTypes.push(...SELECTABLE_WALLETS)
|
||||||
if (selectedWallet) {
|
|
||||||
orderedConnectionTypes.push(selectedWallet)
|
|
||||||
}
|
|
||||||
orderedConnectionTypes.push(...SELECTABLE_WALLETS.filter((wallet) => wallet !== selectedWallet))
|
|
||||||
|
|
||||||
// Add network connection last as it should be the fallback.
|
// Add network connection last as it should be the fallback.
|
||||||
orderedConnectionTypes.push(ConnectionType.NETWORK)
|
orderedConnectionTypes.push(ConnectionType.NETWORK)
|
||||||
|
|
||||||
return orderedConnectionTypes.map((connectionType) => getConnection(connectionType))
|
return orderedConnectionTypes.map((connectionType) => getConnection(connectionType))
|
||||||
}, [selectedWallet])
|
}, [])
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user