rajatK012 / hashconnectWalletConnect

8 stars 7 forks source link

Retrieve Account Id #2

Open Dan-Druff opened 2 years ago

Dan-Druff commented 2 years ago

Sorry to bug you again, But For some reason, even after I connect to hashpack, the walletData does not contain anything. ..

Also, for some reason it's not firing the pairingEvent after hash pack sign in. What am I missing?

What I'm trying to do, is have my app retrieve the accountId of the connected hashpack wallet, then find the NFTs associated with that. I figured out to query the mirror node for the data, but I can't seem to get the accountId from the wallet.

I feel like I'm missing something obvious again. Sorry to open an issue to ask this...

What am i missing to be able to get the accountIds?

Thanks!

rajatK012 commented 2 years ago

At component did mount hooks walletData doesn't contains any account id , When you are connecting to wallet , Paring event handler is fired, That recived account id, and the same account id then provided to hook.

So you can use useEffect hook in your component for requestion nft's of linked account id

   ... required imports
const Compoenent = () => {
  const {
    walletData: { accountIds },
  } = useHashconnect();
  //accountIds  is array of accounts
  useEffect(() => {
    getNFTSofAccount(accountIds[0]);
  }, [accountIds]);
  return <div>Your Element</div>;
};