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 client.ts: reset EthersStoreUtil's error before new operation #1921

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class Web3Modal extends Web3ModalScaffold {
const chainId = HelpersUtil.caipNetworkIdToNumber(caipNetwork?.id)
if (chainId) {
try {
EthersStoreUtil.setError(undefined)
await this.switchNetwork(chainId)
} catch (error) {
EthersStoreUtil.setError(error)
Expand Down Expand Up @@ -198,13 +199,15 @@ export class Web3Modal extends Web3ModalScaffold {
throw new Error('connectionControllerClient:connectInjected - provider is undefined')
}
try {
EthersStoreUtil.setError(undefined)
await InjectedProvider.request({ method: 'eth_requestAccounts' })
this.setInjectedProvider(ethersConfig)
} catch (error) {
EthersStoreUtil.setError(error)
}
} else if (id === ConstantsUtil.EIP6963_CONNECTOR_ID && info && provider) {
try {
EthersStoreUtil.setError(undefined)
await provider.request({ method: 'eth_requestAccounts' })
this.setEIP6963Provider(provider, info.name)
} catch (error) {
Expand All @@ -217,6 +220,7 @@ export class Web3Modal extends Web3ModalScaffold {
}

try {
EthersStoreUtil.setError(undefined)
await CoinbaseProvider.request({ method: 'eth_requestAccounts' })
this.setCoinbaseProvider(ethersConfig)
} catch (error) {
Expand Down Expand Up @@ -395,6 +399,7 @@ export class Web3Modal extends Web3ModalScaffold {
const walletConnectProvider = provider as unknown as EthereumProvider
if (walletConnectProvider) {
try {
EthersStoreUtil.setError(undefined)
await walletConnectProvider.disconnect()
} catch (error) {
EthersStoreUtil.setError(error)
Expand Down Expand Up @@ -440,6 +445,7 @@ export class Web3Modal extends Web3ModalScaffold {
private async getWalletConnectProvider() {
if (!this.walletConnectProvider) {
try {
EthersStoreUtil.setError(undefined)
await this.createProvider()
} catch (error) {
EthersStoreUtil.setError(error)
Expand Down
5 changes: 5 additions & 0 deletions packages/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class Web3Modal extends Web3ModalScaffold {
const chainId = HelpersUtil.caipNetworkIdToNumber(caipNetwork?.id)
if (chainId) {
try {
EthersStoreUtil.setError(undefined)
await this.switchNetwork(chainId)
} catch (error) {
EthersStoreUtil.setError(error)
Expand Down Expand Up @@ -188,13 +189,15 @@ export class Web3Modal extends Web3ModalScaffold {
throw new Error('connectionControllerClient:connectInjected - provider is undefined')
}
try {
EthersStoreUtil.setError(undefined)
await InjectedProvider.request({ method: 'eth_requestAccounts' })
this.setInjectedProvider(ethersConfig)
} catch (error) {
EthersStoreUtil.setError(error)
}
} else if (id === ConstantsUtil.EIP6963_CONNECTOR_ID && info && provider) {
try {
EthersStoreUtil.setError(undefined)
await provider.request({ method: 'eth_requestAccounts' })
} catch (error) {
EthersStoreUtil.setError(error)
Expand All @@ -207,6 +210,7 @@ export class Web3Modal extends Web3ModalScaffold {
}

try {
EthersStoreUtil.setError(undefined)
this.setCoinbaseProvider(ethersConfig)
await CoinbaseProvider.request({ method: 'eth_requestAccounts' })
} catch (error) {
Expand Down Expand Up @@ -411,6 +415,7 @@ export class Web3Modal extends Web3ModalScaffold {
private async getWalletConnectProvider() {
if (!this.walletConnectProvider) {
try {
EthersStoreUtil.setError(undefined)
await this.createProvider()
} catch (error) {
EthersStoreUtil.setError(error)
Expand Down
Loading