Skip to content

Commit

Permalink
Merge pull request #377 from blocto/fix/web3-react-switchchain
Browse files Browse the repository at this point in the history
fix(web3-react): replace eth_accounts with eth_requestAccounts
  • Loading branch information
q20274982 authored Jan 17, 2024
2 parents 06333cf + ec0bf5c commit 6d26e4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-pumpkins-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blocto/web3-react-connector': patch
---

fix(web3-react): use eth_requestAccounts replace eth_accounts
10 changes: 4 additions & 6 deletions adapters/web3-react-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class BloctoConnector extends Connector {
'connect',
async ({ chainId }: ProviderConnectInfo): Promise<void> => {
const accounts = await this.provider.request({
method: 'eth_accounts',
method: 'eth_requestAccounts',
});
this.actions.update({ chainId: parseChainId(chainId), accounts });
}
Expand All @@ -56,13 +56,11 @@ export class BloctoConnector extends Connector {
this.onError?.(error);
});
this.provider.on('chainChanged', async (chainId: string): Promise<void> => {
const accounts = await this.provider.request({ method: 'eth_accounts' });
const accounts = await this.provider.request({
method: 'eth_requestAccounts',
});
this.actions.update({ chainId: parseChainId(chainId), accounts });
});
this.provider.on('accountsChanged', (accounts: string[]): void => {
if (accounts.length === 0) this.actions.resetState();
else this.actions.update({ accounts });
});
}

public async activate(
Expand Down

0 comments on commit 6d26e4b

Please sign in to comment.