@web3-react/walletconnect-connector#UserRejectedRequestError TypeScript Examples

The following examples show how to use @web3-react/walletconnect-connector#UserRejectedRequestError. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WalletConnect.tsx    From hypertext with GNU General Public License v3.0 6 votes vote down vote up
export default function WalletConnect(): JSX.Element | null {
  const { active, error, activate, setError } = useWeb3React<Web3Provider>()

  const [connecting, setConnecting] = useState(false)
  useEffect(() => {
    if (active || error) {
      setConnecting(false)
    }
  }, [active, error])

  if (error) {
    return null
  }

  return (
    <Button
      isLoading={connecting}
      leftIcon={'walletconnect' as 'edit'}
      onClick={(): void => {
        setConnecting(true)
        // reset the connector if it was tried already
        if (walletconnect?.walletConnectProvider?.wc?.uri) {
          walletconnect.walletConnectProvider = undefined
        }
        activate(walletconnect, undefined, true).catch((error) => {
          if (error instanceof UserRejectedRequestError) {
            setConnecting(false)
          } else {
            setError(error)
          }
        })
      }}
    >
      WalletConnect
    </Button>
  )
}