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

feat: Support various redesign signatures in ConfirmPage Storybook #25054

Merged
merged 9 commits into from
Jun 12, 2024
99 changes: 84 additions & 15 deletions ui/pages/confirmations/confirm/confirm.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,96 @@
import React from 'react';
import { Provider } from 'react-redux';
import configureStore from '../../../store/store';
import { cloneDeep } from 'lodash';
import { unapprovedPersonalSignMsg, signatureRequestSIWE } from '../../../../test/data/confirmations/personal_sign';
import { unapprovedTypedSignMsgV1, unapprovedTypedSignMsgV4, permitSignatureMsg } from '../../../../test/data/confirmations/typed_sign';
import mockState from '../../../../test/data/mock-state.json';
import configureStore from '../../../store/store';
import ConfirmPage from './confirm';

const store = configureStore({
confirm: {
currentConfirmation: {
type: 'personal_sign',
},
},
metamask: {
...mockState.metamask,
},
});

/**
* @note When we extend this storybook page to support more confirmation types,
* consider creating a new storybook pages.
*/
const ConfirmPageStory = {
title: 'Pages/Confirm/ConfirmPage',
decorators: [(story) => <Provider store={store}>{story()}</Provider>],
decorators: [(story) => <div style={{ height: '600px' }}>{story()}</div>],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also force the width so it matches the standard MetaMask popup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. As you might have noticed, the height resembles our popup height. I added this to view the scrollToBottom feature on some of the signature pages without needing to hardcode or add a control for this.

I left out the width so that we could easily test various widths. These decisions were subjective. Open to other suggestions

CleanShot 2024-06-07 at 21 21 04

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we still support re-sizing to test wrapping etc, but default to the standard width?

}

const ARGS_SIGNATURE = {
msgParams: { ...unapprovedPersonalSignMsg.msgParams },
}

const ARG_TYPES_SIGNATURE = {
msgParams: {
control: 'object',
description: '(non-param) overrides currentConfirmation.msgParams',
},
}

function SignatureStoryTemplate(args, confirmation) {
const mockConfirmation = cloneDeep(confirmation);
mockConfirmation.msgParams = args.msgParams;

const store = configureStore({
confirm: {
currentConfirmation: mockConfirmation,
},
metamask: { ...mockState.metamask },
});

return <Provider store={store}><ConfirmPage /></Provider>;
}

export const PersonalSignStory = (args) => {
return SignatureStoryTemplate(args, unapprovedPersonalSignMsg);
};

export const DefaultStory = (args) => <ConfirmPage {...args} />;
PersonalSignStory.storyName = 'Personal Sign';
PersonalSignStory.argTypes = ARG_TYPES_SIGNATURE;
PersonalSignStory.args = ARGS_SIGNATURE;

DefaultStory.storyName = 'Default';
export const SignInWithEthereumSIWEStory = (args) => {
return SignatureStoryTemplate(args, signatureRequestSIWE);
};

SignInWithEthereumSIWEStory.storyName = 'Sign-in With Ethereum (SIWE)';
SignInWithEthereumSIWEStory.argTypes = ARG_TYPES_SIGNATURE;
SignInWithEthereumSIWEStory.args = {
...ARGS_SIGNATURE,
msgParams: signatureRequestSIWE.msgParams,
};

export const SignTypedDataStory = (args) => {
return SignatureStoryTemplate(args, unapprovedTypedSignMsgV1);
};

SignTypedDataStory.storyName = 'SignTypedData';
SignTypedDataStory.argTypes = ARG_TYPES_SIGNATURE;
SignTypedDataStory.args = {
...ARGS_SIGNATURE,
msgParams: unapprovedTypedSignMsgV1.msgParams,
};

export const PermitStory = (args) => {
return SignatureStoryTemplate(args, permitSignatureMsg);
};

PermitStory.storyName = 'SignTypedData Permit';
PermitStory.argTypes = ARG_TYPES_SIGNATURE;
PermitStory.args = {
...ARGS_SIGNATURE,
msgParams: permitSignatureMsg.msgParams,
};

export const SignTypedDataV4Story = (args) => {
matthewwalsh0 marked this conversation as resolved.
Show resolved Hide resolved
return SignatureStoryTemplate(args, unapprovedTypedSignMsgV4);
};

SignTypedDataV4Story.storyName = 'SignTypedData V4';
SignTypedDataV4Story.argTypes = ARG_TYPES_SIGNATURE;
SignTypedDataV4Story.args = {
...ARGS_SIGNATURE,
msgParams: unapprovedTypedSignMsgV4.msgParams,
};

export default ConfirmPageStory;