Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { sanitizeString } from '../../../../../../../util/string';
import { getSIWEDetails, SIWEMessage } from '../../../../utils/signature';
import { useSignatureRequest } from '../../../../hooks/useSignatureRequest';
import Address from '../../../UI/InfoRow/InfoValue/Address';
import DisplayURL from '../../../UI/InfoRow/InfoValue/DisplayURL';
import InfoDate from '../../../UI/InfoRow/InfoValue/InfoDate';
import InfoRow from '../../../UI/InfoRow';
import Network from '../../../UI/InfoRow/InfoValue/Network';
Expand Down Expand Up @@ -59,9 +58,7 @@ const DetailedSIWEMessage = ({
return (
<View>
<Text style={styles.siweTos}>{parsedMessage?.statement}</Text>
<InfoRow label={strings('confirm.siwe_message.url')}>
<DisplayURL url={uri} />
</InfoRow>
<InfoRow label={strings('confirm.siwe_message.url')}>{uri}</InfoRow>
<InfoRow label={strings('confirm.siwe_message.network')}>
<Network chainId={numberToHex(parseInt(chainId))} />
</InfoRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ describe('PersonalSign', () => {
),
).toHaveLength(2);
expect(getByText('URL')).toBeDefined();
expect(getAllByText('metamask.github.io')).toHaveLength(2);
expect(getAllByText('metamask.github.io')).toBeDefined();
expect(getAllByText('https://metamask.github.io')).toBeDefined();
expect(getByText('Network')).toBeDefined();
expect(getAllByText('Ethereum Mainnet')).toHaveLength(2);
expect(getByText('Account')).toBeDefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const InfoRowOrigin = () => {
label={strings('confirm.label.request_from')}
tooltip={strings('confirm.personal_sign_tooltip')}
>
<DisplayURL url={approvalRequest.origin} />
{/* TODO: request from url below will only work for signatures */}
<DisplayURL url={approvalRequest?.requestData?.meta?.url} />
</InfoRow>
{isSIWEMessage && (
<InfoRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ describe('DisplayURL', () => {
const { getByText } = render(<DisplayURL url="http://google.com" />);
expect(getByText('HTTP')).toBeTruthy();
});

it('displays only the host part of the URL', () => {
const { getByText } = render(
<DisplayURL url="https://metamask.github.io/test-dapp/" />,
);
expect(getByText('metamask.github.io')).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import Icon, {
IconSize,
} from '../../../../../../../../component-library/components/Icons/Icon';
import Text from '../../../../../../../../component-library/components/Texts/Text';
// import Logger from '../../../../../../../../util/Logger';
import Logger from '../../../../../../../../util/Logger';
import { useStyles } from '../../../../../../../../component-library/hooks';
import styleSheet from './DisplayURL.styles';

interface DisplayURLProps {
url: string;
}

function extractHostname(url: string) {
// eslint-disable-next-line no-useless-escape
const match = url.match(/^(?:https?:\/\/)?([^\/:]+)/);
return match ? match[1] : null;
}

const DisplayURL = ({ url }: DisplayURLProps) => {
const [isHTTP, setIsHTTP] = useState(false);

Expand All @@ -23,14 +29,12 @@ const DisplayURL = ({ url }: DisplayURLProps) => {
try {
urlObject = new URL(url);
} catch (e) {
// Commenting out the line below till issue of missing protocol in origin is addressed
// https://github.com/MetaMask/metamask-mobile/issues/13580#issuecomment-2671458216
// Logger.error(e as Error, `DisplayURL: new URL(url) cannot parse ${url}`);
Logger.error(e as Error, `DisplayURL: new URL(url) cannot parse ${url}`);
}
setIsHTTP(urlObject?.protocol === 'http:');
}, [url]);

const urlWithoutProtocol = url?.replace(/https?:\/\//u, '');
const hostName = extractHostname(url);

const { styles } = useStyles(styleSheet, {});

Expand All @@ -46,7 +50,7 @@ const DisplayURL = ({ url }: DisplayURLProps) => {
<Text style={styles.warningText}>HTTP</Text>
</View>
)}
<Text style={styles.value}>{urlWithoutProtocol}</Text>
<Text style={styles.value}>{hostName}</Text>
</View>
);
};
Expand Down
Loading