From 214afe1992f3f6a74404033ce231743208ad1caa Mon Sep 17 00:00:00 2001 From: ryanml Date: Fri, 13 Jan 2023 12:28:52 -0700 Subject: [PATCH] Remove 'Verify contract details' link on Sig Req screen when 'verifyingContract' is absent (#17128) * Remove 'Verify contract details' link on Sig Req screen when 'verifyingContract' is not provided * Adding tests --- .../signature-request.component.js | 39 +++++++++++-------- .../signature-request.container.test.js | 33 +++++++++++++++- ui/pages/send/send.utils.js | 4 ++ ui/pages/send/send.utils.test.js | 13 +++++++ 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/ui/components/app/signature-request/signature-request.component.js b/ui/components/app/signature-request/signature-request.component.js index 4fb357625..f6ad7a659 100644 --- a/ui/components/app/signature-request/signature-request.component.js +++ b/ui/components/app/signature-request/signature-request.component.js @@ -134,9 +134,11 @@ export default class SignatureRequest extends PureComponent { nativeCurrency, } = this.props; const { trackEvent } = this.context; - const { sanitizedMessage, domain, primaryType } = - this.memoizedParseMessage(data); - + const { + sanitizedMessage, + domain: { verifyingContract }, + primaryType, + } = this.memoizedParseMessage(data); const currentNetwork = this.getNetworkName(); const balanceInBaseAsset = conversionUtil(balance, { @@ -223,20 +225,23 @@ export default class SignatureRequest extends PureComponent { > {this.context.t('signatureRequestGuidance')} -
- -
+ + {this.context.t('verifyContractDetails')} + + + + ) : null} {isLedgerWallet ? (
@@ -261,7 +266,7 @@ export default class SignatureRequest extends PureComponent { /> {this.state.showContractDetails && ( { }, }; + let rerender; + beforeEach(() => { - renderWithProvider(, store); + rerender = renderWithProvider( + , + store, + ).rerender; }); afterEach(() => { @@ -122,4 +127,30 @@ describe('Signature Request', () => { expect(warningText).toBeInTheDocument(); }); + + it('shows verify contract details link when verifyingContract is set', () => { + const verifyingContractLink = screen.getByTestId('verify-contract-details'); + + expect(verifyingContractLink).toBeInTheDocument(); + }); + + it('does not show verify contract details link when verifyingContract is not set', () => { + const newData = JSON.parse(props.txData.msgParams.data); + delete newData.domain.verifyingContract; + + const newProps = { + ...props, + txData: { + ...props.txData, + msgParams: { + ...props.txData.msgParams, + data: JSON.stringify(newData), + }, + }, + }; + + rerender(, store); + + expect(screen.queryByTestId('verify-contract-details')).toBeNull(); + }); }); diff --git a/ui/pages/send/send.utils.js b/ui/pages/send/send.utils.js index 1a0450aa8..2c45e1ccf 100644 --- a/ui/pages/send/send.utils.js +++ b/ui/pages/send/send.utils.js @@ -182,5 +182,9 @@ function getAssetTransferData({ sendToken, fromAddress, toAddress, amount }) { } function ellipsify(text, first = 6, last = 4) { + if (!text) { + return ''; + } + return `${text.slice(0, first)}...${text.slice(-last)}`; } diff --git a/ui/pages/send/send.utils.test.js b/ui/pages/send/send.utils.test.js index 34e6bbc61..bfe9207b3 100644 --- a/ui/pages/send/send.utils.test.js +++ b/ui/pages/send/send.utils.test.js @@ -12,6 +12,7 @@ import { generateERC20TransferData, isBalanceSufficient, isTokenBalanceSufficient, + ellipsify, } from './send.utils'; jest.mock('../../../shared/modules/conversion.utils', () => ({ @@ -154,4 +155,16 @@ describe('send utils', () => { expect(result).toStrictEqual(false); }); }); + + describe('ellipsify()', () => { + it('should ellipsify a contract address', () => { + expect( + ellipsify('0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'), + ).toStrictEqual('0xCcCC...cccC'); + }); + + it('should return an empty string if the passed text is not defined', () => { + expect(ellipsify(undefined)).toStrictEqual(''); + }); + }); });