diff --git a/apps/earn-protocol/components/layout/VaultsListView/VaultsListView.tsx b/apps/earn-protocol/components/layout/VaultsListView/VaultsListView.tsx index 694dbee87..7a250d993 100644 --- a/apps/earn-protocol/components/layout/VaultsListView/VaultsListView.tsx +++ b/apps/earn-protocol/components/layout/VaultsListView/VaultsListView.tsx @@ -15,12 +15,7 @@ import { type SDKNetwork, type SDKVaultsListType, } from '@summerfi/app-types' -import { - formatCryptoBalance, - humanNetworktoSDKNetwork, - sdkNetworkToHumanNetwork, - zero, -} from '@summerfi/app-utils' +import { formatCryptoBalance, sdkNetworkToHumanNetwork, zero } from '@summerfi/app-utils' import { capitalize } from 'lodash-es' import { networkIconByNetworkName } from '@/constants/networkIcons' @@ -50,9 +45,7 @@ export const VaultsListView = ({ selectedNetwork, vaultsList }: VaultsListViewPr const networkFilteredVaults = useMemo( () => localVaultNetwork && localVaultNetwork !== 'all-networks' - ? vaultsList.filter( - (vault) => sdkNetworkToHumanNetwork(vault.protocol.network) === localVaultNetwork, - ) + ? vaultsList.filter(({ protocol }) => protocol.network === localVaultNetwork) : vaultsList, [localVaultNetwork, vaultsList], ) @@ -63,10 +56,8 @@ export const VaultsListView = ({ selectedNetwork, vaultsList }: VaultsListViewPr () => localVaultNetwork && localVaultNetwork !== 'all-networks' ? { - iconName: networkIconByNetworkName[ - humanNetworktoSDKNetwork(localVaultNetwork) - ] as IconNamesList, - value: sdkNetworkToHumanNetwork(localVaultNetwork), + iconName: networkIconByNetworkName[localVaultNetwork] as IconNamesList, + value: localVaultNetwork, label: capitalize(sdkNetworkToHumanNetwork(localVaultNetwork)), } : allNetworksOption, @@ -76,7 +67,7 @@ export const VaultsListView = ({ selectedNetwork, vaultsList }: VaultsListViewPr () => [ ...[...new Set(vaultsList.map(({ protocol }) => protocol.network))].map((network) => ({ iconName: networkIconByNetworkName[network] as IconNamesList, - value: sdkNetworkToHumanNetwork(network), + value: network, label: capitalize(sdkNetworkToHumanNetwork(network)), })), allNetworksOption, @@ -101,7 +92,7 @@ export const VaultsListView = ({ selectedNetwork, vaultsList }: VaultsListViewPr if (selectedVaultData && selectedVaultData.protocol.network !== selected.value) { setVaultId(undefined) } - softRouterPush(`/earn/${selected.value}`) + softRouterPush(`/earn/${sdkNetworkToHumanNetwork(selected.value as SDKNetwork)}`) break } diff --git a/packages/app-utils/src/helpers/earn-network-tools.ts b/packages/app-utils/src/helpers/earn-network-tools.ts index 867087751..3868ee467 100644 --- a/packages/app-utils/src/helpers/earn-network-tools.ts +++ b/packages/app-utils/src/helpers/earn-network-tools.ts @@ -13,12 +13,17 @@ export const isSupportedSDKChain = ( ): chainId is SDKChainId.ARBITRUM | SDKChainId.BASE => typeof chainId === 'number' && sdkSupportedChains.includes(chainId) -export const sdkNetworkToHumanNetwork = (network: SDKNetwork): string => { - const humanReadableNetworkMap = { - [SDKNetwork.ArbitrumOne]: 'arbitrum', - [SDKNetwork.Base]: 'base', - } +const humanReadableNetworkMap = { + [SDKNetwork.ArbitrumOne]: 'arbitrum', + [SDKNetwork.Base]: 'base', +} +const sdkNetworkMap = { + arbitrum: SDKNetwork.ArbitrumOne, + base: SDKNetwork.Base, +} + +export const sdkNetworkToHumanNetwork = (network: SDKNetwork): string => { if (!humanReadableNetworkMap[network as SDKSupportedNetwork]) { // eslint-disable-next-line no-console console.error('sdkNetworkToHumanNetwork: Network needs mapping', network) @@ -30,12 +35,10 @@ export const sdkNetworkToHumanNetwork = (network: SDKNetwork): string => { } export const humanNetworktoSDKNetwork = (network: string): SDKNetwork => { - const sdkNetworkMap = { - arbitrum: SDKNetwork.ArbitrumOne, - base: SDKNetwork.Base, + if (network in humanReadableNetworkMap) { + return network.toLowerCase() as SDKNetwork } - - const sdkNetwork = sdkNetworkMap[network.toLowerCase() as Partial] + const sdkNetwork = sdkNetworkMap[network.toLowerCase() as keyof typeof sdkNetworkMap] // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (!sdkNetwork) {