Commit 07101787 authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

feat: don't allow disconnect/change on injected mobile wallets (#4015)

* feat: don't allow disconnect/change on injected mobile wallets

* new variable
parent 5535c83d
...@@ -7,6 +7,7 @@ import { ExternalLink as LinkIcon } from 'react-feather' ...@@ -7,6 +7,7 @@ import { ExternalLink as LinkIcon } from 'react-feather'
import { useAppDispatch } from 'state/hooks' import { useAppDispatch } from 'state/hooks'
import { updateSelectedWallet } from 'state/user/reducer' import { updateSelectedWallet } from 'state/user/reducer'
import styled, { ThemeContext } from 'styled-components/macro' import styled, { ThemeContext } from 'styled-components/macro'
import { isMobile } from 'utils/userAgent'
import { ReactComponent as Close } from '../../assets/images/x.svg' import { ReactComponent as Close } from '../../assets/images/x.svg'
import { coinbaseWallet, injected } from '../../connectors' import { coinbaseWallet, injected } from '../../connectors'
...@@ -230,6 +231,10 @@ export default function AccountDetails({ ...@@ -230,6 +231,10 @@ export default function AccountDetails({
const theme = useContext(ThemeContext) const theme = useContext(ThemeContext)
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const isMetaMask = !!window.ethereum?.isMetaMask
const isCoinbaseWallet = !!window.ethereum?.isCoinbaseWallet
const isInjectedMobileBrowser = (isMetaMask || isCoinbaseWallet) && isMobile
function formatConnectorName() { function formatConnectorName() {
const { ethereum } = window const { ethereum } = window
const isMetaMask = !!(ethereum && ethereum.isMetaMask) const isMetaMask = !!(ethereum && ethereum.isMetaMask)
...@@ -265,36 +270,40 @@ export default function AccountDetails({ ...@@ -265,36 +270,40 @@ export default function AccountDetails({
<AccountGroupingRow> <AccountGroupingRow>
{formatConnectorName()} {formatConnectorName()}
<div> <div>
<WalletAction {!isInjectedMobileBrowser && (
style={{ fontSize: '.825rem', fontWeight: 400, marginRight: '8px' }} <>
onClick={() => { <WalletAction
if (connector.deactivate) { style={{ fontSize: '.825rem', fontWeight: 400, marginRight: '8px' }}
connector.deactivate() onClick={() => {
if (connector.deactivate) {
// Coinbase Wallet SDK does not emit a disconnect event to the provider, connector.deactivate()
// which is what web3-react uses to reset state. As a workaround we manually
// reset state. // Coinbase Wallet SDK does not emit a disconnect event to the provider,
if (connector === coinbaseWallet) { // which is what web3-react uses to reset state. As a workaround we manually
connector.resetState() // reset state.
} if (connector === coinbaseWallet) {
} else { connector.resetState()
connector.resetState() }
} } else {
connector.resetState()
dispatch(updateSelectedWallet({ wallet: undefined })) }
openOptions()
}} dispatch(updateSelectedWallet({ wallet: undefined }))
> openOptions()
<Trans>Disconnect</Trans> }}
</WalletAction> >
<WalletAction <Trans>Disconnect</Trans>
style={{ fontSize: '.825rem', fontWeight: 400 }} </WalletAction>
onClick={() => { <WalletAction
openOptions() style={{ fontSize: '.825rem', fontWeight: 400 }}
}} onClick={() => {
> openOptions()
<Trans>Change</Trans> }}
</WalletAction> >
<Trans>Change</Trans>
</WalletAction>
</>
)}
</div> </div>
</AccountGroupingRow> </AccountGroupingRow>
<AccountGroupingRow data-testid="web3-account-identifier-row"> <AccountGroupingRow data-testid="web3-account-identifier-row">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment