Skip to content

Commit

Permalink
Merge pull request #512 from hemilabs/reorder-imports-custom-rpc
Browse files Browse the repository at this point in the history
Reorder imports for customizing chain with rpc
  • Loading branch information
jcvernaleo authored Sep 11, 2024
2 parents 2e2f8d5 + da75212 commit 26bcac7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion webapp/networks/mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { overrideRpcUrl } from 'utils/chain'
import { overrideRpcUrl } from 'networks/utils'
import { mainnet as mainnetDefinition } from 'viem/chains'

export const mainnet = overrideRpcUrl(
Expand Down
2 changes: 1 addition & 1 deletion webapp/networks/sepolia.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { overrideRpcUrl } from 'utils/chain'
import { overrideRpcUrl } from 'networks/utils'
import { sepolia as sepoliaDefinition } from 'viem/chains'

export const sepolia = overrideRpcUrl(
Expand Down
17 changes: 17 additions & 0 deletions webapp/networks/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type Chain as ViemChain } from 'viem'
import { defineChain } from 'viem/utils'

export const overrideRpcUrl = function (chain: ViemChain, rpcUrl?: string) {
const isValidCustomSepoliaRpc = !!rpcUrl && rpcUrl.startsWith('https')
if (isValidCustomSepoliaRpc) {
return defineChain({
...chain,
rpcUrls: {
default: {
http: [rpcUrl],
},
},
})
}
return chain
}

0 comments on commit 26bcac7

Please sign in to comment.