import { HexString } from '@gear-js/api'; import { useAlert } from '@gear-js/react-hooks'; import { Input, Textarea, InputWrapper, Button } from '@gear-js/ui'; import { useMemo } from 'react'; import { Link, generatePath, useParams } from 'react-router-dom'; import cx from 'clsx'; import { getDecodedMessagePayload, isMessageWithError, useMessageFromProgram, useMessageToProgram, } from '@/features/message'; import { useProgram } from '@/features/program'; import { useMetadata } from '@/features/metadata'; import { useSails } from '@/features/sails'; import { absoluteRoutes, routes } from '@/shared/config'; import { copyToClipboard, formatDate, getPreformattedText, getShortName } from '@/shared/helpers'; import TimestampSVG from '@/shared/assets/images/indicators/time.svg?react'; import CopySVG from '@/shared/assets/images/actions/copy.svg?react'; import styles from './message.module.scss'; type Params = { messageId: HexString; }; const Message = () => { const { messageId } = useParams() as Params; const alert = useAlert(); const messageToProgram = useMessageToProgram(messageId); const messageFromProgram = useMessageFromProgram(messageId); const message = messageToProgram.data || messageFromProgram.data; const isLoading = messageToProgram.isLoading || messageFromProgram.isLoading; const { timestamp, id, source, value, destination, replyToMessageId, blockHash, service, fn } = message || {}; const { data: program } = useProgram(messageToProgram.data ? destination : source); const { metadata, isMetadataReady } = useMetadata(program?.metahash); const { sails, isLoading: isSailsLoading } = useSails(program?.codeId); const isPayloadLoading = !isMetadataReady || isSailsLoading; const decodedPayload = useMemo( () => message && !isPayloadLoading ? // eslint-disable-next-line @typescript-eslint/unbound-method getDecodedMessagePayload(message, Boolean(messageToProgram.data), metadata, sails, alert.error) : undefined, // eslint-disable-next-line react-hooks/exhaustive-deps [message, metadata, sails, isPayloadLoading], ); const inputClassName = cx(isLoading && styles.loading); const payloadClassName = cx(isPayloadLoading && styles.loading); return (

{getShortName(messageId)}

{timestamp && (
Timestamp: {formatDate(timestamp)}
)}
{service && } {fn && }