Using local sourcify repo for tests

This commit is contained in:
Willian Mitsuda 2021-07-24 20:04:49 -03:00
parent 851a791375
commit 0b328123d3
2 changed files with 12 additions and 3 deletions

View File

@ -1,8 +1,10 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect, useContext } from "react";
import { ethers } from "ethers"; import { ethers } from "ethers";
import ContentFrame from "../ContentFrame"; import ContentFrame from "../ContentFrame";
import Highlight from "react-highlight"; import Highlight from "react-highlight";
import InfoRow from "../components/InfoRow"; import InfoRow from "../components/InfoRow";
import { sourcifyMetadata } from "../url";
import { RuntimeContext } from "../useRuntime";
import "highlight.js/styles/stackoverflow-light.css"; import "highlight.js/styles/stackoverflow-light.css";
import hljs from "highlight.js"; import hljs from "highlight.js";
@ -15,6 +17,7 @@ type ContractProps = {
}; };
const Contract: React.FC<ContractProps> = ({ checksummedAddress }) => { const Contract: React.FC<ContractProps> = ({ checksummedAddress }) => {
const { provider } = useContext(RuntimeContext);
const [rawMetadata, setRawMetadata] = useState<any>(); const [rawMetadata, setRawMetadata] = useState<any>();
useEffect(() => { useEffect(() => {
if (!checksummedAddress) { if (!checksummedAddress) {
@ -24,7 +27,7 @@ const Contract: React.FC<ContractProps> = ({ checksummedAddress }) => {
const fetchMetadata = async () => { const fetchMetadata = async () => {
try { try {
const result = await fetch( const result = await fetch(
`https://repo.sourcify.dev/contracts/full_match/1/${checksummedAddress}/metadata.json` sourcifyMetadata(checksummedAddress, provider!.network.chainId)
); );
if (result.ok) { if (result.ok) {
const json = await result.json(); const json = await result.json();
@ -40,7 +43,7 @@ const Contract: React.FC<ContractProps> = ({ checksummedAddress }) => {
} }
}; };
fetchMetadata(); fetchMetadata();
}, [checksummedAddress]); }, [provider, checksummedAddress]);
const [selected, setSelected] = useState<string>(); const [selected, setSelected] = useState<string>();

View File

@ -13,3 +13,9 @@ export const tokenLogoURL = (
export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`; export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`;
export const blockTxsURL = (blockNum: BlockTag) => `/block/${blockNum}/txs`; export const blockTxsURL = (blockNum: BlockTag) => `/block/${blockNum}/txs`;
export const sourcifyMetadata = (
checksummedAddress: string,
networkId: number
) =>
`http://localhost:7000/sourcify/contracts/full_match/${networkId}/${checksummedAddress}/metadata.json`;