From 0b328123d36dbf3009e53b1a8527e26f1a46930a Mon Sep 17 00:00:00 2001 From: Willian Mitsuda Date: Sat, 24 Jul 2021 20:04:49 -0300 Subject: [PATCH] Using local sourcify repo for tests --- src/address/Contract.tsx | 9 ++++++--- src/url.ts | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/address/Contract.tsx b/src/address/Contract.tsx index ae019a4..357e606 100644 --- a/src/address/Contract.tsx +++ b/src/address/Contract.tsx @@ -1,8 +1,10 @@ -import React, { useState, useEffect } from "react"; +import React, { useState, useEffect, useContext } from "react"; import { ethers } from "ethers"; import ContentFrame from "../ContentFrame"; import Highlight from "react-highlight"; import InfoRow from "../components/InfoRow"; +import { sourcifyMetadata } from "../url"; +import { RuntimeContext } from "../useRuntime"; import "highlight.js/styles/stackoverflow-light.css"; import hljs from "highlight.js"; @@ -15,6 +17,7 @@ type ContractProps = { }; const Contract: React.FC = ({ checksummedAddress }) => { + const { provider } = useContext(RuntimeContext); const [rawMetadata, setRawMetadata] = useState(); useEffect(() => { if (!checksummedAddress) { @@ -24,7 +27,7 @@ const Contract: React.FC = ({ checksummedAddress }) => { const fetchMetadata = async () => { try { const result = await fetch( - `https://repo.sourcify.dev/contracts/full_match/1/${checksummedAddress}/metadata.json` + sourcifyMetadata(checksummedAddress, provider!.network.chainId) ); if (result.ok) { const json = await result.json(); @@ -40,7 +43,7 @@ const Contract: React.FC = ({ checksummedAddress }) => { } }; fetchMetadata(); - }, [checksummedAddress]); + }, [provider, checksummedAddress]); const [selected, setSelected] = useState(); diff --git a/src/url.ts b/src/url.ts index 00e3dc8..0d3c9e6 100644 --- a/src/url.ts +++ b/src/url.ts @@ -13,3 +13,9 @@ export const tokenLogoURL = ( export const blockURL = (blockNum: BlockTag) => `/block/${blockNum}`; 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`;