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

EVM poisoning vol. 2 #10034

Merged
merged 8 commits into from
Feb 6, 2024
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
24 changes: 11 additions & 13 deletions packages/suite/src/actions/wallet/sendFormActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
replaceTransactionThunk,
syncAccountsWithBlockchainThunk,
selectDevice,
selectSpecificTokenDefinition,
} from '@suite-common/wallet-core';
import { notificationsActions } from '@suite-common/toast-notifications';
import {
Expand Down Expand Up @@ -386,7 +387,7 @@ export const signTransaction =
) =>
async (dispatch: Dispatch, getState: GetState) => {
const device = selectDevice(getState());
const { account, network } = getState().wallet.selectedAccount;
const { account } = getState().wallet.selectedAccount;

if (!device || !account) return;

Expand Down Expand Up @@ -424,20 +425,17 @@ export const signTransaction =
}

if (
account.networkType === 'ethereum' &&
!isCardanoTx(account, enhancedTxInfo) &&
enhancedTxInfo.token?.contract &&
network?.chainId
account.networkType === 'ethereum' &&
enhancedTxInfo.token?.contract
) {
const isTokenKnown = await fetch(
`https://data.trezor.io/firmware/eth-definitions/chain-id/${
network.chainId
}/token-${enhancedTxInfo.token.contract.substring(2).toLowerCase()}.dat`,
)
.then(response => response.ok)
.catch(() => false);

enhancedTxInfo.isTokenKnown = isTokenKnown;
const tokenDefinition = selectSpecificTokenDefinition(
getState(),
account.symbol,
enhancedTxInfo.token.contract,
);

enhancedTxInfo.isTokenKnown = !!tokenDefinition?.isTokenKnown;
}

// store formValues and transactionInfo in send reducer to be used by TransactionReviewModal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface AdvancedTxDetailsProps {
tx: WalletAccountTransaction;
chainedTxs?: ChainedTransactions;
explorerUrl: string;
isPhishingTransaction: boolean;
}

export const AdvancedTxDetails = ({
Expand All @@ -63,6 +64,7 @@ export const AdvancedTxDetails = ({
tx,
chainedTxs,
explorerUrl,
isPhishingTransaction,
}: AdvancedTxDetailsProps) => {
const [selectedTab, setSelectedTab] = useState<TabID>(defaultTab ?? 'amount');

Expand All @@ -71,7 +73,7 @@ export const AdvancedTxDetails = ({
if (selectedTab === 'amount') {
content = <AmountDetails tx={tx} isTestnet={isTestnet(network.symbol)} />;
} else if (selectedTab === 'io' && network.networkType !== 'ripple') {
content = <IODetails tx={tx} />;
content = <IODetails tx={tx} isPhishingTransaction={isPhishingTransaction} />;
} else if (selectedTab === 'chained' && chainedTxs) {
content = <ChainedTxs txs={chainedTxs} explorerUrl={explorerUrl} network={network} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ interface IOGridRow {
anonymitySet?: AnonymitySet;
tx: WalletAccountTransaction;
vinvout: WalletAccountTransaction['details']['vin'][number];
isPhishingTransaction?: boolean;
tomasklim marked this conversation as resolved.
Show resolved Hide resolved
}

const IOGridRow = ({
anonymitySet,
tx: { symbol },
vinvout: { isAccountOwned, addresses, value },
isPhishingTransaction,
}: IOGridRow) => {
const anonymity = addresses?.length && anonymitySet?.[addresses[0]];

Expand All @@ -167,6 +169,7 @@ const IOGridRow = ({
txAddress={addresses?.length ? addresses[0] : ''}
explorerUrl={explorerTxUrl}
explorerUrlQueryString={explorerUrlQueryString}
shouldAllowCopy={!isPhishingTransaction}
/>

<br />
Expand Down Expand Up @@ -220,9 +223,16 @@ interface GridRowGroupComponentProps {
to?: string;
symbol: string;
amount?: string | ReactNode;
isPhishingTransaction?: boolean;
}

const GridRowGroupComponent = ({ from, to, symbol, amount }: GridRowGroupComponentProps) => {
const GridRowGroupComponent = ({
from,
to,
symbol,
amount,
isPhishingTransaction,
}: GridRowGroupComponentProps) => {
const theme = useTheme();
const { explorerTxUrl, explorerUrlQueryString } = useExplorerTxUrl();

Expand All @@ -233,6 +243,7 @@ const GridRowGroupComponent = ({ from, to, symbol, amount }: GridRowGroupCompone
txAddress={from}
explorerUrl={explorerTxUrl}
explorerUrlQueryString={explorerUrlQueryString}
shouldAllowCopy={!isPhishingTransaction}
/>
<br />
{typeof amount === 'string' ? (
Expand All @@ -249,6 +260,7 @@ const GridRowGroupComponent = ({ from, to, symbol, amount }: GridRowGroupCompone
txAddress={to}
explorerUrl={explorerTxUrl}
explorerUrlQueryString={explorerUrlQueryString}
shouldAllowCopy={!isPhishingTransaction}
/>
</RowGridItem>
</RowGrid>
Expand All @@ -261,9 +273,13 @@ interface TokensByStandard {

interface EthereumSpecificBalanceDetailsRowProps {
tx: WalletAccountTransaction;
isPhishingTransaction?: boolean;
}

const EthereumSpecificBalanceDetailsRow = ({ tx }: EthereumSpecificBalanceDetailsRowProps) => {
const EthereumSpecificBalanceDetailsRow = ({
tx,
isPhishingTransaction,
}: EthereumSpecificBalanceDetailsRowProps) => {
const tokensByStandard: TokensByStandard = tx.tokens.reduce(
(acc: TokensByStandard, value: TokenTransfer) => {
const { standard } = value;
Expand Down Expand Up @@ -294,6 +310,7 @@ const EthereumSpecificBalanceDetailsRow = ({ tx }: EthereumSpecificBalanceDetail
to={transfer.to}
amount={formatNetworkAmount(transfer.amount, tx.symbol)}
symbol={tx.symbol}
isPhishingTransaction={isPhishingTransaction}
/>
))}
</IOGridGroupWrapper>
Expand Down Expand Up @@ -324,6 +341,7 @@ const EthereumSpecificBalanceDetailsRow = ({ tx }: EthereumSpecificBalanceDetail
)
}
symbol={transfer.symbol}
isPhishingTransaction={isPhishingTransaction}
/>
))}
</IOGridGroupWrapper>
Expand All @@ -333,7 +351,15 @@ const EthereumSpecificBalanceDetailsRow = ({ tx }: EthereumSpecificBalanceDetail
);
};

const SolanaSpecificBalanceDetailsRow = ({ tx }: { tx: WalletAccountTransaction }) => {
type SolanaSpecificBalanceDetailsRowProps = {
tx: WalletAccountTransaction;
isPhishingTransaction?: boolean;
};

const SolanaSpecificBalanceDetailsRow = ({
tx,
isPhishingTransaction,
}: SolanaSpecificBalanceDetailsRowProps) => {
const { tokens } = tx;
return (
<>
Expand All @@ -345,6 +371,7 @@ const SolanaSpecificBalanceDetailsRow = ({ tx }: { tx: WalletAccountTransaction
to={transfer.to}
amount={formatAmount(transfer.amount, transfer.decimals)}
symbol={transfer.symbol}
isPhishingTransaction={isPhishingTransaction}
/>
))}
</>
Expand All @@ -353,9 +380,10 @@ const SolanaSpecificBalanceDetailsRow = ({ tx }: { tx: WalletAccountTransaction

interface BalanceDetailsRowProps {
tx: WalletAccountTransaction;
isPhishingTransaction?: boolean;
}

const BalanceDetailsRow = ({ tx }: BalanceDetailsRowProps) => {
const BalanceDetailsRow = ({ tx, isPhishingTransaction }: BalanceDetailsRowProps) => {
const vout = tx?.details?.vout[0];
const vin = tx?.details?.vin[0];
const value = formatNetworkAmount(vin.value || vout.value || '', tx.symbol);
Expand All @@ -372,6 +400,7 @@ const BalanceDetailsRow = ({ tx }: BalanceDetailsRowProps) => {
to={vout.addresses[0]}
amount={value}
symbol={tx.symbol}
isPhishingTransaction={isPhishingTransaction}
/>
</IOGridGroupWrapper>
</GridGroup>
Expand All @@ -382,9 +411,10 @@ type IOSectionColumnProps = {
tx: WalletAccountTransaction;
inputs: WalletAccountTransaction['details']['vin'][number][];
outputs: WalletAccountTransaction['details']['vin'][number][];
isPhishingTransaction?: boolean;
};

const IOSectionColumn = ({ tx, inputs, outputs }: IOSectionColumnProps) => {
const IOSectionColumn = ({ tx, inputs, outputs, isPhishingTransaction }: IOSectionColumnProps) => {
const theme = useTheme();

const { selectedAccount } = useSelector(state => state.wallet);
Expand All @@ -404,6 +434,7 @@ const IOSectionColumn = ({ tx, inputs, outputs }: IOSectionColumnProps) => {
anonymitySet={anonymitySet}
tx={tx}
vinvout={input}
isPhishingTransaction={isPhishingTransaction}
/>
))}
</div>
Expand All @@ -419,6 +450,7 @@ const IOSectionColumn = ({ tx, inputs, outputs }: IOSectionColumnProps) => {
anonymitySet={anonymitySet}
tx={tx}
vinvout={output}
isPhishingTransaction={isPhishingTransaction}
/>
))}
</div>
Expand All @@ -439,6 +471,7 @@ const CollapsibleIOSection = ({
outputs,
heading,
opened,
isPhishingTransaction,
}: CollapsibleIOSectionProps) => {
const { elevation } = useElevation();
return inputs?.length || outputs?.length ? (
Expand All @@ -448,26 +481,35 @@ const CollapsibleIOSection = ({
isOpen={opened}
variant="large"
>
<IOSectionColumn tx={tx} inputs={inputs} outputs={outputs} />
<IOSectionColumn
tx={tx}
inputs={inputs}
outputs={outputs}
isPhishingTransaction={isPhishingTransaction}
/>
</StyledCollapsibleBox>
) : null;
};

interface IODetailsProps {
tx: WalletAccountTransaction;
isPhishingTransaction: boolean;
}

// Not ready for Cardano tokens, they will not be visible, probably
export const IODetails = ({ tx }: IODetailsProps) => {
export const IODetails = ({ tx, isPhishingTransaction }: IODetailsProps) => {
const { selectedAccount } = useSelector(state => state.wallet);
const { network } = selectedAccount;

if (network?.networkType === 'ethereum') {
return (
<Wrapper>
<AnalyzeInExplorerBanner txid={tx.txid} />
<BalanceDetailsRow tx={tx} />
<EthereumSpecificBalanceDetailsRow tx={tx} />
<BalanceDetailsRow tx={tx} isPhishingTransaction={isPhishingTransaction} />
<EthereumSpecificBalanceDetailsRow
tx={tx}
isPhishingTransaction={isPhishingTransaction}
/>
</Wrapper>
);
}
Expand All @@ -476,8 +518,16 @@ export const IODetails = ({ tx }: IODetailsProps) => {
return (
<Wrapper>
<AnalyzeInExplorerBanner txid={tx.txid} />
<IOSectionColumn tx={tx} inputs={tx.details.vin} outputs={tx.details.vout} />
<SolanaSpecificBalanceDetailsRow tx={tx} />
<IOSectionColumn
tx={tx}
inputs={tx.details.vin}
outputs={tx.details.vout}
isPhishingTransaction={isPhishingTransaction}
/>
<SolanaSpecificBalanceDetailsRow
tx={tx}
isPhishingTransaction={isPhishingTransaction}
/>
</Wrapper>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,27 @@ const onHoverTextOverflowContainerHover = css`
}
`;

const TextOverflowContainer = styled.div`
const TextOverflowContainer = styled.div<{ shouldAllowCopy?: boolean }>`
position: relative;
display: inline-flex;
max-width: 100%;
overflow: hidden;
color: ${({ theme }) => theme.TYPE_DARK_GREY};
cursor: pointer;
cursor: ${({ shouldAllowCopy }) => (shouldAllowCopy ? 'pointer' : 'cursor')};
user-select: none;

@media (hover: none) {
${onHoverTextOverflowContainerHover}
}
${({ shouldAllowCopy }) =>
shouldAllowCopy &&
css`
@media (hover: none) {
${onHoverTextOverflowContainerHover}
}

:hover,
:focus {
${onHoverTextOverflowContainerHover}
}
:hover,
:focus {
${onHoverTextOverflowContainerHover}
}
`}
`;

const SpanTextStart = styled.span`
Expand All @@ -62,13 +66,23 @@ interface IOAddressProps {
explorerUrl?: string;
txAddress?: string;
explorerUrlQueryString?: string;
shouldAllowCopy?: boolean;
}

export const IOAddress = ({ txAddress, explorerUrl, explorerUrlQueryString }: IOAddressProps) => {
export const IOAddress = ({
txAddress,
explorerUrl,
explorerUrlQueryString,
shouldAllowCopy = true,
}: IOAddressProps) => {
const [isClicked, setIsClicked] = useState(false);
const theme = useTheme();

const copy = () => {
if (!shouldAllowCopy) {
return;
}

copyToClipboard(txAddress || '');

setIsClicked(true);
Expand All @@ -84,6 +98,7 @@ export const IOAddress = ({ txAddress, explorerUrl, explorerUrlQueryString }: IO
onMouseLeave={() => setIsClicked(false)}
data-test="@tx-detail/txid-value"
id={txAddress}
shouldAllowCopy={shouldAllowCopy}
>
{txAddress.length <= 5 ? (
<SpanTextEnd onClick={copy}>{txAddress}</SpanTextEnd>
Expand All @@ -93,9 +108,15 @@ export const IOAddress = ({ txAddress, explorerUrl, explorerUrlQueryString }: IO
<SpanTextEnd onClick={copy}>{txAddress.slice(-4)}</SpanTextEnd>
</>
)}
<IconWrapper onClick={copy}>
<Icon icon={isClicked ? 'CHECK' : 'COPY'} size={12} color={theme.BG_WHITE} />
</IconWrapper>
{shouldAllowCopy ? (
<IconWrapper onClick={copy}>
<Icon
icon={isClicked ? 'CHECK' : 'COPY'}
size={12}
color={theme.BG_WHITE}
/>
</IconWrapper>
) : null}
{explorerUrl ? (
<IconWrapper>
<Link
Expand Down
Loading
Loading