Skip to content

Commit

Permalink
chore(networkConfig): remove 1 place where manual testing and code se…
Browse files Browse the repository at this point in the history
…arching would be needed to add chains (#4857)

### Description

we should try to maintain a status quo where all we have to do in every
repo to add a chain is update a "NetworkId" enum and fix all compilation
errors that result from it

### Test plan

added spot checks for the two affected configs

### Related issues

cc
https://linear.app/valora/issue/ACT-1060/add-optimism-arbitrum-to-wallet

### Backwards compatibility

na

---------

Co-authored-by: Tom McGuire <Mcgtom10@gmail.com>
  • Loading branch information
cajubelt and MuckT committed Feb 23, 2024
1 parent d62d676 commit 6fbe62d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/web3/networkConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
walletConnectChainIdToNetwork,
walletConnectChainIdToNetworkId,
} from 'src/web3/networkConfig'
import { NetworkId, Network } from 'src/transactions/types'

describe('networkConfig', () => {
it('walletConnectChainIdToNetworkId spot checks', () => {
// not attempting to check every value (too circular). just making sure inversion of networkIdToWalletConnectChainId is working as expected
expect(walletConnectChainIdToNetworkId['eip155:42220']).toEqual(NetworkId['celo-mainnet'])
expect(walletConnectChainIdToNetworkId['eip155:1']).toEqual(NetworkId['ethereum-mainnet'])
})
it('walletConnectChainIdToNetwork spot checks', () => {
// not checking every value (too circular), just testing the logic used to populate this object
expect(walletConnectChainIdToNetwork['eip155:42220']).toEqual(Network.Celo)
expect(walletConnectChainIdToNetwork['eip155:1']).toEqual(Network.Ethereum)
})
})
26 changes: 7 additions & 19 deletions src/web3/networkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
optimism,
optimismSepolia,
} from 'viem/chains'
import _ from 'lodash'

export enum Testnets {
alfajores = 'alfajores',
Expand Down Expand Up @@ -482,26 +483,13 @@ export const networkIdToWalletConnectChainId: Record<NetworkId, string> = {
[NetworkId['op-sepolia']]: 'eip155:11155420',
}

export const walletConnectChainIdToNetworkId: Record<string, NetworkId> = {
'eip155:44787': NetworkId['celo-alfajores'],
'eip155:42220': NetworkId['celo-mainnet'],
'eip155:1': NetworkId['ethereum-mainnet'],
'eip155:11155111': NetworkId['ethereum-sepolia'],
'eip155:42161': NetworkId['arbitrum-one'],
'eip155:421614': NetworkId['arbitrum-sepolia'],
'eip155:10': NetworkId['op-mainnet'],
'eip155:11155420': NetworkId['op-sepolia'],
}
export const walletConnectChainIdToNetworkId: Record<string, NetworkId> = _.invert(
networkIdToWalletConnectChainId
) as Record<string, NetworkId>

export const walletConnectChainIdToNetwork: Record<string, Network> = {
'eip155:44787': Network.Celo,
'eip155:42220': Network.Celo,
'eip155:1': Network.Ethereum,
'eip155:11155111': Network.Ethereum,
'eip155:42161': Network.Arbitrum,
'eip155:421614': Network.Arbitrum,
'eip155:10': Network.Optimism,
'eip155:11155420': Network.Optimism,
export const walletConnectChainIdToNetwork: Record<string, Network> = {}
for (const [walletConnectChainId, networkId] of Object.entries(walletConnectChainIdToNetworkId)) {
walletConnectChainIdToNetwork[walletConnectChainId] = networkIdToNetwork[networkId]
}

Logger.info('Connecting to testnet: ', DEFAULT_TESTNET)
Expand Down

0 comments on commit 6fbe62d

Please sign in to comment.