Merge branch 'dev' into myf-dev
This commit is contained in:
commit
4abf265197
|
|
@ -29,6 +29,7 @@
|
|||
"import/no-extraneous-dependencies": 0,
|
||||
"no-unused-expressions":0,
|
||||
"jsx-a11y/media-has-caption": 0,
|
||||
"import/prefer-default-export":0,
|
||||
// Exchange
|
||||
"no-param-reassign": ["error", { "props": true, "ignorePropertyModificationsFor": ["state", "memo"] }],
|
||||
"react/require-default-props": 0,
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import React, { lazy, useEffect } from 'react'
|
|||
import { Router, Redirect, Route, Switch } from 'react-router-dom'
|
||||
import { ResetCSS } from '@pancakeswap/uikit'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { uccnDetail, indexInfo } from 'services/user'
|
||||
import BigNumber from 'bignumber.js'
|
||||
import useEagerConnect from 'hooks/useEagerConnect'
|
||||
import { usePollCoreFarmData, useFetchProfile, usePollBlockNumber } from 'state/hooks'
|
||||
import { DatePickerPortal } from 'components/DatePicker'
|
||||
import { initAxios } from 'utils/request'
|
||||
import useToast from 'hooks/useToast'
|
||||
import { useAccountEventListener } from 'hooks/useAccountEventListener'
|
||||
import { fetchUserInfo, clearUserInfo } from 'state/actions'
|
||||
import { useAccount } from 'state/userInfo/hooks'
|
||||
import GlobalStyle from './style/Global'
|
||||
|
|
@ -66,6 +66,7 @@ const App: React.FC = () => {
|
|||
useEagerConnect()
|
||||
useFetchProfile()
|
||||
usePollCoreFarmData()
|
||||
useAccountEventListener()
|
||||
const dispatch = useDispatch()
|
||||
const toast = useToast()
|
||||
const account = useAccount()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
import { useEffect } from 'react'
|
||||
import { useWeb3React } from '@web3-react/core'
|
||||
import { clearUserStates } from 'utils/clearUserStates'
|
||||
import { useAppDispatch } from '../state'
|
||||
|
||||
export const useAccountEventListener = () => {
|
||||
const { account, chainId, connector } = useWeb3React()
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
useEffect(() => {
|
||||
if (account && connector) {
|
||||
const handleEvent = () => {
|
||||
clearUserStates(dispatch)
|
||||
}
|
||||
|
||||
connector.addListener('Web3ReactDeactivate', handleEvent)
|
||||
connector.addListener('Web3ReactUpdate', handleEvent)
|
||||
|
||||
return () => {
|
||||
connector.removeListener('Web3ReactDeactivate', handleEvent)
|
||||
connector.removeListener('Web3ReactUpdate', handleEvent)
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}, [account, chainId, dispatch, connector])
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { useEffect } from 'react'
|
||||
import { connectorLocalStorageKey, ConnectorNames } from '@pancakeswap/uikit'
|
||||
import useAuth from 'hooks/useAuth'
|
||||
import { useDispatch } from 'react-redux'
|
||||
import { clearUserInfo } from 'state/actions'
|
||||
|
||||
const _binanceChainListener = async () =>
|
||||
new Promise<void>((resolve) =>
|
||||
|
|
@ -18,6 +20,7 @@ const _binanceChainListener = async () =>
|
|||
|
||||
const useEagerConnect = () => {
|
||||
const { login } = useAuth()
|
||||
const dispatch = useDispatch()
|
||||
|
||||
useEffect(() => {
|
||||
const connectorId = window.localStorage.getItem(connectorLocalStorageKey) as ConnectorNames
|
||||
|
|
@ -35,8 +38,11 @@ const useEagerConnect = () => {
|
|||
}
|
||||
|
||||
login(connectorId)
|
||||
} else {
|
||||
// 要清掉用户信息
|
||||
dispatch(clearUserInfo())
|
||||
}
|
||||
}, [login])
|
||||
}, [login, dispatch])
|
||||
}
|
||||
|
||||
export default useEagerConnect
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export const useAccount = (ellipsis?: boolean) => {
|
|||
// 钱包登录 但是未签名获取到token
|
||||
export const useUnactiveAccount = () => {
|
||||
const { account } = useWeb3React()
|
||||
return account
|
||||
return account ? account.toLocaleLowerCase() : account
|
||||
}
|
||||
|
||||
export const useToken = () => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
import { Dispatch } from '@reduxjs/toolkit'
|
||||
import { clearUserInfo } from 'state/actions'
|
||||
import { connectorLocalStorageKey } from '@pancakeswap/uikit'
|
||||
import { connectorsByName } from './web3React'
|
||||
|
||||
export const clearUserStates = (dispatch: Dispatch<any>) => {
|
||||
dispatch(clearUserInfo())
|
||||
// This localStorage key is set by @web3-react/walletconnect-connector
|
||||
if (window?.localStorage?.getItem('walletconnect')) {
|
||||
connectorsByName.walletconnect.close()
|
||||
connectorsByName.walletconnect.walletConnectProvider = null
|
||||
}
|
||||
window?.localStorage?.removeItem(connectorLocalStorageKey)
|
||||
}
|
||||
Loading…
Reference in New Issue