Skip to content

Commit

Permalink
feat: rename getBaseChainIdByChainId
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan committed Oct 23, 2024
1 parent 2e1e23c commit ae0d928
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useTransferDuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions packages/arb-token-bridge-ui/src/util/__tests__/networks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { registerCustomArbitrumNetwork } from '@arbitrum/sdk'

import {
ChainId,
getBaseChainIdByChainId,
getBlockNumberReferenceChainIdByChainId,
getDestinationChainIds,
getSupportedChainIds
} from '../networks'
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions packages/arb-token-bridge-ui/src/util/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export type ChainWithRpcUrl = ArbitrumNetwork & {
slug?: string
}

export function getBaseChainIdByChainId({
export function getBlockNumberReferenceChainIdByChainId({
chainId
}: {
chainId: number
Expand Down Expand Up @@ -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}`)
Expand Down

0 comments on commit ae0d928

Please sign in to comment.