Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Redesign] Styling fixes Tx History #2665

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions wormhole-connect/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,27 @@ export const millisToHumanString = (ts: number): string => {
return `~${seconds} sec`;
}
};

// Generates relative time string for days, hours and minutes
export const millisToRelativeTime = (ts: number): string => {
const minsMultiplier = 1000 * 60;
const hoursMultiplier = minsMultiplier * 60;
const daysMultiplier = hoursMultiplier * 24;

if (ts > daysMultiplier) {
// It's been more than a day, show "# days ago"
const days = Math.floor(ts / daysMultiplier);
return `~${days} ${days === 1 ? 'day' : 'days'} ago`;
} else if (ts > hoursMultiplier) {
// It's been more than an hour, show "# hours ago"
const hours = Math.floor(ts / hoursMultiplier);
return `~${hours} ${hours === 1 ? 'hour' : 'hours'} ago`;
} else if (ts > minsMultiplier) {
// It's been more than a minute ago, show "# minutes ago"
const minutes = Math.floor(ts / minsMultiplier);
return `~${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`;
} else {
// It's been less than a minute ago, but we approx up to one minute
return '~1 minute ago';
}
};
2 changes: 1 addition & 1 deletion wormhole-connect/src/views/v2/Bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ const Bridge = () => {
const isTxHistoryDisabled = !sendingWallet?.address;
return (
<div className={classes.bridgeHeader}>
<Header align="left" text={config.ui.title} size={20} />
<Header align="left" text={config.ui.title} size={18} />
<Tooltip
title={isTxHistoryDisabled ? 'No connected wallets found' : ''}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ const TransactionDetails = () => {
<Typography
color={theme.palette.text.secondary}
marginBottom="12px"
>{`Transaction # ${trimTxHash(sendTx)}`}</Typography>
>{`Transaction #${trimTxHash(sendTx)}`}</Typography>
{sentAmount}
{verticalConnector}
{receivedAmount}
Expand Down
25 changes: 16 additions & 9 deletions wormhole-connect/src/views/v2/TxHistory/Item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TokenIcon from 'icons/TokenIcons';
import {
calculateUSDPrice,
getUSDFormat,
trimAddress,
millisToRelativeTime,
trimTxHash,
} from 'utils';

Expand Down Expand Up @@ -63,8 +63,6 @@ const TxHistoryItem = (props: Props) => {
const sourceTokenConfig = config.tokens[tokenKey];
const sourceChainConfig = config.chains[fromChain]!;

const senderAddress = sender ? trimAddress(sender) : '';

return (
<Stack alignItems="center" direction="row" justifyContent="flex-start">
<Badge
Expand All @@ -88,7 +86,7 @@ const TxHistoryItem = (props: Props) => {
<Typography color={theme.palette.text.secondary} fontSize={14}>
{`${getUSDFormat(amountUsd, true)} \u2022 ${
sourceChainConfig?.displayName
} ${senderAddress}`}
}`}
</Typography>
</Stack>
</Stack>
Expand All @@ -102,8 +100,6 @@ const TxHistoryItem = (props: Props) => {
? config.tokens[receivedTokenKey]
: undefined;

const recipientAddress = recipient ? trimAddress(recipient) : '';

const receiveAmountPrice = calculateUSDPrice(
receiveAmount,
props.tokenPrices,
Expand Down Expand Up @@ -134,7 +130,7 @@ const TxHistoryItem = (props: Props) => {
{receiveAmount} {destTokenConfig?.symbol}
</Typography>
<Typography color={theme.palette.text.secondary} fontSize={14}>
{`${receiveAmountDisplay}${destChainConfig?.displayName} ${recipientAddress}`}
{`${receiveAmountDisplay}${destChainConfig?.displayName}`}
</Typography>
</Stack>
</Stack>
Expand All @@ -160,7 +156,18 @@ const TxHistoryItem = (props: Props) => {

const senderDate = new Date(senderTimestamp);

return `${senderDate.toLocaleDateString()} ${senderDate.toLocaleTimeString()}`;
// If it's been less than a day, show relative time
const timePassed = Date.now() - senderDate.getTime();
if (timePassed < 1000 * 60 * 60 * 24) {
return millisToRelativeTime(timePassed);
}

const dateTimeFormat = new Intl.DateTimeFormat('en-US', {
dateStyle: 'short',
timeStyle: 'short',
});

return `${dateTimeFormat.format(senderDate)}`;
}, [senderTimestamp]);

return (
Expand All @@ -180,7 +187,7 @@ const TxHistoryItem = (props: Props) => {
color={theme.palette.text.secondary}
display="flex"
>
<span>{`Transaction # ${trimTxHash(txHash)}`}</span>
<span>{`Transaction #${trimTxHash(txHash)}`}</span>
<span>{transactionDateTime}</span>
</Typography>
}
Expand Down
2 changes: 1 addition & 1 deletion wormhole-connect/src/views/v2/TxHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const TxHistory = () => {
const txHistoryHeader = useMemo(() => {
return (
<div className={classes.txHistoryHeader}>
<Header align="left" text="Transaction history" size={20} />
<Header align="left" size={18} text="Transaction history" />
<IconButton onClick={() => dispatch(setAppRoute('bridge'))}>
<SwapHorizIcon />
</IconButton>
Expand Down
7 changes: 6 additions & 1 deletion wormhole-connect/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ const plugins = [
];

const optimizeDeps = {
include: ['@emotion/styled'],
include: [
'@emotion/react',
'@emotion/styled',
'@mui/material/Tooltip',
'@mui/material/Unstable_Grid2',
],
};

interface AssetInfo {
Expand Down
Loading