Skip to content

Commit

Permalink
added year for not current year swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
paur94 committed Oct 11, 2024
1 parent a268c48 commit 9374771
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/[searchParam]/SearchData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ import { getTimeDifferenceFromNow } from "@/components/utils/CalcTime";
import { SwapData, TransactionType } from "@/models/Swap";
import LayerSwapApiClient from "@/lib/layerSwapApiClient";

const options = {
const optionsWithYear = {
year: 'numeric' as const,
month: 'short' as const,
day: 'numeric' as const,
hour: 'numeric' as const,
minute: 'numeric' as const,
};

const optionsWithoutYear = {
month: 'short' as const,
day: 'numeric' as const,
hour: 'numeric' as const,
Expand Down Expand Up @@ -53,6 +61,9 @@ export default function SearchData({ searchParam }: { searchParam: string }) {
const filteredData = data?.data?.filter(s => s?.swap?.transactions?.some(t => t?.type == TransactionType.Input))?.map(s => s?.swap);
const emptyData = data?.data?.every(s => !s?.swap?.transactions.length);

const currentYear = new Date().getFullYear();
const isCurrentYear = new Date(input_transaction?.timestamp || '').getFullYear() === currentYear

if (error || emptyData) return <NotFound />
if (isLoading) return <LoadingBlocks />

Expand Down Expand Up @@ -227,7 +238,7 @@ export default function SearchData({ searchParam }: { searchParam: string }) {
<span className="whitespace-nowrap text-white align-bottom">&nbsp;
<TooltipProvider delayDuration={0}>
<Tooltip>
<TooltipTrigger className="cursor-default">{new Date(input_transaction?.timestamp)?.toLocaleString('en-US', options)}.</TooltipTrigger>
<TooltipTrigger className="cursor-default">{new Date(input_transaction?.timestamp)?.toLocaleString('en-US', isCurrentYear ? optionsWithoutYear : optionsWithYear)}.</TooltipTrigger>
<TooltipContent>
{new Date(swap.created_date).toUTCString()}
</TooltipContent>
Expand All @@ -253,7 +264,7 @@ export default function SearchData({ searchParam }: { searchParam: string }) {
<span className="whitespace-nowrap text-white align-bottom">&nbsp;
<TooltipProvider delayDuration={0}>
<Tooltip>
<TooltipTrigger className="cursor-default">{new Date(input_transaction?.timestamp)?.toLocaleString('en-US', options)}.</TooltipTrigger>
<TooltipTrigger className="cursor-default">{new Date(input_transaction?.timestamp)?.toLocaleString('en-US', isCurrentYear ? optionsWithoutYear : optionsWithYear)}.</TooltipTrigger>
<TooltipContent>
{new Date(swap.created_date).toUTCString()}
</TooltipContent>
Expand Down

0 comments on commit 9374771

Please sign in to comment.