Skip to content

Commit

Permalink
feat: show paymaster address in redesigned contract interaction (#25396)
Browse files Browse the repository at this point in the history
Display the paymaster address in the contract interaction confirmation.
Replace duplicate `Box` usages with new `ConfirmInfoSection` component.
Add stories for the full contract interaction confirmation page for easier testing.
Create selectors to retrieve paymaster data and address by user operation ID.
Rename `AlertRow` to `ConfirmInfoAlertRow`.
  • Loading branch information
matthewwalsh0 authored Jun 21, 2024
1 parent 5960ae7 commit 3777882
Show file tree
Hide file tree
Showing 36 changed files with 868 additions and 754 deletions.
3 changes: 3 additions & 0 deletions .storybook/images/icons/info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions .storybook/images/icons/question.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = {
'@storybook/addon-designs',
],
staticDirs: ['../app', './images'],
env: (config) => ({
...config,
ENABLE_CONFIRMATION_REDESIGN: true,
}),
// Uses babel.config.js settings and prevents "Missing class properties transform" error
babel: async (options) => ({
overrides: options.overrides,
Expand Down
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/data/confirmations/contract-interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
} from '@metamask/transaction-controller';
import { Confirmation } from '../../../ui/pages/confirmations/types/confirm';

export const PAYMASTER_AND_DATA =
'0x9d6ac51b972544251fcc0f2902e633e3f9bd3f2900000000000000000000000000000000000000000000000000000000666bfd410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003498a76eb88b702e5e52b00fbc16a36baf89ebe3e0dd23170949cffc0a623011383cced660ff67930308c22e5aa746a2d586629ddbd87046a146225bf80e9d6f1b';

export const CONTRACT_INTERACTION_SENDER_ADDRESS =
'0x2e0d7e8c45221fca00d74a3609a0f7097035d09b';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ exports[`ConfirmInfo should match snapshot 1`] = `
</div>
</div>
<div
style="height: 1px;"
style="height: 1px; margin-left: -8px; margin-right: -8px;"
/>
<div
class="mm-box confirm-info-row mm-box--margin-top-2 mm-box--margin-bottom-2 mm-box--padding-right-2 mm-box--padding-left-2 mm-box--display-flex mm-box--flex-direction-row mm-box--flex-wrap-wrap mm-box--justify-content-space-between mm-box--color-text-default mm-box--rounded-lg"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`ConfirmInfoRowDivider should match snapshot 1`] = `
<div>
<div
style="height: 1px;"
style="height: 1px; margin-left: -8px; margin-right: -8px;"
/>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ConfirmInfoSection should match snapshot 1`] = `
<div>
<div
class="mm-box mm-box--margin-bottom-4 mm-box--padding-2 mm-box--background-color-background-default mm-box--rounded-md"
>
Test Content
</div>
</div>
`;

exports[`ConfirmInfoSection should match snapshot without padding 1`] = `
<div>
<div
class="mm-box mm-box--margin-bottom-4 mm-box--padding-0 mm-box--background-color-background-default mm-box--rounded-md"
>
Test Content
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ConfirmInfoRowVariant } from '../row';
import { AlertRow } from './alert-row';
import { ConfirmInfoAlertRow } from './alert-row';
import configureStore from '../../../../../../store/store';
import { Provider } from 'react-redux';
import { Meta } from '@storybook/react';
Expand Down Expand Up @@ -41,7 +41,7 @@ const storeMock = configureStore({
const ConfirmInfoRowStory = {
title: 'Components/App/Confirm/AlertRow',

component: AlertRow,
component: ConfirmInfoAlertRow,
argTypes: {
variant: {
control: 'select',
Expand All @@ -55,9 +55,9 @@ const ConfirmInfoRowStory = {
},
},
decorators: [(story) => <Provider store={storeMock}>{story()}</Provider>],
} as Meta<typeof AlertRow>;
} as Meta<typeof ConfirmInfoAlertRow>;

export const DefaultStory = (args) => <AlertRow {...args} />;
export const DefaultStory = (args) => <ConfirmInfoAlertRow {...args} />;

DefaultStory.storyName = 'Default';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Text } from '../../../../../component-library';
import { renderWithProvider } from '../../../../../../../test/lib/render-helpers';
import { Severity } from '../../../../../../helpers/constants/design-system';
import mockState from '../../../../../../../test/data/mock-state.json';
import { AlertRow, AlertRowProps } from './alert-row';
import { ConfirmInfoAlertRow, ConfirmInfoAlertRowProps } from './alert-row';

const onProcessActionMock = jest.fn();

Expand Down Expand Up @@ -36,7 +36,7 @@ describe('AlertRow', () => {
},
];
const renderAlertRow = (
props?: Partial<AlertRowProps>,
props?: Partial<ConfirmInfoAlertRowProps>,
state?: Record<string, unknown>,
) => {
const STATE_MOCK = {
Expand All @@ -60,7 +60,7 @@ describe('AlertRow', () => {

const mockStore = configureMockStore([])(STATE_MOCK);
return renderWithProvider(
<AlertRow
<ConfirmInfoAlertRow
label={KEY_ALERT_KEY_MOCK}
children={<Text>value</Text>}
ownerId={OWNER_ID_NO_ALERT_MOCK}
Expand Down
6 changes: 3 additions & 3 deletions ui/components/app/confirm/info/row/alert-row/alert-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { Box } from '../../../../../component-library';
import { MultipleAlertModal } from '../../../../alert-system/multiple-alert-modal';

export type AlertRowProps = ConfirmInfoRowProps & {
export type ConfirmInfoAlertRowProps = ConfirmInfoRowProps & {
alertKey: string;
ownerId: string;
};
Expand All @@ -36,12 +36,12 @@ function getAlertTextColors(
}
}

export const AlertRow = ({
export const ConfirmInfoAlertRow = ({
alertKey,
ownerId,
variant,
...rowProperties
}: AlertRowProps) => {
}: ConfirmInfoAlertRowProps) => {
const { getFieldAlerts } = useAlerts(ownerId);
const fieldAlerts = getFieldAlerts(alertKey);
const hasFieldAlert = fieldAlerts.length > 0;
Expand Down
3 changes: 3 additions & 0 deletions ui/components/app/confirm/info/row/divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const ConfirmInfoRowDivider: React.FC = () => {
style={{
height: '1px',
backgroundColor: 'var(--color-border-muted)',
// Ignore the padding from the section.
marginLeft: '-8px',
marginRight: '-8px',
}}
></div>
);
Expand Down
55 changes: 55 additions & 0 deletions ui/components/app/confirm/info/row/section.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { ConfirmInfoSection } from './section';
import { ConfirmInfoRow } from './row';
import { ConfirmInfoRowText } from './text';

const ConfirmInfoSectionStory = {
title: 'Components/App/Confirm/InfoSection',
component: ConfirmInfoSection,

decorators: [
(story) => (
<div
style={{
backgroundColor: 'var(--color-background-alternative)',
padding: 30,
}}
>
{story()}
</div>
),
],

argTypes: {
noPadding: {
control: 'boolean',
},
},
};

export const DefaultStory = (args) => (
<>
<ConfirmInfoSection {...args}>
<ConfirmInfoRow label="Test Label 1">
<ConfirmInfoRowText text="Test Value 1"></ConfirmInfoRowText>
</ConfirmInfoRow>
<ConfirmInfoRow label="Test Label 2">
<ConfirmInfoRowText text="Test Value 2"></ConfirmInfoRowText>
</ConfirmInfoRow>
</ConfirmInfoSection>
<ConfirmInfoSection {...args}>
<ConfirmInfoRow label="Test Label 3">
<ConfirmInfoRowText text="Test Value 3"></ConfirmInfoRowText>
</ConfirmInfoRow>
<ConfirmInfoRow label="Test Label 4">
<ConfirmInfoRowText text="Test Value 4"></ConfirmInfoRowText>
</ConfirmInfoRow>
</ConfirmInfoSection>
</>
);

DefaultStory.args = {
noPadding: false,
};

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

describe('ConfirmInfoSection', () => {
it('should match snapshot', () => {
const { container } = render(
<ConfirmInfoSection>Test Content</ConfirmInfoSection>,
);
expect(container).toMatchSnapshot();
});

it('should match snapshot without padding', () => {
const { container } = render(
<ConfirmInfoSection noPadding>Test Content</ConfirmInfoSection>,
);
expect(container).toMatchSnapshot();
});
});
27 changes: 27 additions & 0 deletions ui/components/app/confirm/info/row/section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { Box } from '../../../../component-library';
import {
BackgroundColor,
BorderRadius,
} from '../../../../../helpers/constants/design-system';

export type ConfirmInfoSectionProps = {
children: React.ReactNode | string;
noPadding?: boolean;
};

export const ConfirmInfoSection = ({
children,
noPadding,
}: ConfirmInfoSectionProps) => {
return (
<Box
backgroundColor={BackgroundColor.backgroundDefault}
borderRadius={BorderRadius.MD}
padding={noPadding ? 0 : 2}
marginBottom={4}
>
{children}
</Box>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const MMISignatureMismatchBanner: React.FC = memo(() => {
}, [currentConfirmation, allAccounts]);

if (
selectedAccount &&
fromAccount &&
!selectedAccount ||
!fromAccount ||
selectedAccount.address === fromAccount.address
) {
return null;
Expand Down
Loading

0 comments on commit 3777882

Please sign in to comment.