Skip to content

Commit

Permalink
fix: Improved getBlockPrices func and removed markNetworkActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKostroma committed Sep 27, 2024
1 parent bf512f0 commit eedbc1e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 33 deletions.
1 change: 0 additions & 1 deletion background/services/block/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Dexie, { DexieOptions } from "dexie"

import { AnyEVMBlock } from "../../networks"
import { NetworkInterface } from "../../constants/networks/networkTypes"
import { ChainDatabase } from "../chain/db"

export class BlockDatabase extends Dexie {
private blocks!: Dexie.Table<AnyEVMBlock, [string, string]>
Expand Down
15 changes: 7 additions & 8 deletions background/services/block/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getZoneForAddress, JsonRpcProvider, Shard, Zone } from "quais"
import { JsonRpcProvider, Shard, toZone } from "quais"
import { NetworkInterface } from "../../constants/networks/networkTypes"
import logger from "../../lib/logger"
import { AnyEVMBlock, BlockPrices, toHexChainID } from "../../networks"
Expand Down Expand Up @@ -144,9 +144,9 @@ export default class BlockService extends BaseService<Events> {
async getBlockPrices(
network: NetworkInterface,
provider: JsonRpcProvider,
shard: Shard,
zone: Zone
shard: Shard
): Promise<BlockPrices> {
const zone = toZone(shard)
const [currentBlock, feeData] = await Promise.all([
provider.getBlock(shard, "latest"),
provider.getFeeData(zone),
Expand Down Expand Up @@ -232,16 +232,15 @@ export default class BlockService extends BaseService<Events> {

const { address } = await this.preferenceService.getSelectedAccount()
const shard = getExtendedZoneForAddress(address, false) as Shard
const zone = getZoneForAddress(address)
if (!zone) {
logger.warn(`Can't get zone for ${address}`)

if (!shard) {
logger.warn(`Can't get shard for ${address}`)
return
}
const blockPrices = await this.getBlockPrices(
subscription.network,
subscription.provider,
shard,
zone
shard
)
await this.emitter.emit("blockPrices", {
blockPrices,
Expand Down
11 changes: 1 addition & 10 deletions background/services/chain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ export default class ChainService extends BaseService<Events> {
}: AddressOnNetwork): Promise<void> {
const addressWasInactive = this.addressIsInactive(address)
const networkWasInactive = this.networkIsInactive(network.chainID)
this.markNetworkActivity(network.chainID)
this.lastUserActivityOnNetwork[network.chainID] = Date.now()
this.lastUserActivityOnAddress[address] = Date.now()
if (addressWasInactive || networkWasInactive) {
// Reactivating a potentially deactivated address
Expand All @@ -799,15 +799,6 @@ export default class ChainService extends BaseService<Events> {
}
}

async markNetworkActivity(chainID: string): Promise<void> {
const networkWasInactive = this.networkIsInactive(chainID)
this.lastUserActivityOnNetwork[chainID] = Date.now()
if (networkWasInactive) {
// TODO
// await this.blockService.pollBlockPricesForNetwork(chainID)
}
}

addressIsInactive(address: string): boolean {
return (
Date.now() - NETWORK_POLLING_TIMEOUT >
Expand Down
14 changes: 0 additions & 14 deletions background/services/chain/tests/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ describe("Chain Service", () => {

jest.advanceTimersByTime(100)

chainService.markNetworkActivity(QuaiGoldenAgeTestnet.chainID)

expect(lastUserActivity).toBeLessThan(
(chainService as unknown as ChainServiceExternalized)
.lastUserActivityOnNetwork[QuaiGoldenAgeTestnet.chainID]
Expand Down Expand Up @@ -123,18 +121,6 @@ describe("Chain Service", () => {
await chainService.stopService()
})

it("should call markNetworkActivity with the correct network", async () => {
const stub = sandbox
.stub(chainService, "markNetworkActivity")
.callsFake(async () => {})

chainService.markAccountActivity(
createAddressOnNetwork({ network: QuaiGoldenAgeTestnet })
)

expect(stub.calledWith(QuaiGoldenAgeTestnet.chainID)).toEqual(true)
})

it("should call loadRecentAssetTransfers if the NETWORK_POLLING_TIMEOUT has been exceeded", async () => {
const account = createAddressOnNetwork({ network: QuaiGoldenAgeTestnet })

Expand Down

0 comments on commit eedbc1e

Please sign in to comment.