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

Ts fix entry exit details #57

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@ import { Text, CaptionText } from '@deriv-com/quill-ui';
import CardWrapper from '../CardWrapper';
import React, { useMemo } from 'react';
import { TContractInfo, addComma, getEndTime } from '@deriv/shared';
import { Localize } from '@deriv/translations';

const getDateTimeFromEpoch = (epoch: number) => {
const date = new Date(epoch * 1000);
const formattedDate = date.toUTCString().split(' ').slice(0, 4).join(' ');
const formattedTime = `${date.toUTCString().split(' ')[4]} GMT`;
return {
date: formattedDate,
time: formattedTime,
};
const getDateTimeFromEpoch = (epoch?: number) => {
if (epoch) {
const date = new Date(epoch * 1000);
const formattedDate = date.toUTCString().split(' ').slice(0, 4).join(' ');
const formattedTime = `${date.toUTCString().split(' ')[4]} GMT`;
return {
date: formattedDate,
time: formattedTime,
};
}
};

const DateTimeRow = ({ label, value, date, time }: { label: string; value?: string; date: string; time: string }) => (
const DateTimeRow = ({
label,
value,
date,
time,
}: {
label: React.ReactNode;
value?: string;
date: string;
time: string;
}) => (
<div className='entry-exit-details__table-row'>
<div className='entry-exit-details__table-cell'>
<Text size='sm' color='quill-typography__color--subtle'>
Expand Down Expand Up @@ -50,12 +63,24 @@ const EntryExitDetails = ({ contract_info }: { contract_info: TContractInfo }) =
return (
<CardWrapper title='Entry & exit details' className='entry-exit-details'>
<div className='entry-exit-details__table'>
{dateTimes.start && <DateTimeRow label='Start time' {...dateTimes.start} />}
{dateTimes.start && (
<DateTimeRow label={<Localize i18n_default_text='Start time' />} {...dateTimes.start} />
)}
{dateTimes.entry && entryValue && (
<DateTimeRow label='Entry spot' value={entryValue} {...dateTimes.entry} />
<DateTimeRow
label={<Localize i18n_default_text='Entry spot' />}
value={entryValue}
{...dateTimes.entry}
/>
)}
{dateTimes.end && <DateTimeRow label={<Localize i18n_default_text='Exit time' />} {...dateTimes.end} />}
{dateTimes.exit && exitValue && (
<DateTimeRow
label={<Localize i18n_default_text='Exit spot' />}
value={exitValue}
{...dateTimes.exit}
/>
)}
{dateTimes.end && <DateTimeRow label='Exit time' {...dateTimes.end} />}
{dateTimes.exit && exitValue && <DateTimeRow label='Exit spot' value={exitValue} {...dateTimes.exit} />}
</div>
</CardWrapper>
);
Expand Down
Loading