Skip to content

Commit

Permalink
en: disconnect调整
Browse files Browse the repository at this point in the history
  • Loading branch information
Oaciqihz committed Jan 4, 2024
1 parent d4bc3ea commit 5fcfe4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
15 changes: 6 additions & 9 deletions src/containers/AppHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function AppHeader({ isMobile, user }) {
console.log(err);
}
})
const { disconnect } = useDisconnect();
const { disconnectAsync } = useDisconnect();
const navigateTo = useNavigate();
const location = useLocation();
let [isOpenM, setIsOpenM] = useState(false);
Expand Down Expand Up @@ -127,16 +127,13 @@ export default function AppHeader({ isMobile, user }) {

}

function goDisconnect() {
async function goDisconnect() {
if (walletType === "evm") {
disconnect();
ClearStorage();
await disconnectAsync();
}else{
wallet.adapter.disconnect()
.then(res => {
ClearStorage();
})
await wallet.adapter.disconnect()
}
ClearStorage();

// 判断是否是claim页
const path = location.pathname;
Expand Down Expand Up @@ -247,7 +244,7 @@ export default function AppHeader({ isMobile, user }) {

{
isConnected ?
<Button danger type="primary" onClick={() => disconnect()}>{t("header.disconnect")}</Button>
<Button danger type="primary" onClick={() => goDisconnect()}>{t("header.disconnect")}</Button>
:
<Button onClick={() => openModal()}>{t("header.connect")}</Button>
}
Expand Down
13 changes: 5 additions & 8 deletions src/containers/DefaultLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MyContext from "@/provider/context";
import store, { hideCustomSigner, showCustomSigner } from "@/redux/store";
import { useAddress } from "@/hooks/useAddress";
import { useWallet } from "@solana/wallet-adapter-react";
import { useAccount, useDisconnect } from "wagmi";
import { useDisconnect } from "wagmi";
import { getUnreadMessage, readMessage } from "@/request/api/public";
import { useTranslation } from "react-i18next";
import CustomDisconnect from "@/redux/CustomDisconnect";
Expand All @@ -35,7 +35,7 @@ export default function DefaultLayout(params) {

const { address, isConnected, walletType } = useAddress();
const { wallet, connected } = useWallet();
const { disconnect } = useDisconnect()
const { disconnectAsync } = useDisconnect()

// 获取当前账号未读信息
const { runAsync, cancel } = useRequest(getUnreadMessage, {
Expand Down Expand Up @@ -186,14 +186,11 @@ export default function DefaultLayout(params) {
await sign()
}else{
if (walletType === "evm") {
disconnect();
ClearStorage();
await disconnectAsync();
}else{
wallet.adapter.disconnect()
.then(res => {
ClearStorage();
})
await wallet.adapter.disconnect()
}
ClearStorage();
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/redux/CustomDisconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ function CustomDisconnect(props) {

const { wallet } = useWallet();
const { walletType, isConnected } = useAddress();
const { disconnect } = useDisconnect();
const { disconnectAsync } = useDisconnect();


function goDisconnect() {
async function goDisconnect() {
props.setDisConnect(false);
if (walletType === "evm") {
disconnect();
ClearStorage();
await disconnectAsync();
}else{
wallet.adapter.disconnect()
.then(res => {
ClearStorage();
})
await wallet.adapter.disconnect()
}
ClearStorage();
}

useEffect(() => {
Expand Down

0 comments on commit 5fcfe4c

Please sign in to comment.