Skip to content

Commit

Permalink
Merge branch 'main' into kylan/address-book-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sethkfman authored May 31, 2024
2 parents 40f9212 + d5feb26 commit 78f1a48
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { selectNetworkConfigurations } from '../../../../../selectors/networkCon
import { strings } from '../../../../../../locales/i18n';
import Routes from '../../../../../constants/navigation/Routes';

import PopularList from '../../../../../util/networks/customNetworks';
import { PopularList } from '../../../../../util/networks/customNetworks';

function NetworkSwitcher() {
const navigation = useNavigation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import EmptyPopularList from '../emptyList';
import { useNavigation } from '@react-navigation/native';
import { strings } from '../../../../../../../locales/i18n';
import { useTheme } from '../../../../../../util/theme';
import PopularList from '../../../../../../util/networks/customNetworks';
import { PopularList } from '../../../../../../util/networks/customNetworks';
import createStyles from '../styles';
import { CustomNetworkProps, Network } from './CustomNetwork.types';
import { selectNetworkConfigurations } from '../../../../../../selectors/networkController';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import AppConstants from '../../../../../core/AppConstants';
import { MetaMetricsEvents } from '../../../../../core/Analytics';
import ScrollableTabView from 'react-native-scrollable-tab-view';
import DefaultTabBar from 'react-native-scrollable-tab-view/DefaultTabBar';
import PopularList from '../../../../../util/networks/customNetworks';
import { PopularList } from '../../../../../util/networks/customNetworks';
import WarningMessage from '../../../confirmations/SendFlow/WarningMessage';
import InfoModal from '../../../../UI/Swaps/components/InfoModal';
import {
Expand Down
2 changes: 1 addition & 1 deletion app/core/RPCMethods/networkChecker.util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';
import { BannerAlertSeverity } from '../../component-library/components/Banners/Banner';
import { strings } from '../../../locales/i18n';
import PopularList from '../../util/networks/customNetworks';
import { PopularList } from '../../util/networks/customNetworks';

import { toHex } from '@metamask/controller-utils';

Expand Down
2 changes: 1 addition & 1 deletion app/util/getImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PopularList from './networks/customNetworks';
import { PopularList } from './networks/customNetworks';

const getImage = (chainId: string) => {
const customNetworkData = PopularList.filter(
Expand Down
2 changes: 1 addition & 1 deletion app/util/networks/customNetworks.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PopularList from './customNetworks';
import { PopularList } from './customNetworks';
import { toHex } from '@metamask/controller-utils';

describe('popularNetwork', () => {
Expand Down
34 changes: 32 additions & 2 deletions app/util/networks/customNetworks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { toHex } from '@metamask/controller-utils';
const InfuraKey = process.env.MM_INFURA_PROJECT_ID;
const infuraProjectId = InfuraKey === 'null' ? '' : InfuraKey;

const PopularList = [
export const PopularList = [
{
chainId: toHex('43114'),
nickname: 'Avalanche Mainnet C-Chain',
Expand Down Expand Up @@ -98,4 +98,34 @@ const PopularList = [
},
];

export default PopularList;
/**
* List of popularList will change in the future, removing networks from the list will lead to users not
* seeing the logo of the network anymore.
* We can keep this new list updated with any network removed from the popular list so we keep returning the logo of the network.
*/
export const UnpopularNetworkList = [
{
chainId: toHex('250'),
nickname: 'Fantom Opera',
rpcUrl: 'https://rpc.ftm.tools/',
ticker: 'FTM',
warning: true,
rpcPrefs: {
blockExplorerUrl: 'https://ftmscan.com',
imageUrl: 'FTM',
imageSource: require('../../images/fantom.png'),
},
},
{
chainId: toHex('1666600000'),
nickname: 'Harmony Mainnet Shard 0',
rpcUrl: 'https://api.harmony.one/',
ticker: 'ONE',
warning: true,
rpcPrefs: {
blockExplorerUrl: 'https://basescan.org',
imageUrl: 'BASE',
imageSource: require('../../images/base.png'),
},
},
];
12 changes: 9 additions & 3 deletions app/util/networks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const lineaTestnetLogo = require('../../images/linea-testnet-logo.png');
const lineaMainnetLogo = require('../../images/linea-mainnet-logo.png');

/* eslint-enable */
import PopularList from './customNetworks';
import { PopularList, UnpopularNetworkList } from './customNetworks';
import { strings } from '../../../locales/i18n';
import {
getEtherscanAddressUrl,
Expand Down Expand Up @@ -414,11 +414,17 @@ export const getNetworkImageSource = ({ networkType, chainId }) => {
return defaultNetwork.imageSource;
}

const unpopularNetwork = UnpopularNetworkList.find(
(networkConfig) => networkConfig.chainId === chainId,
);

const popularNetwork = PopularList.find(
(networkConfig) => networkConfig.chainId === chainId,
);
if (popularNetwork) {
return popularNetwork.rpcPrefs.imageSource;

const network = unpopularNetwork || popularNetwork;
if (network) {
return network.rpcPrefs.imageSource;
}
return getTestNetImage(networkType);
};
Expand Down

0 comments on commit 78f1a48

Please sign in to comment.