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(mobile): Spread pure props in ActionListItem #601

Merged
merged 1 commit into from
Oct 12, 2023
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
8 changes: 8 additions & 0 deletions packages/@core-js/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ export function throttle<Args extends unknown[]>(

return throttled;
}

export function excludeUndefinedValues<T extends object>(obj: T): T {
return Object.keys(obj).reduce((acc, key) => {
const _acc = acc;
if (obj[key] !== undefined) _acc[key] = obj[key];
return _acc;
}, {} as T);
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const SignRawModal = memo<SignRawModalProps>((props) => {
}
}

return null;
return undefined;
};

return (
Expand All @@ -173,9 +173,9 @@ export const SignRawModal = memo<SignRawModalProps>((props) => {
<ActionListItemByType
value={formatValue(action)}
subvalue={amountToFiat(action)}
title={getActionTitle(action)}
disablePressable
action={action}
{...(getActionTitle(action) && { title: getActionTitle(action) })}
subtitle={
action.destination === 'in'
? t('confirmSendModal.to_your_address')
Expand Down
40 changes: 21 additions & 19 deletions packages/shared/components/ActivityList/ActionListItemByType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,36 @@ import { t } from '../../i18n';
import { memo } from 'react';

import { getImplementationIcon } from '@tonkeeper/mobile/src/utils/staking';
import { excludeUndefinedValues } from '@tonkeeper/core/src/utils/common';

export const ActionListItemByType = memo<ActionListItemProps>((props) => {
const { action } = props;
const { type, payload } = action;

const pureProps = excludeUndefinedValues(props);
switch (type) {
case ActionType.TonTransfer:
return (
<ActionListItem {...props}>
<ActionListItem {...pureProps}>
{!!payload.comment && <ListItemContentText text={payload.comment.trim()} />}
</ActionListItem>
);
case ActionType.JettonTransfer:
return (
<ActionListItem {...props}>
<ActionListItem {...pureProps}>
{!!payload.comment && <ListItemContentText text={payload.comment.trim()} />}
</ActionListItem>
);
case ActionType.NftItemTransfer:
return (
<ActionListItem {...props} value="NFT">
<ActionListItem {...pureProps} value="NFT">
<NftPreviewContent disabled={props.disablePressable} nftAddress={payload.nft} />
{!!payload.comment && <ListItemContentText text={payload.comment.trim()} />}
</ActionListItem>
);
case ActionType.NftPurchase:
return (
<ActionListItem {...props}>
<ActionListItem {...pureProps}>
<NftPreviewContent disabled={props.disablePressable} nftItem={payload.nft} />
</ActionListItem>
);
Expand All @@ -47,7 +49,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
subtitle={Address.parse(payload.contract.address).toShort()}
title={t('transactions.smartcontract_exec')}
iconName="ic-gear-28"
{...props}
{...pureProps}
/>
);
case ActionType.Unknown:
Expand All @@ -56,7 +58,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
title={t('transactions.unknown')}
subtitle={t('transactions.unknown_description')}
subtitleNumberOfLines={2}
{...props}
{...pureProps}
/>
);
case ActionType.AuctionBid:
Expand All @@ -65,7 +67,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
subtitle={modifyNftName(payload.nft?.metadata?.name)}
title={t('transactions.bid')}
iconName="ic-tray-arrow-up-28"
{...props}
{...pureProps}
/>
);
case ActionType.ContractDeploy:
Expand All @@ -74,7 +76,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
subtitle={Address.parse(payload.address).toShort()}
title={t('transactions.wallet_initialized')}
iconName="ic-donemark-28"
{...props}
{...pureProps}
/>
);
case ActionType.ReceiveTRC20:
Expand All @@ -84,7 +86,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
title={t('transaction_type_receive')}
iconName="ic-tray-arrow-down-28"
greenValue
{...props}
{...pureProps}
/>
);
case ActionType.SendTRC20:
Expand All @@ -93,7 +95,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
subtitle={Address.toShort(payload.recipient)}
title={t('transaction_type_sent')}
iconName="ic-tray-arrow-up-28"
{...props}
{...pureProps}
/>
);
case ActionType.JettonBurn:
Expand All @@ -102,15 +104,15 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
subtitle={payload.jetton.name}
title={t('transactions.burned')}
iconName="ic-fire-28"
{...props}
{...pureProps}
/>
);
case ActionType.JettonMint:
return (
<ActionListItem
subtitle={payload.jetton.name}
title={t('transaction_type_receive')}
{...props}
{...pureProps}
/>
);
case ActionType.DepositStake:
Expand All @@ -119,7 +121,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
pictureSource={getImplementationIcon(action.payload.implementation)}
title={t('transactions.deposit')}
subtitle={payload.pool.name}
{...props}
{...pureProps}
/>
);
case ActionType.WithdrawStake:
Expand All @@ -129,7 +131,7 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
title={t('transactions.withdraw')}
subtitle={payload.pool.name}
iconName="ic-donemark-28"
{...props}
{...pureProps}
/>
);
case ActionType.WithdrawStakeRequest:
Expand All @@ -139,17 +141,17 @@ export const ActionListItemByType = memo<ActionListItemProps>((props) => {
title={t('transactions.withdrawal_request')}
subtitle={payload.pool.name}
iconName="ic-donemark-28"
{...props}
{...pureProps}
/>
);
case ActionType.JettonSwap:
return <JettonSwapActionListItem {...props} action={action} />;
return <JettonSwapActionListItem {...pureProps} action={action} />;
case ActionType.Subscribe:
return <SubscribeActionListItem {...props} action={action} />;
return <SubscribeActionListItem {...pureProps} action={action} />;
case ActionType.UnSubscribe:
return <UnSubscribeActionListItem {...props} action={action} />;
return <UnSubscribeActionListItem {...pureProps} action={action} />;
default:
return <ActionListItem {...props} isSimplePreview />;
return <ActionListItem {...pureProps} isSimplePreview />;
}
});

Expand Down