-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Matthew Maxwell <[email protected]>
- Loading branch information
1 parent
a4d95ad
commit 25ab455
Showing
7 changed files
with
42 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 20 additions & 15 deletions
35
packages/shared/src/lib/core/layer-2/actions/pollEvmChainGasPrices.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
import { EvmChainId } from '@core/network/enums' | ||
import { NetworkId } from '@core/network/types' | ||
import { MILLISECONDS_PER_SECOND } from '@core/utils' | ||
import { updateEvmChainGasPrice } from './updateEvmChainGasPrice' | ||
|
||
const EVM_CHAIN_GAS_PRICE_POLLING_INTERVAL: number = 15 * MILLISECONDS_PER_SECOND | ||
const EVM_CHAIN_GAS_PRICE_POLLING_INTERVAL: number = 60 * MILLISECONDS_PER_SECOND | ||
|
||
const pollIntervalMap: { [key in EvmChainId]?: number } = {} | ||
const pollIntervalMap: { [id in NetworkId]?: number } = {} | ||
|
||
export function pollEvmChainGasPrice(chainId: NetworkId): void { | ||
if (!chainId || typeof pollIntervalMap[chainId] === 'number') { | ||
export function pollEvmChainGasPrice(networkId: NetworkId): void { | ||
if (!networkId || isPollingEvmChainGasPrice(networkId)) { | ||
return | ||
} | ||
void updateEvmChainGasPrice(chainId) | ||
pollIntervalMap[chainId] = window.setInterval(() => { | ||
void updateEvmChainGasPrice(chainId) | ||
void updateEvmChainGasPrice(networkId) | ||
pollIntervalMap[networkId] = window.setInterval(() => { | ||
void updateEvmChainGasPrice(networkId) | ||
}, EVM_CHAIN_GAS_PRICE_POLLING_INTERVAL) | ||
} | ||
|
||
export function pollEvmChainGasPrices(chainIds: NetworkId[]): void { | ||
export function pollEvmChainGasPrices(networkIds: NetworkId[]): void { | ||
stopPollingEvmChainGasPrices() | ||
for (const chainId of chainIds) { | ||
pollEvmChainGasPrice(chainId) | ||
for (const networkId of networkIds) { | ||
pollEvmChainGasPrice(networkId) | ||
} | ||
} | ||
|
||
export function stopPollingEvmChainGasPrices(chainIdsToIgnore?: NetworkId[]): void { | ||
for (const chainId of Object.keys(pollIntervalMap)) { | ||
if (!chainIdsToIgnore?.includes(chainId as NetworkId)) { | ||
clearInterval(pollIntervalMap[chainId]) | ||
export function stopPollingEvmChainGasPrices(networkIdsToIgnore?: NetworkId[]): void { | ||
for (const networkId of Object.keys(pollIntervalMap) as NetworkId[]) { | ||
if (!networkIdsToIgnore?.includes(networkId)) { | ||
if (isPollingEvmChainGasPrice(networkId)) { | ||
clearInterval(pollIntervalMap[networkId]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function isPollingEvmChainGasPrice(networkId: NetworkId): boolean { | ||
return typeof pollIntervalMap[networkId] === 'number' | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/shared/src/lib/core/layer-2/actions/updateEvmChainGasPrice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/shared/src/lib/core/layer-2/types/evm-chain-gas-prices.type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { EvmChainId } from '@core/network' | ||
import { NetworkId } from '@core/network/types' | ||
|
||
export type EvmChainGasPrices = { | ||
[key in EvmChainId]?: bigint | ||
[id in NetworkId]?: bigint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters