Skip to content

Commit

Permalink
feat: Add information to msg transaction cards (#104)
Browse files Browse the repository at this point in the history
- Display duration in dest tx card per request from @Skunkchain 
- Display mailbox address in both tx cards
- Hide API docs page link which was disabled in #77 
- Fix missing type annotation
  • Loading branch information
jmrossy authored Aug 16, 2024
1 parent 9fb83e5 commit 2309073
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/components/nav/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export function Header({ pathName }: { pathName: string }) {
<a className={navLinkClass()} target="_blank" href={links.home} rel="noopener noreferrer">
About
</a>
<Link href="/api-docs" className={navLinkClass('/api-docs')}>
{/* <Link href="/api-docs" className={navLinkClass('/api-docs')}>
API
</Link>
</Link> */}
<a
className={navLinkClass()}
target="_blank"
Expand Down Expand Up @@ -95,11 +95,11 @@ export function Header({ pathName }: { pathName: string }) {
Settings
</MobileNavLink>
),
(c: Fn) => (
<MobileNavLink href="/api" closeDropdown={c} key="API">
API
</MobileNavLink>
),
// (c: Fn) => (
// <MobileNavLink href="/api" closeDropdown={c} key="API">
// API
// </MobileNavLink>
// ),
(c: Fn) => (
<MobileNavLink href={docLinks.home} closeDropdown={c} key="Docs">
Docs
Expand Down
6 changes: 6 additions & 0 deletions src/features/messages/MessageDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import CheckmarkIcon from '../../images/icons/checkmark-circle.svg';
import { useMultiProvider, useStore } from '../../store';
import { Message, MessageStatus } from '../../types';
import { logger } from '../../utils/logger';
import { getHumanReadableDuration } from '../../utils/time';
import { getChainDisplayName, isEvmChain } from '../chains/utils';
import { useMessageDeliveryStatus } from '../deliveryStatus/useMessageDeliveryStatus';

Expand Down Expand Up @@ -84,6 +85,10 @@ export function MessageDetails({ messageId, message: messageFromUrlParams }: Pro
isPiMsg,
} = message;

const duration = destination?.timestamp
? getHumanReadableDuration(destination.timestamp - origin.timestamp, 3)
: undefined;

const showTimeline =
!isPiMsg &&
isEvmChain(multiProvider, originChainId) &&
Expand Down Expand Up @@ -120,6 +125,7 @@ export function MessageDetails({ messageId, message: messageFromUrlParams }: Pro
domainId={destinationDomainId}
status={status}
transaction={destination}
duration={duration}
debugResult={debugResult}
isStatusFetching={isDeliveryStatusFetching}
isPiMsg={isPiMsg}
Expand Down
27 changes: 26 additions & 1 deletion src/features/messages/cards/TransactionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Link from 'next/link';
import { PropsWithChildren, ReactNode, useState } from 'react';

import { MultiProvider } from '@hyperlane-xyz/sdk';
import { isAddress, isZeroish } from '@hyperlane-xyz/utils';

import { Spinner } from '../../../components/animations/Spinner';
import { ChainLogo } from '../../../components/icons/ChainLogo';
Expand Down Expand Up @@ -48,6 +49,7 @@ export function DestinationTransactionCard({
domainId,
status,
transaction,
duration,
debugResult,
isStatusFetching,
isPiMsg,
Expand All @@ -57,6 +59,7 @@ export function DestinationTransactionCard({
domainId: DomainId;
status: MessageStatus;
transaction?: MessageTx;
duration?: string;
debugResult?: MessageDebugResult;
isStatusFetching: boolean;
isPiMsg?: boolean;
Expand All @@ -74,6 +77,7 @@ export function DestinationTransactionCard({
transaction={transaction}
chainId={chainId}
domainId={domainId}
duration={duration}
blur={blur}
/>
);
Expand Down Expand Up @@ -190,16 +194,18 @@ function TransactionDetails({
chainId,
domainId,
transaction,
duration,
blur,
}: {
chainId: ChainId;
domainId: DomainId;
transaction: MessageTx;
duration?: string;
blur: boolean;
}) {
const multiProvider = useMultiProvider();

const { hash, from, timestamp, blockNumber } = transaction;
const { hash, from, timestamp, blockNumber, mailbox } = transaction;

const txExplorerLink =
hash && !new BigNumber(hash).isZero()
Expand Down Expand Up @@ -230,6 +236,16 @@ function TransactionDetails({
showCopy={true}
blurValue={blur}
/>
{mailbox && isAddress(mailbox) && !isZeroish(mailbox) && (
<KeyValueRow
label="Mailbox:"
labelWidth="w-16"
display={mailbox}
displayWidth="w-60 sm:w-64"
showCopy={true}
blurValue={blur}
/>
)}
{!!timestamp && (
<KeyValueRow
label="Time:"
Expand All @@ -247,6 +263,15 @@ function TransactionDetails({
displayWidth="w-60 sm:w-64"
blurValue={blur}
/>
{duration && (
<KeyValueRow
label="Duration:"
labelWidth="w-16"
display={duration}
displayWidth="w-60 sm:w-64"
blurValue={blur}
/>
)}
{txExplorerLink && (
<a
className={`block ${styles.textLink}`}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface MessageTx extends MessageTxStub {
nonce: number;
gasLimit: number;
gasPrice: number;
effectiveGasPrice;
effectiveGasPrice: number;
gasUsed: number;
cumulativeGasUsed: number;
maxFeePerGas: number;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export function getHumanReadableDuration(ms: number, minSec?: number) {
}

if (seconds <= 60) {
return `${seconds} sec`;
return `${seconds} seconds`;
}
const minutes = Math.floor(seconds / 60);
if (minutes < 60) {
return `${minutes} min`;
return `${minutes} minutes`;
}
const hours = Math.floor(minutes / 60);
return `${hours} hr`;
return `${hours} hours`;
}

export function getDateTimeString(timestamp: number) {
Expand Down

0 comments on commit 2309073

Please sign in to comment.