Skip to content

Commit

Permalink
fix: hide ApprovalTagUrl when origins is internal
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistevam committed Dec 10, 2024
1 parent 800d116 commit 9f854c6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ApprovalTagUrl renders correctly 1`] = `
exports[`ApprovalTagUrl renders correctly when origin is not an internal origin 1`] = `
<View
style={
{
Expand Down

0 comments on commit 9f854c6

Please sign in to comment.