Use env variable REACT_APP_CONTRACT_SHARD to specify contract shard id (#243)

pull/246/head
Artem 2 years ago committed by GitHub
parent 5490f00232
commit 75462fb838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/config/index.ts
  2. 27
      src/pages/AddressPage/ContractDetails/helpers.ts
  3. 6
      src/pages/AddressPage/index.tsx

@ -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
}

@ -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
}
}

@ -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)

Loading…
Cancel
Save