Skip to content

Commit

Permalink
Merge pull request #1191 from DarkFlorist/universal-chains-chainlist-fix
Browse files Browse the repository at this point in the history
Fix duplicate entry in chain list
  • Loading branch information
KillariDev authored Nov 25, 2024
2 parents 967b99c + 5114918 commit e5820bd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion 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,5 +178,11 @@ export const getAddressBookEntryOrAFiller = (addressMetaData: readonly AddressBo
}

export const rpcEntriesToChainEntriesWithAllChainsEntry = (rpcEntries: RpcEntries): readonly ChainEntry[] => {
return [ ...rpcEntries.map((rpcEntry) => ({ name: rpcEntry.name, chainId: rpcEntry.chainId })), { name: 'All Chains', chainId: 'AllChains' as const }]
const entries = rpcEntries.map(({ chainId }): [string, ChainEntry] => {
const chainIdString = chainId.toString()
return [chainIdString, { chainId, name: CHAIN_NAMES.get(chainIdString) || `Chain ID: ${ chainIdString }` }]
})
const chainsMap = new Map<string, ChainEntry>(entries)
chainsMap.set('AllChains', { name: 'All Chains', chainId: 'AllChains' })
return [...chainsMap.values()]
}

0 comments on commit e5820bd

Please sign in to comment.