Skip to content

Commit

Permalink
getChainByChainId
Browse files Browse the repository at this point in the history
  • Loading branch information
fionnachan committed Dec 11, 2023
1 parent 15fd50c commit 5ba97a4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getL2ChainIds,
isNetwork
} from '../../util/networks'
import { getWagmiChain } from '../../util/wagmi/getWagmiChain'
import { getChainByChainId } from '../../util/wagmi/getChainByChainId'
import {
AdvancedSettings,
useDestinationAddressStore
Expand Down Expand Up @@ -110,7 +110,7 @@ export function SwitchNetworksButton(
}

function getListboxOptionsFromL1Network(network: Chain) {
return getL2ChainIds(network.id).map(chainId => getWagmiChain(chainId))
return getL2ChainIds(network.id).map(chainId => getChainByChainId(chainId))
}

function CustomAddressBanner({
Expand Down
10 changes: 5 additions & 5 deletions packages/arb-token-bridge-ui/src/hooks/useNetworksAndSigners.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
isNetwork,
rpcURLs
} from '../util/networks'
import { getWagmiChain } from '../util/wagmi/getWagmiChain'
import { getChainByChainId } from '../util/wagmi/getChainByChainId'
import { useArbQueryParams } from './useArbQueryParams'
import { trackEvent } from '../util/AnalyticsUtils'
import { errorToast } from '../components/common/atoms/Toast'
Expand Down Expand Up @@ -335,11 +335,11 @@ export function NetworksAndSignersProvider(
setResult({
status: UseNetworksAndSignersStatus.CONNECTED,
l1: {
network: getWagmiChain(parentChain.chainID),
network: getChainByChainId(parentChain.chainID),
provider: parentProvider
},
l2: {
network: getWagmiChain(chain.chainID),
network: getChainByChainId(chain.chainID),
provider: chainProvider
}
})
Expand Down Expand Up @@ -388,11 +388,11 @@ export function NetworksAndSignersProvider(
setResult({
status: UseNetworksAndSignersStatus.CONNECTED,
l1: {
network: getWagmiChain(parentChain.chainID),
network: getChainByChainId(parentChain.chainID),
provider: parentProvider
},
l2: {
network: getWagmiChain(chain.chainID),
network: getChainByChainId(chain.chainID),
provider: chainProvider
}
})
Expand Down
12 changes: 12 additions & 0 deletions packages/arb-token-bridge-ui/src/util/wagmi/getChainByChainId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Chain } from 'wagmi'
import { chainList } from './setup'

export function getChainByChainId(chainId: number): Chain {
const chain = chainList.find(chain => chain.id === chainId)

if (!chain) {
throw new Error(`[getWagmiChain] Unexpected chain id: ${chainId}`)
}

return chain
}
68 changes: 0 additions & 68 deletions packages/arb-token-bridge-ui/src/util/wagmi/getWagmiChain.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/arb-token-bridge-ui/src/util/wagmi/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const customChains = getCustomChainsFromLocalStorage().map(chain =>
chainToWagmiChain(chain)
)

const chainList = isTestingEnvironment
export const chainList = isTestingEnvironment
? [
// mainnet, arb1, & arb nova are for network switch tests
mainnet,
Expand Down Expand Up @@ -61,10 +61,6 @@ const chainList = isTestingEnvironment
...customChains
]

export function getChainByChainId(chainId: ChainId) {
return chainList.find(chain => chain.id === chainId)
}

const projectId = process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID!

if (!projectId) {
Expand Down

0 comments on commit 5ba97a4

Please sign in to comment.