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

feat: disconnect for coinbase wallet (#3993)

* feat: disconnect for coinbase wallet

* change isActive logic

* remove logs

* reset state for coinbase wallet

* active -> isActive

* rm data-cy
parent d36f13d7
...@@ -265,19 +265,28 @@ export default function AccountDetails({ ...@@ -265,19 +265,28 @@ export default function AccountDetails({
<AccountGroupingRow> <AccountGroupingRow>
{formatConnectorName()} {formatConnectorName()}
<div> <div>
{/* Coinbase Wallet reloads the page right now, which breaks the selectedWallet from being set properly on localStorage */}
{connector !== coinbaseWallet && (
<WalletAction <WalletAction
style={{ fontSize: '.825rem', fontWeight: 400, marginRight: '8px' }} style={{ fontSize: '.825rem', fontWeight: 400, marginRight: '8px' }}
onClick={() => { onClick={() => {
connector.deactivate ? connector.deactivate() : connector.resetState() if (connector.deactivate) {
connector.deactivate()
// Coinbase Wallet SDK does not emit a disconnect event to the provider,
// which is what web3-react uses to reset state. As a workaround we manually
// reset state.
if (connector === coinbaseWallet) {
connector.resetState()
}
} else {
connector.resetState()
}
dispatch(updateSelectedWallet({ wallet: undefined })) dispatch(updateSelectedWallet({ wallet: undefined }))
openOptions() openOptions()
}} }}
> >
<Trans>Disconnect</Trans> <Trans>Disconnect</Trans>
</WalletAction> </WalletAction>
)}
<WalletAction <WalletAction
style={{ fontSize: '.825rem', fontWeight: 400 }} style={{ fontSize: '.825rem', fontWeight: 400 }}
onClick={() => { onClick={() => {
......
...@@ -3,8 +3,8 @@ import styled from 'styled-components/macro' ...@@ -3,8 +3,8 @@ import styled from 'styled-components/macro'
import { ExternalLink } from '../../theme' import { ExternalLink } from '../../theme'
const InfoCard = styled.button<{ active?: boolean }>` const InfoCard = styled.button<{ isActive?: boolean }>`
background-color: ${({ theme, active }) => (active ? theme.bg3 : theme.bg2)}; background-color: ${({ theme, isActive }) => (isActive ? theme.bg3 : theme.bg2)};
padding: 1rem; padding: 1rem;
outline: none; outline: none;
border: 1px solid; border: 1px solid;
...@@ -13,7 +13,7 @@ const InfoCard = styled.button<{ active?: boolean }>` ...@@ -13,7 +13,7 @@ const InfoCard = styled.button<{ active?: boolean }>`
&:focus { &:focus {
box-shadow: 0 0 0 1px ${({ theme }) => theme.primary1}; box-shadow: 0 0 0 1px ${({ theme }) => theme.primary1};
} }
border-color: ${({ theme, active }) => (active ? 'transparent' : theme.bg3)}; border-color: ${({ theme, isActive }) => (isActive ? 'transparent' : theme.bg3)};
` `
const OptionCard = styled(InfoCard as any)` const OptionCard = styled(InfoCard as any)`
...@@ -97,7 +97,7 @@ export default function Option({ ...@@ -97,7 +97,7 @@ export default function Option({
header, header,
subheader = null, subheader = null,
icon, icon,
active = false, isActive = false,
id, id,
}: { }: {
link?: string | null link?: string | null
...@@ -108,20 +108,20 @@ export default function Option({ ...@@ -108,20 +108,20 @@ export default function Option({
header: React.ReactNode header: React.ReactNode
subheader: React.ReactNode | null subheader: React.ReactNode | null
icon: string icon: string
active?: boolean isActive?: boolean
id: string id: string
}) { }) {
const content = ( const content = (
<OptionCardClickable <OptionCardClickable
id={id} id={id}
onClick={onClick} onClick={onClick}
clickable={clickable && !active} clickable={clickable && !isActive}
active={active} active={isActive}
data-testid="wallet-modal-option" data-testid="wallet-modal-option"
> >
<OptionCardLeft> <OptionCardLeft>
<HeaderText color={color}> <HeaderText color={color}>
{active ? ( {isActive ? (
<CircleWrapper> <CircleWrapper>
<GreenCircle> <GreenCircle>
<div /> <div />
......
...@@ -189,10 +189,9 @@ export default function WalletModal({ ...@@ -189,10 +189,9 @@ export default function WalletModal({
const isCoinbaseWallet = !!window.ethereum?.isCoinbaseWallet const isCoinbaseWallet = !!window.ethereum?.isCoinbaseWallet
return Object.keys(SUPPORTED_WALLETS).map((key) => { return Object.keys(SUPPORTED_WALLETS).map((key) => {
const option = SUPPORTED_WALLETS[key] const option = SUPPORTED_WALLETS[key]
const isActive = option.connector === connector
const optionProps = { const optionProps = {
active: isActive, isActive: option.connector === connector,
id: `connect-${key}`, id: `connect-${key}`,
link: option.href, link: option.href,
header: option.name, header: option.name,
...@@ -212,7 +211,7 @@ export default function WalletModal({ ...@@ -212,7 +211,7 @@ export default function WalletModal({
<Option <Option
{...optionProps} {...optionProps}
onClick={() => { onClick={() => {
if (!isActive && !option.href && !!option.connector) { if (!option.href && !!option.connector) {
tryActivation(option.connector) tryActivation(option.connector)
} }
}} }}
...@@ -262,7 +261,7 @@ export default function WalletModal({ ...@@ -262,7 +261,7 @@ export default function WalletModal({
}} }}
color={'#E8831D'} color={'#E8831D'}
header={<Trans>Tally</Trans>} header={<Trans>Tally</Trans>}
active={option.connector === connector} isActive={option.connector === connector}
subheader={null} subheader={null}
link={null} link={null}
icon={TallyIcon} icon={TallyIcon}
......
...@@ -114,6 +114,7 @@ export const [coinbaseWallet, coinbaseWalletHooks] = initializeConnector<Coinbas ...@@ -114,6 +114,7 @@ export const [coinbaseWallet, coinbaseWalletHooks] = initializeConnector<Coinbas
url: INFURA_NETWORK_URLS[SupportedChainId.MAINNET], url: INFURA_NETWORK_URLS[SupportedChainId.MAINNET],
appName: 'Uniswap', appName: 'Uniswap',
appLogoUrl: UNISWAP_LOGO_URL, appLogoUrl: UNISWAP_LOGO_URL,
reloadOnDisconnect: false,
}, },
onError, onError,
}) })
......
...@@ -1285,7 +1285,7 @@ ...@@ -1285,7 +1285,7 @@
exec-sh "^0.3.2" exec-sh "^0.3.2"
minimist "^1.2.0" minimist "^1.2.0"
"@coinbase/wallet-sdk@^3.2.0": "@coinbase/wallet-sdk@^3.3.0":
version "3.3.0" version "3.3.0"
resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-3.3.0.tgz#e77383bce1388e5367dc35f8309702e73be47503" resolved "https://registry.yarnpkg.com/@coinbase/wallet-sdk/-/wallet-sdk-3.3.0.tgz#e77383bce1388e5367dc35f8309702e73be47503"
integrity sha512-Prmxs5eYRxe5i+kDSsny97oPG4Pa5PhLmNDx8f7UQrvlPowGy5Tg0gHOqCie6ck2shVMdW8sKJ+RCLIRZ9kIjA== integrity sha512-Prmxs5eYRxe5i+kDSsny97oPG4Pa5PhLmNDx8f7UQrvlPowGy5Tg0gHOqCie6ck2shVMdW8sKJ+RCLIRZ9kIjA==
......
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