fix(trading): external explorer link (#5973)
This commit is contained in:
parent
2153367258
commit
917bdde0bb
@ -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',
|
||||||
|
@ -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 (
|
||||||
|
@ -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';
|
||||||
|
@ -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 {
|
||||||
|
@ -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}
|
||||||
|
@ -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':
|
@ -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]
|
||||||
|
@ -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';
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
|
@ -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
4
libs/markets/src/lib/__generated__/markets.ts
generated
4
libs/markets/src/lib/__generated__/markets.ts
generated
File diff suppressed because one or more lines are too long
@ -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
@ -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>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user