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

fix: wallet_addEthereumChain condition #2476

Merged
merged 7 commits into from
Jul 3, 2024
16 changes: 5 additions & 11 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,19 +1255,13 @@ export class Web3Modal extends Web3ModalScaffold {
EthersStoreUtil.setChainId(chainId)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (switchError: any) {
if (
switchError.code === EthersConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID ||
switchError.code === EthersConstantsUtil.ERROR_CODE_DEFAULT ||
switchError?.data?.originalError?.code ===
EthersConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID
) {
await EthersHelpersUtil.addEthereumChain(
WalletConnectProvider as unknown as Provider,
chain
)
} else {
if (/(?<temp1>user rejected)/u.test(switchError?.message)) {
ganchoradkov marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Chain is not supported')
}
await EthersHelpersUtil.addEthereumChain(
WalletConnectProvider as unknown as Provider,
chain
)
}
}
} else if (providerType === ConstantsUtil.INJECTED_CONNECTOR_ID && chain) {
Expand Down
16 changes: 5 additions & 11 deletions packages/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,19 +972,13 @@ export class Web3Modal extends Web3ModalScaffold {
EthersStoreUtil.setChainId(chainId)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (switchError: any) {
if (
switchError.code === EthersConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID ||
switchError.code === EthersConstantsUtil.ERROR_CODE_DEFAULT ||
switchError?.data?.originalError?.code ===
EthersConstantsUtil.ERROR_CODE_UNRECOGNIZED_CHAIN_ID
) {
await EthersHelpersUtil.addEthereumChain(
WalletConnectProvider as unknown as Provider,
chain
)
} else {
if (/(?<temp1>user rejected)/u.test(switchError?.message)) {
throw new Error('Chain is not supported')
}
await EthersHelpersUtil.addEthereumChain(
WalletConnectProvider as unknown as Provider,
chain
)
}
}
} else if (providerType === ConstantsUtil.EIP6963_CONNECTOR_ID && chain) {
Expand Down
Loading