Skip to content

Commit

Permalink
feat(suite): add message system debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemonexe committed Jan 6, 2025
1 parent 852b857 commit a16733f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
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);

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 @@ -22,6 +22,7 @@ import { Backends } from './Backends';
import { PreField } from './PreField';
import { Tor } from './Tor';
import { Metadata } from './Metadata';
import { MessageSystemDebugInfo } from './MessageSystemDebugInfo';

export const SettingsDebug = () => {
const flags = useSelector(selectSuiteFlags);
Expand Down Expand Up @@ -80,6 +81,9 @@ export const SettingsDebug = () => {
<SettingsSection title="Metadata">
<Metadata />
</SettingsSection>
<SettingsSection title="Message system info">
<MessageSystemDebugInfo />
</SettingsSection>
</SettingsLayout>
);
};

0 comments on commit a16733f

Please sign in to comment.