fix: close WalletModal on connection (#4670)

* fix: close WalletModal on connection

* fix test
This commit is contained in:
vignesh mohankumar 2022-09-20 14:08:09 -04:00 committed by GitHub
parent 16a5e15070
commit 04164a550d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

@ -24,6 +24,7 @@ describe('Wallet', () => {
}) })
it('shows connect buttons after disconnect', () => { it('shows connect buttons after disconnect', () => {
cy.get('[data-testid=web3-status-connected]').contains(TEST_ADDRESS_NEVER_USE_SHORTENED).click()
cy.contains('Disconnect').click() cy.contains('Disconnect').click()
cy.get('[data-testid=option-grid]').should('exist') cy.get('[data-testid=option-grid]').should('exist')
}) })

@ -8,6 +8,7 @@ import { AutoColumn } from 'components/Column'
import { AutoRow } from 'components/Row' import { AutoRow } from 'components/Row'
import { getConnection, getConnectionName, getIsCoinbaseWallet, getIsInjected, getIsMetaMask } from 'connection/utils' import { getConnection, getConnectionName, getIsCoinbaseWallet, getIsInjected, getIsMetaMask } from 'connection/utils'
import { RedesignVariant, useRedesignFlag } from 'featureFlags/flags/redesign' import { RedesignVariant, useRedesignFlag } from 'featureFlags/flags/redesign'
import usePrevious from 'hooks/usePrevious'
import { useCallback, useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
import { ArrowLeft } from 'react-feather' import { ArrowLeft } from 'react-feather'
import { updateConnectionError } from 'state/connection/reducer' import { updateConnectionError } from 'state/connection/reducer'
@ -149,6 +150,8 @@ export default function WalletModal({
}) { }) {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const { connector, account, chainId } = useWeb3React() const { connector, account, chainId } = useWeb3React()
const previousAccount = usePrevious(account)
const [connectedWallets, addWalletToConnectedWallets] = useConnectedWallets() const [connectedWallets, addWalletToConnectedWallets] = useConnectedWallets()
const redesignFlag = useRedesignFlag() const redesignFlag = useRedesignFlag()
@ -174,6 +177,12 @@ export default function WalletModal({
} }
}, [walletModalOpen, setWalletView, account]) }, [walletModalOpen, setWalletView, account])
useEffect(() => {
if (account && account !== previousAccount && walletModalOpen) {
toggleWalletModal()
}
}, [account, previousAccount, toggleWalletModal, walletModalOpen])
useEffect(() => { useEffect(() => {
if (pendingConnector && walletView !== WALLET_VIEWS.PENDING) { if (pendingConnector && walletView !== WALLET_VIEWS.PENDING) {
updateConnectionError({ connectionType: getConnection(pendingConnector).type, error: undefined }) updateConnectionError({ connectionType: getConnection(pendingConnector).type, error: undefined })