Skip to content

Commit

Permalink
Replaced addresses by the address component on SignTypedData v4 signa…
Browse files Browse the repository at this point in the history
…tures (#16018)

* Replaced addresses by the address component on SignTypedData v4 signatures

* Fixing signature-request e2e tests

* Modified scss file for signature-request message

* Using address component for rendering the addresses and bold label where hex address is not valid

* Modify the address component

* Added proper BEM syntax for class names and used Box and Typography

* FIxing e2e tests

* Commited requested changes from George and added storybook

* Review requested changes

* Created new component for rendering data in signature-request-message.js

* Fixing proper usage for getAccountName and getMetadataContractName selectors

* Fixing e2e tests
  • Loading branch information
VSaric authored Nov 10, 2022
1 parent 4a247a9 commit 42be5a0
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 174 deletions.
2 changes: 1 addition & 1 deletion development/ts-migration-dashboard/files-to-convert.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@
"ui/components/app/signature-request/signature-request-header/signature-request-header.component.js",
"ui/components/app/signature-request/signature-request-header/signature-request-header.stories.js",
"ui/components/app/signature-request/signature-request-message/index.js",
"ui/components/app/signature-request/signature-request-message/signature-request-message.component.js",
"ui/components/app/signature-request/signature-request-message/signature-request-message.js",
"ui/components/app/signature-request/signature-request.component.js",
"ui/components/app/signature-request/signature-request.component.test.js",
"ui/components/app/signature-request/signature-request.container.js",
Expand Down
8 changes: 6 additions & 2 deletions test/e2e/tests/signature-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Sign Typed Data V4 Signature Request', function () {
const origin = content[0];
const address = content[1];
const message = await driver.findElement(
'.signature-request-message--node-value',
'.signature-request-data__node__value',
);
assert.equal(await title.getText(), 'Signature request');
assert.equal(await name.getText(), 'Ether Mail');
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('Sign Typed Data V3 Signature Request', function () {
const origin = content[0];
const address = content[1];
const messages = await driver.findElements(
'.signature-request-message--node-value',
'.signature-request-data__node__value',
);
assert.equal(await title.getText(), 'Signature request');
assert.equal(await name.getText(), 'Ether Mail');
Expand All @@ -154,6 +154,10 @@ describe('Sign Typed Data V3 Signature Request', function () {
assert.equal(await messages[4].getText(), 'Hello, Bob!');

// Approve signing typed data
await driver.clickElement(
'[data-testid="signature-request-scroll-button"]',
);
await driver.delay(regularDelayMs);
await driver.clickElement({ text: 'Sign', tag: 'button' });
await driver.waitUntilXWindowHandles(2);
windowHandles = await driver.getAllWindowHandles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getSwapsDefaultToken,
getMetadataContractName,
getAccountName,
getMetaMaskIdentities,
} from '../../../selectors';
import ConfirmPageContainer from './confirm-page-container.component';

Expand All @@ -17,8 +18,9 @@ function mapStateToProps(state, ownProps) {
const networkIdentifier = getNetworkIdentifier(state);
const defaultToken = getSwapsDefaultToken(state);
const accountBalance = defaultToken.string;
const toName = getAccountName(state, to);
const toMetadataName = getMetadataContractName(to);
const identities = getMetaMaskIdentities(state);
const toName = getAccountName(identities, to);
const toMetadataName = getMetadataContractName(state, to);

return {
isBuyableChain,
Expand Down
1 change: 1 addition & 0 deletions ui/components/app/signature-request/index.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import 'signature-request-footer/index';
@import 'signature-request-header/index';
@import 'signature-request-message/index';
@import 'signature-request-data/index';

.signature-request {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './signature-request-data';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.signature-request-data {
&__node {
&__value {
white-space: pre-line;
overflow: hidden;
word-wrap: break-word;

&__address {
[dir='rtl'] & {
/*rtl:ignore*/
direction: ltr;

/*rtl:ignore*/
text-align: right;

span {
display: block;

/*rtl:ignore*/
direction: rtl;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import { useSelector } from 'react-redux';
import PropTypes from 'prop-types';
import { getMetaMaskIdentities, getAccountName } from '../../../../selectors';
import Address from '../../transaction-decoding/components/decoding/address';
import {
isValidHexAddress,
toChecksumHexAddress,
} from '../../../../../shared/modules/hexstring-utils';
import Box from '../../../ui/box';
import Typography from '../../../ui/typography';
import {
DISPLAY,
COLORS,
FONT_WEIGHT,
TYPOGRAPHY,
} from '../../../../helpers/constants/design-system';

export default function SignatureRequestData({ data }) {
const identities = useSelector(getMetaMaskIdentities);

return (
<Box className="signature-request-data__node">
{Object.entries(data).map(([label, value], i) => (
<Box
className="signature-request-data__node"
key={i}
paddingLeft={2}
display={
typeof value !== 'object' || value === null ? DISPLAY.FLEX : null
}
>
<Typography
as="span"
color={COLORS.TEXT_DEFAULT}
marginLeft={4}
fontWeight={
typeof value === 'object' ? FONT_WEIGHT.BOLD : FONT_WEIGHT.NORMAL
}
>
{label.charAt(0).toUpperCase() + label.slice(1)}:{' '}
</Typography>
{typeof value === 'object' && value !== null ? (
<SignatureRequestData data={value} />
) : (
<Typography
as="span"
color={COLORS.TEXT_DEFAULT}
marginLeft={4}
className="signature-request-data__node__value"
>
{isValidHexAddress(value, {
mixedCaseUseChecksum: true,
}) ? (
<Typography
variant={TYPOGRAPHY.H7}
color={COLORS.INFO_DEFAULT}
className="signature-request-data__node__value__address"
>
<Address
addressOnly
checksummedRecipientAddress={toChecksumHexAddress(value)}
recipientName={getAccountName(identities, value)}
/>
</Typography>
) : (
`${value}`
)}
</Typography>
)}
</Box>
))}
</Box>
);
}

SignatureRequestData.propTypes = {
data: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './signature-request-message.component';
export { default } from './signature-request-message';
Original file line number Diff line number Diff line change
@@ -1,75 +1,24 @@
.signature-request-message {
flex: 1 60%;
display: flex;
max-height: 231px;
flex-direction: column;
position: relative;

&__title {
@include H6;

font-weight: 500;
color: var(--color-text-alternative);
margin-left: 12px;
}

h2 {
@include H6;

flex: 1 1 0;
text-align: left;
border-bottom: 1px solid var(--color-border-default);
padding: 0.5rem;
margin: 0;
color: var(--color-text-alternative);
}

&--root {
&__root {
flex: 1 100%;
background-color: var(--color-background-alternative);
padding-bottom: 0.5rem;
overflow: auto;
padding-left: 12px;
padding-right: 12px;

@include screen-sm-min {
width: auto;
}
}

&--node,
&--node-leaf {
padding-left: 0.3rem;

&-label {
color: var(--color-text-alternative);
margin-left: 0.5rem;
}

&-value {
color: var(--color-text-default);
margin-left: 0.5rem;
white-space: pre-line;
overflow: hidden;
word-wrap: break-word;
}
}

&--node-leaf {
display: flex;
}

&__scroll-button {
display: flex;
align-items: center;
justify-content: center;
border: 1px solid var(--color-border-default);
background: var(--color-background-alternative);
color: var(--color-icon-default);
position: absolute;
right: 24px;
right: 28px;
bottom: 12px;
border-radius: 50%;
height: 24px;
width: 24px;
cursor: pointer;
}
}

This file was deleted.

Loading

0 comments on commit 42be5a0

Please sign in to comment.