diff --git a/packages/suite/src/components/wallet/WalletLayout/AccountBanners/ContextMessage.tsx b/packages/suite/src/components/wallet/WalletLayout/AccountBanners/ContextMessage.tsx index 9751fe51fd1..16e7188e6bb 100644 --- a/packages/suite/src/components/wallet/WalletLayout/AccountBanners/ContextMessage.tsx +++ b/packages/suite/src/components/wallet/WalletLayout/AccountBanners/ContextMessage.tsx @@ -1,5 +1,3 @@ -import { useMemo } from 'react'; - import { Context, selectContextMessageContent } from '@suite-common/message-system'; import { Banner, Row } from '@trezor/components'; @@ -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 | 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 ( - {actionConfig && ( + {message.cta && ( - {message.cta?.label} + {message.cta.label} )}