1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 10:30:04 +01:00
metamask-extension/ui/components/app/signature-request/signature-request-message/signature-request-message.js
Ujwal Kumar 04839a250d
Issue 17670 replace typography with text (#19433)
* Replace Typograph with Text component in numeric-input-component.js

* Replace Typography with Text component in signature-request-message.js

* Replace Typography with Text component in signature-request.component.js

* Replacing deprecating constants and fixing some signature story warnings

* Updating snapshot

* Fixing import

---------

Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
Co-authored-by: Garrett Bear <gwhisten@gmail.com>
2023-06-26 15:50:08 -07:00

103 lines
2.9 KiB
JavaScript

import React, { useContext, useState } from 'react';
import PropTypes from 'prop-types';
import { debounce } from 'lodash';
import { I18nContext } from '../../../../contexts/i18n';
import Box from '../../../ui/box';
import { Text } from '../../../component-library';
import {
Display,
FlexDirection,
AlignItems,
JustifyContent,
Color,
BackgroundColor,
BorderColor,
BorderRadius,
TextColor,
FontWeight,
} from '../../../../helpers/constants/design-system';
import SignatureRequestData from '../signature-request-data';
export default function SignatureRequestMessage({
data,
onMessageScrolled,
setMessageRootRef,
messageRootRef,
messageIsScrollable,
primaryType,
}) {
const t = useContext(I18nContext);
const [messageIsScrolled, setMessageIsScrolled] = useState(false);
const setMessageIsScrolledAtBottom = () => {
if (!messageRootRef || messageIsScrolled) {
return;
}
const { scrollTop, offsetHeight, scrollHeight } = messageRootRef;
const isAtBottom = Math.round(scrollTop) + offsetHeight >= scrollHeight;
if (isAtBottom) {
setMessageIsScrolled(true);
onMessageScrolled();
}
};
return (
<Box
display={Display.Flex}
flexDirection={FlexDirection.Column}
onScroll={debounce(setMessageIsScrolledAtBottom, 25)}
className="signature-request-message"
>
{messageIsScrollable ? (
<Box
display={Display.Flex}
alignItems={AlignItems.center}
justifyContent={JustifyContent.center}
borderColor={BorderColor.borderDefault}
backgroundColor={BackgroundColor.backgroundDefault}
color={Color.iconDefault}
onClick={() => {
setMessageIsScrolled(true);
onMessageScrolled();
messageRootRef?.scrollTo(0, messageRootRef?.scrollHeight);
}}
className="signature-request-message__scroll-button"
data-testid="signature-request-scroll-button"
>
<i className="fa fa-arrow-down" aria-label={t('scrollDown')} />
</Box>
) : null}
<Box
backgroundColor={BackgroundColor.backgroundDefault}
paddingBottom={3}
paddingTop={3}
paddingRight={3}
margin={2}
borderRadius={BorderRadius.XL}
borderColor={BorderColor.borderMuted}
className="signature-request-message__root"
ref={setMessageRootRef}
>
<Text
fontWeight={FontWeight.Bold}
color={TextColor.textDefault}
marginLeft={4}
>
{primaryType}
</Text>
<SignatureRequestData data={data.value} />
</Box>
</Box>
);
}
SignatureRequestMessage.propTypes = {
data: PropTypes.object.isRequired,
onMessageScrolled: PropTypes.func,
setMessageRootRef: PropTypes.func,
messageRootRef: PropTypes.object,
messageIsScrollable: PropTypes.bool,
primaryType: PropTypes.string,
};