Skip to content

Commit

Permalink
fix missing testnets in supported chains
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Feb 13, 2025
1 parent 8f314af commit 55a0953
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 116 deletions.
8 changes: 1 addition & 7 deletions src/core/resources/assets/userAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { staleBalancesStore } from '~/core/state/staleBalances';
import { ParsedAssetsDictByChain, ParsedUserAsset } from '~/core/types/assets';
import { ChainId } from '~/core/types/chains';
import { AddressAssetsReceivedMessage } from '~/core/types/refraction';
import { getSupportedChains } from '~/core/utils/chains';
import { RainbowError, logger } from '~/logger';

import { parseUserAssets } from './common';
Expand Down Expand Up @@ -129,16 +128,11 @@ async function userAssetsQueryFunction({
const supportedAssetsChainIds = networkStore
.getState()
.getSupportedAssetsChainIds();
const supportedChainIds = getSupportedChains({
testnets: testnetMode,
})
.map(({ id }) => id)
.filter((id) => supportedAssetsChainIds.includes(id));
staleBalancesStore.getState().clearExpiredData(address as Address);
const staleBalancesParam = staleBalancesStore
.getState()
.getStaleBalancesQueryParam(address as Address);
const url = `/${supportedChainIds.join(
const url = `/${supportedAssetsChainIds.join(
',',
)}/${address}/assets/?currency=${currency.toLowerCase()}${staleBalancesParam}`;
const res = await addysHttp.get<AddressAssetsReceivedMessage>(url, {
Expand Down
25 changes: 6 additions & 19 deletions src/core/state/networks/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { fetchNetworks } from '~/core/resources/networks/networks';
import { favoritesStore } from '~/core/state/favorites';
import { createQueryStore } from '~/core/state/internal/createQueryStore';
import {
LOCAL_NETWORKS,
buildInitialUserPreferences,
differenceOrUnionOf,
mergeChainData,
Expand All @@ -26,10 +25,8 @@ import {

const IS_DEV = process.env.IS_DEV === 'true';
const INTERNAL_BUILD = process.env.INTERNAL_BUILD === 'true';
const IS_TESTING = process.env.IS_TESTING === 'true';

const DEFAULT_PRIVATE_MEMPOOL_TIMEOUT = 2 * 60 * 1_000; // 2 minutes
const LOCAL_TESTING_NETWORKS = IS_TESTING ? LOCAL_NETWORKS : [];

export interface NetworkState {
networks: Networks; // contains backend-driven networks and backend-driven custom networks
Expand Down Expand Up @@ -517,20 +514,14 @@ export const networkStore = createQueryStore<
getSupportedCustomNetworks: createSelector(
({ networks, mergedChainData }) => {
const existingNetworks = Object.keys(mergedChainData).map(Number);
return [
...networks.customNetworks.customNetworks,
...LOCAL_TESTING_NETWORKS,
]
return networks.customNetworks.customNetworks
.filter((network) => !existingNetworks.includes(network.id))
.sort((a, b) => a.name.localeCompare(b.name));
},
),

getSupportedCustomNetworksIconUrls: createSelector(({ networks }) => {
return [
...networks.customNetworks.customNetworks,
...LOCAL_TESTING_NETWORKS,
].reduce(
return networks.customNetworks.customNetworks.reduce(
(acc, network) => ({
...acc,
[network.id]: network.iconURL,
Expand All @@ -540,10 +531,7 @@ export const networkStore = createQueryStore<
}),

getSupportedCustomNetworksTestnetFaucets: createSelector(({ networks }) => {
return [
...networks.customNetworks.customNetworks,
...LOCAL_TESTING_NETWORKS,
].reduce(
return networks.customNetworks.customNetworks.reduce(
(acc, network) => ({
...acc,
[network.id]: network.testnet.FaucetURL,
Expand All @@ -555,10 +543,9 @@ export const networkStore = createQueryStore<
getSupportedCustomNetworkTestnetFaucet: createParameterizedSelector(
({ networks }) => {
return (chainId: ChainId) => {
const network = [
...networks.customNetworks.customNetworks,
...LOCAL_TESTING_NETWORKS,
].find((network) => network.id === chainId);
const network = networks.customNetworks.customNetworks.find(
(network) => network.id === chainId,
);
return network?.testnet.FaucetURL;
};
},
Expand Down
175 changes: 85 additions & 90 deletions src/core/state/networks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AddressZero } from '@ethersproject/constants';
import {
type Chain,
avalancheFuji,
Expand All @@ -16,7 +15,6 @@ import {
BackendNetworks,
ChainId,
ChainPreferences,
CustomNetwork,
Networks,
TransformedChain,
} from '~/core/types/chains';
Expand All @@ -26,6 +24,7 @@ import { logger } from '~/logger';
const RPC_PROXY_API_KEY = process.env.RPC_PROXY_API_KEY;
const INTERNAL_BUILD = process.env.INTERNAL_BUILD === 'true';
const IS_DEV = process.env.IS_DEV === 'true';
const IS_TESTING = process.env.IS_TESTING === 'true';

export const DEFAULT_PRIVATE_MEMPOOL_TIMEOUT = 2 * 60 * 1_000;

Expand Down Expand Up @@ -343,130 +342,122 @@ export function getDefaultPollingInterval(chainId: ChainId): number {
}
}

export const LOCAL_NETWORKS: CustomNetwork[] = [
export const LOCAL_TESTNETS: Chain[] = [
{
id: 1337,
name: 'Hardhat',
iconURL: '',
nativeAsset: {
decimals: 18,
testnet: true,
nativeCurrency: {
name: 'Hardhat ETH',
symbol: 'ETH',
iconURL: '',
decimals: 18,
},
defaultRPCURL: 'http://127.0.0.1:8545',
defaultExplorerURL: '',
testnet: {
FaucetURL: '',
isTestnet: true,
mainnetChainID: 1,
rpcUrls: {
default: {
http: ['http://127.0.0.1:8545'],
},
},
},
{
id: 1338,
name: 'Hardhat OP',
iconURL: '',
nativeAsset: {
decimals: 18,
symbol: 'ETH',
iconURL: '',
},
defaultRPCURL: 'http://127.0.0.1:8545',
defaultExplorerURL: '',
testnet: {
FaucetURL: '',
isTestnet: true,
mainnetChainID: 1,
},
},
{
id: 1,
name: 'Mainnet Fork',
iconURL: '',
nativeAsset: {
decimals: 18,
testnet: true,
nativeCurrency: {
name: 'Hardhat OP',
symbol: 'ETH',
iconURL: '',
},
defaultRPCURL: 'http://127.0.0.1:8545',
defaultExplorerURL: '',
testnet: {
FaucetURL: '',
isTestnet: true,
mainnetChainID: 1,
},
},
{
id: 31337,
name: 'Mainnet (Dev)',
iconURL: '',
nativeAsset: {
decimals: 18,
symbol: 'ETH',
iconURL: '',
},
defaultRPCURL: 'http://127.0.0.1:8545',
defaultExplorerURL: '',
testnet: {
FaucetURL: '',
isTestnet: true,
mainnetChainID: 1,
rpcUrls: {
default: {
http: ['http://127.0.0.1:8545'],
},
},
},
{
id: avalancheFuji.id,
name: avalancheFuji.name,
iconURL: '',
nativeAsset: {
decimals: avalancheFuji.nativeCurrency.decimals,
testnet: true,
nativeCurrency: {
name: avalancheFuji.nativeCurrency.name,
symbol: avalancheFuji.nativeCurrency.symbol,
iconURL: '',
decimals: avalancheFuji.nativeCurrency.decimals,
},
defaultRPCURL: avalancheFuji.rpcUrls.default.http[0],
defaultExplorerURL: avalancheFuji.blockExplorers.default.name,
testnet: {
FaucetURL: '',
isTestnet: avalancheFuji.testnet,
mainnetChainID: avalancheFuji.id,
rpcUrls: {
default: {
http: [avalancheFuji.rpcUrls.default.http[0]],
},
},
blockExplorers: {
default: {
url: avalancheFuji.blockExplorers.default.url,
name: avalancheFuji.blockExplorers.default.name,
},
},
},
{
id: curtis.id,
name: curtis.name,
iconURL: '',
nativeAsset: {
decimals: curtis.nativeCurrency.decimals,
testnet: true,
nativeCurrency: {
name: curtis.nativeCurrency.name,
symbol: curtis.nativeCurrency.symbol,
iconURL: '',
decimals: curtis.nativeCurrency.decimals,
},
defaultRPCURL: curtis.rpcUrls.default.http[0],
defaultExplorerURL: curtis.blockExplorers.default.name,
testnet: {
FaucetURL: '',
isTestnet: curtis.testnet,
mainnetChainID: curtis.id,
rpcUrls: {
default: {
http: [curtis.rpcUrls.default.http[0]],
},
},
blockExplorers: {
default: {
url: curtis.blockExplorers.default.url,
name: curtis.blockExplorers.default.name,
},
},
},
{
id: inkSepolia.id,
name: inkSepolia.name,
iconURL: '',
nativeAsset: {
testnet: true,
nativeCurrency: {
name: inkSepolia.nativeCurrency.name,
symbol: inkSepolia.nativeCurrency.symbol,
decimals: inkSepolia.nativeCurrency.decimals,
},
rpcUrls: {
default: {
http: [inkSepolia.rpcUrls.default.http[0]],
},
},
blockExplorers: {
default: {
url: inkSepolia.blockExplorers.default.url,
name: inkSepolia.blockExplorers.default.name,
},
},
},
{
id: inkSepolia.id,
name: inkSepolia.name,
testnet: true,
nativeCurrency: {
name: inkSepolia.nativeCurrency.name,
symbol: inkSepolia.nativeCurrency.symbol,
iconURL: '',
decimals: inkSepolia.nativeCurrency.decimals,
},
defaultRPCURL: inkSepolia.rpcUrls.default.http[0],
defaultExplorerURL: inkSepolia.blockExplorers.default.name,
testnet: {
FaucetURL: '',
isTestnet: inkSepolia.testnet,
mainnetChainID: inkSepolia.id,
rpcUrls: {
default: {
http: [inkSepolia.rpcUrls.default.http[0]],
},
},
blockExplorers: {
default: {
url: inkSepolia.blockExplorers.default.url,
name: inkSepolia.blockExplorers.default.name,
},
},
},
].map((n) => ({
...n,
nativeAsset: { ...n.nativeAsset, address: AddressZero },
}));
];

export const oldDefaultRPC: { [key in ChainId]?: string } = {
[ChainId.mainnet]: process.env.ETH_MAINNET_RPC,
Expand Down Expand Up @@ -508,7 +499,11 @@ export const mergeChainData = (
networks.backendNetworks.networks,
);

for (const chain of backendNetworks) {
const LOCAL_TEST_NETWORKS = IS_TESTING ? LOCAL_TESTNETS : [];

const allNetworks = [...LOCAL_TEST_NETWORKS, ...backendNetworks];

for (const chain of allNetworks) {
const chainId = chain.id;
const userPrefs = userPreferences[chainId];
const order = chainOrder.indexOf(chainId);
Expand Down

0 comments on commit 55a0953

Please sign in to comment.