Skip to content

Commit

Permalink
Fix wrong logic on switch/add network
Browse files Browse the repository at this point in the history
  • Loading branch information
philogicae committed Sep 6, 2024
1 parent 4f5604a commit 4ec378c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/evm/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ export abstract class EVMAccount extends ECIESAccount {
public async changeNetwork(chainOrRpc: RpcType | RpcId = RpcId.ETH): Promise<void> {
if (this.wallet instanceof JsonRPCWallet) {
await this.wallet.changeNetwork(chainOrRpc)
}
if (this.wallet instanceof ethers.Wallet) {
//await this.wallet.provider.send("wallet_switchEthereumChain", [{ chainId: chainId.toString(16) }]);
} else if (this.wallet instanceof ethers.Wallet) {
throw new Error('Not implemented for ethers.Wallet')
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/evm/src/provider/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ export class JsonRPCWallet extends BaseProviderWallet {
try {
await this.provider.send('wallet_switchEthereumChain', [{ chainId: chainData.chainId }])
} catch (error) {
await this.addNetwork(chainData)
if ((error as { code: number }).code === 4001) console.log('User rejected the switch chain request')
else await this.addNetwork(chainData)
}
}

Expand Down

0 comments on commit 4ec378c

Please sign in to comment.