Skip to content

Commit c85cc73

Browse files
refactor(receive): make address cards self-contained and use shared copy action
1 parent 15f89d8 commit c85cc73

28 files changed

Lines changed: 672 additions & 521 deletions

packages/suite/src/components/suite/notifications/NotificationRenderer/NotificationRenderer.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ import { AUTH_DEVICE, type NotificationEntry } from '@suite-common/toast-notific
1515
import { getTradingErrorDisplay } from '@suite-common/trading';
1616
import { getNetworkDisplaySymbol } from '@suite-common/wallet-config';
1717
import { DEVICE } from '@trezor/connect';
18-
import { ArrowDownIcon, ArrowUpIcon, CheckIcon, GearIcon, TorBrowserIcon } from '@trezor/icons';
18+
import {
19+
ArrowDownIcon,
20+
ArrowUpIcon,
21+
CheckIcon,
22+
CopyIcon,
23+
GearIcon,
24+
TorBrowserIcon,
25+
} from '@trezor/icons';
1926
import { exhaustive } from '@trezor/type-utils';
2027

2128
import { ActionRenderer } from './ActionRenderer';
@@ -161,8 +168,9 @@ export const NotificationRenderer = ({
161168

162169
case 'copy-to-clipboard':
163170
return renderNotificationView(render, notification, {
164-
variant: 'success',
171+
variant: 'transparent',
165172
message: 'TOAST_COPY_TO_CLIPBOARD',
173+
icon: CopyIcon,
166174
});
167175

168176
case 'raw-tx-sent':

suite-common/address/src/getFirstFreshAddress.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { type Account, type ReceiveInfo } from '@suite-common/wallet-types';
1+
import { type Account, type AccountAddress, type ReceiveInfo } from '@suite-common/wallet-types';
22
import { comparePath } from '@trezor/crypto-utils';
33

4-
type AccountAddress = NonNullable<Account['addresses']>['used'][number];
5-
64
const isPathLowerThanAnyUsedPath = (path: string, usedPaths: string[]) =>
75
usedPaths.some(usedPath => comparePath(path, usedPath) < 0);
86

suite-common/address/src/getReceiveAddressHistory.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { type Account, type ReceiveInfo } from '@suite-common/wallet-types';
1+
import { type Account, type AccountAddress, type ReceiveInfo } from '@suite-common/wallet-types';
22
import { comparePath } from '@trezor/crypto-utils';
33

44
import { getFirstFreshAddress, getFreshAddresses } from './getFirstFreshAddress';
55

6-
type AccountAddress = NonNullable<Account['addresses']>['used'][number];
7-
86
type CurrentFreshAddress = {
97
path: string;
108
address: string;

suite-common/wallet-types/src/account.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import type {
77
StakingPool,
88
TronAccountExtraData,
99
} from '@trezor/blockchain-link-types';
10-
import type { AccountInfo, PROTO, TokenInfo } from '@trezor/connect';
10+
import type { AccountAddress, AccountInfo, PROTO, TokenInfo } from '@trezor/connect';
1111
import type { Bip43Path } from '@trezor/crypto-utils';
1212
import type { StaticSessionId } from '@trezor/device-utils';
1313
import { type Branded } from '@trezor/type-utils';
1414

15+
export type { AccountAddress };
16+
1517
export type XpubAddress = string;
1618

1719
export type TokenSymbol = string & Branded<'TokenSymbol'>;

suite/intl/src/messages.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ export const messages = defineMessages({
19291929
id: 'TR_CONFIRM_ACTION_ON_YOUR',
19301930
},
19311931
TR_COMPARE_ADDRESS_ON_TREZOR: {
1932-
defaultMessage: 'Compare the pasted address against your Trezor',
1932+
defaultMessage: 'View the address on your Trezor',
19331933
id: 'TR_COMPARE_ADDRESS_ON_TREZOR',
19341934
},
19351935
TR_CONFIRM_EMPTY_HIDDEN_WALLET_ON: {
@@ -4976,6 +4976,10 @@ export const messages = defineMessages({
49764976
id: 'RECEIVE_ADDRESS_LIMIT_REACHED',
49774977
defaultMessage: "You've reached the maximum limit of 21 fresh, unused addresses",
49784978
},
4979+
RECEIVE_UNUSED_ADDRESS_LIMIT_REACHED: {
4980+
id: 'RECEIVE_UNUSED_ADDRESS_LIMIT_REACHED',
4981+
defaultMessage: 'You can generate only 20 unused addresses.',
4982+
},
49794983
RECEIVE_ADDRESS_UNAVAILABLE: {
49804984
id: 'RECEIVE_ADDRESS_UNAVAILABLE',
49814985
defaultMessage: 'Unavailable',

suite/labeling/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ export { Labeling, type LabelingProps } from './Labeling';
22
export { LabelingSettings, type LabelingSelectValue } from './LabelingSettings';
33
export { LabelingSwitchToLegacyModal } from './LabelingSwitchToLegacyModal';
44
export { processLegacyMetadataIntoSuiteSyncThunk } from './processLegacyMetadataIntoSuiteSyncThunk';
5-
export { selectIsLabelActionEnabled } from './selectIsLabelActionEnabled';
5+
export {
6+
type SelectIsLabelActionEnabledState,
7+
selectIsLabelActionEnabled,
8+
} from './selectIsLabelActionEnabled';

suite/labeling/src/selectIsLabelActionEnabled.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import {
1818
} from '@suite-common/suite-sync';
1919
import { type StaticSessionId } from '@trezor/connect';
2020

21+
export type SelectIsLabelActionEnabledState = WithSuiteSyncAndDeviceState &
22+
MetadataRootState &
23+
DesktopSuiteSyncRootState &
24+
MessageSystemRootState;
25+
2126
export const selectIsLabelActionEnabled = (
22-
state: WithSuiteSyncAndDeviceState &
23-
MetadataRootState &
24-
DesktopSuiteSyncRootState &
25-
MessageSystemRootState,
27+
state: SelectIsLabelActionEnabledState,
2628
deviceStaticSessionId: StaticSessionId,
2729
legacyEntityKey: string,
2830
): boolean => {

suite/receive/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@trezor/components": "workspace:*",
3232
"@trezor/crypto-utils": "workspace:*",
3333
"@trezor/device-utils": "workspace:*",
34-
"@trezor/dom-utils": "workspace:*",
3534
"@trezor/icons": "workspace:*",
3635
"@trezor/product-components": "workspace:*",
3736
"react": "19.2.3",

suite/receive/src/AddressCardDetail.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { useSelector } from 'react-redux';
1+
import { useDispatch, useSelector } from 'react-redux';
22

3+
import { copyAddressToClipboard } from '@suite/address';
34
import { Translation } from '@suite/intl';
45
import { type AccountsRootState, selectAccountByKey } from '@suite-common/wallet-core';
56
import { type AccountKey } from '@suite-common/wallet-types';
@@ -10,8 +11,8 @@ import { belowBreakpoint, breakpoints } from '@trezor/theme';
1011

1112
import { AddressLabeling } from './AddressLabeling';
1213
import { CoinQrCode } from './CoinQrCode';
13-
import { type ReceiveAddressItem } from './receiveTypes';
14-
import { canShareAddress, shareAddress } from './share';
14+
import { type ReceiveAddressItem } from './receive';
15+
import { canShareAddress, shareAddress } from './sharing/share';
1516

1617
const QR_SIZE = 148;
1718

@@ -21,7 +22,7 @@ type AddressCardDetailProps = {
2122
disabled: boolean;
2223
isVerifyLoading: boolean;
2324
isVerifyDisabled: boolean;
24-
onCopy: (path: string, address: string) => void;
25+
onCopied: (path: string) => void;
2526
onVerify: (path: string) => void;
2627
};
2728

@@ -31,14 +32,20 @@ export const AddressCardDetail = ({
3132
disabled,
3233
isVerifyLoading,
3334
isVerifyDisabled,
34-
onCopy,
35+
onCopied,
3536
onVerify,
3637
}: AddressCardDetailProps) => {
38+
const dispatch = useDispatch();
3739
const account = useSelector((state: AccountsRootState) =>
3840
selectAccountByKey(state, accountKey),
3941
);
4042
const isBelowTablet = useMediaQuery(belowBreakpoint(breakpoints.tablet));
4143

44+
const handleCopy = () => {
45+
dispatch(copyAddressToClipboard(item.address));
46+
onCopied(item.path);
47+
};
48+
4249
if (!account) {
4350
return null;
4451
}
@@ -81,11 +88,7 @@ export const AddressCardDetail = ({
8188
</Text>
8289
</Column>
8390
<Row gap={12} flexWrap="wrap">
84-
<Button
85-
size="large"
86-
iconLeft={CopyIcon}
87-
onClick={() => onCopy(item.path, item.address)}
88-
>
91+
<Button size="large" iconLeft={CopyIcon} onClick={handleCopy}>
8992
<Translation id="TR_COPY_TO_CLIPBOARD" />
9093
</Button>
9194
{canShareAddress() && (

suite/receive/src/AddressCopiedModal.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)