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

chore: delete WalletConnect v1 (#6857)

* chore: remove walletConnectFallback flag

* chore: remove walletConnectV2 flag

* chore: delete WalletConnect v1

* chore: remove walletConnectV2 flag (#6856)

* rm hidden

* toggle account drawer

* fix test

* Revert "rm hidden"

This reverts commit 9e8dd65b04b1072d3565cb70defb46d1524791f3.

* fix test

* -u

* optional?

* Revert "optional?"

This reverts commit 8456080b78cfae58737918daeb929bdaf0758cba.

* switch mock

* expect

* test

* fix test

* update connection tests
parent c8a17f5f
......@@ -42,10 +42,9 @@ export default function UniwalletModal() {
const [uri, setUri] = useState<string>()
// Displays the modal if a Uniswap Wallet Connection is pending & qrcode URI is available
const uniswapWalletConnectors = [ConnectionType.UNISWAP_WALLET, ConnectionType.UNISWAP_WALLET_V2]
const open =
activationState.status === ActivationStatus.PENDING &&
uniswapWalletConnectors.includes(activationState.connection.type) &&
activationState.connection.type === ConnectionType.UNISWAP_WALLET_V2 &&
!!uri
useEffect(() => {
......
......@@ -112,9 +112,9 @@ exports[`StatusIcon with account renders children in correct order 1`] = `
class="c1"
>
<img
alt="Install MetaMask icon"
alt="WalletConnect icon"
class="c2"
src="metamask-icon.svg"
src="walletconnect-icon.svg"
/>
</div>
<div
......@@ -240,9 +240,9 @@ exports[`StatusIcon with no account renders children in correct order 1`] = `
class="c1"
>
<img
alt="Install MetaMask icon"
alt="WalletConnect icon"
class="c2"
src="metamask-icon.svg"
src="walletconnect-icon.svg"
/>
</div>
<div
......
import { t } from '@lingui/macro'
import { ChainId } from '@uniswap/sdk-core'
import { useWeb3React } from '@web3-react/core'
import { WalletConnect } from '@web3-react/walletconnect-v2'
import { showTestnetsAtom } from 'components/AccountDrawer/TestnetsToggle'
import { MouseoverTooltip } from 'components/Tooltip'
import { getConnection } from 'connection'
import { ConnectionType } from 'connection/types'
import { WalletConnectV2 } from 'connection/WalletConnectV2'
import { getChainInfo } from 'constants/chainInfo'
import { L1_CHAIN_IDS, L2_CHAIN_IDS, TESTNET_CHAIN_IDS, UniWalletSupportedChains } from 'constants/chains'
import { useOnClickOutside } from 'hooks/useOnClickOutside'
......@@ -38,8 +38,8 @@ function useWalletSupportedChains(): ChainId[] {
switch (connectionType) {
case ConnectionType.WALLET_CONNECT_V2:
return getSupportedChainIdsFromWalletConnectSession((connector as WalletConnect).provider?.session)
case ConnectionType.UNISWAP_WALLET:
return getSupportedChainIdsFromWalletConnectSession((connector as WalletConnectV2).provider?.session)
case ConnectionType.UNISWAP_WALLET_V2:
return UniWalletSupportedChains
default:
return NETWORK_SELECTOR_CHAINS
......
......@@ -4,7 +4,6 @@ import { AutoColumn } from 'components/Column'
import { AutoRow } from 'components/Row'
import { getConnections, networkConnection } from 'connection'
import { ActivationStatus, useActivationState } from 'connection/activate'
import { ConnectionType } from 'connection/types'
import { isSupportedChain } from 'constants/chains'
import { useEffect } from 'react'
import { Settings } from 'react-feather'
......@@ -45,8 +44,6 @@ export default function WalletModal({ openSettings }: { openSettings: () => void
const { activationState } = useActivationState()
const hiddenWalletConnectTypes = [ConnectionType.WALLET_CONNECT, ConnectionType.UNISWAP_WALLET]
// Keep the network connector in sync with any active user connector to prevent chain-switching on wallet disconnection.
useEffect(() => {
if (chainId && isSupportedChain(chainId) && connector !== networkConnection.connector) {
......@@ -66,7 +63,7 @@ export default function WalletModal({ openSettings }: { openSettings: () => void
<AutoColumn gap="16px">
<OptionGrid data-testid="option-grid">
{connections
.filter((connection) => connection.shouldDisplay() && !hiddenWalletConnectTypes.includes(connection.type))
.filter((connection) => connection.shouldDisplay())
.map((connection) => (
<Option key={connection.getName()} connection={connection} />
))}
......
import { sendAnalyticsEvent } from '@uniswap/analytics'
import { URI_AVAILABLE, WalletConnect, WalletConnectConstructorArgs } from '@web3-react/walletconnect'
import { isIOS } from 'utils/userAgent'
import { RPC_URLS } from '../constants/networks'
// Avoid testing for the best URL by only passing a single URL per chain.
// Otherwise, WC will not initialize until all URLs have been tested (see getBestUrl in web3-react).
const RPC_URLS_WITHOUT_FALLBACKS = Object.entries(RPC_URLS).reduce(
(map, [chainId, urls]) => ({
...map,
[chainId]: urls[0],
}),
{}
)
export class WalletConnectV1 extends WalletConnect {
ANALYTICS_EVENT = 'Wallet Connect QR Scan'
constructor({
actions,
onError,
qrcode = true,
}: Omit<WalletConnectConstructorArgs, 'options'> & { qrcode?: boolean }) {
super({ actions, options: { qrcode, rpc: RPC_URLS_WITHOUT_FALLBACKS }, onError })
}
activate(chainId?: number) {
sendAnalyticsEvent(this.ANALYTICS_EVENT)
return super.activate(chainId)
}
}
// Custom class for Uniswap Wallet specific functionality
export class UniwalletConnect extends WalletConnectV1 {
ANALYTICS_EVENT = 'Uniswap Wallet QR Scan'
static UNI_URI_AVAILABLE = 'uni_uri_available'
constructor({ actions, onError }: Omit<WalletConnectConstructorArgs, 'options'>) {
// disables walletconnect's proprietary qr code modal; instead UniwalletModal will listen for events to trigger our custom modal
super({ actions, qrcode: false, onError })
this.events.once(URI_AVAILABLE, () => {
this.provider?.connector.on('disconnect', () => {
this.deactivate()
})
})
this.events.on(URI_AVAILABLE, (uri) => {
if (!uri) return
// Emits custom wallet connect code, parseable by the Uniswap Wallet
this.events.emit(UniwalletConnect.UNI_URI_AVAILABLE, `hello_uniwallet:${uri}`)
// Opens deeplink to Uniswap Wallet if on iOS
if (isIOS) {
const newTab = window.open(`https://uniswap.org/app/wc?uri=${encodeURIComponent(uri)}`)
// Fixes blank tab opening on mobile Chrome
newTab?.close()
}
})
}
deactivate() {
this.events.emit(URI_AVAILABLE)
return super.deactivate()
}
}
......@@ -240,10 +240,10 @@ describe('Should gracefully handle intentional user-rejection errors', () => {
const wcConnection = createMockConnection(
jest
.fn()
.mockImplementationOnce(() => Promise.reject(ErrorCode.WC_MODAL_CLOSED))
.mockImplementationOnce(() => Promise.reject(ErrorCode.WC_V2_MODAL_CLOSED))
.mockImplementationOnce(() => Promise.resolve),
jest.fn(),
ConnectionType.WALLET_CONNECT
ConnectionType.WALLET_CONNECT_V2
)
const onSuccess = jest.fn()
......
......@@ -19,10 +19,10 @@ describe('connection utility/metadata tests', () => {
UserAgentMock.isMobile = isMobile
global.window.ethereum = ethereum
const displayed = getConnections().filter((c) => c.shouldDisplay() && c.type !== ConnectionType.WALLET_CONNECT)
const displayed = getConnections().filter((c) => c.shouldDisplay())
const injected = getConnection(ConnectionType.INJECTED)
const coinbase = getConnection(ConnectionType.COINBASE_WALLET)
const uniswap = getConnection(ConnectionType.UNISWAP_WALLET)
const uniswap = getConnection(ConnectionType.UNISWAP_WALLET_V2)
const walletconnect = getConnection(ConnectionType.WALLET_CONNECT_V2)
return { displayed, injected, coinbase, uniswap, walletconnect }
......@@ -39,7 +39,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('Install MetaMask')
expect(injected.overrideActivate?.()).toBeTruthy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('MetaMask-Injected Desktop', async () => {
......@@ -49,7 +49,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('MetaMask')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Coinbase-Injected Desktop', async () => {
......@@ -60,7 +60,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('Install MetaMask')
expect(injected.overrideActivate?.()).toBeTruthy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Coinbase and MetaMask Injected Desktop', async () => {
......@@ -71,7 +71,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('MetaMask')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Trust Wallet Injected Desktop', async () => {
......@@ -81,7 +81,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('Trust Wallet')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Rabby Wallet Injected Desktop', async () => {
......@@ -91,7 +91,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('Rabby')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('LedgerConnect Wallet Injected Desktop', async () => {
......@@ -101,7 +101,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('Ledger')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Brave Browser Wallet Injected Desktop', async () => {
......@@ -111,7 +111,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('Brave')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Phantom Wallet Injected Desktop displays as MetaMask', async () => {
......@@ -122,7 +122,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('MetaMask')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
const UNKNOWN_MM_INJECTOR = { isRandomWallet: true, isMetaMask: true } as Window['window']['ethereum']
......@@ -133,7 +133,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getName()).toBe('MetaMask')
expect(injected.overrideActivate?.()).toBeFalsy()
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
const UNKNOWN_INJECTOR = { isRandomWallet: true } as Window['window']['ethereum']
......@@ -148,7 +148,7 @@ describe('connection utility/metadata tests', () => {
expect(injected.getIcon?.(/* isDarkMode= */ true)).toBe(INJECTED_DARK_ICON)
// Ensures we provide multiple connection options if in an unknown injected browser
expect(displayed.length).toEqual(5)
expect(displayed.length).toEqual(4)
})
it('Generic Wallet Browser with delayed injection', async () => {
......@@ -191,6 +191,6 @@ describe('connection utility/metadata tests', () => {
// Expect coinbase option to launch coinbase app in a regular mobile browser
expect(coinbase.overrideActivate?.()).toBeTruthy()
expect(displayed.length).toEqual(4)
expect(displayed.length).toEqual(3)
})
})
......@@ -16,7 +16,6 @@ import { RPC_URLS } from '../constants/networks'
import { RPC_PROVIDERS } from '../constants/providers'
import { Connection, ConnectionType } from './types'
import { getInjection, getIsCoinbaseWallet, getIsInjected, getIsMetaMaskWallet } from './utils'
import { UniwalletConnect, WalletConnectV1 } from './WalletConnect'
import { UniwalletConnect as UniwalletWCV2Connect, WalletConnectV2 } from './WalletConnectV2'
function onError(error: Error) {
......@@ -70,18 +69,6 @@ export const gnosisSafeConnection: Connection = {
shouldDisplay: () => false,
}
const [web3WalletConnect, web3WalletConnectHooks] = initializeConnector<WalletConnectV1>(
(actions) => new WalletConnectV1({ actions, onError })
)
export const walletConnectV1Connection: Connection = {
getName: () => 'WalletConnect',
connector: web3WalletConnect,
hooks: web3WalletConnectHooks,
type: ConnectionType.WALLET_CONNECT,
getIcon: () => WALLET_CONNECT_ICON,
shouldDisplay: () => !getIsInjectedMobileBrowser(),
}
export const walletConnectV2Connection: Connection = new (class implements Connection {
private initializer = (actions: Actions, defaultChainId = ChainId.MAINNET) =>
new WalletConnectV2({ actions, defaultChainId, onError })
......@@ -105,19 +92,6 @@ export const walletConnectV2Connection: Connection = new (class implements Conne
}
})()
const [web3UniwalletConnect, web3UniwalletConnectHooks] = initializeConnector<UniwalletConnect>(
(actions) => new UniwalletConnect({ actions, onError })
)
export const uniwalletConnectConnection: Connection = {
getName: () => 'Uniswap Wallet',
connector: web3UniwalletConnect,
hooks: web3UniwalletConnectHooks,
type: ConnectionType.UNISWAP_WALLET,
getIcon: () => UNIWALLET_ICON,
shouldDisplay: () => Boolean(!getIsInjectedMobileBrowser() && !isNonIOSPhone),
isNew: true,
}
const [web3WCV2UniwalletConnect, web3WCV2UniwalletConnectHooks] = initializeConnector<UniwalletWCV2Connect>(
(actions) => new UniwalletWCV2Connect({ actions, onError })
)
......@@ -164,11 +138,9 @@ const coinbaseWalletConnection: Connection = {
export function getConnections() {
return [
uniwalletConnectConnection,
uniwalletWCV2ConnectConnection,
injectedConnection,
walletConnectV2Connection,
walletConnectV1Connection,
coinbaseWalletConnection,
gnosisSafeConnection,
networkConnection,
......@@ -188,13 +160,8 @@ export function getConnection(c: Connector | ConnectionType) {
return injectedConnection
case ConnectionType.COINBASE_WALLET:
return coinbaseWalletConnection
case ConnectionType.WALLET_CONNECT:
return walletConnectV1Connection
case ConnectionType.WALLET_CONNECT_V2:
return walletConnectV2Connection
case ConnectionType.UNIWALLET:
case ConnectionType.UNISWAP_WALLET:
return uniwalletConnectConnection
case ConnectionType.UNISWAP_WALLET_V2:
return uniwalletWCV2ConnectConnection
case ConnectionType.NETWORK:
......
......@@ -3,13 +3,9 @@ import { Web3ReactHooks } from '@web3-react/core'
import { Connector } from '@web3-react/types'
export enum ConnectionType {
UNISWAP_WALLET = 'UNISWAP_WALLET',
UNISWAP_WALLET_V2 = 'UNISWAP_WALLET_V2',
/** @deprecated - Use {@link UNISWAP_WALLET} instead. */
UNIWALLET = 'UNIWALLET',
INJECTED = 'INJECTED',
COINBASE_WALLET = 'COINBASE_WALLET',
WALLET_CONNECT = 'WALLET_CONNECT',
WALLET_CONNECT_V2 = 'WALLET_CONNECT_V2',
NETWORK = 'NETWORK',
GNOSIS_SAFE = 'GNOSIS_SAFE',
......
......@@ -70,7 +70,6 @@ export function didUserReject(connection: Connection, error: any): boolean {
return (
error?.code === ErrorCode.USER_REJECTED_REQUEST ||
(connection.type === ConnectionType.WALLET_CONNECT_V2 && error?.toString?.() === ErrorCode.WC_V2_MODAL_CLOSED) ||
(connection.type === ConnectionType.WALLET_CONNECT && error?.toString?.() === ErrorCode.WC_MODAL_CLOSED) ||
(connection.type === ConnectionType.COINBASE_WALLET && error?.toString?.() === ErrorCode.CB_REJECTED_REQUEST)
)
}
......@@ -4,9 +4,9 @@ import { useMemo } from 'react'
import { useAppSelector } from 'state/hooks'
const SELECTABLE_WALLETS = [
ConnectionType.UNISWAP_WALLET,
ConnectionType.UNISWAP_WALLET_V2,
ConnectionType.INJECTED,
ConnectionType.WALLET_CONNECT,
ConnectionType.WALLET_CONNECT_V2,
ConnectionType.COINBASE_WALLET,
]
......
import { ChainId, SupportedChainsType } from '@uniswap/sdk-core'
import { Connector } from '@web3-react/types'
import {
networkConnection,
uniwalletConnectConnection,
uniwalletWCV2ConnectConnection,
walletConnectV1Connection,
walletConnectV2Connection,
} from 'connection'
import { networkConnection, uniwalletWCV2ConnectConnection, walletConnectV2Connection } from 'connection'
import { getChainInfo } from 'constants/chainInfo'
import { isSupportedChain } from 'constants/chains'
import { FALLBACK_URLS, RPC_URLS } from 'constants/networks'
......@@ -40,9 +34,7 @@ export function useSwitchChain() {
try {
if (
[
walletConnectV1Connection.connector,
walletConnectV2Connection.connector,
uniwalletConnectConnection.connector,
uniwalletWCV2ConnectConnection.connector,
networkConnection.connector,
].includes(connector)
......
......@@ -125,9 +125,16 @@ const userSlice = createSlice({
// for all existing users with a previous version of the state in their localStorage.
// In order to avoid this, we need to set a default value for each new property manually during hydration.
builder.addCase(updateVersion, (state) => {
// If `selectedWallet` is ConnectionType.UNI_WALLET (deprecated) switch it to ConnectionType.UNISWAP_WALLET
if (state.selectedWallet === 'UNIWALLET') {
state.selectedWallet = ConnectionType.UNISWAP_WALLET
// If `selectedWallet` is a WalletConnect v1 wallet, reset to default.
if (state.selectedWallet) {
const selectedWallet = state.selectedWallet as string
if (
selectedWallet === 'UNIWALLET' ||
selectedWallet === 'UNISWAP_WALLET' ||
selectedWallet === 'WALLET_CONNECT'
) {
delete state.selectedWallet
}
}
// If `userSlippageTolerance` is not present or its value is invalid, reset to default
......
This diff is collapsed.
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