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

record.content.name doesn't change on chainChanged event.... #85

Open
C0D3O opened this issue Jul 17, 2023 · 0 comments
Open

record.content.name doesn't change on chainChanged event.... #85

C0D3O opened this issue Jul 17, 2023 · 0 comments

Comments

@C0D3O
Copy link

C0D3O commented Jul 17, 2023

hey, first of all I need to ask whether I understand it correctly, that the user Id is being set for the particular chain, and not for every one?
For example if I set the id for the ethereum mainnet, there should be no name when I change to goerli for example, right?

If yes then the issue.. the name stays the same for any chain, tho it should be set to null or smth when the chain change.. I tried even deleting the cookie mannually tho, doesn't help

so on chain change I disconnect from the authProvider and connect to the new one again.. and I guess it should change the name also?... what do I do wrong could you tell please, thank you:)

maybe I should use State hook to store the authProvider there and interact with it in the chain change callback?))) ok I'll try it now

no, doesn't change anything..:(

it seems like the provider doesn't change inside of the ethereumAuthProvider.... when I change the chain, I still get the names from the prev chain, or still not getting anything, if there weren't any names in the prev chain

here's the logs and the code

doesn't change

const getProvider = async () => {
		try {
			disconnect();
			dispatch(setAccountName(''));
			dispatch(setDID(''));
			console.log('chain change event');
			console.log('Browser provider chainId', window.ethereum.chainId);

			if (!window.ethereum) throw new Error("Metamask isn't installed");
			await getChainId();

			const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
			const authProvider = new EthereumAuthProvider(window.ethereum, accounts[0]);

			console.log('ethAuthProvider chain', (await authProvider.accountId()).chainId.reference);

			connect(authProvider);
			dispatch(setAccount(accounts[0]));
		} catch (error: any) {
			dispatch(setErrors([error]));

			if (error.code === -32002) await connectTheWallet();
		}
	};
	
useEffect(() => {
			window.ethereum.on('chainChanged', getProvider);
			
			return () => {
			window.ethereum?.removeListener('chainChanged', getProvider);
			}
			
			
},[])

and I use the top-level provider inside of my root nextjs layout.. if I try to use it inside of the separate page where I need to read the data from ceramic, I get the no QueryClientProvider error....

so how should I change the chainId inside of the ethAuthProvider? thank you

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

1 participant