From cca8a62dac082ba5b9b30f3cb5d2ce1c63f76ede Mon Sep 17 00:00:00 2001 From: gary <1032230992@qq.com> Date: Thu, 21 Apr 2022 20:59:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 ++++ .eslintrc | 3 ++- src/components/Menu/index.tsx | 35 +++++++++++++++++++++++++++------ src/components/UnlockButton.tsx | 26 ++++++++++++++++++++---- src/services/login.ts | 16 +++++++-------- src/services/user.ts | 32 ++---------------------------- src/state/userInfo/hooks.ts | 12 ++++++----- src/utils/request.ts | 10 ++++------ 8 files changed, 78 insertions(+), 60 deletions(-) diff --git a/.env.development b/.env.development index c2b3e9a..eeb149f 100644 --- a/.env.development +++ b/.env.development @@ -16,3 +16,7 @@ REACT_APP_GRAPH_API_LOTTERY = "https://api.thegraph.com/subgraphs/name/pancakesw REACT_APP_SNAPSHOT_BASE_URL = "https://testnet.snapshot.org" REACT_APP_SNAPSHOT_VOTING_API = "https://xtjyd0liqe.execute-api.ap-northeast-1.amazonaws.com/dev/api" + + + +REACT_APP_REQUEST_URL = 'http://101.35.117.69:9090' diff --git a/.eslintrc b/.eslintrc index 4cbd176..bc519ce 100644 --- a/.eslintrc +++ b/.eslintrc @@ -33,7 +33,8 @@ "no-param-reassign": ["error", { "props": true, "ignorePropertyModificationsFor": ["state", "memo"] }], "react/require-default-props": 0, "no-nested-ternary": 0, - "max-classes-per-file": 0 + "max-classes-per-file": 0, + "react-hooks/exhaustive-deps":0 // End temporary rules } } diff --git a/src/components/Menu/index.tsx b/src/components/Menu/index.tsx index 7194980..8a04874 100644 --- a/src/components/Menu/index.tsx +++ b/src/components/Menu/index.tsx @@ -1,26 +1,49 @@ -import React from 'react' -import { Menu as UikitMenu } from '@pancakeswap/uikit' +import React, { useEffect, useState } from 'react' +import { Menu as UikitMenu, ConnectorNames } from '@pancakeswap/uikit' import { useWeb3React } from '@web3-react/core' import { languageList } from 'config/localization/languages' import { useTranslation } from 'contexts/Localization' import useTheme from 'hooks/useTheme' import useAuth from 'hooks/useAuth' +import { useDispatch } from 'react-redux' import { usePriceCakeBusd, useProfile } from 'state/hooks' +import { useUnactiveAccount, useSignLogin, useAccount } from 'state/userInfo/hooks' +import useWeb3Provider from 'hooks/useActiveWeb3React' +import { clearUserInfo } from 'state/actions' import config from './config' const Menu = (props) => { - const { account } = useWeb3React() + const account = useAccount() const { login, logout } = useAuth() + const [hasWalletLogin, setHasWalletLogin] = useState(false) const { isDark, toggleTheme } = useTheme() const cakePriceUsd = usePriceCakeBusd() + const { library } = useWeb3Provider() + const unActiveAccount = useUnactiveAccount() + const dispatch = useDispatch() const { profile } = useProfile() const { currentLanguage, setLanguage, t } = useTranslation() - + const sign = useSignLogin() + const handleLogin = async (connectorID: ConnectorNames) => { + await login(connectorID) + setHasWalletLogin(true) + } + const handleLogout = () => { + dispatch(clearUserInfo()) + logout() + } + // 钱包登录后 + useEffect(() => { + if (unActiveAccount && library.provider && hasWalletLogin) { + setHasWalletLogin(false) + sign() + } + }, [unActiveAccount, hasWalletLogin, library]) return ( { const { t } = useTranslation() const { login, logout } = useAuth() - const { onPresentConnectModal } = useWalletModal(login, logout) - + const [hasWalletLogin, setHasWalletLogin] = useState(false) + const { library } = useWeb3Provider() + const unActiveAccount = useUnactiveAccount() + const { toastInfo } = useToast() + const sign = useSignLogin() + const handleLogin = async (connectorID: ConnectorNames) => { + await login(connectorID) + setHasWalletLogin(true) + } + const { onPresentConnectModal } = useWalletModal(handleLogin, logout) + // 钱包登录后 + useEffect(() => { + if (unActiveAccount && library.provider && hasWalletLogin) { + setHasWalletLogin(false) + sign() + } + }, [unActiveAccount, hasWalletLogin, library]) return (