Skip to content

Commit

Permalink
Sign-in With Ethereum SIWE cleanup (#18230)
Browse files Browse the repository at this point in the history
* signature-req: replace Typography w/ Text
- this does update styles slightly

* siwe: extract showSecurityProviderBanner

* siwe: rn -> hasAgreedToDomainWarning

* siwe: update snapshot for updated Text usage
  • Loading branch information
digiwand authored Apr 21, 2023
1 parent f833f0e commit 8bfcd5b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,100 +122,100 @@ exports[`SignatureRequestSIWE (Sign in with Ethereum) should match snapshot 1`]
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Message:
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Click to sign in and accept the Terms of Service: https://community.metamask.io/tos
</h6>
</p>
</div>
<div
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
URI:
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
http://localhost:8080
</h6>
</p>
</div>
<div
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Version:
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
1
</h6>
</p>
</div>
<div
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Chain ID:
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
1
</h6>
</p>
</div>
<div
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Nonce:
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
STMt6KQMwwdOXE306
</h6>
</p>
</div>
<div
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Issued At:
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
2023-03-18T21:40:40.823Z
</h6>
</p>
</div>
<div
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row"
>
<h4
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography typography--h4 typography--weight-normal typography--style-normal typography--color-text-default"
class="box mm-text mm-text--body-lg-medium box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
Resources: 2
</h4>
<h6
class="box box--margin-top-2 box--margin-bottom-2 box--flex-direction-row typography signature-request-siwe-message__sub-text typography--h6 typography--weight-normal typography--style-normal typography--color-text-default"
<p
class="box mm-text signature-request-siwe-message__sub-text mm-text--body-md mm-text--overflow-wrap-break-word box--margin-top-2 box--margin-bottom-2 box--flex-direction-row box--color-text-default"
>
ipfs://Qme7ss3ARVgxv6rXqVPiikMJ8u2NLgmgszg13pYrDKEoiu
https://example.com/my-web2-claim.json
</h6>
</p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
&__sub-text {
white-space: pre-line;
overflow: hidden;
word-wrap: break-word;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import Box from '../../../ui/box';
import Typography from '../../../ui/typography';
import { Text } from '../../../component-library';

import {
FLEX_DIRECTION,
TypographyVariant,
OVERFLOW_WRAP,
TextVariant,
} from '../../../../helpers/constants/design-system';

const SignatureRequestSIWEMessage = ({ data }) => {
Expand All @@ -14,21 +15,22 @@ const SignatureRequestSIWEMessage = ({ data }) => {
<Box flexDirection={FLEX_DIRECTION.COLUMN}>
{data.map(({ label, value }, i) => (
<Box key={i.toString()} marginTop={2} marginBottom={2}>
<Typography
variant={TypographyVariant.H4}
<Text
as="h4"
variant={TextVariant.bodyLgMedium}
marginTop={2}
marginBottom={2}
>
{label}
</Typography>
<Typography
</Text>
<Text
className="signature-request-siwe-message__sub-text"
variant={TypographyVariant.H6}
overflowWrap={OVERFLOW_WRAP.BREAK_WORD}
marginTop={2}
marginBottom={2}
>
{value}
</Typography>
</Text>
</Box>
))}
</Box>
Expand Down
26 changes: 16 additions & 10 deletions ui/components/app/signature-request-siwe/signature-request-siwe.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ export default function SignatureRequestSIWE({
const isSIWEDomainValid = checkSIWEDomain();

const [isShowingDomainWarning, setIsShowingDomainWarning] = useState(false);
const [agreeToDomainWarning, setAgreeToDomainWarning] = useState(false);
const [hasAgreedToDomainWarning, setHasAgreedToDomainWarning] =
useState(false);

const showSecurityProviderBanner =
(txData?.securityProviderResponse?.flagAsDangerous !== undefined &&
txData?.securityProviderResponse?.flagAsDangerous !==
SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_MALICIOUS) ||
(txData?.securityProviderResponse &&
Object.keys(txData.securityProviderResponse).length === 0);

const onSign = useCallback(
async (event) => {
Expand Down Expand Up @@ -96,15 +104,13 @@ export default function SignatureRequestSIWE({
isSIWEDomainValid={isSIWEDomainValid}
subjectMetadata={targetSubjectMetadata}
/>
{(txData?.securityProviderResponse?.flagAsDangerous !== undefined &&
txData?.securityProviderResponse?.flagAsDangerous !==
SECURITY_PROVIDER_MESSAGE_SEVERITIES.NOT_MALICIOUS) ||
(txData?.securityProviderResponse &&
Object.keys(txData.securityProviderResponse).length === 0) ? (

{showSecurityProviderBanner && (
<SecurityProviderBannerMessage
securityProviderResponse={txData.securityProviderResponse}
/>
) : null}
)}

<Message data={formatMessageParams(parsedMessage, t)} />
{!isMatchingAddress && (
<BannerAlert
Expand Down Expand Up @@ -165,16 +171,16 @@ export default function SignatureRequestSIWE({
onSubmit={onSign}
submitText={t('confirm')}
submitButtonType="danger-primary"
disabled={!agreeToDomainWarning}
disabled={!hasAgreedToDomainWarning}
/>
}
>
<div className="signature-request-siwe__warning-popover__checkbox-wrapper">
<Checkbox
id="signature-request-siwe_domain-checkbox"
checked={agreeToDomainWarning}
checked={hasAgreedToDomainWarning}
className="signature-request-siwe__warning-popover__checkbox-wrapper__checkbox"
onClick={() => setAgreeToDomainWarning((checked) => !checked)}
onClick={() => setHasAgreedToDomainWarning((checked) => !checked)}
/>
<label
className="signature-request-siwe__warning-popover__checkbox-wrapper__label"
Expand Down

0 comments on commit 8bfcd5b

Please sign in to comment.