From 2be73c8ab5d0034c16343907f6d6f75083b5d202 Mon Sep 17 00:00:00 2001 From: Gabriel Montes Date: Fri, 12 Apr 2024 13:05:47 -0300 Subject: [PATCH] Extend explorer link to support more chains --- .../{EtherscanLink.js => ExplorerLink.js} | 23 +++++++++++++++---- site/components/TransactionsModal.js | 10 +++++--- .../payment-streams/StreamsTable.js | 12 ++++++---- .../[locale]/dp-auctions/auctions/index.js | 10 +++++--- site/pages/[locale]/token-revokes.js | 7 +++--- 5 files changed, 44 insertions(+), 18 deletions(-) rename site/components/{EtherscanLink.js => ExplorerLink.js} (57%) diff --git a/site/components/EtherscanLink.js b/site/components/ExplorerLink.js similarity index 57% rename from site/components/EtherscanLink.js rename to site/components/ExplorerLink.js index 436746d..c19992e 100644 --- a/site/components/EtherscanLink.js +++ b/site/components/ExplorerLink.js @@ -1,19 +1,32 @@ const formatShort = text => `${text.substr(0, 6)}...${text.slice(-4)}` -const ETHERSCAN_URL = 'https://etherscan.io' +const explorerUrls = { + 1: 'https://etherscan.io', + 43111: 'https://explorer.hemi.network', + 743111: 'https://testnet.explorer.hemi.network' +} /** - * A link to an address or a transaction in Etherscan. + * A link to an address or transaction in a chain explorer. + * Defaults to Etherscan. * * @param {object} options Link data. * @param {string} [options.address] The address of the link. + * @param {number} [options.chainId] The chainId of the address or tx. + * @param {boolean} [options.long] Whether the hash has to be complete or short. * @param {string} [options.text] The text of the link. * @param {string} [options.tx] The transaction hash of the link. - * @param {boolean} [options.long] Whether the hash has to be complete or short. * @returns */ -export const EtherscanLink = function ({ address, text, tx, long = false }) { - const url = `${ETHERSCAN_URL}${address ? `/address/${address}` : `/tx/${tx}`}` +export const ExplorerLink = function ({ + address, + chainId = 1, + long = false, + text, + tx +}) { + const baseUrl = explorerUrls[chainId] + const url = `${baseUrl}${address ? `/address/${address}` : `/tx/${tx}`}` const hash = address ?? tx return ( ( /> ) -// eslint-disable-next-line complexity const TransactionsModal = function ({ transaction, modalIsOpen, closeModal }) { + const { chainId } = useWeb3React() const t = useTranslations() const formatNumber = useNumberFormat() @@ -123,7 +124,10 @@ const TransactionsModal = function ({ transaction, modalIsOpen, closeModal }) { + } /> )} diff --git a/site/components/payment-streams/StreamsTable.js b/site/components/payment-streams/StreamsTable.js index 42dead3..442a09b 100644 --- a/site/components/payment-streams/StreamsTable.js +++ b/site/components/payment-streams/StreamsTable.js @@ -10,14 +10,14 @@ import { Link, useRouter } from '../../navigation' import { bigToCrypto, fromUnit } from '../../utils' import { updateStreamInfo } from '../../utils/streams' import TransactionsContext from '../context/Transactions' -import { EtherscanLink } from '../EtherscanLink' +import { ExplorerLink } from '../ExplorerLink' import SvgContainer from '../svg/SvgContainer' import Tabs from '../Tabs' import { PaymentStreamsLibContext } from './PaymentStreamsLib' const StreamsTable = function () { - const { active, account } = useWeb3React() + const { active, account, chainId } = useWeb3React() const t = useTranslations('payment-streams-util') const router = useRouter() const connected = !!(active && account) @@ -393,13 +393,17 @@ const StreamsTable = function () { {status} - {streamsView === 'outgoing' && ( - + )} {/* {dateFormatter.format(startDate)} */} diff --git a/site/pages/[locale]/dp-auctions/auctions/index.js b/site/pages/[locale]/dp-auctions/auctions/index.js index 8329b4c..366eeda 100644 --- a/site/pages/[locale]/dp-auctions/auctions/index.js +++ b/site/pages/[locale]/dp-auctions/auctions/index.js @@ -10,7 +10,7 @@ import Button from '../../../../components/Button' import TransactionsContext from '../../../../components/context/Transactions' import { DPAuctionsContext } from '../../../../components/DPAuctionsContext' import DPAuctionsLayout from '../../../../components/DPAuctionsLayout' -import { EtherscanLink } from '../../../../components/EtherscanLink' +import { ExplorerLink } from '../../../../components/ExplorerLink' import TokenAmount from '../../../../components/TokenAmount' import Transactions from '../../../../components/Transactions' import { fromUnit } from '../../../../utils' @@ -344,12 +344,14 @@ const DPAuctionBuyControl = function ({ auction }) { // This component shows the end status of the auction. const DPAuctionEndStatus = function ({ auction }) { + const { chainId } = useWeb3React() const t = useTranslations() return auction.status === 'won' ? ( <>
- {t('won-by')}: + {t('won-by')}:{' '} +
{t('winning-price')}:{' '} @@ -363,6 +365,7 @@ const DPAuctionEndStatus = function ({ auction }) { // This component renders the details view of an auction. const DPAuction = function ({ auction }) { + const { chainId } = useWeb3React() const t = useTranslations() if (!auction) { @@ -376,7 +379,8 @@ const DPAuction = function ({ auction }) {
- {t('seller')}: + {t('seller')}:{' '} +
diff --git a/site/pages/[locale]/token-revokes.js b/site/pages/[locale]/token-revokes.js index dea9cbf..53e6dcb 100644 --- a/site/pages/[locale]/token-revokes.js +++ b/site/pages/[locale]/token-revokes.js @@ -7,7 +7,7 @@ import useSWR from 'swr' import Button from '../../components/Button' import PureContext from '../../components/context/Pure' -import { EtherscanLink } from '../../components/EtherscanLink' +import { ExplorerLink } from '../../components/ExplorerLink' import Layout from '../../components/Layout' import UtilFormBox from '../../components/UtilFormBox' import { fromUnit } from '../../utils' @@ -313,12 +313,13 @@ const Balance = function ({ address }) { } const Token = function ({ address }) { + const { chainId } = useWeb3React() const { data: token } = useErc20Token(address) if (!token) { - return + return } const { symbol } = token - return + return } const TokenRevokes = function () {