Skip to content

Commit 5382897

Browse files
matusbalascaktomasklim
authored andcommitted
chore(suite): show all accounts in global send modal
1 parent da67bbe commit 5382897

File tree

7 files changed

+48
-55
lines changed

7 files changed

+48
-55
lines changed

packages/suite/src/components/suite/asset-picker/components/AssetsListEmpty/AssetsListEmpty.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
33
import { TranslationKey } from '@suite-common/intl-types';
44
import { getNetworkSymbolForProtocol } from '@suite-common/suite-utils';
55
import { getNetworkDisplaySymbolName } from '@suite-common/wallet-config';
6-
import { selectSelectedDevice } from '@suite-common/wallet-core';
6+
import { selectHasRunningDiscovery, selectSelectedDevice } from '@suite-common/wallet-core';
77
import { Button, Column, Paragraph, Text } from '@trezor/components';
88
import { spacings } from '@trezor/theme';
99

@@ -29,6 +29,7 @@ export const AssetsListEmpty = ({
2929
const dispatch = useDispatch();
3030
const protocolScheme = useSelector(state => state.protocol.sendForm.scheme);
3131
const device = useSelector(selectSelectedDevice);
32+
const isDiscoveryRunning = useSelector(selectHasRunningDiscovery);
3233

3334
const protocolSymbol = protocolScheme ? getNetworkSymbolForProtocol(protocolScheme) : undefined;
3435
const network = protocolSymbol ? getNetworkDisplaySymbolName(protocolSymbol) : undefined;
@@ -74,7 +75,9 @@ export const AssetsListEmpty = ({
7475
<Button
7576
onClick={openActivateNetworkModal}
7677
margin={{ top: spacings.md }}
78+
isLoading={isDiscoveryRunning}
7779
intent="neutral"
80+
priority="secondary"
7881
>
7982
<Translation id="TR_ACCOUNT_SEARCH_ACTIVATE_NETWORK_CTA" values={{ network }} />
8083
</Button>

packages/suite/src/components/suite/layouts/SuiteLayout/PageHeader/GlobalSendReceive/GlobalSendModal/hooks/useAccountWithTokensOptions.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from 'react';
22
import { useThrottle } from 'react-use';
33

4-
import { TokenDefinitionsState, selectTokenDefinitions } from '@suite-common/token-definitions';
4+
import { selectTokenDefinitions } from '@suite-common/token-definitions';
55
import { NetworkSymbol } from '@suite-common/wallet-config';
66
import {
77
selectAllAccountsToList,
@@ -14,7 +14,6 @@ import {
1414
findAccountsByNetwork,
1515
} from '@suite-common/wallet-utils';
1616
import { useCurrentRef } from '@trezor/react-utils';
17-
import { BigNumber } from '@trezor/utils';
1817

1918
import {
2019
ASSET_ROW_ACCOUNT_HEIGHT,
@@ -26,7 +25,6 @@ import {
2625
TokensWithRates,
2726
enhanceTokensWithRates,
2827
getTokens,
29-
hasVisibleTokens,
3028
sortTokensWithRates,
3129
} from 'src/utils/wallet/tokenUtils';
3230

@@ -50,17 +48,6 @@ function filterAccountsByNetworkSymbol(
5048
return networkSymbol ? findAccountsByNetwork(networkSymbol, accounts) : accounts;
5149
}
5250

53-
function getAccountsWithPositiveBalanceOrVisibleTokens(
54-
accounts: Account[],
55-
tokenDefinitions: TokenDefinitionsState,
56-
): Account[] {
57-
return accounts.filter(
58-
account =>
59-
new BigNumber(account.availableBalance).gt(0) ||
60-
hasVisibleTokens(account.symbol, account.tokens, tokenDefinitions),
61-
);
62-
}
63-
6451
export function useAccountWithTokensOptions(): AccountWithTokensOption[] {
6552
const networkSymbol = useSelector(globalSendReceiveFilters.selectors.selectNetworkSymbol);
6653
const accounts = useSelector(selectAllAccountsToList);
@@ -81,12 +68,7 @@ export function useAccountWithTokensOptions(): AccountWithTokensOption[] {
8168

8269
const networkAccounts = filterAccountsByNetworkSymbol(throttledAccounts, networkSymbol);
8370

84-
const accountsWithPositiveBalanceOrTokens = getAccountsWithPositiveBalanceOrVisibleTokens(
85-
networkAccounts,
86-
tokenDefinitions,
87-
);
88-
89-
const accountsAndTokensSortedByFiatBalance = accountsWithPositiveBalanceOrTokens
71+
const accountsAndTokensSortedByFiatBalance = networkAccounts
9072
.toSorted(function sortByFiatBalanceInDescOrder(accountA, accountB) {
9173
return accountsFiatBalanceInDescOrderComparator({
9274
accountA,

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getNetworkDisplaySymbolName,
99
} from '@suite-common/wallet-config';
1010
import { selectDeviceAccountsByNetworkSymbol } from '@suite-common/wallet-core';
11+
import { isBech32AddressUppercase } from '@suite-common/wallet-utils';
1112
import { Text } from '@trezor/components';
1213
import { CoinLogo } from '@trezor/product-components';
1314
import { BigNumber } from '@trezor/utils';
@@ -87,6 +88,14 @@ export const CoinProtocolRenderer = ({
8788
onCancel(false);
8889
};
8990

91+
const renderAddress = () => {
92+
if (networkSymbol === 'btc' && isBech32AddressUppercase(notification.address)) {
93+
return notification.address.toLowerCase();
94+
}
95+
96+
return notification.address;
97+
};
98+
9099
return (
91100
<ConditionalActionRenderer
92101
render={render}
@@ -100,7 +109,7 @@ export const CoinProtocolRenderer = ({
100109
body={
101110
<>
102111
<Row>
103-
<Text typographyStyle="hint">{notification.address}</Text>
112+
<Text typographyStyle="hint">{renderAddress()}</Text>
104113
</Row>
105114
{notification.amount && (
106115
<>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const ConditionalActionRenderer = ({
2929
}: ConditionalActionRendererProps) => {
3030
const actions: NotificationAction[] = [
3131
{ onClick: onAction, label: actionLabel, position: 'bottom', variant: 'primary' },
32-
{ onClick: onCancel, label: 'TR_CANCEL', position: 'bottom' },
32+
{ onClick: onCancel, label: 'TR_CANCEL', position: 'bottom', priority: 'secondary' },
3333
];
3434

3535
return (

packages/suite/src/components/suite/notifications/Notifications/NotificationGroup/NotificationList/NotificationView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { JSX } from 'react';
33
import { ExtendedMessageDescriptor } from '@suite-common/intl-types';
44
import type { NotificationEntry } from '@suite-common/toast-notifications';
55
import { Button, ButtonProps, Column, Icon, IconName, Paragraph, Row } from '@trezor/components';
6+
import { ButtonPriority } from '@trezor/components/src/components/buttons/types';
67
import { spacings } from '@trezor/theme';
78

89
import { FormattedDateWithBullet } from 'src/components/suite';
@@ -18,6 +19,7 @@ export interface NotificationAction {
1819
label: ExtendedMessageDescriptor['id'];
1920
position?: 'bottom' | 'right';
2021
variant?: NotificationActionVariant;
22+
priority?: ButtonPriority;
2123
}
2224

2325
export interface NotificationViewProps {
@@ -84,6 +86,7 @@ export const NotificationView = ({
8486
) : (
8587
<Button
8688
intent={mapActionVariantToIntent(action.variant)}
89+
priority={action.priority}
8790
size="small"
8891
onClick={action.onClick}
8992
minWidth={80}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const ToastNotification = ({
7575
<Button
7676
key={a.label}
7777
intent={mapActionVariantToIntent(a.variant)}
78+
priority={a.priority}
7879
onClick={a.onClick}
7980
size="small"
8081
margin={

packages/suite/src/hooks/wallet/useSendForm.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export const useSendForm = (props: UseSendFormProps): SendContextValues => {
298298
protocol.sendForm.scheme &&
299299
selectedAccount.network.symbol === getNetworkSymbolForProtocol(protocol.sendForm.scheme)
300300
) {
301+
reset(getLoadedValues());
301302
// for now we always fill only first output
302303
const outputIndex = 0;
303304

@@ -313,8 +314,13 @@ export const useSendForm = (props: UseSendFormProps): SendContextValues => {
313314

314315
if (protocol.sendForm.address) {
315316
setValue(`outputs.${outputIndex}.address`, protocol.sendForm.address, {
316-
shouldValidate: true,
317+
shouldDirty: true,
317318
});
319+
320+
// Defer validation until after Address component renders and registers validators
321+
setTimeout(() => {
322+
trigger(`outputs.${outputIndex}.address`);
323+
}, 0);
318324
}
319325

320326
dispatch(fillSendForm(false));
@@ -330,46 +336,35 @@ export const useSendForm = (props: UseSendFormProps): SendContextValues => {
330336
composeRequest,
331337
shouldSendInSats,
332338
state.network.decimals,
339+
reset,
340+
getLoadedValues,
341+
trigger,
333342
]);
334343

335344
// load draft from reducer and reset current form values, this should be only called once on mount
336345
useEffect(() => {
337346
const loadDraftValues = async () => {
338-
// Check if we should fill from protocol data instead of draft
339-
const shouldFillFromProtocol =
340-
protocol.sendForm.shouldFill &&
341-
protocol.sendForm.scheme &&
342-
protocol.sendForm.address &&
343-
selectedAccount.network.symbol ===
344-
getNetworkSymbolForProtocol(protocol.sendForm.scheme);
345-
346-
if (shouldFillFromProtocol) {
347-
const values = getLoadedValues();
348-
values.outputs[0].address = protocol.sendForm.address!;
349-
350-
if (protocol.sendForm.amount) {
351-
const amount = protocol.sendForm.amount.toString();
352-
values.outputs[0].amount = shouldSendInSats
353-
? convertAmountUnitsToSubunits(amount, state.network.decimals)
354-
: amount;
355-
}
356-
357-
reset(values);
358-
dispatch(fillSendForm(false));
359-
composeRequest();
360-
} else {
361-
const storedState = await dispatch(getSendFormDraftThunk()).unwrap();
362-
const values = getLoadedValues(storedState);
347+
const storedState = await dispatch(getSendFormDraftThunk()).unwrap();
348+
const values = getLoadedValues(storedState);
363349

364-
reset(values, { keepDefaultValues: !!storedState });
350+
reset(values, { keepDefaultValues: !!storedState });
365351

366-
if (storedState) {
367-
draft.current = storedState;
368-
composeDraft(storedState);
369-
}
352+
if (storedState) {
353+
draft.current = storedState;
354+
composeDraft(storedState);
370355
}
371356
};
372-
loadDraftValues();
357+
const shouldFillFromProtocol =
358+
protocol.sendForm.shouldFill &&
359+
protocol.sendForm.scheme &&
360+
protocol.sendForm.address &&
361+
selectedAccount.network.symbol ===
362+
getNetworkSymbolForProtocol(protocol.sendForm.scheme);
363+
364+
if (!shouldFillFromProtocol) {
365+
loadDraftValues();
366+
}
367+
373368
// composeDraft is excluded because its reference changes with each feeInfo update.
374369
// eslint-disable-next-line react-hooks/exhaustive-deps
375370
}, [dispatch, getLoadedValues, reset]);

0 commit comments

Comments
 (0)