From 9e591cc97f6a007501370990fc574dd675dc3e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20Mi=C3=B1o?= Date: Thu, 29 Aug 2024 13:23:20 -0400 Subject: [PATCH] pass connected to hardhat as network object prop --- android/.project | 11 +++++++++++ src/networks/index.ts | 15 ++++++++++----- src/networks/mainnet.ts | 5 ++--- src/references/chain-assets.json | 2 -- src/resources/assets/hardhatAssets.ts | 7 ++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/android/.project b/android/.project index 3964dd3f5b7..327f55189a0 100644 --- a/android/.project +++ b/android/.project @@ -14,4 +14,15 @@ org.eclipse.buildship.core.gradleprojectnature + + + 1724950860383 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/src/networks/index.ts b/src/networks/index.ts index b4c5dd2f1f6..78b59e54f8a 100644 --- a/src/networks/index.ts +++ b/src/networks/index.ts @@ -1,4 +1,4 @@ -import { ChainId } from '@/networks/types'; +import { ChainId, NetworkProperties } from '@/networks/types'; import store from '@/redux/store'; import * as ls from '@/storage'; import { getArbitrumNetworkObject } from './arbitrum'; @@ -12,7 +12,6 @@ import { getGoerliNetworkObject } from './goerli'; import { getMainnetNetworkObject } from './mainnet'; import { getOptimismNetworkObject } from './optimism'; import { getPolygonNetworkObject } from './polygon'; -import { NetworkProperties } from './types'; import { getZoraNetworkObject } from './zora'; /** @@ -52,11 +51,17 @@ export const RainbowSupportedChainIds = [ /** * Helper function to get specific Rainbow Network's Object */ -export function getNetworkObject({ chainId }: { chainId: ChainId }): NetworkProperties { +export function getNetworkObject({ + chainId, + connectedToHardhat = false, +}: { + chainId: ChainId; + connectedToHardhat?: boolean; +}): NetworkProperties { switch (chainId) { // Mainnet case ChainId.mainnet: - return getMainnetNetworkObject(); + return getMainnetNetworkObject({ connectedToHardhat }); // L2s case ChainId.arbitrum: @@ -85,7 +90,7 @@ export function getNetworkObject({ chainId }: { chainId: ChainId }): NetworkProp // Fallback default: - return getMainnetNetworkObject(); + return getMainnetNetworkObject({ connectedToHardhat }); } } diff --git a/src/networks/mainnet.ts b/src/networks/mainnet.ts index e185b5c1b25..879ceca9763 100644 --- a/src/networks/mainnet.ts +++ b/src/networks/mainnet.ts @@ -4,9 +4,8 @@ import { gasUtils } from '@/utils'; import { mainnet } from '@wagmi/chains'; import { ETH_ADDRESS } from '@/references'; import { getRemoteConfig } from '@/model/remoteConfig'; -import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; -export const getMainnetNetworkObject = (): NetworkProperties => { +export const getMainnetNetworkObject = (opts: { connectedToHardhat?: boolean } = {}): NetworkProperties => { const { mainnet_enabled, mainnet_tx_enabled } = getRemoteConfig(); return { // wagmi chain data @@ -26,7 +25,7 @@ export const getMainnetNetworkObject = (): NetworkProperties => { }, getProvider: () => getProvider({ chainId: ChainId.mainnet }), - rpc: () => (useConnectedToHardhatStore.getState().connectedToHardhat ? 'http://127.0.0.1:8545' : proxyRpcEndpoint(mainnet.id)), + rpc: () => (opts?.connectedToHardhat ? 'http://127.0.0.1:8545' : proxyRpcEndpoint(mainnet.id)), balanceCheckerAddress: '0x4dcf4562268dd384fe814c00fad239f06c2a0c2b', // features diff --git a/src/references/chain-assets.json b/src/references/chain-assets.json index 3f05d7c252a..222968ab740 100644 --- a/src/references/chain-assets.json +++ b/src/references/chain-assets.json @@ -9,7 +9,6 @@ "fallback": "#E8EAF5", "primary": "#808088" }, - "chainId": 5, "decimals": 18, "icon_url": "https://s3.amazonaws.com/icons.assets/ETH.png", "name": "Goerli", @@ -39,7 +38,6 @@ "fallback": "#E8EAF5", "primary": "#808088" }, - "chainId": 1, "decimals": 18, "icon_url": "https://s3.amazonaws.com/icons.assets/ETH.png", "name": "Ethereum", diff --git a/src/resources/assets/hardhatAssets.ts b/src/resources/assets/hardhatAssets.ts index df898634440..6e496e11c27 100644 --- a/src/resources/assets/hardhatAssets.ts +++ b/src/resources/assets/hardhatAssets.ts @@ -10,13 +10,15 @@ import { AddressZero } from '@ethersproject/constants'; import chainAssetsByChainId from '@/references/testnet-assets-by-chain'; import { getNetworkObject } from '@/networks'; import { ChainId, ChainName, Network } from '@/networks/types'; +import { useConnectedToHardhatStore } from '@/state/connectedToHardhat'; const fetchHardhatBalancesWithBalanceChecker = async ( tokens: string[], address: string, chainId: ChainId = ChainId.mainnet ): Promise<{ [tokenAddress: string]: string } | null> => { - const networkObject = getNetworkObject({ chainId }); + const connectedToHardhat = useConnectedToHardhatStore.getState().connectedToHardhat; + const networkObject = getNetworkObject({ chainId, connectedToHardhat }); const balanceCheckerContract = new Contract(networkObject.balanceCheckerAddress, balanceCheckerContractAbi, web3Provider); try { const values = await balanceCheckerContract.balances([address], tokens); @@ -47,6 +49,8 @@ export const fetchHardhatBalances = async (accountAddress: string, chainId: Chai chainAssets[`${chainId}` as keyof typeof chainAssets], ({ asset }) => `${asset.asset_code}_${asset.chainId}` ); + console.log('chainAssetsMap', chainAssetsMap); + console.log('chainAssetsMap val', Object.values(chainAssetsMap)[0]); const tokenAddresses = Object.values(chainAssetsMap).map(({ asset: { asset_code } }) => asset_code === ETH_ADDRESS ? AddressZero : asset_code.toLowerCase() @@ -60,6 +64,7 @@ export const fetchHardhatBalances = async (accountAddress: string, chainId: Chai asset: { ...chainAsset.asset, network: chainAsset.asset.network as Network, + chainId: chainAsset.asset.chainId, }, quantity: balances[assetCode], };