diff --git a/src/config/index.ts b/src/config/index.ts index 83e37ac..74b3cf4 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -25,7 +25,10 @@ const shardUrls = availableShards .map(shardId => process.env[`REACT_APP_RPC_URL_SHARD${shardId}`] as string) .filter(url => url) +const contractShardId = +(process.env.REACT_APP_CONTRACT_SHARD || '0') as ShardID + export const config = { availableShards, - shardUrls + shardUrls, + contractShardId } diff --git a/src/pages/AddressPage/ContractDetails/helpers.ts b/src/pages/AddressPage/ContractDetails/helpers.ts index 251d62a..e561ea0 100644 --- a/src/pages/AddressPage/ContractDetails/helpers.ts +++ b/src/pages/AddressPage/ContractDetails/helpers.ts @@ -15,30 +15,15 @@ export const convertInputs = (inputs: string[], abiInputs: AbiInput[]) => { }); }; -export const getContractInAllShards = async (contractId: string) => { - const { availableShards } = config +export const getContractByAddress = async (contractId: string) => { + const { contractShardId } = config let contract = null - let shardId = null - - for(let i = 0; i < availableShards.length; i++) { - try { - const sId = availableShards[i] - contract = await getContractsByField([sId, "address", contractId]); - if (contract) { - shardId = sId - break - } - - // Temp optimization to reduce number of requests - if(sId === 1) { - break - } - } catch (_) {} - } - + try { + contract = await getContractsByField([contractShardId, "address", contractId]); + } catch (_) {} return { contract, - shardId + shardId: contractShardId } } diff --git a/src/pages/AddressPage/index.tsx b/src/pages/AddressPage/index.tsx index d9a3605..901e579 100644 --- a/src/pages/AddressPage/index.tsx +++ b/src/pages/AddressPage/index.tsx @@ -32,7 +32,7 @@ import { parseHexToText } from "../../web3/parseHex"; import { EventsTab } from "./tabs/events/Events"; import { ToolsTab } from "./tabs/tools"; import useQuery from "../../hooks/useQuery"; -import {getContractInAllShards} from "./ContractDetails/helpers"; +import {getContractByAddress} from "./ContractDetails/helpers"; export function AddressPage() { const history = useHistory(); @@ -124,7 +124,7 @@ export function AddressPage() { const getContracts = async () => { try { - let { contract, shardId } = await getContractInAllShards(id); + let { contract, shardId } = await getContractByAddress(id); if (contract) { const mergedContracts: any = erc721Map[contract.address] ? { ...contracts, ...erc721Map[contract.address] } @@ -135,7 +135,7 @@ export function AddressPage() { setSourceCode(code) if(contract.implementationAddress) { - let { contract: contractData, shardId } = await getContractInAllShards(contract.implementationAddress); + let { contract: contractData, shardId } = await getContractByAddress(contract.implementationAddress); if (contractData) { const implCode = await getContractCode(contractData.address, shardId || 0) console.log('Implementation contract loaded:', contractData)