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

fix: formatting of deadline in permit signature page #25321

Merged
merged 11 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion test/e2e/tests/confirmations/signatures/permit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async function assertInfoValues(driver: Driver) {
});
const value = driver.findElement({ text: '3000' });
const nonce = driver.findElement({ text: '0' });
const deadline = driver.findElement({ text: '50000000000' });
const deadline = driver.findElement({ text: '02 August 1971, 16:53' });

assert.ok(await origin, 'origin');
assert.ok(await contractPetName, 'contractPetName');
Expand Down
26 changes: 26 additions & 0 deletions ui/components/app/confirm/info/row/date.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';

import { ConfirmInfoRow } from './row';
import { ConfirmInfoRowDate } from './date';

const ConfirmInfoRowDateStory = {
title: 'Components/App/Confirm/InfoRowDate',
component: ConfirmInfoRowDate,

decorators: [
(story) => <ConfirmInfoRow label="Date">{story()}</ConfirmInfoRow>,
],

argTypes: {
url: {
control: 'date',
},
},
};

export const DefaultStory = ({ date }) => <ConfirmInfoRowDate date={date} />;
DefaultStory.args = {
date: 1633019124000,
};

export default ConfirmInfoRowDateStory;
11 changes: 11 additions & 0 deletions ui/components/app/confirm/info/row/date.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { render } from '@testing-library/react';

import { ConfirmInfoRowDate } from './date';

describe('ConfirmInfoRowDate', () => {
it('should match snapshot', () => {
const { getByText } = render(<ConfirmInfoRowDate date={1633019124000} />);
expect(getByText('30 September 2021, 16:25')).toBeInTheDocument();
});
});
27 changes: 27 additions & 0 deletions ui/components/app/confirm/info/row/date.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

import {
AlignItems,
Display,
FlexWrap,
TextColor,
} from '../../../../../helpers/constants/design-system';
import { formatUTCDate } from '../../../../../helpers/utils/util';
import { Box, Text } from '../../../../component-library';

export type ConfirmInfoRowDateProps = {
date: number;
};

export const ConfirmInfoRowDate = ({ date }: ConfirmInfoRowDateProps) => (
<Box
display={Display.Flex}
alignItems={AlignItems.center}
flexWrap={FlexWrap.Wrap}
gap={2}
>
<Text color={TextColor.inherit} style={{ whiteSpace: 'pre-wrap' }}>
{formatUTCDate(date)}
</Text>
</Box>
);
1 change: 1 addition & 0 deletions ui/components/app/confirm/info/row/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './address';
export * from './date';
export * from './divider';
export * from './row';
export * from './text';
Expand Down
10 changes: 10 additions & 0 deletions ui/helpers/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ export function formatDate(date, format = "M/d/y 'at' T") {
return DateTime.fromMillis(date).toFormat(format);
}

export const formatUTCDate = (dateInMillis) => {
if (!dateInMillis) {
return dateInMillis;
}

return DateTime.fromMillis(dateInMillis)
.setZone('utc')
.toFormat('dd LLLL yyyy, HH:mm');
};

export function formatDateWithYearContext(
date,
formatThisYear = 'MMM d',
Expand Down
12 changes: 12 additions & 0 deletions ui/helpers/utils/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,4 +1042,16 @@ describe('util', () => {
expect(util.hexToText(hexValue)).toBe(hexValue);
});
});

describe('formatUTCDate', () => {
it('formats passed date string', () => {
expect(util.formatUTCDate(1633019124000)).toStrictEqual(
'30 September 2021, 16:25',
);
});

it('returns empty string if empty string is passed', () => {
expect(util.formatUTCDate('')).toStrictEqual('');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { DateTime } from 'luxon';
import { useSelector } from 'react-redux';
import { toHex } from '@metamask/controller-utils';

Expand All @@ -9,9 +10,9 @@ import { SignatureRequestType } from '../../../../../types/confirm';
import {
ConfirmInfoRow,
ConfirmInfoRowAddress,
ConfirmInfoRowDate,
ConfirmInfoRowText,
} from '../../../../../../../components/app/confirm/info/row';
import { formatDate } from '../../../../../utils/date';
matthewwalsh0 marked this conversation as resolved.
Show resolved Hide resolved

const SIWESignInfo: React.FC = () => {
const t = useI18nContext();
Expand Down Expand Up @@ -64,7 +65,9 @@ const SIWESignInfo: React.FC = () => {
<ConfirmInfoRowText text={nonce} />
</ConfirmInfoRow>
<ConfirmInfoRow label={t('siweIssued')}>
<ConfirmInfoRowText text={formatDate(issuedAt)} />
<ConfirmInfoRowDate
date={DateTime.fromISO(issuedAt).toJSDate().getTime()}
matthewwalsh0 marked this conversation as resolved.
Show resolved Hide resolved
/>
</ConfirmInfoRow>
{requestId && (
<ConfirmInfoRow label={t('siweRequestId')}>
Expand Down
Loading