Skip to content

Commit

Permalink
feat(message-system): add context banner to solana staking tab
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroslavProchazka authored and tomasklim committed Mar 4, 2025
1 parent 3963fc6 commit d7b1bb0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Context } from '@suite-common/message-system';
import { isSupportedEthStakingNetworkSymbol } from '@suite-common/wallet-utils';
import {
isSupportedEthStakingNetworkSymbol,
isSupportedSolStakingNetworkSymbol,
} from '@suite-common/wallet-utils';
import { Column } from '@trezor/components';
import { spacings } from '@trezor/theme';

Expand Down Expand Up @@ -31,6 +34,9 @@ export const AccountBanners = ({ account }: AccountBannersProps) => {
{account?.symbol &&
isSupportedEthStakingNetworkSymbol(account.symbol) &&
route?.name === 'wallet-staking' && <ContextMessage context={Context.ethStaking} />}
{account?.symbol &&
isSupportedSolStakingNetworkSymbol(account.symbol) &&
route?.name === 'wallet-staking' && <ContextMessage context={Context.solStaking} />}
<AuthConfirmFailed />
<BackendDisconnected />
<DeviceUnavailable />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Context, selectContextMessageContent } from '@suite-common/message-system';
import { Banner } from '@trezor/components';
import { Banner, Row } from '@trezor/components';

import { useSelector } from 'src/hooks/suite';
import { selectLanguage } from 'src/reducers/suite/suiteReducer';
import { goto } from 'src/actions/suite/routerActions';
import { useDispatch, useSelector } from 'src/hooks/suite';
import { selectLanguage, selectTorState } from 'src/reducers/suite/suiteReducer';
import { getTorUrlIfAvailable } from 'src/utils/suite/tor';

type ContextMessageProps = {
context: (typeof Context)[keyof typeof Context];
Expand All @@ -11,17 +13,43 @@ type ContextMessageProps = {
export const ContextMessage = ({ context }: ContextMessageProps) => {
const language = useSelector(selectLanguage);
const message = useSelector(state => selectContextMessageContent(state, context, language));
const { isTorEnabled } = useSelector(selectTorState);
const torOnionLinks = useSelector(state => state.suite.settings.torOnionLinks);
const dispatch = useDispatch();

return message ? (
if (!message) return null;

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 (
<Banner
variant={message.variant === 'critical' ? 'destructive' : message.variant}
rightContent={
message.cta ? (
<Banner.Button href={message.cta.link}>{message.cta.label}</Banner.Button>
) : undefined
message.cta && (
<Row gap={8}>
<Banner.Button
onClick={onCallToAction(message.cta)}
data-testid={`@context-message/${context}/cta`}
>
{message.cta.label}
</Banner.Button>
</Row>
)
}
>
{message.content}
</Banner>
) : null;
);
};
1 change: 1 addition & 0 deletions suite-common/message-system/src/messageSystemTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type FeatureDomain = (typeof Feature)[keyof typeof Feature];
export const Context = {
coinjoin: 'accounts.coinjoin',
ethStaking: 'accounts.eth.staking',
solStaking: 'accounts.sol.staking',
} as const;

export type ContextDomain = (typeof Context)[keyof typeof Context];
Expand Down

0 comments on commit d7b1bb0

Please sign in to comment.