Skip to content

Commit

Permalink
feat(suite): display contract address error
Browse files Browse the repository at this point in the history
  • Loading branch information
enjojoy committed Sep 10, 2024
1 parent 9477e88 commit f5cc569
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/suite/src/support/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,14 @@ export default defineMessages({
defaultMessage: 'Unable to verify address history. Check that the address is correct.',
id: 'TR_ETH_ADDRESS_CANT_VERIFY_HISTORY',
},
TR_ETH_ADDRESS_IS_CONTRACT: {
defaultMessage: 'It is a contract address. Are you sure you want to send to this address?',
id: 'TR_ETH_ADDRESS_IS_CONTRACT',
},
TR_I_UNDERSTAND_THE_RISK: {
defaultMessage: 'I understand the risk',
id: 'TR_I_UNDERSTAND_THE_RISK',
},
TR_NEEDS_ATTENTION_BOOTLOADER: {
defaultMessage: 'Trezor is in Bootloader mode.',
id: 'TR_NEEDS_ATTENTION_BOOTLOADER',
Expand Down
28 changes: 28 additions & 0 deletions packages/suite/src/views/wallet/send/Outputs/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const Address = ({ output, outputId, outputsCount }: AddressProps) => {
const [addressDeprecatedUrl, setAddressDeprecatedUrl] =
useState<ReturnType<typeof isAddressDeprecated>>(undefined);
const [hasAddressChecksummed, setHasAddressChecksummed] = useState<boolean | undefined>();
let contractAddressWarningDismissed = false;
const dispatch = useDispatch();
const { device } = useDevice();
const {
Expand All @@ -80,6 +81,7 @@ export const Address = ({ output, outputId, outputsCount }: AddressProps) => {
metadataEnabled,
watch,
setDraftSaveRequest,
trigger,
} = useSendFormContext();
const { translationString } = useTranslation();
const { descriptor, networkType, symbol } = account;
Expand Down Expand Up @@ -185,6 +187,14 @@ export const Address = ({ output, outputId, outputsCount }: AddressProps) => {
}),
text: translationString('TR_CONVERT_TO_LOWERCASE'),
};
case 'contract':
return {
onClick: () => {
contractAddressWarningDismissed = true;
trigger(inputName);
},
text: translationString('TR_I_UNDERSTAND_THE_RISK'),
};
default:
return undefined;
}
Expand Down Expand Up @@ -260,6 +270,24 @@ export const Address = ({ output, outputId, outputsCount }: AddressProps) => {
return translationString('TR_ETH_ADDRESS_CANT_VERIFY_HISTORY');
}
},
contract: async (address: string) => {
if (networkType === 'ethereum' && !contractAddressWarningDismissed) {
if (isOnline) {
const params = {
descriptor: address,
coin: symbol,
};
const result = await TrezorConnect.getAccountInfo(params);

if (result.success) {
const isContract = result.payload.misc?.contractInfo;
if (isContract) {
return translationString('TR_ETH_ADDRESS_IS_CONTRACT');
}
}
}
}
},
rippleToSelf: (value: string) => {
if (networkType === 'ripple' && value === descriptor) {
return translationString('RECIPIENT_CANNOT_SEND_TO_MYSELF');
Expand Down

0 comments on commit f5cc569

Please sign in to comment.