mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
[FLASK] Unblock personal_sign
for snaps (#19998)
* Add snap legacy authorship header * Add legacy snap header to personal_sign * Disable SIWE for snaps * Add comment
This commit is contained in:
parent
59102e37b8
commit
ba001b597c
@ -3,6 +3,9 @@ import PropTypes from 'prop-types';
|
|||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import { ObjectInspector } from 'react-inspector';
|
import { ObjectInspector } from 'react-inspector';
|
||||||
import { ethErrors, serializeError } from 'eth-rpc-errors';
|
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 LedgerInstructionField from '../ledger-instruction-field';
|
||||||
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
import { MESSAGE_TYPE } from '../../../../shared/constants/app';
|
||||||
import {
|
import {
|
||||||
@ -46,6 +49,9 @@ import ConfirmPageContainerNavigation from '../confirm-page-container/confirm-pa
|
|||||||
import SecurityProviderBannerMessage from '../security-provider-banner-message/security-provider-banner-message';
|
import SecurityProviderBannerMessage from '../security-provider-banner-message/security-provider-banner-message';
|
||||||
|
|
||||||
import SignatureRequestHeader from '../signature-request-header';
|
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';
|
import SignatureRequestOriginalWarning from './signature-request-original-warning';
|
||||||
|
|
||||||
export default class SignatureRequestOriginal extends Component {
|
export default class SignatureRequestOriginal extends Component {
|
||||||
@ -179,6 +185,17 @@ export default class SignatureRequestOriginal extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
<div className="request-signature__origin">
|
<div className="request-signature__origin">
|
||||||
|
{
|
||||||
|
// 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
|
<SiteOrigin
|
||||||
title={txData.msgParams.origin}
|
title={txData.msgParams.origin}
|
||||||
siteOrigin={txData.msgParams.origin}
|
siteOrigin={txData.msgParams.origin}
|
||||||
@ -189,6 +206,10 @@ export default class SignatureRequestOriginal extends Component {
|
|||||||
}
|
}
|
||||||
chip
|
chip
|
||||||
/>
|
/>
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
||||||
|
)
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
export { default } from './snap-legacy-authorship-header';
|
@ -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;
|
@ -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',
|
||||||
|
};
|
@ -4,6 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
|
|||||||
import { useHistory, withRouter } from 'react-router-dom';
|
import { useHistory, withRouter } from 'react-router-dom';
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
import { cloneDeep } from 'lodash';
|
import { cloneDeep } from 'lodash';
|
||||||
|
import { SubjectType } from '@metamask/permission-controller';
|
||||||
import * as actions from '../../store/actions';
|
import * as actions from '../../store/actions';
|
||||||
import txHelper from '../../helpers/utils/tx-helper';
|
import txHelper from '../../helpers/utils/tx-helper';
|
||||||
import SignatureRequest from '../../components/app/signature-request';
|
import SignatureRequest from '../../components/app/signature-request';
|
||||||
@ -16,13 +17,14 @@ import {
|
|||||||
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
||||||
getSelectedAccount,
|
getSelectedAccount,
|
||||||
///: END:ONLY_INCLUDE_IN
|
///: END:ONLY_INCLUDE_IN
|
||||||
|
getTargetSubjectMetadata,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
import { MESSAGE_TYPE } from '../../../shared/constants/app';
|
||||||
import { TransactionStatus } from '../../../shared/constants/transaction';
|
import { TransactionStatus } from '../../../shared/constants/transaction';
|
||||||
import { getSendTo } from '../../ducks/send';
|
import { getSendTo } from '../../ducks/send';
|
||||||
import { getProviderConfig } from '../../ducks/metamask/metamask';
|
import { getProviderConfig } from '../../ducks/metamask/metamask';
|
||||||
|
|
||||||
const signatureSelect = (txData) => {
|
const signatureSelect = (txData, targetSubjectMetadata) => {
|
||||||
const {
|
const {
|
||||||
type,
|
type,
|
||||||
msgParams: { version, siwe },
|
msgParams: { version, siwe },
|
||||||
@ -36,7 +38,7 @@ const signatureSelect = (txData) => {
|
|||||||
return SignatureRequest;
|
return SignatureRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (siwe?.isSIWEMessage) {
|
if (siwe?.isSIWEMessage && targetSubjectMetadata !== SubjectType.Snap) {
|
||||||
return SignatureRequestSIWE;
|
return SignatureRequestSIWE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,11 +169,16 @@ const ConfirmTxScreen = ({ match }) => {
|
|||||||
const txData = getTxData() || {};
|
const txData = getTxData() || {};
|
||||||
|
|
||||||
const { msgParams } = txData;
|
const { msgParams } = txData;
|
||||||
|
|
||||||
|
const targetSubjectMetadata = useSelector((state) =>
|
||||||
|
getTargetSubjectMetadata(state, msgParams?.origin),
|
||||||
|
);
|
||||||
|
|
||||||
if (!msgParams) {
|
if (!msgParams) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SigComponent = signatureSelect(txData);
|
const SigComponent = signatureSelect(txData, targetSubjectMetadata);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SigComponent
|
<SigComponent
|
||||||
|
Loading…
Reference in New Issue
Block a user