Skip to content

Commit

Permalink
Fix client.ts: reset EthersStoreUtil's error before new operation (#1921
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dextfprotocol authored Feb 14, 2024
1 parent fa5ca37 commit 76bd130
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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

0 comments on commit 76bd130

Please sign in to comment.