1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

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
This commit is contained in:
ryanml 2023-01-13 12:28:52 -07:00 committed by GitHub
parent 7760f4d658
commit 214afe1992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 18 deletions

View File

@ -134,9 +134,11 @@ export default class SignatureRequest extends PureComponent {
nativeCurrency, nativeCurrency,
} = this.props; } = this.props;
const { trackEvent } = this.context; const { trackEvent } = this.context;
const { sanitizedMessage, domain, primaryType } = const {
this.memoizedParseMessage(data); sanitizedMessage,
domain: { verifyingContract },
primaryType,
} = this.memoizedParseMessage(data);
const currentNetwork = this.getNetworkName(); const currentNetwork = this.getNetworkName();
const balanceInBaseAsset = conversionUtil(balance, { const balanceInBaseAsset = conversionUtil(balance, {
@ -223,20 +225,23 @@ export default class SignatureRequest extends PureComponent {
> >
{this.context.t('signatureRequestGuidance')} {this.context.t('signatureRequestGuidance')}
</Typography> </Typography>
<div> {verifyingContract ? (
<Button <div>
type="link" <Button
onClick={() => this.setState({ showContractDetails: true })} type="link"
className="signature-request-content__verify-contract-details" onClick={() => this.setState({ showContractDetails: true })}
> className="signature-request-content__verify-contract-details"
<Typography data-testid="verify-contract-details"
variant={TYPOGRAPHY.H7}
color={COLORS.PRIMARY_DEFAULT}
> >
{this.context.t('verifyContractDetails')} <Typography
</Typography> variant={TYPOGRAPHY.H7}
</Button> color={COLORS.PRIMARY_DEFAULT}
</div> >
{this.context.t('verifyContractDetails')}
</Typography>
</Button>
</div>
) : null}
</div> </div>
{isLedgerWallet ? ( {isLedgerWallet ? (
<div className="confirm-approve-content__ledger-instruction-wrapper"> <div className="confirm-approve-content__ledger-instruction-wrapper">
@ -261,7 +266,7 @@ export default class SignatureRequest extends PureComponent {
/> />
{this.state.showContractDetails && ( {this.state.showContractDetails && (
<ContractDetailsModal <ContractDetailsModal
toAddress={domain.verifyingContract} toAddress={verifyingContract}
chainId={chainId} chainId={chainId}
rpcPrefs={rpcPrefs} rpcPrefs={rpcPrefs}
origin={origin} origin={origin}

View File

@ -91,8 +91,13 @@ describe('Signature Request', () => {
}, },
}; };
let rerender;
beforeEach(() => { beforeEach(() => {
renderWithProvider(<SignatureRequest.WrappedComponent {...props} />, store); rerender = renderWithProvider(
<SignatureRequest.WrappedComponent {...props} />,
store,
).rerender;
}); });
afterEach(() => { afterEach(() => {
@ -122,4 +127,30 @@ describe('Signature Request', () => {
expect(warningText).toBeInTheDocument(); 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(<SignatureRequest.WrappedComponent {...newProps} />, store);
expect(screen.queryByTestId('verify-contract-details')).toBeNull();
});
}); });

View File

@ -182,5 +182,9 @@ function getAssetTransferData({ sendToken, fromAddress, toAddress, amount }) {
} }
function ellipsify(text, first = 6, last = 4) { function ellipsify(text, first = 6, last = 4) {
if (!text) {
return '';
}
return `${text.slice(0, first)}...${text.slice(-last)}`; return `${text.slice(0, first)}...${text.slice(-last)}`;
} }

View File

@ -12,6 +12,7 @@ import {
generateERC20TransferData, generateERC20TransferData,
isBalanceSufficient, isBalanceSufficient,
isTokenBalanceSufficient, isTokenBalanceSufficient,
ellipsify,
} from './send.utils'; } from './send.utils';
jest.mock('../../../shared/modules/conversion.utils', () => ({ jest.mock('../../../shared/modules/conversion.utils', () => ({
@ -154,4 +155,16 @@ describe('send utils', () => {
expect(result).toStrictEqual(false); 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('');
});
});
}); });