Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial isLoading state error when auto connect is disabled #259

Open
Metal-joker opened this issue Apr 27, 2024 · 2 comments
Open

Initial isLoading state error when auto connect is disabled #259

Metal-joker opened this issue Apr 27, 2024 · 2 comments

Comments

@Metal-joker
Copy link

The isLoading state should represent whether there's an action ongoing, but when autoConnect is set to false, the initial isLoading state seems to always be true.

// a local state to track whether wallet connect request is loading
// https://github.com/aptos-labs/aptos-wallet-adapter/issues/94
const [isLoading, setIsLoading] = useState<boolean>(true);

useEffect(() => {
if (autoConnect) {
if (localStorage.getItem("AptosWalletName") && !connected) {
connect(localStorage.getItem("AptosWalletName") as WalletName);
} else {
// if we dont use autoconnect set the connect is loading to false
setIsLoading(false);
}
}
}, wallets);

return (
<WalletContext.Provider
value={{
connect,
account,
network,
connected,
disconnect,
wallet,
wallets,
signAndSubmitTransaction,
signTransaction,
signMessage,
signMessageAndVerify,
isLoading,
submitTransaction,
}}
>
{children}
</WalletContext.Provider>
);

@servroxsolutions
Copy link

Can confirm.

@gsong
Copy link
Contributor

gsong commented Sep 26, 2024

I attempted the obvious fix but that didn't resolve the issue, unfortunately. So I'm using a workaround in the meantime:

import { useWallet as useWalletImpl } from "@aptos-labs/wallet-adapter-react";

export const useWallet = () => {
  const { connected, ...wallet } = useWalletImpl();
  const isLoading = useIsLoading();

  const connectedStatus = isLoading ? undefined : connected;

  return { ...wallet, connected: connectedStatus, isLoading };
};

const useIsLoading = () => {
  const { wallets, isLoading } = useWalletImpl();

  return isLoading || !wallets || wallets.length === 0;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants