Skip to content

Commit

Permalink
fix: disables "swap and send" for MMI (#25886)
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**

We need to disable the Swap & Send functionality for MMI, as we don't
support the swaps flow in MM.

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- 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**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.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
zone-live authored Jul 17, 2024
1 parent b31c31e commit c12237f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/e2e/tests/multichain/asset-picker-send.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Driver } from '../../webdriver/driver';
import { RECIPIENT_ADDRESS_MOCK } from '../simulation-details/types';

describe('AssetPickerSendFlow', function () {
describe('AssetPickerSendFlow @no-mmi', function () {
const chainId = CHAIN_IDS.MAINNET;

const fixtures = {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/swap-send/swap-send-erc20.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { SWAP_SEND_QUOTES_RESPONSE_TST_ETH } from './mocks/erc20-data';

const RECIPIENT_ADDRESS = '0xc427D562164062a23a5cFf596A4a3208e72Acd28';

describe('Swap-Send ERC20', function () {
describe('Swap-Send ERC20 @no-mmi', function () {
describe('to non-contract address with data that matches swap data signature', function (this: Suite) {
it('submits a transaction successfully', async function () {
await withFixtures(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/swap-send/swap-send-eth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

const RECIPIENT_ADDRESS = '0xc427D562164062a23a5cFf596A4a3208e72Acd28';

describe('Swap-Send ETH', function () {
describe('Swap-Send ETH @no-mmi', function () {
describe('to non-contract address with data that matches swap data signature', function (this: Suite) {
it('submits a transaction successfully', async function () {
await withFixtures(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
import Tooltip from '../../../ui/tooltip';
import { LARGE_SYMBOL_LENGTH } from '../constants';
import { getAssetImageURL } from '../../../../helpers/utils/util';
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
import { useI18nContext } from '../../../../hooks/useI18nContext';
///: END:ONLY_INCLUDE_IF
import { MetaMetricsContext } from '../../../../contexts/metametrics';
import {
MetaMetricsEventCategory,
Expand Down Expand Up @@ -66,7 +68,9 @@ export function AssetPicker({
sendingAsset,
isDisabled = false,
}: AssetPickerProps) {
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
const t = useI18nContext();
///: END:ONLY_INCLUDE_IF
const trackEvent = useContext(MetaMetricsContext);
const sendAnalytics = useSelector(getSendAnalyticProperties);

Expand Down Expand Up @@ -119,6 +123,16 @@ export function AssetPicker({
const currentNetwork = useSelector(getCurrentNetwork);
const testNetworkBackgroundColor = useSelector(getTestNetworkBackgroundColor);

const handleAssetPickerTitle = (): string | undefined => {
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
if (isDisabled) {
return t('swapTokenNotAvailable');
}
///: END:ONLY_INCLUDE_IF

return undefined;
};

return (
<>
{/* This is the Modal that ask to choose token to send */}
Expand Down Expand Up @@ -162,7 +176,7 @@ export function AssetPicker({
marginInlineStart: 0,
display: isDisabled ? Display.None : Display.InlineBlock,
}}
title={isDisabled ? t('swapTokenNotAvailable') : undefined}
title={handleAssetPickerTitle()}
>
<Box display={Display.Flex} alignItems={AlignItems.center} gap={3}>
<BadgeWrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { useCallback, useMemo, useRef } from 'react';
import React, {
useCallback,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
useMemo,
///: END:ONLY_INCLUDE_IF
useRef,
} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
BannerAlert,
Expand All @@ -11,20 +17,25 @@ import {
acknowledgeRecipientWarning,
getBestQuote,
getCurrentDraftTransaction,
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
getIsSwapAndSendDisabledForNetwork,
getSendAsset,
getSwapsBlockedTokens,
///: END:ONLY_INCLUDE_IF
getSendAsset,
} from '../../../../../ducks/send';
import { AssetType } from '../../../../../../shared/constants/transaction';
import { CONTRACT_ADDRESS_LINK } from '../../../../../helpers/constants/common';
import { Display } from '../../../../../helpers/constants/design-system';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
import { AssetPickerAmount } from '../../..';
import { decimalToHex } from '../../../../../../shared/modules/conversion.utils';
///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
import {
getIsSwapsChain,
getUseExternalServices,
} from '../../../../../selectors';
///: END:ONLY_INCLUDE_IF

import type { Quote } from '../../../../../ducks/send/swap-and-send-utils';
import { isEqualCaseInsensitive } from '../../../../../../shared/modules/string-utils';
import { SendHexData, SendPageRow, QuoteCard } from '.';
Expand All @@ -45,6 +56,13 @@ export const SendPageRecipientContent = ({
isSwapQuoteLoading,
} = useSelector(getCurrentDraftTransaction);

let isSwapAllowed;

///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
isSwapAllowed = false;
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask)
const isBasicFunctionality = useSelector(getUseExternalServices);
const isSwapsChain = useSelector(getIsSwapsChain);
const isSwapAndSendDisabledForNetwork = useSelector(
Expand All @@ -54,12 +72,14 @@ export const SendPageRecipientContent = ({
const memoizedSwapsBlockedTokens = useMemo(() => {
return new Set(swapsBlockedTokens);
}, [swapsBlockedTokens]);
const isSwapAllowed =

isSwapAllowed =
isSwapsChain &&
!isSwapAndSendDisabledForNetwork &&
[AssetType.token, AssetType.native].includes(sendAsset.type) &&
isBasicFunctionality &&
!memoizedSwapsBlockedTokens.has(sendAsset.details?.address?.toLowerCase());
///: END:ONLY_INCLUDE_IF

const bestQuote: Quote = useSelector(getBestQuote);

Expand Down

0 comments on commit c12237f

Please sign in to comment.