mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01: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:
parent
7760f4d658
commit
214afe1992
@ -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,11 +225,13 @@ export default class SignatureRequest extends PureComponent {
|
|||||||
>
|
>
|
||||||
{this.context.t('signatureRequestGuidance')}
|
{this.context.t('signatureRequestGuidance')}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
{verifyingContract ? (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
type="link"
|
type="link"
|
||||||
onClick={() => this.setState({ showContractDetails: true })}
|
onClick={() => this.setState({ showContractDetails: true })}
|
||||||
className="signature-request-content__verify-contract-details"
|
className="signature-request-content__verify-contract-details"
|
||||||
|
data-testid="verify-contract-details"
|
||||||
>
|
>
|
||||||
<Typography
|
<Typography
|
||||||
variant={TYPOGRAPHY.H7}
|
variant={TYPOGRAPHY.H7}
|
||||||
@ -237,6 +241,7 @@ export default class SignatureRequest extends PureComponent {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</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}
|
||||||
|
@ -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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -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)}`;
|
||||||
}
|
}
|
||||||
|
@ -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('');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user