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: pending transaction listener infinite requests #3443

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 22 additions & 0 deletions .changeset/tame-walls-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@reown/appkit-adapter-ethers5': patch
'@reown/appkit-adapter-ethers': patch
'@reown/appkit-adapter-wagmi': patch
'@reown/appkit-adapter-solana': patch
'@reown/appkit': patch
'@reown/appkit-utils': patch
'@reown/appkit-cdn': patch
'@reown/appkit-cli': patch
'@reown/appkit-common': patch
'@reown/appkit-core': patch
'@reown/appkit-experimental': patch
'@reown/appkit-polyfills': patch
'@reown/appkit-scaffold-ui': patch
'@reown/appkit-siwe': patch
'@reown/appkit-siwx': patch
'@reown/appkit-ui': patch
'@reown/appkit-wallet': patch
'@reown/appkit-wallet-button': patch
---

Fixed an issue where pending transaction listener was causing infinite request.
24 changes: 0 additions & 24 deletions packages/adapters/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
type Connector,
type ConnectorType,
type Provider,
AlertController,
CoreHelperUtil
} from '@reown/appkit-core'
import { ConstantsUtil, PresetsUtil } from '@reown/appkit-utils'
Expand All @@ -18,7 +17,6 @@
import type { W3mFrameProvider } from '@reown/appkit-wallet'
import { EthersMethods } from './utils/EthersMethods.js'
import { ProviderUtil } from '@reown/appkit/store'
import { BrowserProvider } from 'ethers'

export interface EIP6963ProviderDetail {
info: Connector['info']
Expand Down Expand Up @@ -265,7 +263,7 @@
connectors.forEach(connector => {
const key = connector === 'coinbase' ? 'coinbaseWalletSDK' : connector

const injectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID

Check warning on line 266 in packages/adapters/ethers/src/client.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Variable name `injectedConnector` must have one of the following prefixes: is, has, can, should, will, did

if (this.namespace) {
this.addConnector({
Expand Down Expand Up @@ -481,26 +479,6 @@
return { profileName: undefined, profileImage: undefined }
}

private listenPendingTransactions(provider: Provider) {
const browserProvider = new BrowserProvider(provider)

try {
browserProvider.on('pending', () => {
this.emit('pendingTransactions')
})
} catch (error) {
// eslint-disable-next-line no-console
AlertController.open(
{
shortMessage: 'Error listening to pending transactions',
longMessage:
'The BrowserProvider in the EthersAdapter failed to listen to pending transactions.'
},
'error'
)
}
}

private providerHandlers: {
disconnect: () => void
accountsChanged: (accounts: string[]) => void
Expand Down Expand Up @@ -528,8 +506,6 @@
this.emit('switchNetwork', { chainId: chainIdNumber })
}

this.listenPendingTransactions(provider)

provider.on('disconnect', disconnectHandler)
provider.on('accountsChanged', accountsChangedHandler)
provider.on('chainChanged', chainChangedHandler)
Expand Down
22 changes: 0 additions & 22 deletions packages/adapters/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type { CaipNetwork } from '@reown/appkit-common'
import { ConstantsUtil as CommonConstantsUtil } from '@reown/appkit-common'
import {
AlertController,
CoreHelperUtil,
type CombinedProvider,
type Connector,
Expand Down Expand Up @@ -265,7 +264,7 @@
connectors.forEach(connector => {
const key = connector === 'coinbase' ? 'coinbaseWalletSDK' : connector

const injectedConnector = connector === ConstantsUtil.INJECTED_CONNECTOR_ID

Check warning on line 267 in packages/adapters/ethers5/src/client.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Variable name `injectedConnector` must have one of the following prefixes: is, has, can, should, will, did

if (this.namespace) {
this.addConnector({
Expand Down Expand Up @@ -484,25 +483,6 @@
return { profileName: undefined, profileImage: undefined }
}

private listenPendingTransactions(provider: Provider) {
const web3Provider = new ethers.providers.Web3Provider(provider)

try {
web3Provider.on('pending', () => {
this.emit('pendingTransactions')
})
} catch (error) {
AlertController.open(
{
shortMessage: 'Error listening to pending transactions',
longMessage:
'The Web3Provider in the Ethers5Adapter failed to listen to pending transactions.'
},
'error'
)
}
}

private providerHandlers: {
disconnect: () => void
accountsChanged: (accounts: string[]) => void
Expand Down Expand Up @@ -530,8 +510,6 @@
this.emit('switchNetwork', { chainId: chainIdNumber })
}

this.listenPendingTransactions(provider)

provider.on('disconnect', disconnectHandler)
provider.on('accountsChanged', accountsChangedHandler)
provider.on('chainChanged', chainChangedHandler)
Expand Down
1 change: 1 addition & 0 deletions packages/adapters/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export class WagmiAdapter extends AdapterBlueprint {

private setupWatchers() {
watchPendingTransactions(this.wagmiConfig, {
pollingInterval: 15_000,
/* Magic RPC does not support the pending transactions. We handle transaction for the AuthConnector cases in AppKit client to handle all clients at once. Adding the onError handler to avoid the error to throw. */
// eslint-disable-next-line @typescript-eslint/no-empty-function
onError: () => {},
Expand Down
Loading