Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
spsjvc committed Jan 13, 2025
1 parent a383cf1 commit fe22afa
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
18 changes: 18 additions & 0 deletions packages/arb-token-bridge-ui/src/types/ChainId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export enum ChainId {
// L1
Ethereum = 1,
// L1 Testnets
Local = 1337,
Sepolia = 11155111,
Holesky = 17000,
// L2
ArbitrumOne = 42161,
ArbitrumNova = 42170,
Base = 8453,
// L2 Testnets
ArbitrumSepolia = 421614,
ArbitrumLocal = 412346,
BaseSepolia = 84532,
// L3 Testnets
L3Local = 333333
}
2 changes: 1 addition & 1 deletion packages/arb-token-bridge-ui/src/util/rpc/alchemy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadEnvironmentVariableWithFallback } from '..'
import { ChainId } from '../networks'
import { ChainId } from '../../types/ChainId'
import { ProductionChainId } from './getRpcUrl'

export function getAlchemyRpcUrl(
Expand Down
21 changes: 21 additions & 0 deletions packages/arb-token-bridge-ui/src/util/rpc/getRpcUrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ChainId } from '../../types/ChainId'
import { getRpcUrl } from './getRpcUrl'
import { getInfuraRpcUrl, InfuraSupportedChainId } from './infura'

it('(infura) returns rpc for ethereum mainnet', () => {
expect(getRpcUrl(1, 'infura', '123456')).toEqual(
'https://mainnet.infura.io/v3/123456'
)
})

it('(infura) returns public rpc for arbitrum nova', () => {
expect(getRpcUrl(ChainId.ArbitrumNova, 'infura', '654321')).toEqual(
'https://nova.arbitrum.io/rpc'
)
})

it('(alchemy) returns rpc for ethereum mainnet', () => {
expect(getRpcUrl(1, 'alchemy', '123456')).toEqual(
'https://eth-mainnet.g.alchemy.com/v2/123456'
)
})
4 changes: 2 additions & 2 deletions packages/arb-token-bridge-ui/src/util/rpc/getRpcUrl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainId } from '../networks'
import { ChainId } from '../../types/ChainId'

import { getInfuraRpcUrl } from './infura'
import { getAlchemyRpcUrl } from './alchemy'
Expand All @@ -17,7 +17,7 @@ function getRpcProvider(): RpcProvider {

export function getRpcUrl(
chainId: ProductionChainId,
rpcProvider: string = getRpcProvider(),
rpcProvider: RpcProvider = getRpcProvider(),
rpcProviderKey?: string
): string | undefined {
switch (rpcProvider) {
Expand Down
6 changes: 3 additions & 3 deletions packages/arb-token-bridge-ui/src/util/rpc/infura.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadEnvironmentVariableWithFallback } from '..'
import { ChainId } from '../networks'
import { ChainId } from '../../types/ChainId'
import { ProductionChainId } from './getRpcUrl'

export type InfuraSupportedChainId = Exclude<
Expand All @@ -8,7 +8,7 @@ export type InfuraSupportedChainId = Exclude<
ChainId.ArbitrumNova
>

export function getInfuraKey(chainId: InfuraSupportedChainId): string {
export function getInfuraKeyFromEnv(chainId: InfuraSupportedChainId): string {
const defaultInfuraKey = process.env.NEXT_PUBLIC_INFURA_KEY

switch (chainId) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export function getInfuraKey(chainId: InfuraSupportedChainId): string {

export function getInfuraRpcUrl(
chainId: InfuraSupportedChainId,
infuraKey: string = getInfuraKey(chainId)
infuraKey: string = getInfuraKeyFromEnv(chainId)
): string {
switch (chainId) {
// L1 Mainnet
Expand Down

0 comments on commit fe22afa

Please sign in to comment.