Skip to content

Commit

Permalink
fix: Use domain for origin pill component (#11730)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**
This PR fixes an issue where the full URL is displayed in the origin
pill for transaction requests triggered from a dapp within the in-app
browser, rather than just the domain. The expected behavior is to
display only the domain, similar to how signature requests are handled.
This update ensures consistency across both transaction and signature
requests.

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

## **Related issues**

Fixes: #11690

## **Manual testing steps**

1. Open a dapp within the in app browser
2. Trigger a transaction request
3. See the origin pill

## **Screenshots/Recordings**


[origin.webm](https://github.com/user-attachments/assets/31736e36-9054-496e-992e-5ab55688361c)

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
vinistevam authored Oct 11, 2024
1 parent 092d567 commit 3774729
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 11 deletions.
34 changes: 34 additions & 0 deletions app/components/UI/ApprovalTagUrl/ApprovalTagUrl.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import renderWithProvider from '../../../util/test/renderWithProvider';
import ApprovalTagUrl from './ApprovalTagUrl';
import { backgroundState } from '../../../util/test/initial-root-state';

const ADDRESS_MOCK = '0x1234567890abcdef1234567890abcdef12345678';
const DOMAIN_MOCK = 'metamask.github.io';
const mockInitialState = {
settings: {},
engine: {
backgroundState: {
...backgroundState,
PreferencesController: {
selectedAddress: ADDRESS_MOCK,
},
},
},
};

describe('ApprovalTagUrl', () => {
it('renders correctly', () => {
const { toJSON } = renderWithProvider(
<ApprovalTagUrl
from={ADDRESS_MOCK}
origin={DOMAIN_MOCK}
url={`https://${DOMAIN_MOCK}/test-dapp/mock-url-query`}
sdkDappMetadata={{ url: '', icon: '' }}
/>,
{ state: mockInitialState },
);

expect(toJSON()).toMatchSnapshot();
});
});
6 changes: 3 additions & 3 deletions app/components/UI/ApprovalTagUrl/ApprovalTagUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useStyles } from '../../../component-library/hooks';
import AppConstants from '../../../core/AppConstants';
import { selectInternalAccounts } from '../../../selectors/accountsController';
import { selectAccountsByChainId } from '../../../selectors/accountTrackerController';
import { prefixUrlWithProtocol } from '../../../util/browser';
import { getHost, prefixUrlWithProtocol } from '../../../util/browser';
import useFavicon from '../../hooks/useFavicon/useFavicon';
import stylesheet from './ApprovalTagUrl.styles';

Expand Down Expand Up @@ -51,8 +51,8 @@ const ApprovalTagUrl = ({
const domainTitle = useMemo(() => {
let title = '';

if (url || currentEnsName || origin) {
title = prefixUrlWithProtocol(currentEnsName || origin || url);
if (currentEnsName || origin || url) {
title = prefixUrlWithProtocol(currentEnsName || origin || getHost(url));
} else {
title = '';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ApprovalTagUrl renders correctly 1`] = `
<View
style={
{
"alignItems": "center",
"alignSelf": "center",
"backgroundColor": "#ffffff",
"borderColor": "#bbc0c5",
"borderRadius": 99,
"borderWidth": 1,
"flexDirection": "row",
"marginBottom": 16,
"paddingLeft": 8,
"paddingRight": 16,
"paddingVertical": 8,
}
}
testID="APPROVAL_TAG_URL_ORIGIN_PILL"
>
<View
style={
{
"backgroundColor": "#ffffff",
"borderRadius": 16,
"height": 24,
"marginRight": 8,
"overflow": "hidden",
"width": 24,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source={
{
"uri": "",
}
}
style={
{
"flex": 1,
"height": undefined,
"width": undefined,
}
}
testID="favicon-avatar-image"
/>
</View>
<Text
accessibilityRole="text"
style={
{
"color": "#6a737d",
"flexShrink": 1,
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"letterSpacing": 0,
"lineHeight": 22,
}
}
>
https://metamask.github.io
</Text>
</View>
`;
4 changes: 2 additions & 2 deletions app/components/Views/AccountConnect/AccountConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
getAddressAccountType,
safeToChecksumAddress,
} from '../../../util/address';
import { getUrlObj, prefixUrlWithProtocol } from '../../../util/browser';
import { getHost, getUrlObj, prefixUrlWithProtocol } from '../../../util/browser';
import { getActiveTabUrl } from '../../../util/transactions';
import { Account, useAccounts } from '../../hooks/useAccounts';

Expand Down Expand Up @@ -177,7 +177,7 @@ const AccountConnect = (props: AccountConnectProps) => {

const urlWithProtocol =
hostname && !isUUID(hostname)
? prefixUrlWithProtocol(hostname)
? prefixUrlWithProtocol(getHost(hostname))
: domainTitle;

const isAllowedOrigin = useCallback((origin: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck - Confirmations team or Transactions team
import { toChecksumAddress } from 'ethereumjs-util';
import React, { useEffect, useState } from 'react';
import { View } from 'react-native';
Expand Down Expand Up @@ -27,6 +25,7 @@ import stylesheet from './ApproveTransactionHeader.styles';
import { ApproveTransactionHeaderI } from './ApproveTransactionHeader.types';
import { selectInternalAccounts } from '../../../../../selectors/accountsController';
import ApprovalTagUrl from '../../../../UI/ApprovalTagUrl';
import { RootState } from '../../../../../reducers';

const ApproveTransactionHeader = ({
from,
Expand All @@ -51,9 +50,7 @@ const ApproveTransactionHeader = ({
const networkName = useSelector(selectNetworkName);

const useBlockieIcon = useSelector(
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(state: any) => state.settings.useBlockieIcon,
(state: RootState) => state.settings.useBlockieIcon,
);

useEffect(() => {
Expand All @@ -70,7 +67,7 @@ const ApproveTransactionHeader = ({

const networkImage = useSelector(selectNetworkImageSource);

const accountTypeLabel = getLabelTextByAddress(activeAddress);
const accountTypeLabel = getLabelTextByAddress(activeAddress) ?? undefined;

return (
<View style={styles.transactionHeader}>
Expand Down

0 comments on commit 3774729

Please sign in to comment.