Skip to content

Commit

Permalink
Adjust rendering order in network switcher
Browse files Browse the repository at this point in the history
Pushes Ethereum and Mezo to the top of the list
  • Loading branch information
hyphenized committed Feb 25, 2025
1 parent 63340d8 commit b3c78d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions ui/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@
"popupEdition": "Community Edition",
"protocol": {
"mainnet": "Mainnet",
"mezoTestnet": "Mezo (Testnet)",
"beta": "Mainnet (beta)",
"testnet": "Test Network",
"l2": "L2 scaling solution",
Expand Down
24 changes: 23 additions & 1 deletion ui/components/TopMenu/TopMenuProtocolList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
OPTIMISM,
POLYGON,
ROOTSTOCK,
MEZO_TESTNET,
} from "@tallyho/tally-background/constants"
import { EVMNetwork, sameNetwork } from "@tallyho/tally-background/networks"
import { selectCurrentNetwork } from "@tallyho/tally-background/redux-slices/selectors"
Expand All @@ -24,6 +25,7 @@ import { i18n } from "../../_locales/i18n"

export const productionNetworkInfo = {
[ETHEREUM.chainID]: i18n.t("protocol.mainnet"),
[MEZO_TESTNET.chainID]: i18n.t("protocol.mezoTestnet"),
[POLYGON.chainID]: i18n.t("protocol.l2"),
[OPTIMISM.chainID]: i18n.t("protocol.l2"),
[ARBITRUM_ONE.chainID]: i18n.t("protocol.l2"),
Expand Down Expand Up @@ -52,6 +54,23 @@ type TopMenuProtocolListProps = {
onProtocolChange: (network: EVMNetwork) => void
}

/**
* Places Ethereum and Mezo network above other networks
*/
const sortByNetworkPriority = (a: EVMNetwork, b: EVMNetwork) => {
const getPriority = (network: EVMNetwork) => {
switch (true) {
case sameNetwork(ETHEREUM, network):
return 0
case sameNetwork(MEZO_TESTNET, network):
return 1
default:
return 2
}
}
return getPriority(a) - getPriority(b)
}

export default function TopMenuProtocolList({
onProtocolChange,
}: TopMenuProtocolListProps): ReactElement {
Expand All @@ -60,7 +79,10 @@ export default function TopMenuProtocolList({
const showTestNetworks = useBackgroundSelector(selectShowTestNetworks)
const productionNetworks = useBackgroundSelector(selectProductionEVMNetworks)

const builtinNetworks = productionNetworks.filter(isBuiltInNetwork)
const builtinNetworks = productionNetworks
.filter(isBuiltInNetwork)
.sort(sortByNetworkPriority)

const customNetworks = productionNetworks.filter(
(network) => !isBuiltInNetwork(network),
)
Expand Down

0 comments on commit b3c78d8

Please sign in to comment.