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: Make confirmations exclusively use approval origin #12980

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions app/components/Views/AccountConnect/AccountConnect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Third party dependencies.
import { useNavigation } from '@react-navigation/native';
import { isEqual } from 'lodash';
import React, {
useCallback,
useContext,
Expand Down Expand Up @@ -41,7 +40,6 @@ import {
getUrlObj,
prefixUrlWithProtocol,
} from '../../../util/browser';
import { getActiveTabUrl } from '../../../util/transactions';
import { Account, useAccounts } from '../../hooks/useAccounts';

// Internal dependencies.
Expand Down Expand Up @@ -84,6 +82,7 @@ import { AvatarSize } from '../../../component-library/components/Avatars/Avatar
import { selectNetworkConfigurations } from '../../../selectors/networkController';
import { isUUID } from '../../../core/SDKConnect/utils/isUUID';
import useOriginSource from '../../hooks/useOriginSource';
import useApprovalRequest from '../confirmations/hooks/useApprovalRequest';

const createStyles = () =>
StyleSheet.create({
Expand All @@ -98,6 +97,7 @@ const AccountConnect = (props: AccountConnectProps) => {
const { hostInfo, permissionRequestId } = props.route.params;
const [isLoading, setIsLoading] = useState(false);
const navigation = useNavigation();
const { approvalRequest } = useApprovalRequest();
const { trackEvent, createEventBuilder } = useMetrics();

const [blockedUrl, setBlockedUrl] = useState('');
Expand Down Expand Up @@ -133,8 +133,7 @@ const AccountConnect = (props: AccountConnectProps) => {

const { toastRef } = useContext(ToastContext);

// origin is set to the last active tab url in the browser which can conflict with sdk
const inappBrowserOrigin: string = useSelector(getActiveTabUrl, isEqual);
const origin = approvalRequest?.origin;
const accountsLength = useSelector(selectAccountsLength);
const { wc2Metadata } = useSelector((state: RootState) => state.sdk);

Expand Down Expand Up @@ -177,7 +176,7 @@ const AccountConnect = (props: AccountConnectProps) => {
dappHostname = title;
} else if (!isChannelId && (dappUrl || channelIdOrHostname)) {
title = prefixUrlWithProtocol(dappUrl || channelIdOrHostname);
dappHostname = inappBrowserOrigin;
dappHostname = origin as string;
} else {
title = strings('sdk.unknown');
setIsSdkUrlUnknown(true);
Expand All @@ -186,7 +185,7 @@ const AccountConnect = (props: AccountConnectProps) => {
return { domainTitle: title, hostname: dappHostname };
}, [
isOriginWalletConnect,
inappBrowserOrigin,
origin,
isOriginMMSDKRemoteConn,
isChannelId,
dappUrl,
Expand Down Expand Up @@ -264,15 +263,15 @@ const AccountConnect = (props: AccountConnectProps) => {
}
}, [selectedChainIds, chainId, hostname]);

const isAllowedOrigin = useCallback((origin: string) => {
const isAllowedOrigin = useCallback((originToCheck: string) => {
const { PhishingController } = Engine.context;

// Update phishing configuration if it is out-of-date
// This is async but we are not `await`-ing it here intentionally, so that we don't slow
// down network requests. The configuration is updated for the next request.
PhishingController.maybeUpdateState();

const phishingControllerTestResult = PhishingController.test(origin);
const phishingControllerTestResult = PhishingController.test(originToCheck);

return !phishingControllerTestResult.result;
}, []);
Expand All @@ -288,7 +287,7 @@ const AccountConnect = (props: AccountConnectProps) => {
}, [isAllowedOrigin, dappUrl, channelIdOrHostname]);

const faviconSource = useFavicon(
inappBrowserOrigin || (!isChannelId ? channelIdOrHostname : ''),
origin || (!isChannelId ? channelIdOrHostname : ''),
);

const actualIcon = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import TransactionReviewData from './TransactionReviewData';
import TransactionReviewInformation from './TransactionReviewInformation';
import TransactionReviewSummary from './TransactionReviewSummary';
import DevLogger from '../../../../../core/SDKConnect/utils/DevLogger';
import { prefixUrlWithProtocol } from '../../../../../util/browser';

const POLLING_INTERVAL_ESTIMATED_L1_FEE = 30000;

Expand Down Expand Up @@ -546,7 +547,7 @@ class TransactionReview extends PureComponent {
if (currentConnection) {
url = currentConnection.originatorInfo.url;
} else {
url = this.getUrlFromBrowser();
url = prefixUrlWithProtocol(origin);
}

const styles = this.getStyles();
Expand Down
Loading