From 6bb5d52843688c977bcdc245bd581e906f62bbba Mon Sep 17 00:00:00 2001 From: artemkolodko Date: Mon, 4 Sep 2023 16:47:13 +0100 Subject: [PATCH] Add env REACT_APP_VERIFICATION_SERVICE_URL; refactor 4bytes request --- src/api/explorerV1.ts | 8 +++--- src/config/index.ts | 4 ++- .../tabs/transactions/Transactions.tsx | 27 ++++++++++++------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/api/explorerV1.ts b/src/api/explorerV1.ts index 9d6e153..a7ad61c 100644 --- a/src/api/explorerV1.ts +++ b/src/api/explorerV1.ts @@ -1,6 +1,6 @@ import { ShardID } from "src/types"; import { AbiItem } from "web3-utils"; -import { getContractsByField } from "./client"; +import { config } from '../config' export interface IVerifyContractData { contractAddress: string; @@ -65,7 +65,7 @@ export const verifyContractCode = async (data: IVerifyContractDataSendData) => { } const response = await fetch( - `${process.env.REACT_APP_EXPLORER_V1_API_URL}codeVerification`, + `${config.verificationServiceUrl}/codeVerification`, { method: "POST", mode: "cors", @@ -86,7 +86,7 @@ export const verifyContractCode = async (data: IVerifyContractDataSendData) => { } else { const response = await fetch( - `${process.env.REACT_APP_EXPLORER_V1_API_URL}codeVerification`, + `${config.verificationServiceUrl}/codeVerification`, { method: "POST", mode: "cors", @@ -113,7 +113,7 @@ export const verifyContractCode = async (data: IVerifyContractDataSendData) => { export const loadSourceCode = async (address: string, shard: ShardID): Promise => { const response = await fetch( - `${process.env.REACT_APP_EXPLORER_V1_API_URL}fetchContractCode?contractAddress=${address}&shard=${shard}`, + `${config.verificationServiceUrl}/fetchContractCode?contractAddress=${address}&shard=${shard}`, { mode: "cors", cache: "no-cache", diff --git a/src/config/index.ts b/src/config/index.ts index 84d5248..a5123e1 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -31,6 +31,7 @@ const contractShardId = +(process.env.REACT_APP_CONTRACT_SHARD || '0') as ShardI const oneCountryContractAddress = process.env.REACT_APP_ONE_COUNTRY_CONTRACT_ADDRESS || '' const oneCountryNFTContractAddress = process.env.REACT_APP_ONE_COUNTRY_NFT_CONTRACT_ADDRESS || '' const ipfsGateway = process.env.REACT_APP_INDEXER_IPFS_GATEWAY || '' +const verificationServiceUrl = process.env.REACT_APP_VERIFICATION_SERVICE_URL || 'https://ctrver.t.hmny.io' export const config = { availableShards, @@ -38,5 +39,6 @@ export const config = { contractShardId, oneCountryContractAddress, oneCountryNFTContractAddress, - ipfsGateway + ipfsGateway, + verificationServiceUrl } diff --git a/src/pages/AddressPage/tabs/transactions/Transactions.tsx b/src/pages/AddressPage/tabs/transactions/Transactions.tsx index b1b69ab..cedd971 100644 --- a/src/pages/AddressPage/tabs/transactions/Transactions.tsx +++ b/src/pages/AddressPage/tabs/transactions/Transactions.tsx @@ -130,18 +130,27 @@ export function Transactions(props: { // for transactions we display call method if any if (props.type === "transaction") { - const methodSignatures = await Promise.all( - txs.map((tx: any) => { - return tx.input && tx.input.length > 10 - ? getByteCodeSignatureByHash([tx.input.slice(0, 10)]) - : Promise.resolve([]); + const txInputsMap: Record = {} + txs.forEach((tx) => { + if(tx.input && tx.input.length > 10) { + txInputsMap[tx.input.slice(0, 10)] = '' + } + }) + + await Promise.all( + Object.keys(txInputsMap).map(async (txInput: string) => { + txInputsMap[txInput] = await getByteCodeSignatureByHash([txInput]); }) ); - txs = txs.map((l, i) => ({ - ...l, - signatures: methodSignatures[i], - })); + txs = txs.map((tx, i) => { + return { + ...tx, + signatures: tx.input + ? txInputsMap[tx.input.slice(0, 10)] || [] + : [], + } + }); } txs = txs.map((tx: any) => {