Skip to content

Commit

Permalink
feat: UI facelift of the Affected transactions in the RBF flow
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-sanderson committed Jan 27, 2025
1 parent 5b36afc commit a7ffca5
Show file tree
Hide file tree
Showing 24 changed files with 419 additions and 428 deletions.
18 changes: 11 additions & 7 deletions packages/components/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled, { css } from 'styled-components';

import { borders, Elevation, spacingsPx } from '@trezor/theme';

import { ElevationUp, useElevation } from '../ElevationContext/ElevationContext';
import { ElevationContext, ElevationUp, useElevation } from '../ElevationContext/ElevationContext';
import {
FrameProps,
FramePropsKeys,
Expand Down Expand Up @@ -38,7 +38,7 @@ const Container = styled.div<{ $fillType: FillType } & TransientProps<AllowedFra
width: 100%;
border-radius: ${borders.radii.md};
background: ${({ theme, $fillType }) =>
$fillType !== 'none' && theme.backgroundTertiaryDefaultOnElevation0};
$fillType !== 'flat' && theme.backgroundTertiaryDefaultOnElevation0};
padding: ${spacingsPx.xxxs};
${withFrameProps}
Expand All @@ -65,11 +65,11 @@ const CardContainer = styled.div<
position: relative;
padding: ${mapPaddingTypeToPadding};
border-radius: ${borders.radii.md};
transition:
background 0.3s,
box-shadow 0.2s,
border-color 0.2s;
cursor: ${({ $isClickable }) => ($isClickable ? 'pointer' : 'default')};
transition:
background 0.5s,
border 0.5s,
box-shadow 0.5s;
${({ theme, $variant, $paddingType }) =>
$variant &&
Expand Down Expand Up @@ -145,7 +145,11 @@ const CardComponent = forwardRef<HTMLDivElement, CardPropsWithTransientProps>(
{...rest}
data-testid={dataTest}
>
{fillType === 'none' ? children : <ElevationUp>{children}</ElevationUp>}
{fillType === 'flat' ? (
<ElevationContext baseElevation={-1}>{children}</ElevationContext>
) : (
<ElevationUp>{children}</ElevationUp>
)}
</CardContainer>
);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/Card/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UIVariant } from '../../config/types';
export const paddingTypes = ['small', 'none', 'normal', 'large'] as const;
export type PaddingType = (typeof paddingTypes)[number];

export const fillTypes = ['none', 'default'] as const;
export const fillTypes = ['flat', 'default'] as const;
export type FillType = (typeof fillTypes)[number];

export const cardVariants = ['primary', 'warning'] as const;
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/components/Card/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
spacingsPx,
Elevation,
mapElevationToBackground,
mapElevationToBorder,
SpacingPxValues,
CSSColor,
} from '@trezor/theme';
Expand Down Expand Up @@ -61,6 +60,7 @@ export const mapFillTypeToCSS = ({
default: css`
background: ${mapElevationToBackground({ $elevation, theme })};
box-shadow: ${$elevation === 1 && !$hasLabel && theme.boxShadowBase};
border: 1px solid transparent;
${$isClickable &&
css`
Expand All @@ -69,8 +69,9 @@ export const mapFillTypeToCSS = ({
}
`}
`,
none: css`
border: 1px solid ${mapElevationToBorder({ $elevation, theme })};
flat: css`
background: ${theme.backgroundSurfaceElevationNegative};
border: 1px solid ${theme.borderElevation0};
`,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import styled from 'styled-components';

// Todo: replace once Adams PR is merged (here https://github.com/trezor/trezor-suite/pull/16465 but shall be separated ane generalized first)
const AddressWrapper = styled.p`
text-wrap: balance;
font-variant-numeric: tabular-nums;
letter-spacing: 0;
`;

// Todo: replace once Adams PR is merged (here https://github.com/trezor/trezor-suite/pull/16465 but shall be separated ane generalized first)
const addSpacing = (value: string) => value.match(/.{1,4}/g)?.join(' ') || value;

// Todo: replace once Adams PR is merged (here https://github.com/trezor/trezor-suite/pull/16465 but shall be separated ane generalized first)
export type AddressProps = {
value: string;
isTruncated?: boolean;
};

// Todo: replace once Adams PR is merged (here https://github.com/trezor/trezor-suite/pull/16465 but shall be separated ane generalized first)
export const AddressReplaceMeAfterAdamsMerge = ({ value, isTruncated }: AddressProps) => {
const formattedValue = isTruncated
? `${addSpacing(value.slice(0, 8))} ... ${addSpacing(value.slice(-8))}`
: addSpacing(value);

const handleCopy = (e: React.ClipboardEvent) => {
const selection = window.getSelection()?.toString();

e.preventDefault();
e.clipboardData?.setData('text/plain', selection?.replace(/\s/g, '') ?? value);
};

return <AddressWrapper onCopy={handleCopy}>{formattedValue}</AddressWrapper>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useTheme } from 'styled-components';

import { Icon, InfoSegments, Row, Text } from '@trezor/components';
import { WalletAccountTransaction } from '@suite-common/wallet-types';
import { Transaction } from '@trezor/blockchain-link-types';
import { spacings } from '@trezor/theme';

import { FormattedDate, HiddenPlaceholder } from 'src/components/suite';

import { AddressReplaceMeAfterAdamsMerge } from './AddressReplaceMeAfterAdamsMerge';

type RowIcon = {
txType: Transaction['type'];
isAccountOwned: boolean | undefined;
};

const RowIcon = ({ txType, isAccountOwned }: RowIcon) => {
const theme = useTheme();

const iconType = txType === 'recv' ? 'receive' : 'send';

return (
<Icon
size={16}
color={theme.legacy.TYPE_LIGHT_GREY}
name={isAccountOwned ? iconType : 'clock'}
/>
);
};

type AffectedTransactionItemProps = {
tx: WalletAccountTransaction;
isAccountOwned?: boolean;
};

export const AffectedTransactionItem = ({ tx, isAccountOwned }: AffectedTransactionItemProps) => (
<Row gap={spacings.sm}>
<RowIcon isAccountOwned={isAccountOwned} txType={tx.type} />

<InfoSegments>
{tx.blockTime && <FormattedDate value={new Date(tx.blockTime * 1000)} date time />}

<Text typographyStyle="hint" variant="tertiary">
<HiddenPlaceholder>
<AddressReplaceMeAfterAdamsMerge value={tx.txid} isTruncated />
</HiddenPlaceholder>
</Text>
</InfoSegments>
</Row>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Banner, Card, Column, Divider, Link, Row, Table, Text } from '@trezor/components';
import { spacings } from '@trezor/theme';
import { ChainedTransactions } from '@suite-common/wallet-types';

import { Translation } from 'src/components/suite';

import { AffectedTransactionItem } from './AffectedTransactionItem';

type AffectedTransactionsProps = {
chainedTxs?: ChainedTransactions;
showChained: () => void;
};

export const AffectedTransactions = ({ chainedTxs, showChained }: AffectedTransactionsProps) => {
if (chainedTxs === undefined) {
return null;
}

return (
<Card fillType="flat" paddingType="none">
<Row justifyContent="space-between" alignItems="center" padding={spacings.md}>
<Text typographyStyle="body">
<Translation id="TR_CHAINED_TXS" />
</Text>
<Text variant="primary" typographyStyle="hint">
<Link onClick={showChained} icon="arrowUpRight" variant="nostyle">
<Translation id="TR_SEE_DETAILS" />
</Link>
</Text>
</Row>
<Divider margin={spacings.zero} />
<Column margin={spacings.md}>
<Banner variant="warning" margin={{ bottom: spacings.md }}>
<Translation id="TR_AFFECTED_TXS" />
</Banner>
<Table>
{chainedTxs.own.map(tx => (
<Table.Row key={tx.txid}>
<Table.Cell>
<AffectedTransactionItem tx={tx} isAccountOwned />
</Table.Cell>
</Table.Row>
))}
{chainedTxs.others.map(tx => (
<Table.Row key={tx.txid}>
<Table.Cell>
<AffectedTransactionItem tx={tx} />
</Table.Cell>
</Table.Row>
))}
</Table>
</Column>
</Card>
);
};
Loading

0 comments on commit a7ffca5

Please sign in to comment.