Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(suite-native): show spinner for pending transactions in lists #16105

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export const TransactionNotification = ({
transactionType={transactionType}
symbol={notification.symbol}
isAnimated={isIconAnimated}
iconColor={isIconAnimated ? 'iconAlertYellow' : 'iconSubdued'}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shenkys explicitly asked for the icon to use the default colour no matter what. I missed this in the initial commit.

/>
}
iconRight={<Icon name="caretCircleRight" />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import { Badge, Box, DiscreetTextTrigger, Text, VStack } from '@suite-native/atoms';
import { isPending } from '@suite-common/wallet-utils';
import { AccountKey } from '@suite-common/wallet-types';
import { isPending } from '@suite-common/wallet-utils';
import { Badge, Box, DiscreetTextTrigger, Text, VStack } from '@suite-native/atoms';
import {
CryptoAmountFormatter,
CryptoToFiatAmountFormatter,
SignValueFormatter,
TokenAmountFormatter,
TokenToFiatAmountFormatter,
SignValueFormatter,
} from '@suite-native/formatters';
import { Translation } from '@suite-native/intl';
import { TypedTokenTransfer, WalletAccountTransaction } from '@suite-native/tokens';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import { Translation } from '@suite-native/intl';

import { useTransactionFiatRate } from '../../hooks/useTransactionFiatRate';
import { TransactionIcon } from '../TransactionsList/TransactionIcon';
import { getTransactionValueSign } from '../../utils';
import { TransactionIcon } from '../TransactionsList/TransactionIcon';

type TransactionDetailHeaderProps = {
transaction: WalletAccountTransaction;
tokenTransfer?: TypedTokenTransfer;
accountKey: AccountKey;
};

const ICON_SIZE = 56;
const ICON_SPINNER_WIDTH = 3;

const failedTxStyle = prepareNativeStyle<{ isFailedTx: boolean }>((_, { isFailedTx }) => ({
extend: {
condition: isFailedTx,
Expand Down Expand Up @@ -65,11 +62,8 @@ export const TransactionDetailHeader = ({
<TransactionIcon
transactionType={txType}
isAnimated={isPendingTx}
containerSize={ICON_SIZE}
containerSize={56}
iconSize="extraLarge"
spinnerWidth={ICON_SPINNER_WIDTH}
iconColor="iconDefault"
spinnerColor="backgroundAlertYellowBold"
backgroundColor="backgroundSurfaceElevation1"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@ type TransactionIconProps = {
symbol?: NetworkSymbol;
contractAddress?: TokenAddress;
isAnimated?: boolean;
iconColor?: Color;
spinnerColor?: Color;
spinnerWidth?: number;
backgroundColor?: Color;
containerSize?: number;
iconSize?: IconSize;
};

const DEFAULT_CONTAINER_SIZE = 48;

const transactionIconMap: Record<TransactionType, IconName> = {
recv: 'arrowDown',
sent: 'arrowUp',
Expand All @@ -46,29 +41,25 @@ export const TransactionIcon = ({
contractAddress,
transactionType,
backgroundColor,
spinnerColor,
spinnerWidth,
containerSize = DEFAULT_CONTAINER_SIZE,
containerSize = 48,
iconSize = 'mediumLarge',
isAnimated = false,
iconColor = 'iconSubdued',
}: TransactionIconProps) => {
const { applyStyle } = useNativeStyles();

return (
<Box>
<RoundedIcon
name={transactionIconMap[transactionType]}
color={iconColor}
iconSize={iconSize}
backgroundColor={backgroundColor}
containerSize={containerSize}
/>
{isAnimated && (
<TransactionIconSpinner
size={containerSize}
color={spinnerColor ?? iconColor}
width={spinnerWidth}
color="backgroundAlertYellowBold"
width={3}
/>
)}
{symbol && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@ import { ENDLESS_ANIMATION_VALUE } from '@suite-native/atoms';
type TransactionIconSpinnerProps = {
size: number;
color: Color;
width?: number;
width: number;
};

const FULL_CIRCLE_TURN = 360;
const ROTATION_DURATION = 2500;
const DEFAULT_STROKE_WIDTH = 8;

const ContainerStyle = prepareNativeStyle(_ => ({
position: 'absolute',
}));

export const TransactionIconSpinner = ({
size,
color,
width = DEFAULT_STROKE_WIDTH,
}: TransactionIconSpinnerProps) => {
export const TransactionIconSpinner = ({ size, color, width }: TransactionIconSpinnerProps) => {
const { applyStyle, utils } = useNativeStyles();

const rotation = useSharedValue(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector } from 'react-redux';

import { useNavigation } from '@react-navigation/native';

import { isPending } from '@suite-common/wallet-utils';
import { AccountKey, TransactionType, WalletAccountTransaction } from '@suite-common/wallet-types';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import {
Expand All @@ -15,14 +16,12 @@ import { Badge, Box, DiscreetText, HStack, Text } from '@suite-native/atoms';
import { useFormatters } from '@suite-common/formatters';
import {
selectIsPhishingTransaction,
selectIsTransactionPending,
selectTransactionBlockTimeById,
selectTransactionByAccountKeyAndTxid,
TransactionsRootState,
} from '@suite-common/wallet-core';
import { NetworkSymbol } from '@suite-common/wallet-config';
import { TypedTokenTransfer } from '@suite-native/tokens';
import { Color } from '@trezor/theme';
import { Translation } from '@suite-native/intl';
import { TokenDefinitionsRootState } from '@suite-common/token-definitions';

Expand Down Expand Up @@ -129,16 +128,12 @@ export const TransactionListItemContainer = ({
selectTransactionBlockTimeById(state, accountKey, txid),
);

const isTransactionPending = useSelector((state: TransactionsRootState) =>
selectIsTransactionPending(state, txid, accountKey),
);

const isTransactionPending = isPending(transaction);
const isPhishingTransaction = useSelector(
(state: TokenDefinitionsRootState & TransactionsRootState) =>
selectIsPhishingTransaction(state, txid, accountKey),
);

const iconColor: Color = isTransactionPending ? 'backgroundAlertYellowBold' : 'iconSubdued';
const coinSymbol = isPhishingTransaction ? undefined : symbol;
const contractAddress = isPhishingTransaction ? undefined : tokenTransfer?.contract;

Expand All @@ -155,7 +150,6 @@ export const TransactionListItemContainer = ({
contractAddress={contractAddress}
transactionType={transactionType}
isAnimated={isTransactionPending}
iconColor={iconColor}
/>
<Box marginLeft="sp16" flex={1}>
<HStack flexDirection="row" alignItems="center" spacing="sp4">
Expand Down
Loading