Skip to content

Commit

Permalink
Merge pull request #2233 from webb-tools/linh/handle-explorer
Browse files Browse the repository at this point in the history
Update Explorer links on Tangle Dapp + getUrlExplorer + Chains Config
  • Loading branch information
drewstone authored Apr 15, 2024
2 parents 762b53e + 6912a65 commit e6b5ae8
Show file tree
Hide file tree
Showing 21 changed files with 225 additions and 136 deletions.
2 changes: 1 addition & 1 deletion apps/bridge-dapp/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
useWebContext,
useConnectWallet,
} from '@webb-tools/api-provider-environment';
import { TANGLE_TESTNET_NATIVE_EXPLORER_URL } from '@webb-tools/dapp-config/constants/tangle';
import { WebbLogoIcon } from '@webb-tools/icons';
import {
Breadcrumbs,
Expand All @@ -20,7 +21,6 @@ import {
import {
GITHUB_REQUEST_FEATURE_URL,
SOCIAL_URLS_RECORD,
TANGLE_TESTNET_NATIVE_EXPLORER_URL,
WEBB_DOCS_URL,
WEBB_FAUCET_URL,
WEBB_MKT_URL,
Expand Down
2 changes: 1 addition & 1 deletion apps/faucet/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TANGLE_TESTNET_NATIVE_EXPLORER_URL } from '@webb-tools/dapp-config/constants/tangle';
import { FaucetIcon, TangleIcon } from '@webb-tools/icons';
import {
Breadcrumbs,
Expand All @@ -14,7 +15,6 @@ import {
GITHUB_REQUEST_FEATURE_URL,
SOCIAL_URLS_RECORD,
TANGLE_MKT_URL,
TANGLE_TESTNET_NATIVE_EXPLORER_URL,
} from '@webb-tools/webb-ui-components/constants';
import Link from 'next/link';
import { type FC } from 'react';
Expand Down
6 changes: 4 additions & 2 deletions apps/faucet/src/constants/sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
TANGLE_TESTNET_EVM_EXPLORER_URL,
TANGLE_TESTNET_NATIVE_EXPLORER_URL,
} from '@webb-tools/dapp-config/constants/tangle';
import {
AppsLine,
DocumentationIcon,
Expand All @@ -18,8 +22,6 @@ import {
DKG_STATS_PROPOSALS_URL,
TANGLE_DOCS_URL,
TANGLE_MKT_URL,
TANGLE_TESTNET_EVM_EXPLORER_URL,
TANGLE_TESTNET_NATIVE_EXPLORER_URL,
} from '@webb-tools/webb-ui-components/constants';

const items: SideBarItemProps[] = [
Expand Down
2 changes: 1 addition & 1 deletion apps/hubble-stats/containers/Layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
NavigationMenuTrigger,
Logo,
} from '@webb-tools/webb-ui-components';
import { TANGLE_TESTNET_NATIVE_EXPLORER_URL } from '@webb-tools/dapp-config/constants/tangle';
import { WebbLogoIcon } from '@webb-tools/icons';
import { Breadcrumbs, SideBarMenu } from '../../components';
import {
Expand All @@ -16,7 +17,6 @@ import {
GITHUB_REQUEST_FEATURE_URL,
SOCIAL_URLS_RECORD,
TANGLE_MKT_URL,
TANGLE_TESTNET_NATIVE_EXPLORER_URL,
} from '@webb-tools/webb-ui-components/constants';

const Header: FC = () => {
Expand Down
8 changes: 4 additions & 4 deletions apps/stats-dapp/src/containers/KeyDetail/KeyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
TitleWithInfo,
} from '@webb-tools/webb-ui-components/components';
import { fuzzyFilter } from '@webb-tools/webb-ui-components/components/Filter/utils';
import { POLKADOT_EXPLORER_URL } from '@webb-tools/webb-ui-components/constants';
import { POLKADOT_JS_EXPLORER_URL } from '@webb-tools/webb-ui-components/constants';
import { Typography } from '@webb-tools/webb-ui-components/typography';
import cx from 'classnames';
import getUnicodeFlagIcon from 'country-flag-icons/unicode';
Expand Down Expand Up @@ -250,7 +250,7 @@ export const KeyDetail = forwardRef<HTMLDivElement, KeyDetailProps>(
title={status}
time={at}
blockHash={hash}
externalUrl={POLKADOT_EXPLORER_URL + hash}
externalUrl={POLKADOT_JS_EXPLORER_URL + hash}
/>
);
}
Expand All @@ -262,7 +262,7 @@ export const KeyDetail = forwardRef<HTMLDivElement, KeyDetailProps>(
title={status}
time={at}
blockHash={hash}
externalUrl={POLKADOT_EXPLORER_URL + hash}
externalUrl={POLKADOT_JS_EXPLORER_URL + hash}
/>
);
}
Expand All @@ -274,7 +274,7 @@ export const KeyDetail = forwardRef<HTMLDivElement, KeyDetailProps>(
title={status}
time={at}
blockHash={hash}
externalUrl={POLKADOT_EXPLORER_URL + hash}
externalUrl={POLKADOT_JS_EXPLORER_URL + hash}
/>
);
}
Expand Down
7 changes: 4 additions & 3 deletions apps/tangle-dapp/app/claim/success/SuccessClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { AppTemplate } from '@webb-tools/webb-ui-components/containers/AppTempla
import { Typography } from '@webb-tools/webb-ui-components/typography/Typography';
import { type FC } from 'react';

import useExplorerUrl, { ExplorerType } from '../../../hooks/useExplorerUrl';
import useTxExplorerUrl from '../../../hooks/useTxExplorerUrl';
import { ExplorerType } from '../../../types';

const SuccessClient: FC<{ blockHash: HexString }> = ({ blockHash }) => {
const getExplorerUrl = useExplorerUrl();
const txExplorerUrl = getExplorerUrl(blockHash, ExplorerType.Substrate);
const getTxExplorerUrl = useTxExplorerUrl();
const txExplorerUrl = getTxExplorerUrl(blockHash, ExplorerType.Substrate);

return (
<AppTemplate.Content>
Expand Down
90 changes: 51 additions & 39 deletions apps/tangle-dapp/app/services/[serviceId]/JobsListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
Table,
Typography,
} from '@webb-tools/webb-ui-components';
import { FC } from 'react';
import { FC, useMemo } from 'react';
import { twMerge } from 'tailwind-merge';

import { SkeletonRow } from '../../../components/skeleton';
import { HeaderCell, StringCell } from '../../../components/tableCells';
import useNetworkStore from '../../../context/useNetworkStore';
import { useServiceJobs } from '../../../data/ServiceDetails';
import type { ServiceJob } from '../../../types';

Expand All @@ -36,48 +37,59 @@ const TANGLE_BLOCK_EXPLORER =

const columnHelper = createColumnHelper<ServiceJob>();

const columns = [
columnHelper.accessor('id', {
header: () => <HeaderCell title="Job ID" className="justify-start" />,
cell: (props) => <StringCell value={props.getValue()} />,
}),
columnHelper.accessor('txHash', {
header: () => <HeaderCell title="Tx Hash" className="justify-start" />,
cell: (props) => {
const txHash = props.getValue();

// TODO: This should be based off the active network, cannot assume it is always the testnet!
const txExplorerURI = TANGLE_BLOCK_EXPLORER
? getExplorerURI(
TANGLE_BLOCK_EXPLORER,
txHash,
'tx',
'polkadot'
).toString()
: null;
return (
<div className="flex gap-1 items-center">
<StringCell value={shortenHex(txHash, 5)} />
{txExplorerURI && (
<a href={txExplorerURI} target="_blank" rel="noopener noreferrer">
<ExternalLinkLine />
</a>
)}
</div>
);
},
}),
columnHelper.accessor('timestamp', {
header: () => <HeaderCell title="Timestamp" className="justify-start" />,
cell: (props) => (
<StringCell value={formatDate(new Date(props.getValue()))} />
),
}),
];
const idColumn = columnHelper.accessor('id', {
header: () => <HeaderCell title="Job ID" className="justify-start" />,
cell: (props) => <StringCell value={props.getValue()} />,
});

const timestampColumn = columnHelper.accessor('timestamp', {
header: () => <HeaderCell title="Timestamp" className="justify-start" />,
cell: (props) => (
<StringCell value={formatDate(new Date(props.getValue()))} />
),
});

const JobsListTable: FC<JobsListTableProps> = ({ serviceId, className }) => {
const { network } = useNetworkStore();
const { data, isLoading, error } = useServiceJobs(serviceId);

const columns = useMemo(
() => [
idColumn,
columnHelper.accessor('txHash', {
header: () => <HeaderCell title="Tx Hash" className="justify-start" />,
cell: (props) => {
const txHash = props.getValue();

const txExplorerURI = TANGLE_BLOCK_EXPLORER
? getExplorerURI(
network.polkadotExplorerUrl,
txHash,
'tx',
'polkadot'
).toString()
: null;
return (
<div className="flex gap-1 items-center">
<StringCell value={shortenHex(txHash, 5)} />
{txExplorerURI && (
<a
href={txExplorerURI}
target="_blank"
rel="noopener noreferrer"
>
<ExternalLinkLine />
</a>
)}
</div>
);
},
}),
timestampColumn,
],
[network.polkadotExplorerUrl]
);

const table = useReactTable({
data: data ?? [],
columns,
Expand Down
2 changes: 1 addition & 1 deletion apps/tangle-dapp/components/KeyStatsItem/KeyStatsItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const KeyStatsItem: FC<KeyStatsItemProps> = ({
<div className="flex items-center gap-0.5">
<Typography
variant="body1"
className="text-mono-140 dark:text-mono-40 break-all"
className="text-mono-140 dark:text-mono-40 break-all xl:whitespace-nowrap"
>
{title}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
import { KeyValueWithButton } from '@webb-tools/webb-ui-components/components/KeyValueWithButton';
import { FC, useCallback } from 'react';

import useExplorerUrl, { ExplorerType } from '../../hooks/useExplorerUrl';
import useTxExplorerUrl from '../../hooks/useTxExplorerUrl';
import { ExplorerType } from '../../types';
import { TxConfirmationModalProps } from './types';

export const TxConfirmationModal: FC<TxConfirmationModalProps> = ({
Expand All @@ -26,9 +27,9 @@ export const TxConfirmationModal: FC<TxConfirmationModalProps> = ({
txHash,
txType,
}) => {
const getExplorerUrl = useExplorerUrl();
const getTxExplorerUrl = useTxExplorerUrl();

const txExplorerUrl = getExplorerUrl(
const txExplorerUrl = getTxExplorerUrl(
txHash,
txType === 'evm' ? ExplorerType.EVM : ExplorerType.Substrate
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
'use client';

import { isEthereumAddress } from '@polkadot/util-crypto';
import { getExplorerURI } from '@webb-tools/api-provider-environment/transaction/utils';
import { Button, Typography } from '@webb-tools/webb-ui-components';
import { TANGLE_DOCS_URL } from '@webb-tools/webb-ui-components/constants';
import Link from 'next/link';
import { FC } from 'react';

import GlassCard from '../../components/GlassCard/GlassCard';
import useNetworkStore from '../../context/useNetworkStore';
import useAgnosticAccountInfo from '../../hooks/useAgnosticAccountInfo';
import useActiveAccountAddress from '../../hooks/useActiveAccountAddress';
import { ExplorerType } from '../../types';

const RecentTxContainer: FC = () => {
const { network } = useNetworkStore();
const { isEvm } = useAgnosticAccountInfo();
const activeAccountAddress = useActiveAccountAddress();

const isEvm =
activeAccountAddress === null
? null
: isEthereumAddress(activeAccountAddress);

const accountExplorerUrl = activeAccountAddress
? getExplorerURI(
isEvm ? network.evmExplorerUrl : network.polkadotExplorerUrl,
activeAccountAddress,
'address',
isEvm ? ExplorerType.EVM : ExplorerType.Substrate
).toString()
: undefined;

return (
<GlassCard className="flex flex-col gap-3 sm:gap-0">
Expand All @@ -22,7 +39,8 @@ const RecentTxContainer: FC = () => {
color="primary"
className="uppercase"
target="_blank"
href={isEvm ? network.evmExplorerUrl : network.polkadotExplorerUrl}
href={accountExplorerUrl}
isDisabled={!accountExplorerUrl}
>
Open Explorer
</Button>
Expand Down
10 changes: 5 additions & 5 deletions apps/tangle-dapp/hooks/useExecuteTxWithNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Button, Typography } from '@webb-tools/webb-ui-components';
import { useSnackbar } from 'notistack';
import { useCallback } from 'react';

import { ExplorerType } from '../types';
import ensureError from '../utils/ensureError';
import { evmPublicClient } from '../utils/evm';
import useExplorerUrl, { ExplorerType } from './useExplorerUrl';
import useTxExplorerUrl from './useTxExplorerUrl';

const useExecuteTxWithNotification = () => {
const { activeWallet } = useWebContext();
const getExplorerUrl = useExplorerUrl();
const getTxExplorerUrl = useTxExplorerUrl();
const { enqueueSnackbar: enqueueNotifications } = useSnackbar();

/**
Expand Down Expand Up @@ -51,8 +52,7 @@ const useExecuteTxWithNotification = () => {
throw new Error(errorMessage);
}

// TODO: tx explorer url is incorrect
const txExplorerUrl = getExplorerUrl(
const txExplorerUrl = getTxExplorerUrl(
txHash,
activeWallet?.platform === 'EVM'
? ExplorerType.EVM
Expand Down Expand Up @@ -104,7 +104,7 @@ const useExecuteTxWithNotification = () => {
throw error;
}
},
[activeWallet?.platform, getExplorerUrl, enqueueNotifications]
[activeWallet?.platform, getTxExplorerUrl, enqueueNotifications]
);

return executeTx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import { getExplorerURI } from '@webb-tools/api-provider-environment/transaction
import { useCallback } from 'react';

import useNetworkStore from '../context/useNetworkStore';
import { ExplorerType } from '../types';

export enum ExplorerType {
Substrate = 'polkadot',
EVM = 'web3',
}

const useExplorerUrl = () => {
const useTxExplorerUrl = () => {
const { network } = useNetworkStore();

return useCallback(
(transactionOrBlockHash: string, type: ExplorerType): URL | null => {
(txHash: string, type: ExplorerType): URL | null => {
const explorerUrl =
type === ExplorerType.Substrate
? network.polkadotExplorerUrl
Expand All @@ -22,10 +18,10 @@ const useExplorerUrl = () => {
return null;
}

return getExplorerURI(explorerUrl, transactionOrBlockHash, 'tx', type);
return getExplorerURI(explorerUrl, txHash, 'tx', type);
},
[network.evmExplorerUrl, network.polkadotExplorerUrl]
);
};

export default useExplorerUrl;
export default useTxExplorerUrl;
5 changes: 5 additions & 0 deletions apps/tangle-dapp/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,8 @@ export type ServiceParticipant = {
export enum NetworkFeature {
Faucet,
}

export enum ExplorerType {
Substrate = 'polkadot',
EVM = 'web3',
}
2 changes: 1 addition & 1 deletion apps/testnet-leaderboard/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';

import { AccordionTrigger } from '@radix-ui/react-accordion';
import { TANGLE_TESTNET_NATIVE_EXPLORER_URL } from '@webb-tools/dapp-config/constants/tangle';
import { ArrowRight, ChevronDown, Menu } from '@webb-tools/icons';
import {
Accordion,
Expand All @@ -16,7 +17,6 @@ import {
import { MenuItem } from '@webb-tools/webb-ui-components/components/MenuItem';
import {
TANGLE_MKT_URL,
TANGLE_TESTNET_NATIVE_EXPLORER_URL,
WEBB_BLOG_URL,
} from '@webb-tools/webb-ui-components/constants';
import { Typography } from '@webb-tools/webb-ui-components/typography/Typography';
Expand Down
Loading

0 comments on commit e6b5ae8

Please sign in to comment.