Skip to content

Commit

Permalink
[ECO-1823] Fix infinite connect wallet bug by removing manual autocon…
Browse files Browse the repository at this point in the history
…nect (#111)

Co-authored-by: matt <[email protected]>
Co-authored-by: alnoki <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2024
1 parent b1a2bad commit 51cd31a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/typescript/frontend/src/context/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ThemedApp: React.FC<{ children: React.ReactNode }> = ({ children }) => {
<QueryClientProvider client={queryClient}>
<WebSocketEventsProvider>
<MarketDataProvider>
<AptosWalletAdapterProvider plugins={wallets} autoConnect>
<AptosWalletAdapterProvider plugins={wallets} autoConnect={true}>
<ConnectWalletContextProvider>
<AptosContextProvider>
<GlobalStyle />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useWallet, type WalletName } from "@aptos-labs/wallet-adapter-react";
import { createContext, type PropsWithChildren, useContext, useEffect, useState } from "react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import { createContext, type PropsWithChildren, useContext, useState } from "react";
import { toast } from "react-toastify";

import { BaseModal } from "components/modal/BaseModal";
Expand All @@ -16,35 +16,6 @@ const WalletItemClassName =
"transition-all hover:text-ec-blue " +
"text-black group";

let t: NodeJS.Timeout | null = null;
const AutoConnect = () => {
const { account, connect } = useWallet();
useEffect(() => {
if (!account && localStorage.getItem("AptosWalletName")) {
const f = async () => {
try {
connect(localStorage.getItem("AptosWalletName") as WalletName);
} catch (error) {
if (t) {
clearInterval(t);
}
}
};
f();
t = setInterval(f, 100);
} else if (t) {
clearInterval(t);
}
return () => {
if (t) {
clearInterval(t);
}
};
}, [account]); /* eslint-disable-line react-hooks/exhaustive-deps */

return null;
};

export function ConnectWalletContextProvider({ children }: PropsWithChildren) {
const { connect, wallet: activeWallet, wallets, disconnect } = useWallet();
const [open, setOpen] = useState<boolean>(false);
Expand All @@ -56,7 +27,6 @@ export function ConnectWalletContextProvider({ children }: PropsWithChildren) {

return (
<ConnectWalletContext.Provider value={value}>
<AutoConnect />
{children}
<BaseModal
className="md:w-[430px]"
Expand Down

0 comments on commit 51cd31a

Please sign in to comment.