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 ( {messageIsScrollable ? ( { setMessageIsScrolled(true); onMessageScrolled(); messageRootRef?.scrollTo(0, messageRootRef?.scrollHeight); }} className="signature-request-message__scroll-button" data-testid="signature-request-scroll-button" > ) : null} {primaryType} ); } SignatureRequestMessage.propTypes = { data: PropTypes.object.isRequired, onMessageScrolled: PropTypes.func, setMessageRootRef: PropTypes.func, messageRootRef: PropTypes.object, messageIsScrollable: PropTypes.bool, primaryType: PropTypes.string, };