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

fix: hide ApprovalTagUrl when origins is internal #12629

Merged
merged 3 commits into from
Jan 6, 2025
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
21 changes: 19 additions & 2 deletions app/components/UI/ApprovalTagUrl/ApprovalTagUrl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import renderWithProvider from '../../../util/test/renderWithProvider';
import ApprovalTagUrl from './ApprovalTagUrl';
import ApprovalTagUrl, { APPROVAL_TAG_URL_ORIGIN_PILL } from './ApprovalTagUrl';
import { backgroundState } from '../../../util/test/initial-root-state';
import { INTERNAL_ORIGINS } from '../../../constants/transaction';

const ADDRESS_MOCK = '0x1234567890abcdef1234567890abcdef12345678';
const DOMAIN_MOCK = 'metamask.github.io';

const mockInitialState = {
settings: {},
engine: {
Expand All @@ -19,7 +21,7 @@ const mockInitialState = {

describe('ApprovalTagUrl', () => {
it('renders correctly', () => {
const { toJSON } = renderWithProvider(
const { toJSON, getByTestId } = renderWithProvider(
<ApprovalTagUrl
from={ADDRESS_MOCK}
origin={DOMAIN_MOCK}
Expand All @@ -30,5 +32,20 @@ describe('ApprovalTagUrl', () => {
);

expect(toJSON()).toMatchSnapshot();
expect(getByTestId(APPROVAL_TAG_URL_ORIGIN_PILL)).toBeDefined();
});

it('does not render when origin is an internal origin', () => {
const { queryByTestId } = renderWithProvider(
<ApprovalTagUrl
from={ADDRESS_MOCK}
origin={INTERNAL_ORIGINS[0]}
url={`https://${INTERNAL_ORIGINS[0]}`}
sdkDappMetadata={{ url: '', icon: '' }}
/>,
{ state: mockInitialState },
);

expect(queryByTestId(APPROVAL_TAG_URL_ORIGIN_PILL)).toBeNull();
});
});
5 changes: 4 additions & 1 deletion app/components/UI/ApprovalTagUrl/ApprovalTagUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { selectAccountsByChainId } from '../../../selectors/accountTrackerContro
import { getHost, prefixUrlWithProtocol } from '../../../util/browser';
import useFavicon from '../../hooks/useFavicon/useFavicon';
import stylesheet from './ApprovalTagUrl.styles';
import { INTERNAL_ORIGINS } from '../../../constants/transaction';

const { ORIGIN_DEEPLINK, ORIGIN_QR_CODE } = AppConstants.DEEPLINKS;
export const APPROVAL_TAG_URL_ORIGIN_PILL = 'APPROVAL_TAG_URL_ORIGIN_PILL';
Expand Down Expand Up @@ -76,7 +77,9 @@ const ApprovalTagUrl = ({
uri: '',
};

if (origin && !isOriginDeepLink) {
const showOrigin = origin && !isOriginDeepLink && !INTERNAL_ORIGINS.includes(origin);

if (showOrigin) {
return (
<TagUrl
testID={APPROVAL_TAG_URL_ORIGIN_PILL}
Expand Down
Loading