Skip to content

Commit

Permalink
pull chain names from utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jubalm committed Nov 14, 2024
1 parent d5cedcc commit dd55f49
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/ts/components/ui-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { checksummedAddress } from '../utils/bigint.js'
import { PopupOrTabId } from '../types/websiteAccessTypes.js'
import { checkAndThrowRuntimeLastError, safeGetTab, safeGetWindow, updateTabIfExists, updateWindowIfExists } from '../utils/requests.js'
import { ChainEntry, RpcEntries } from '../types/rpc.js'
import { CHAIN_NAMES } from '../utils/chainNames.js'

function assertIsNode(e: EventTarget | null): asserts e is Node {
if (!e || !('nodeType' in e)) {
Expand Down Expand Up @@ -177,11 +178,11 @@ export const getAddressBookEntryOrAFiller = (addressMetaData: readonly AddressBo
}

export const rpcEntriesToChainEntriesWithAllChainsEntry = (rpcEntries: RpcEntries): readonly ChainEntry[] => {
const chainsMap = new Map<bigint | string, ChainEntry>()
for (const { chainId, name } of rpcEntries) {
if (chainsMap.has(chainId)) continue
chainsMap.set(chainId, { name, chainId })
}
const entries = rpcEntries.map(({ chainId }): [string, ChainEntry] => {
const chainIdString = String(Number(chainId))
return [chainIdString, { chainId, name: CHAIN_NAMES.get(chainIdString) || chainIdString }]
})
const chainsMap = new Map<string, ChainEntry>(entries)
chainsMap.set('AllChains', { name: 'All Chains', chainId: 'AllChains' })
return [...chainsMap.values()]
}

0 comments on commit dd55f49

Please sign in to comment.