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