Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(suite): add message system debug info #16093

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useState } from 'react';

import { Box, Button, ButtonGroup, Column, NewModal, Paragraph, Row } from '@trezor/components';
import { selectAllValidMessages, selectMessageSystemConfig } from '@suite-common/message-system';
import { copyToClipboard } from '@trezor/dom-utils';
import { Message } from '@suite-common/suite-types';
import { spacings } from '@trezor/theme';

import { useSelector } from 'src/hooks/suite';

const serializeCategory = (category: Message['category']): string =>
typeof category === 'string' ? category : category.join(', ');

export const MessageSystemDebugInfo = () => {
const config = useSelector(selectMessageSystemConfig);
const allValidMessages = useSelector(selectAllValidMessages);

const [isModalOpen, setIsModalOpen] = useState(false);

const handleCopyConfig = () => {
if (config === null) return;
copyToClipboard(JSON.stringify(config));
};
const handleOpenValidMessages = () => setIsModalOpen(true);
const handleCLoseValidMessages = () => setIsModalOpen(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const handleCLoseValidMessages = () => setIsModalOpen(false);
const handleCloseValidMessages = () => setIsModalOpen(false);


return (
<>
<Row justifyContent="space-between">
<Box>
<Paragraph>Sequence: {config?.sequence}</Paragraph>
<Paragraph>Timestamp: {config?.timestamp}</Paragraph>
</Box>
<ButtonGroup size="small">
<Button onClick={handleCopyConfig}>Copy full config</Button>
<Button
onClick={handleOpenValidMessages}
isDisabled={allValidMessages.length === 0}
>
See active messages
</Button>
</ButtonGroup>
</Row>
{isModalOpen && (
<NewModal onCancel={handleCLoseValidMessages}>
<Column gap={spacings.sm}>
{allValidMessages.map(m => (
<div key={m.id}>
<Paragraph typographyStyle="highlight">
{m.id} ({serializeCategory(m.category)})
</Paragraph>
<Paragraph>{m.content.en}</Paragraph>
</div>
))}
</Column>
</NewModal>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TriggerHighlight } from './TriggerHighlight';
import { Backends } from './Backends';
import { PreField } from './PreField';
import { Tor } from './Tor';
import { MessageSystemDebugInfo } from './MessageSystemDebugInfo';

export const SettingsDebug = () => {
const flags = useSelector(selectSuiteFlags);
Expand Down Expand Up @@ -76,6 +77,9 @@ export const SettingsDebug = () => {
<SettingsSection title="Flags JSON">
<PreField>{JSON.stringify(flags)}</PreField>
</SettingsSection>
<SettingsSection title="Message system info">
<MessageSystemDebugInfo />
</SettingsSection>
</SettingsLayout>
);
};
Loading