Commit 678cd1a0 authored by Noah Zinsmeister's avatar Noah Zinsmeister Committed by GitHub

upgrade to walletconnect v1 (#903)

parent a5ff3beb
...@@ -15,7 +15,7 @@ const InfoCard = styled.button<{ active?: boolean }>` ...@@ -15,7 +15,7 @@ const InfoCard = styled.button<{ active?: boolean }>`
border-color: ${({ theme, active }) => (active ? 'transparent' : theme.bg3)}; border-color: ${({ theme, active }) => (active ? 'transparent' : theme.bg3)};
` `
const OptionCard = styled(InfoCard)` const OptionCard = styled(InfoCard as any)`
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
...@@ -30,7 +30,7 @@ const OptionCardLeft = styled.div` ...@@ -30,7 +30,7 @@ const OptionCardLeft = styled.div`
height: 100%; height: 100%;
` `
const OptionCardClickable = styled(OptionCard)<{ clickable?: boolean }>` const OptionCardClickable = styled(OptionCard as any)<{ clickable?: boolean }>`
margin-top: 0; margin-top: 0;
&:hover { &:hover {
cursor: ${({ clickable }) => (clickable ? 'pointer' : '')}; cursor: ${({ clickable }) => (clickable ? 'pointer' : '')};
...@@ -114,7 +114,6 @@ export default function Option({ ...@@ -114,7 +114,6 @@ export default function Option({
<OptionCardClickable id={id} onClick={onClick} clickable={clickable && !active} active={active}> <OptionCardClickable id={id} onClick={onClick} clickable={clickable && !active} active={active}>
<OptionCardLeft> <OptionCardLeft>
<HeaderText color={color}> <HeaderText color={color}>
{' '}
{active ? ( {active ? (
<CircleWrapper> <CircleWrapper>
<GreenCircle> <GreenCircle>
......
...@@ -3,8 +3,7 @@ import React from 'react' ...@@ -3,8 +3,7 @@ import React from 'react'
import styled from 'styled-components' import styled from 'styled-components'
import Option from './Option' import Option from './Option'
import { SUPPORTED_WALLETS } from '../../constants' import { SUPPORTED_WALLETS } from '../../constants'
import WalletConnectData from './WalletConnectData' import { injected } from '../../connectors'
import { walletconnect, injected } from '../../connectors'
import { darken } from 'polished' import { darken } from 'polished'
import Loader from '../Loader' import Loader from '../Loader'
...@@ -65,28 +64,22 @@ const LoadingWrapper = styled.div` ...@@ -65,28 +64,22 @@ const LoadingWrapper = styled.div`
` `
export default function PendingView({ export default function PendingView({
uri = '',
size,
connector, connector,
error = false, error = false,
setPendingError, setPendingError,
tryActivation tryActivation
}: { }: {
uri?: string
size?: number
connector?: AbstractConnector connector?: AbstractConnector
error?: boolean error?: boolean
setPendingError: (error: boolean) => void setPendingError: (error: boolean) => void
tryActivation: (connector: AbstractConnector) => void tryActivation: (connector: AbstractConnector) => void
}) { }) {
const isMetamask = window.ethereum && window.ethereum.isMetaMask const isMetamask = window?.ethereum?.isMetaMask
return ( return (
<PendingSection> <PendingSection>
{!error && connector === walletconnect && <WalletConnectData size={size} uri={uri} />}
<LoadingMessage error={error}> <LoadingMessage error={error}>
<LoadingWrapper> <LoadingWrapper>
{!error && <StyledLoader />}
{error ? ( {error ? (
<ErrorGroup> <ErrorGroup>
<div>Error connecting.</div> <div>Error connecting.</div>
...@@ -99,10 +92,11 @@ export default function PendingView({ ...@@ -99,10 +92,11 @@ export default function PendingView({
Try Again Try Again
</ErrorButton> </ErrorButton>
</ErrorGroup> </ErrorGroup>
) : connector === walletconnect ? (
'Scan QR code with a compatible wallet...'
) : ( ) : (
'Initializing...' <>
<StyledLoader />
Initializing...
</>
)} )}
</LoadingWrapper> </LoadingWrapper>
</LoadingMessage> </LoadingMessage>
......
import React from 'react'
import styled from 'styled-components'
import QRCode from 'qrcode.react'
const QRCodeWrapper = styled.div`
${({ theme }) => theme.flexColumnNoWrap};
align-items: center;
justify-content: center;
border-radius: 12px;
margin-bottom: 20px;
`
const StyledQRCode = styled(QRCode)`
border: 3px solid white;
`
interface WalletConnectDataProps {
uri?: string
size: number
}
export default function WalletConnectData({ uri = '', size }: WalletConnectDataProps) {
return <QRCodeWrapper>{uri && <StyledQRCode size={size} value={uri} />}</QRCodeWrapper>
}
...@@ -3,7 +3,6 @@ import ReactGA from 'react-ga' ...@@ -3,7 +3,6 @@ import ReactGA from 'react-ga'
import styled from 'styled-components' import styled from 'styled-components'
import { isMobile } from 'react-device-detect' import { isMobile } from 'react-device-detect'
import { UnsupportedChainIdError, useWeb3React } from '@web3-react/core' import { UnsupportedChainIdError, useWeb3React } from '@web3-react/core'
import { URI_AVAILABLE } from '@web3-react/walletconnect-connector'
import usePrevious from '../../hooks/usePrevious' import usePrevious from '../../hooks/usePrevious'
import { useWalletModalOpen, useWalletModalToggle } from '../../state/application/hooks' import { useWalletModalOpen, useWalletModalToggle } from '../../state/application/hooks'
...@@ -15,8 +14,9 @@ import { SUPPORTED_WALLETS } from '../../constants' ...@@ -15,8 +14,9 @@ import { SUPPORTED_WALLETS } from '../../constants'
import { ExternalLink } from '../../theme' import { ExternalLink } from '../../theme'
import MetamaskIcon from '../../assets/images/metamask.png' import MetamaskIcon from '../../assets/images/metamask.png'
import { ReactComponent as Close } from '../../assets/images/x.svg' import { ReactComponent as Close } from '../../assets/images/x.svg'
import { injected, walletconnect, fortmatic, portis } from '../../connectors' import { injected, fortmatic, portis } from '../../connectors'
import { OVERLAY_READY } from '../../connectors/Fortmatic' import { OVERLAY_READY } from '../../connectors/Fortmatic'
import { WalletConnectConnector } from '@web3-react/walletconnect-connector'
const CloseIcon = styled.div` const CloseIcon = styled.div`
position: absolute; position: absolute;
...@@ -152,19 +152,6 @@ export default function WalletModal({ ...@@ -152,19 +152,6 @@ export default function WalletModal({
} }
}, [walletModalOpen]) }, [walletModalOpen])
// set up uri listener for walletconnect
const [uri, setUri] = useState()
useEffect(() => {
const activateWC = uri => {
setUri(uri)
// setWalletView(WALLET_VIEWS.PENDING)
}
walletconnect.on(URI_AVAILABLE, activateWC)
return () => {
walletconnect.off(URI_AVAILABLE, activateWC)
}
}, [])
// close modal when a connection is successful // close modal when a connection is successful
const activePrevious = usePrevious(active) const activePrevious = usePrevious(active)
const connectorPrevious = usePrevious(connector) const connectorPrevious = usePrevious(connector)
...@@ -190,6 +177,12 @@ export default function WalletModal({ ...@@ -190,6 +177,12 @@ export default function WalletModal({
}) })
setPendingWallet(connector) // set wallet for pending view setPendingWallet(connector) // set wallet for pending view
setWalletView(WALLET_VIEWS.PENDING) setWalletView(WALLET_VIEWS.PENDING)
// if the connector is walletconnect and the user has already tried to connect, manually reset the connector
if (connector instanceof WalletConnectConnector && connector.walletConnectProvider?.wc?.uri) {
connector.walletConnectProvider = undefined
}
activate(connector, undefined, true).catch(error => { activate(connector, undefined, true).catch(error => {
if (error instanceof UnsupportedChainIdError) { if (error instanceof UnsupportedChainIdError) {
activate(connector) // a little janky...can't use setError because the connector isn't set activate(connector) // a little janky...can't use setError because the connector isn't set
...@@ -345,8 +338,6 @@ export default function WalletModal({ ...@@ -345,8 +338,6 @@ export default function WalletModal({
<ContentWrapper> <ContentWrapper>
{walletView === WALLET_VIEWS.PENDING ? ( {walletView === WALLET_VIEWS.PENDING ? (
<PendingView <PendingView
uri={uri}
size={220}
connector={pendingWallet} connector={pendingWallet}
error={pendingError} error={pendingError}
setPendingError={setPendingError} setPendingError={setPendingError}
......
...@@ -27,7 +27,7 @@ export const injected = new InjectedConnector({ ...@@ -27,7 +27,7 @@ export const injected = new InjectedConnector({
export const walletconnect = new WalletConnectConnector({ export const walletconnect = new WalletConnectConnector({
rpc: { 1: NETWORK_URL }, rpc: { 1: NETWORK_URL },
bridge: 'https://bridge.walletconnect.org', bridge: 'https://bridge.walletconnect.org',
qrcode: false, qrcode: true,
pollingInterval: POLLING_INTERVAL pollingInterval: POLLING_INTERVAL
}) })
......
...@@ -58,7 +58,7 @@ export const DUMMY_PAIRS_TO_PIN: { readonly [chainId in ChainId]?: Pair[] } = { ...@@ -58,7 +58,7 @@ export const DUMMY_PAIRS_TO_PIN: { readonly [chainId in ChainId]?: Pair[] } = {
] ]
} }
const MAINNET_WALLETS = { const TESTNET_CAPABLE_WALLETS = {
INJECTED: { INJECTED: {
connector: injected, connector: injected,
name: 'Injected', name: 'Injected',
...@@ -80,9 +80,9 @@ const MAINNET_WALLETS = { ...@@ -80,9 +80,9 @@ const MAINNET_WALLETS = {
export const SUPPORTED_WALLETS = export const SUPPORTED_WALLETS =
process.env.REACT_APP_CHAIN_ID !== '1' process.env.REACT_APP_CHAIN_ID !== '1'
? MAINNET_WALLETS ? TESTNET_CAPABLE_WALLETS
: { : {
...MAINNET_WALLETS, ...TESTNET_CAPABLE_WALLETS,
...{ ...{
WALLET_CONNECT: { WALLET_CONNECT: {
connector: walletconnect, connector: walletconnect,
...@@ -90,7 +90,8 @@ export const SUPPORTED_WALLETS = ...@@ -90,7 +90,8 @@ export const SUPPORTED_WALLETS =
iconName: 'walletConnectIcon.svg', iconName: 'walletConnectIcon.svg',
description: 'Connect to Trust Wallet, Rainbow Wallet and more...', description: 'Connect to Trust Wallet, Rainbow Wallet and more...',
href: null, href: null,
color: '#4196FC' color: '#4196FC',
mobile: true
}, },
WALLET_LINK: { WALLET_LINK: {
connector: walletlink, connector: walletlink,
......
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