Skip to content

Commit

Permalink
feat(explorer): rebrand tx block quick overview (#2479)
Browse files Browse the repository at this point in the history
* feat: add displaystats component

* feat: rename prop, updtae styles and colors

* feat: add icon prop

* feat: add w-full

* feat: update display stats component

* feat: rebrand object page

* feat: add div to prevent wrong gap

* feat: rebrand transaction blocks

* feat: refine grid

* eat: add word break and height full

* feat: improve accordion

* feat: improve styles

* feat: add truncate and width

* feat: cleanup

* feat: uodate grid

* feat: update modal bg

* feat: refinements

* feat: rebrand txblock details

* minor fix

* feat: bring back domainName

* feat: add isTuncated to storybook

* feat: update truncate

---------

Co-authored-by: Begoña Alvarez <[email protected]>
  • Loading branch information
evavirseda and begonaalvarezd authored Sep 13, 2024
1 parent 8f6ea50 commit c6c4d54
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 108 deletions.
15 changes: 3 additions & 12 deletions apps/explorer/src/pages/transaction-result/TransactionData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
type ProgrammableTransaction,
type IotaTransactionBlockResponse,
} from '@iota/iota-sdk/client';

import { TransactionDetailCard } from './transaction-summary/TransactionDetailCard';
import { GasBreakdown } from '~/components';
import { useRecognizedPackages } from '~/hooks/useRecognizedPackages';
import { InputsCard } from '~/pages/transaction-result/programmable-transaction-view/InputsCard';
Expand All @@ -32,15 +30,8 @@ export function TransactionData({ transaction }: TransactionDataProps): JSX.Elem
const programmableTxn = transaction.transaction!.data.transaction as ProgrammableTransaction;

return (
<div className="flex flex-wrap gap-3 pl-1 pr-2 md:gap-6">
<section className="flex w-96 flex-1 flex-col gap-3 max-md:min-w-[50%] md:gap-6">
<TransactionDetailCard
timestamp={summary?.timestamp}
sender={summary?.sender}
checkpoint={transaction.checkpoint}
executedEpoch={transaction.effects?.executedEpoch}
/>

<div className="flex w-full flex-col gap-3 pl-1 pr-2 md:gap-6">
<section className="flex w-full flex-1 flex-col gap-3 md:gap-6">
{isProgrammableTransaction && (
<div data-testid="inputs-card">
<InputsCard inputs={programmableTxn.inputs} />
Expand All @@ -49,7 +40,7 @@ export function TransactionData({ transaction }: TransactionDataProps): JSX.Elem
</section>

{isProgrammableTransaction && (
<section className="flex w-96 flex-1 flex-col gap-3 md:min-w-transactionColumn md:gap-6">
<section className="flex w-full flex-1 flex-col gap-3 md:min-w-transactionColumn md:gap-6">
<div data-testid="transactions-card">
<TransactionsCard transactions={programmableTxn.transactions} />
</div>
Expand Down
19 changes: 17 additions & 2 deletions apps/explorer/src/pages/transaction-result/TransactionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import { Signatures } from './Signatures';

import { LocalStorageSplitPaneKey } from '~/lib/enums';
import styles from './TransactionResult.module.css';
import { TransactionDetails } from './transaction-summary/TransactionDetails';
import { useTransactionSummary } from '@iota/core';
import { useRecognizedPackages } from '~/hooks';

interface TabsContentContainerProps {
value: string;
Expand Down Expand Up @@ -91,10 +94,22 @@ export function TransactionView({ transaction }: TransactionViewProps): JSX.Elem
minSize: 40,
defaultSize: isProgrammableTransaction ? 65 : 50,
};

const recognizedPackagesList = useRecognizedPackages();
const summary = useTransactionSummary({
transaction,
recognizedPackagesList,
});
return (
<div className={clsx(styles.txdetailsbg)}>
<div className="h-screen md:h-full">
<div className="flex h-screen flex-col gap-2xl md:h-full">
<div>
<TransactionDetails
timestamp={summary?.timestamp}
sender={summary?.sender}
checkpoint={transaction.checkpoint}
executedEpoch={transaction.effects?.executedEpoch}
/>
</div>
<SplitPanes
autoSaveId={LocalStorageSplitPaneKey.TransactionView}
onCollapse={setIsCollapsed}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Mysten Labs, Inc.
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { DisplayStats } from '@iota/apps-ui-kit';
import { formatDate, useResolveIotaNSName } from '@iota/core';

interface TransactionDetailsProps {
sender?: string;
checkpoint?: string | null;
executedEpoch?: string;
timestamp?: string | null;
}

export function TransactionDetails({
sender,
checkpoint,
executedEpoch,
timestamp,
}: TransactionDetailsProps): JSX.Element {
const { data: domainName } = useResolveIotaNSName(sender);

return (
<div className="grid grid-cols-1 gap-sm md:grid-cols-4">
{sender && (
<DisplayStats
label="Sender"
value={sender}
valueLink={domainName ?? `/address/${sender}`}
isTruncated
/>
)}
{checkpoint && (
<DisplayStats
label="Checkpoint"
value={Number(checkpoint).toLocaleString()}
valueLink={`/checkpoint/${checkpoint}`}
/>
)}
{executedEpoch && (
<DisplayStats
label="Epoch"
value={executedEpoch}
valueLink={`/epoch/${executedEpoch}`}
/>
)}

{timestamp && <DisplayStats label="Date" value={formatDate(Number(timestamp))} />}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ interface DisplayStatsProps {
* The value link is external.
*/
isExternalLink?: boolean;
/**
* The value is truncated
*/
isTruncated?: boolean;
}

export function DisplayStats({
Expand All @@ -69,13 +73,19 @@ export function DisplayStats({
icon,
valueLink,
isExternalLink = false,
isTruncated = false,
}: DisplayStatsProps): React.JSX.Element {
const backgroundClass = BACKGROUND_CLASSES[type];
const sizeClass = SIZE_CLASSES[size];
const textClass = TEXT_CLASSES[type];
const valueTextClass = VALUE_TEXT_CLASSES[size];
const labelTextClass = LABEL_TEXT_CLASSES[size];
const supportingLabelTextClass = SUPPORTING_LABEL_TEXT_CLASSES[size];
function truncate(value: string, startLength: number, endLength: number): string {
return value.length > startLength + endLength && isTruncated
? `${value.slice(0, startLength)}...${value.slice(-endLength)}`
: value;
}
return (
<div
className={cx(
Expand All @@ -100,19 +110,19 @@ export function DisplayStats({
</div>
{icon && <span className="text-neutral-10 dark:text-neutral-92">{icon}</span>}
</div>
<div className="flex flex-row items-baseline gap-xxs break-all">
<div className="flex w-full flex-row items-baseline gap-xxs">
{valueLink ? (
<a
href={valueLink}
target={isExternalLink ? '_blank' : '_self'}
rel="noreferrer"
className={cx('text-primary-30 dark:text-primary-80', valueTextClass)}
>
{value}
{truncate(value, 6, 6)}
</a>
) : (
<>
<span className={cx(valueTextClass)}>{value}</span>
<span className={cx(valueTextClass)}>{truncate(value, 6, 6)}</span>
{supportingLabel && (
<span className={cx('opacity-40', supportingLabelTextClass)}>
{supportingLabel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ export const Default: Story = {
isExternalLink: {
control: 'boolean',
},
isTruncated: {
control: 'boolean',
},
},
};

0 comments on commit c6c4d54

Please sign in to comment.