Skip to content

Commit

Permalink
feat: improve date/time format
Browse files Browse the repository at this point in the history
  • Loading branch information
evavirseda committed Dec 27, 2024
1 parent ab9526d commit 4c7e7c5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { useGetCurrentEpochStartTimestamp } from '@/hooks';
import { DisplayStats, DisplayStatsType } from '@iota/apps-ui-kit';
import { useFormatCoin } from '@iota/core';
import { formatDate, useFormatCoin } from '@iota/core';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { LockLocked } from '@iota/ui-icons';

Expand All @@ -20,9 +20,15 @@ export function VestingScheduleBox({
const { data: currentEpochMs } = useGetCurrentEpochStartTimestamp();

const isLocked = expirationTimestampMs > Number(currentEpochMs);
const transactionDate = formatDate(Number(expirationTimestampMs), [
'month',
'day',
'hour',
'minute',
]);
return (
<DisplayStats
label={new Date(expirationTimestampMs).toLocaleDateString()}
label={transactionDate}
value={`${formattedAmountVested} ${amountVestedSymbol}`}
type={isLocked ? DisplayStatsType.Default : DisplayStatsType.Secondary}
icon={isLocked && <LockLocked className="h-4 w-4" />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import React, { useState } from 'react';
import TransactionIcon from './TransactionIcon';
import formatTimestamp from '@/lib/utils/time';
import { ExtendedTransaction, TransactionState } from '@/lib/interfaces';
import {
Card,
Expand All @@ -18,7 +17,7 @@ import {
CardActionType,
Dialog,
} from '@iota/apps-ui-kit';
import { useFormatCoin, getLabel, useTransactionSummary } from '@iota/core';
import { useFormatCoin, getLabel, useTransactionSummary, formatDate } from '@iota/core';
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils';
import { useCurrentAccount } from '@iota/dapp-kit';
import { TransactionDetailsLayout } from '../Dialogs/transaction/TransactionDetailsLayout';
Expand Down Expand Up @@ -47,7 +46,9 @@ export function TransactionTile({ transaction }: TransactionTileProps): JSX.Elem
setOpen(true);
}

const transactionDate = transaction?.timestamp && formatTimestamp(transaction.timestamp);
const transactionDate =
transaction?.timestamp &&
formatDate(Number(transaction?.timestamp), ['month', 'day', 'hour', 'minute']);

return (
<>
Expand Down
5 changes: 0 additions & 5 deletions apps/wallet-dashboard/lib/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export default function formatTimestamp(timeStamp: number): string {
const date = new Date(timeStamp);
return new Intl.DateTimeFormat('en-US').format(date);
}

export function parseTimestamp(timestampMs: string): number {
const timestamp = parseInt(timestampMs, 10);
if (!Number.isFinite(timestamp)) {
Expand Down

0 comments on commit 4c7e7c5

Please sign in to comment.