From ae0d9288561339ad9f508a43cbcf2e5310b3985e Mon Sep 17 00:00:00 2001 From: Fionna <13184582+fionnachan@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:16:29 +0100 Subject: [PATCH] feat: rename getBaseChainIdByChainId --- .../src/hooks/useTransferDuration.ts | 4 ++-- .../src/util/__tests__/networks.test.ts | 22 +++++++++---------- .../arb-token-bridge-ui/src/util/networks.ts | 6 +++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts b/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts index 7fb58bf135..7a1777538e 100644 --- a/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts +++ b/packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts @@ -4,7 +4,7 @@ import { isValidTeleportChainPair } from '@/token-bridge-sdk/teleport' import { MergedTransaction } from '../state/app/state' import { useRemainingTimeCctp } from '../state/cctpState' import { - getBaseChainIdByChainId, + getBlockNumberReferenceChainIdByChainId, getConfirmPeriodBlocks, getL1BlockTime, isNetwork @@ -121,7 +121,7 @@ export function getWithdrawalConfirmationDate({ // For new txs createdAt won't be defined yet, we default to the current time in that case const createdAtDate = createdAt ? dayjs(createdAt) : dayjs() - const baseChainId = getBaseChainIdByChainId({ + const baseChainId = getBlockNumberReferenceChainIdByChainId({ chainId: withdrawalFromChainId }) // the block time is always base chain's block time regardless of withdrawing from L3 to L2 or from L2 to L1 diff --git a/packages/arb-token-bridge-ui/src/util/__tests__/networks.test.ts b/packages/arb-token-bridge-ui/src/util/__tests__/networks.test.ts index 2dbeb6f3cb..20743cca16 100644 --- a/packages/arb-token-bridge-ui/src/util/__tests__/networks.test.ts +++ b/packages/arb-token-bridge-ui/src/util/__tests__/networks.test.ts @@ -2,7 +2,7 @@ import { registerCustomArbitrumNetwork } from '@arbitrum/sdk' import { ChainId, - getBaseChainIdByChainId, + getBlockNumberReferenceChainIdByChainId, getDestinationChainIds, getSupportedChainIds } from '../networks' @@ -63,21 +63,21 @@ beforeAll(() => { registerCustomArbitrumNetwork(polterTestnet) }) -describe('getBaseChainIdByChainId', () => { +describe('getBlockNumberReferenceChainIdByChainId', () => { describe('chainId is the id of a base chain', () => { it('should return the chainId', () => { expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.Ethereum }) ).toBe(ChainId.Ethereum) expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.Sepolia }) ).toBe(ChainId.Sepolia) expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.Local }) ).toBe(ChainId.Local) @@ -87,22 +87,22 @@ describe('getBaseChainIdByChainId', () => { describe('chainId is the id of an L2 chain', () => { it('should return the correct base chain', () => { expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.ArbitrumOne }) ).toBe(ChainId.Ethereum) expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.ArbitrumNova }) ).toBe(ChainId.Ethereum) expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.ArbitrumSepolia }) ).toBe(ChainId.Sepolia) expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: ChainId.ArbitrumLocal }) ).toBe(ChainId.Local) @@ -112,7 +112,7 @@ describe('getBaseChainIdByChainId', () => { describe('chainId is the id of an L3 Orbit chain', () => { it('should return the correct base chain', () => { expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: xaiTestnetChainId }) ).toBe(ChainId.Sepolia) @@ -122,7 +122,7 @@ describe('getBaseChainIdByChainId', () => { describe('chainId is the id of an chain not added to the list of chains', () => { it('should return the chainId', () => { expect( - getBaseChainIdByChainId({ + getBlockNumberReferenceChainIdByChainId({ chainId: 2222 }) ).toBe(2222) diff --git a/packages/arb-token-bridge-ui/src/util/networks.ts b/packages/arb-token-bridge-ui/src/util/networks.ts index 02d26cdeb3..1d0d3e5941 100644 --- a/packages/arb-token-bridge-ui/src/util/networks.ts +++ b/packages/arb-token-bridge-ui/src/util/networks.ts @@ -106,7 +106,7 @@ export type ChainWithRpcUrl = ArbitrumNetwork & { slug?: string } -export function getBaseChainIdByChainId({ +export function getBlockNumberReferenceChainIdByChainId({ chainId }: { chainId: number @@ -271,7 +271,9 @@ export const getExplorerUrl = (chainId: ChainId) => { } export const getL1BlockTime = (chainId: number) => { - const chain = getChainByChainId(getBaseChainIdByChainId({ chainId })) + const chain = getChainByChainId( + getBlockNumberReferenceChainIdByChainId({ chainId }) + ) if (!chain || !isBlockNumberReferenceNetwork(chain)) { throw new Error(`Couldn't get block time. Unexpected chain ID: ${chainId}`)