Skip to content

Commit

Permalink
fixup! feat(message-system): add context banner to solana staking tab
Browse files Browse the repository at this point in the history
  • Loading branch information
marekrjpolak committed Feb 28, 2025
1 parent c9a2cc5 commit 33686c6
Showing 1 changed file with 17 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useMemo } from 'react';

import { Context, selectContextMessageContent } from '@suite-common/message-system';
import { Banner, Row } from '@trezor/components';

Expand All @@ -19,44 +17,33 @@ export const ContextMessage = ({ context }: ContextMessageProps) => {
const torOnionLinks = useSelector(state => state.suite.settings.torOnionLinks);
const dispatch = useDispatch();

const actionConfig = useMemo(() => {
if (!message?.cta) return undefined;

const { action, link, anchor } = message.cta;
let onClick: () => Window | Promise<void> | null;
if (!message) return null;

if (action === 'internal-link') {
// @ts-expect-error: impossible to add all href options to the message system config json schema
onClick = () => dispatch(goto(link, { anchor, preserveParams: true }));
} else if (action === 'external-link') {
onClick = () =>
window.open(
isTorEnabled && torOnionLinks ? getTorUrlIfAvailable(link) : link,
'_blank',
);
} else {
return undefined;
const onCallToAction = ({ action, link, anchor }: NonNullable<(typeof message)['cta']>) => {
switch (action) {
case 'internal-link':
// @ts-expect-error: impossible to add all href options to the message system config json schema
return () => dispatch(goto(link, { anchor, preserveParams: true }));
case 'external-link':
return () =>
window.open(
isTorEnabled && torOnionLinks ? getTorUrlIfAvailable(link) : link,
'_blank',
);
}

return {
onClick,
'data-testid': `@context-message/${context}/cta`,
};
}, [message, dispatch, isTorEnabled, torOnionLinks, context]);

if (!message) return null;
};

return (
<Banner
variant={message.variant === 'critical' ? 'destructive' : message.variant}
rightContent={
<Row gap={8}>
{actionConfig && (
{message.cta && (
<Banner.Button
onClick={actionConfig.onClick}
data-testid={actionConfig['data-testid']}
onClick={onCallToAction(message.cta)}
data-testid={`@context-message/${context}/cta`}
>
{message.cta?.label}
{message.cta.label}
</Banner.Button>
)}
</Row>
Expand Down

0 comments on commit 33686c6

Please sign in to comment.