Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename getBaseChainIdByChainId #2017

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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({
brtkx marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -62,21 +62,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 @@ -86,22 +86,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 @@ -111,7 +111,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 @@ -121,7 +121,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