Skip to content

Commit

Permalink
fix: support query params for parents w/o children (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan authored Oct 18, 2024
1 parent d8f9e39 commit 189603d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ describe('sanitizeQueryParams', () => {
})
})
})
describe('when `destinationChainId` is valid but has no paired source chains and `sourceChainId` is undefined', () => {
it('should set `sourceChainId` to Ethereum and `destinationChainId` to Arbitrum One', () => {
const result = sanitizeQueryParams({
sourceChainId: undefined,
destinationChainId: ChainId.Holesky
})
expect(result).toEqual({
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
})
})
})

describe('when `destinationChainId` is invalid and `sourceChainId` is valid', () => {
it('should set `destinationChainId` based on `sourceChainId`', () => {
Expand Down Expand Up @@ -207,4 +219,16 @@ describe('sanitizeQueryParams', () => {
})
})
})
describe('when `destinationChainId` is undefined and `sourceChainId` is valid but has no paired destination chains', () => {
it('should set `sourceChainId` to Ethereum and `destinationChainId` to Arbitrum One', () => {
const result = sanitizeQueryParams({
sourceChainId: ChainId.Holesky,
destinationChainId: undefined
})
expect(result).toEqual({
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
})
})
})
})
20 changes: 18 additions & 2 deletions packages/arb-token-bridge-ui/src/hooks/useNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ export function sanitizeQueryParams({
isSupportedChainId(destinationChainId)
) {
const [defaultSourceChainId] = getDestinationChainIds(destinationChainId)
return { sourceChainId: defaultSourceChainId!, destinationChainId }

if (typeof defaultSourceChainId === 'undefined') {
return {
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
}
}

return { sourceChainId: defaultSourceChainId, destinationChainId }
}

// sourceChainId is valid and destinationChainId is undefined
Expand All @@ -83,9 +91,17 @@ export function sanitizeQueryParams({
!isSupportedChainId(destinationChainId)
) {
const [defaultDestinationChainId] = getDestinationChainIds(sourceChainId)

if (typeof defaultDestinationChainId === 'undefined') {
return {
sourceChainId: ChainId.Ethereum,
destinationChainId: ChainId.ArbitrumOne
}
}

return {
sourceChainId: sourceChainId,
destinationChainId: defaultDestinationChainId!
destinationChainId: defaultDestinationChainId
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/arb-token-bridge-ui/src/types/ChainQueryParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { chainToWagmiChain } from '../util/wagmi/wagmiAdditionalNetworks'
const chainQueryParams = [
'ethereum',
'sepolia',
'holesky',
'arbitrum-one',
'arbitrum-nova',
'arbitrum-sepolia',
Expand Down Expand Up @@ -50,6 +51,9 @@ export function getChainQueryParamForChain(chainId: ChainId): ChainQueryParam {
case ChainId.ArbitrumNova:
return 'arbitrum-nova'

case ChainId.Holesky:
return 'holesky'

case ChainId.Sepolia:
return 'sepolia'

Expand Down Expand Up @@ -94,6 +98,9 @@ export function getChainForChainKeyQueryParam(
case 'sepolia':
return chains.sepolia

case 'holesky':
return customChains.holesky

case 'arbitrum-one':
return chains.arbitrum

Expand Down

0 comments on commit 189603d

Please sign in to comment.