diff --git a/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts b/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts index c579509dce..316ea56c4d 100644 --- a/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts +++ b/packages/arb-token-bridge-ui/src/token-bridge-sdk/EnhancedProvider.ts @@ -1,13 +1,17 @@ import { + JsonRpcBatchProvider, + Network, Networkish, - StaticJsonRpcProvider, TransactionReceipt } from '@ethersproject/providers' -import { BigNumber } from 'ethers' +import { BigNumber, version } from 'ethers' import { ChainId } from '../types/ChainId' -import { ConnectionInfo } from 'ethers/lib/utils.js' +import { ConnectionInfo, defineReadOnly } from 'ethers/lib/utils.js' import { isNetwork } from '../util/networks' +import { Logger } from '@ethersproject/logger' +const logger = new Logger(version) + interface Storage { getItem(key: string): string | null setItem(key: string, value: string): void @@ -128,7 +132,31 @@ function addTxReceiptToCache( ) } -export class EnhancedProvider extends StaticJsonRpcProvider { +export class EnhancedProvider extends JsonRpcBatchProvider { + async detectNetwork(): Promise { + let network = this.network + if (network == null) { + network = await super.detectNetwork() + + if (!network) { + logger.throwError( + 'no network detected', + Logger.errors.UNKNOWN_ERROR, + {} + ) + } + + // If still not set, set it + if (this._network == null) { + // A static network does not support "any" + defineReadOnly(this, '_network', network) + + this.emit('network', network, null) + } + } + return network + } + private storage: Storage constructor(