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

[FLASK] Unblock personal_sign for snaps #19998

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
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 @@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';
import { ObjectInspector } from 'react-inspector';
import { ethErrors, serializeError } from 'eth-rpc-errors';
///: BEGIN:ONLY_INCLUDE_IN(snaps)
import { SubjectType } from '@metamask/permission-controller';
///: END:ONLY_INCLUDE_IN
import LedgerInstructionField from '../ledger-instruction-field';
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
import {
Expand Down Expand Up @@ -46,6 +49,9 @@ import ConfirmPageContainerNavigation from '../confirm-page-container/confirm-pa
import SecurityProviderBannerMessage from '../security-provider-banner-message/security-provider-banner-message';

import SignatureRequestHeader from '../signature-request-header';
///: BEGIN:ONLY_INCLUDE_IN(snaps)
import SnapLegacyAuthorshipHeader from '../snaps/snap-legacy-authorship-header';
///: END:ONLY_INCLUDE_IN
import SignatureRequestOriginalWarning from './signature-request-original-warning';

export default class SignatureRequestOriginal extends Component {
Expand Down Expand Up @@ -179,16 +185,31 @@ export default class SignatureRequestOriginal extends Component {
}

<div className="request-signature__origin">
<SiteOrigin
title={txData.msgParams.origin}
siteOrigin={txData.msgParams.origin}
iconSrc={targetSubjectMetadata?.iconUrl}
iconName={
getURLHostName(targetSubjectMetadata?.origin) ||
targetSubjectMetadata?.origin
}
chip
/>
{
// Use legacy authorship header for snaps
///: BEGIN:ONLY_INCLUDE_IN(snaps)
targetSubjectMetadata?.subjectType === SubjectType.Snap ? (
<SnapLegacyAuthorshipHeader
snapId={targetSubjectMetadata.origin}
marginLeft={4}
marginRight={4}
/>
) : (
///: END:ONLY_INCLUDE_IN
<SiteOrigin
title={txData.msgParams.origin}
siteOrigin={txData.msgParams.origin}
iconSrc={targetSubjectMetadata?.iconUrl}
iconName={
getURLHostName(targetSubjectMetadata?.origin) ||
targetSubjectMetadata?.origin
}
chip
/>
///: BEGIN:ONLY_INCLUDE_IN(snaps)
)
///: END:ONLY_INCLUDE_IN
}
</div>

<Typography
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './snap-legacy-authorship-header';
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useSelector } from 'react-redux';
import {
BackgroundColor,
TextColor,
TextVariant,
AlignItems,
FontWeight,
Display,
FlexDirection,
BlockSize,
BorderColor,
BorderRadius,
} from '../../../../helpers/constants/design-system';
import {
getSnapName,
removeSnapIdPrefix,
} from '../../../../helpers/utils/util';

import { Box, Text } from '../../../component-library';
import { getTargetSubjectMetadata } from '../../../../selectors';
import SnapAvatar from '../snap-avatar';

const SnapLegacyAuthorshipHeader = ({
snapId,
className,
marginLeft,
marginRight,
}) => {
const packageName = snapId && removeSnapIdPrefix(snapId);

const subjectMetadata = useSelector((state) =>
getTargetSubjectMetadata(state, snapId),
);

const friendlyName = snapId && getSnapName(snapId, subjectMetadata);

return (
<Box
className={classnames('snap-legacy-authorship-header', className)}
backgroundColor={BackgroundColor.backgroundDefault}
width={BlockSize.Full}
alignItems={AlignItems.center}
display={Display.Flex}
padding={2}
borderColor={BorderColor.borderDefault}
borderRadius={BorderRadius.pill}
marginLeft={marginLeft}
marginRight={marginRight}
>
<Box>
<SnapAvatar snapId={snapId} />
</Box>
<Box
marginLeft={4}
marginRight={4}
display={Display.Flex}
flexDirection={FlexDirection.Column}
style={{ overflow: 'hidden' }}
>
<Text ellipsis fontWeight={FontWeight.Medium}>
{friendlyName}
</Text>
<Text
ellipsis
variant={TextVariant.bodySm}
color={TextColor.textAlternative}
>
{packageName}
</Text>
</Box>
</Box>
);
};

SnapLegacyAuthorshipHeader.propTypes = {
/**
* The id of the snap
*/
snapId: PropTypes.string,
/**
* The className of the SnapLegacyAuthorshipHeader
*/
className: PropTypes.string,
marginLeft: PropTypes.number,
marginRight: PropTypes.number,
};

export default SnapLegacyAuthorshipHeader;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import SnapLegacyAuthorshipHeader from './snap-legacy-authorship-header';

export default {
title: 'Components/App/Snaps/SnapLegacyAuthorshipHeader',

component: SnapLegacyAuthorshipHeader,
argTypes: {
snapId: {
control: 'text',
},
},
};

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

DefaultStory.storyName = 'Default';

DefaultStory.args = {
snapId: 'npm:@metamask/test-snap-bip44',
};
13 changes: 10 additions & 3 deletions ui/pages/confirm-signature-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { useHistory, withRouter } from 'react-router-dom';
import log from 'loglevel';
import { cloneDeep } from 'lodash';
import { SubjectType } from '@metamask/permission-controller';
import * as actions from '../../store/actions';
import txHelper from '../../helpers/utils/tx-helper';
import SignatureRequest from '../../components/app/signature-request';
Expand All @@ -16,13 +17,14 @@ import {
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
getSelectedAccount,
///: END:ONLY_INCLUDE_IN
getTargetSubjectMetadata,
} from '../../selectors';
import { MESSAGE_TYPE } from '../../../shared/constants/app';
import { TransactionStatus } from '../../../shared/constants/transaction';
import { getSendTo } from '../../ducks/send';
import { getProviderConfig } from '../../ducks/metamask/metamask';

const signatureSelect = (txData) => {
const signatureSelect = (txData, targetSubjectMetadata) => {
const {
type,
msgParams: { version, siwe },
Expand All @@ -36,7 +38,7 @@ const signatureSelect = (txData) => {
return SignatureRequest;
}

if (siwe?.isSIWEMessage) {
if (siwe?.isSIWEMessage && targetSubjectMetadata !== SubjectType.Snap) {
return SignatureRequestSIWE;
}

Expand Down Expand Up @@ -167,11 +169,16 @@ const ConfirmTxScreen = ({ match }) => {
const txData = getTxData() || {};

const { msgParams } = txData;

const targetSubjectMetadata = useSelector((state) =>
getTargetSubjectMetadata(state, msgParams?.origin),
);

if (!msgParams) {
return <Loading />;
}

const SigComponent = signatureSelect(txData);
const SigComponent = signatureSelect(txData, targetSubjectMetadata);

return (
<SigComponent
Expand Down