fix(trading): external explorer link (#5973)

This commit is contained in:
Matthew Russell 2024-03-12 13:56:55 +00:00 committed by GitHub
parent 2153367258
commit 917bdde0bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 55 additions and 21 deletions

View File

@ -1,5 +1,8 @@
import type { ChainIdMapping } from './external-chain'; import type { ChainIdMapping } from '@vegaprotocol/environment';
import { SUPPORTED_CHAIN_IDS, SUPPORTED_CHAIN_LABELS } from './external-chain'; import {
SUPPORTED_CHAIN_IDS,
SUPPORTED_CHAIN_LABELS,
} from '@vegaprotocol/environment';
export const SUPPORTED_CHAIN_ICON_URLS: ChainIdMapping = { export const SUPPORTED_CHAIN_ICON_URLS: ChainIdMapping = {
'1': '/assets/chain-eth-logo.svg', '1': '/assets/chain-eth-logo.svg',

View File

@ -1,5 +1,5 @@
import Hash from '../hash'; import Hash from '../hash';
import { getExternalExplorerLink } from './external-chain'; import { getExternalExplorerLink } from '@vegaprotocol/environment';
import { ExternalChainIcon } from './external-chain-icon'; import { ExternalChainIcon } from './external-chain-icon';
export enum EthExplorerLinkTypes { export enum EthExplorerLinkTypes {
@ -23,7 +23,7 @@ export const ExternalExplorerLink = ({
code = false, code = false,
...props ...props
}: ExternalExplorerLinkProps) => { }: ExternalExplorerLinkProps) => {
const link = `${getExternalExplorerLink(chain, type)}/${type}/${id}${ const link = `${getExternalExplorerLink(chain)}/${type}/${id}${
code ? '#code' : '' code ? '#code' : ''
}`; }`;
return ( return (

View File

@ -4,7 +4,7 @@ import {
ExternalExplorerLink, ExternalExplorerLink,
EthExplorerLinkTypes, EthExplorerLinkTypes,
} from '../../../links/external-explorer-link/external-explorer-link'; } from '../../../links/external-explorer-link/external-explorer-link';
import { getExternalChainLabel } from '../../../links/external-explorer-link/external-chain'; import { getExternalChainLabel } from '@vegaprotocol/environment';
import type { components } from '../../../../../types/explorer'; import type { components } from '../../../../../types/explorer';
import { defaultAbiCoder, base64 } from 'ethers/lib/utils'; import { defaultAbiCoder, base64 } from 'ethers/lib/utils';
import { BigNumber } from 'ethers'; import { BigNumber } from 'ethers';

View File

@ -4,7 +4,7 @@ import {
ExternalExplorerLink, ExternalExplorerLink,
EthExplorerLinkTypes, EthExplorerLinkTypes,
} from '../../../components/links/external-explorer-link/external-explorer-link'; } from '../../../components/links/external-explorer-link/external-explorer-link';
import { getExternalChainLabel } from '../../../components/links/external-explorer-link/external-chain'; import { getExternalChainLabel } from '@vegaprotocol/environment';
import { t } from 'i18next'; import { t } from 'i18next';
interface OracleDetailsEthSourceProps { interface OracleDetailsEthSourceProps {

View File

@ -2,18 +2,21 @@ import { ExternalLink } from '@vegaprotocol/ui-toolkit';
import type { ComponentProps } from 'react'; import type { ComponentProps } from 'react';
import { ETHERSCAN_ADDRESS, ETHERSCAN_TX, useEtherscanLink } from '../hooks'; import { ETHERSCAN_ADDRESS, ETHERSCAN_TX, useEtherscanLink } from '../hooks';
import { useT } from '../use-t'; import { useT } from '../use-t';
import { getExternalChainLabel } from '../external-chain';
export const EtherscanLink = ({ export const EtherscanLink = ({
address, address,
tx, tx,
sourceChainId,
children, children,
...props ...props
}: { }: {
address?: string; address?: string;
tx?: string; tx?: string;
sourceChainId?: number;
} & ComponentProps<typeof ExternalLink>) => { } & ComponentProps<typeof ExternalLink>) => {
const t = useT(); const t = useT();
const etherscanLink = useEtherscanLink(); const etherscanLink = useEtherscanLink(sourceChainId);
let href = ''; let href = '';
if ((!address && !tx) || (address && tx)) { if ((!address && !tx) || (address && tx)) {
@ -30,7 +33,13 @@ export const EtherscanLink = ({
return ( return (
<ExternalLink <ExternalLink
href={href} href={href}
title={t('View on Etherscan (opens in a new tab)')} title={
sourceChainId
? t('View on {{chainLabel}} (opens in a new tab)', {
chainLabel: getExternalChainLabel(sourceChainId.toString()),
})
: t('View on Etherscan (opens in a new tab)')
}
{...props} {...props}
> >
{children || address || tx} {children || address || tx}

View File

@ -10,7 +10,7 @@ export const SUPPORTED_CHAIN_LABELS: ChainIdMapping = {
'11155111': 'Sepolia', '11155111': 'Sepolia',
}; };
export function getExternalExplorerLink(chainId: string, type: string) { export function getExternalExplorerLink(chainId: string) {
if (SUPPORTED_CHAIN_IDS.includes(chainId)) { if (SUPPORTED_CHAIN_IDS.includes(chainId)) {
switch (chainId) { switch (chainId) {
case '1': case '1':

View File

@ -3,6 +3,7 @@ import { useCallback } from 'react';
import { Networks } from '../types'; import { Networks } from '../types';
import { ENV, useEnvironment } from './use-environment'; import { ENV, useEnvironment } from './use-environment';
import { stripFullStops } from '@vegaprotocol/utils'; import { stripFullStops } from '@vegaprotocol/utils';
import { getExternalExplorerLink } from '../external-chain';
const VEGA_DOCS_URL = const VEGA_DOCS_URL =
process.env['NX_VEGA_DOCS_URL'] || 'https://docs.vega.xyz/mainnet'; process.env['NX_VEGA_DOCS_URL'] || 'https://docs.vega.xyz/mainnet';
@ -119,9 +120,15 @@ export const useLinks = (dapp: DApp, network?: Net) => {
return link; return link;
}; };
export const useEtherscanLink = () => { export const useEtherscanLink = (sourceChainId?: number) => {
const { ETHERSCAN_URL } = useEnvironment(); const { ETHERSCAN_URL } = useEnvironment();
const baseUrl = trim(ETHERSCAN_URL, '/');
const otherScanUrl = sourceChainId
? getExternalExplorerLink(sourceChainId.toString())
: undefined;
const baseUrl = trim(otherScanUrl || ETHERSCAN_URL, '/');
const link = useCallback( const link = useCallback(
(url?: string) => `${baseUrl}/${trim(url, '/') || ''}`, (url?: string) => `${baseUrl}/${trim(url, '/') || ''}`,
[baseUrl] [baseUrl]

View File

@ -9,3 +9,6 @@ export * from './types';
// Utils // Utils
export * from './utils/__generated__/NodeCheck'; export * from './utils/__generated__/NodeCheck';
// External chain environments
export * from './external-chain';

View File

@ -38,6 +38,7 @@
"This app will only work on {{VEGA_ENV}}. Select a node to connect to.": "This app will only work on {{VEGA_ENV}}. Select a node to connect to.", "This app will only work on {{VEGA_ENV}}. Select a node to connect to.": "This app will only work on {{VEGA_ENV}}. Select a node to connect to.",
"VALIDATOR_TESTNET": "VALIDATOR_TESTNET", "VALIDATOR_TESTNET": "VALIDATOR_TESTNET",
"View on Etherscan (opens in a new tab)": "View on Etherscan (opens in a new tab)", "View on Etherscan (opens in a new tab)": "View on Etherscan (opens in a new tab)",
"View on {{chainLabel}} (opens in a new tab)": "View on {{chainLabel}} (opens in a new tab)",
"Warning delay ( >{{warningLatency}} sec): {{blockUpdateLatency}} sec": "Warning delay ( >{{warningLatency}} sec): {{blockUpdateLatency}} sec", "Warning delay ( >{{warningLatency}} sec): {{blockUpdateLatency}} sec": "Warning delay ( >{{warningLatency}} sec): {{blockUpdateLatency}} sec",
"Yes": "Yes" "Yes": "Yes"
} }

View File

@ -144,6 +144,7 @@
"View governance proposal": "View governance proposal", "View governance proposal": "View governance proposal",
"View liquidity provision table": "View liquidity provision table", "View liquidity provision table": "View liquidity provision table",
"View on Etherscan": "View on Etherscan", "View on Etherscan": "View on Etherscan",
"View on {{chainLabel}}": "View on {{chainLabel}}",
"View settlement data specification": "View settlement data specification", "View settlement data specification": "View settlement data specification",
"View settlement schedule specification": "View settlement schedule specification", "View settlement schedule specification": "View settlement schedule specification",
"View termination specification": "View termination specification", "View termination specification": "View termination specification",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,7 @@ fragment DataSource on DataSourceSpec {
operator operator
} }
} }
sourceChainId
} }
... on DataSourceSpecConfiguration { ... on DataSourceSpecConfiguration {
signers { signers {

File diff suppressed because one or more lines are too long

View File

@ -58,6 +58,7 @@ import {
useEnvironment, useEnvironment,
useLinks, useLinks,
DocsLinks, DocsLinks,
getExternalChainLabel,
} from '@vegaprotocol/environment'; } from '@vegaprotocol/environment';
import type { Provider } from '../../oracle-schema'; import type { Provider } from '../../oracle-schema';
import { OracleBasicProfile } from '../../components/oracle-basic-profile'; import { OracleBasicProfile } from '../../components/oracle-basic-profile';
@ -893,8 +894,15 @@ export const EthOraclePanel = ({ sourceType }: { sourceType: EthCallSpec }) => {
</KeyValueTable> </KeyValueTable>
<div className="my-2"> <div className="my-2">
<EtherscanLink address={sourceType.address}> <EtherscanLink
{t('View on Etherscan')} address={sourceType.address}
sourceChainId={sourceType.sourceChainId}
>
{t('View on {{chainLabel}}', {
chainLabel: getExternalChainLabel(
sourceType.sourceChainId.toString()
),
})}
</EtherscanLink> </EtherscanLink>
</div> </div>
</> </>