Skip to content

Commit

Permalink
fix: Wallet connect qr code problems and make error messages human re…
Browse files Browse the repository at this point in the history
…adable (pancakeswap#649)

* fix: Wallet connect qr code problems and make error messages human readable

* fix: Format
  • Loading branch information
memoyil authored Mar 15, 2021
1 parent 0e741b7 commit c3993c2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { useCallback } from 'react'
import { useWeb3React, UnsupportedChainIdError } from '@web3-react/core'
import { ConnectorNames } from '@pancakeswap-libs/uikit'
import { NoBscProviderError } from '@binance-chain/bsc-connector'
import {
NoEthereumProviderError,
UserRejectedRequestError as UserRejectedRequestErrorInjected,
} from '@web3-react/injected-connector'
import {
UserRejectedRequestError as UserRejectedRequestErrorWalletConnect,
WalletConnectConnector,
} from '@web3-react/walletconnect-connector'
import { ConnectorNames, connectorLocalStorageKey } from '@pancakeswap-libs/uikit'
import { useToast } from 'state/hooks'
import { connectorsByName } from 'utils/web3React'
import { setupNetwork } from 'utils/wallet'
Expand All @@ -19,7 +28,21 @@ const useAuth = () => {
activate(connector)
}
} else {
toastError(error.name, error.message)
window.localStorage.removeItem(connectorLocalStorageKey)
if (error instanceof NoEthereumProviderError || error instanceof NoBscProviderError) {
toastError('Provider Error', 'No provider was found')
} else if (
error instanceof UserRejectedRequestErrorInjected ||
error instanceof UserRejectedRequestErrorWalletConnect
) {
if (connector instanceof WalletConnectConnector) {
const walletConnector = connector as WalletConnectConnector
walletConnector.walletConnectProvider = null
}
toastError('Authorization Error', 'Please authorize to access your account')
} else {
toastError(error.name, error.message)
}
}
})
} else {
Expand Down

0 comments on commit c3993c2

Please sign in to comment.