Skip to content

Commit

Permalink
skipDataScamCheck if the the tx is a transfer and the sender == receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
radumojic committed Nov 14, 2024
1 parent ca4f4c6 commit 47efb49
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
14 changes: 11 additions & 3 deletions src/components/DataDecode/DataDecode.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import {
Dispatch,
ReactNode,
SetStateAction,
useEffect,
useState
} from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import BigNumber from 'bignumber.js';
import { Anchor, Dropdown } from 'react-bootstrap';
Expand Down Expand Up @@ -197,13 +203,15 @@ export const DataDecode = ({
className,
initialDecodeMethod,
setDecodeMethod,
identifier
identifier,
children
}: {
value: string;
className?: string;
initialDecodeMethod?: DecodeMethodEnum;
setDecodeMethod?: Dispatch<SetStateAction<DecodeMethodEnum>>;
identifier?: string;
children?: ReactNode;
}) => {
const defaultDecodeMethod =
initialDecodeMethod &&
Expand Down Expand Up @@ -253,7 +261,7 @@ export const DataDecode = ({
}`}
>
<div className={`form-control textarea ${className ? className : ''}`}>
{displayValue}
{children ? children : displayValue}
</div>
{value && value !== 'N/A' && (
<div className='d-flex button-holder'>
Expand Down
43 changes: 26 additions & 17 deletions src/pages/TransactionDetails/components/DataField/DataField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import {
useGetTransactionUrlHashParams
} from 'hooks';
import { transactionsRoutes } from 'routes';
import { ScamInfoType } from 'types';
import { ScamInfoType, WithClassnameType } from 'types';

export const DataField = ({
data,
scamInfo
}: {
export interface DataFieldUIType extends WithClassnameType {
data?: string;
scamInfo?: ScamInfoType;
}) => {
skipDataScamCheck?: boolean;
}

export const DataField = ({
data,
scamInfo,
skipDataScamCheck
}: DataFieldUIType) => {
const navigate = useNavigate();
const networkRoute = useNetworkRoute();
const activeRoute = useActiveRoute();
Expand Down Expand Up @@ -59,26 +63,31 @@ export const DataField = ({
}
}, [decodeMethod, pathname]);

const showRawLinks =
decodeMethod === DecodeMethodEnum.raw && (showData || skipDataScamCheck);
const value = truncate(
skipDataScamCheck ? dataString : output,
MAX_DISPLAY_TX_DATA_LENGTH
);

return (
<DetailItem title='Input Data' className='data-field'>
{showData ? (
<div className='textarea form-control col cursor-text mt-1'>
<DataDecode
value={value}
initialDecodeMethod={!id ? dataDecode : DecodeMethodEnum.raw}
setDecodeMethod={setDecodeMethod}
>
{showRawLinks && (
<Anchorme
linkComponent={ModalLink}
target='_blank'
rel='noreferrer nofollow noopener'
>
{stringWithLinks}
</Anchorme>
</div>
) : (
<DataDecode
value={truncate(output, MAX_DISPLAY_TX_DATA_LENGTH)}
initialDecodeMethod={!id ? dataDecode : DecodeMethodEnum.raw}
setDecodeMethod={setDecodeMethod}
/>
)}
{found && (
)}
</DataDecode>
{found && !skipDataScamCheck && (
<a href='/#' onClick={show} className='small-font text-muted'>
{!showData ? 'Show' : 'Hide'} original message
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { activeNetworkSelector } from 'redux/selectors';
import {
TransactionType,
TransactionActionCategoryEnum,
TransactionActionEnum,
TransactionApiStatusEnum
} from 'types';

Expand Down Expand Up @@ -67,6 +68,11 @@ export const TransactionDetailsPanel = ({
const showTotalTxTokenUsdValue =
totalTxTokenUsdValue !== new BigNumber(0).toString();

const skipDataScamCheck =
transaction.sender === receiver &&
transaction.function === TransactionActionEnum.transfer &&
(!transaction.scamInfo || transaction.scamInfo?.type === 'potentialScam');

return (
<>
<DetailItem title='Hash'>
Expand Down Expand Up @@ -324,7 +330,11 @@ export const TransactionDetailsPanel = ({
<TransactionWarningMessage transaction={transaction} />
</DetailItem>

<DataField data={transaction.data} scamInfo={transaction.scamInfo} />
<DataField
data={transaction.data}
scamInfo={transaction.scamInfo}
skipDataScamCheck={skipDataScamCheck}
/>

{transaction.results && transaction.results?.length > 0 && (
<DetailItem
Expand Down

0 comments on commit 47efb49

Please sign in to comment.