From eb6f6e9fc598f5a236e0e265a929490e54c13dae Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 21 Nov 2024 11:44:44 -0700 Subject: [PATCH] WIP - Bump swaps-controller --- app/components/Nav/Main/RootRPCMethodsUI.js | 2 +- .../UI/AssetOverview/AssetOverview.tsx | 13 +- app/components/UI/Swaps/QuotesView.js | 21 ++- app/components/UI/Swaps/SwapsLiveness.ts | 2 +- .../ApprovalTransactionEditionModal.js | 2 +- .../components/LoadingAnimation/index.js | 12 +- app/components/UI/Swaps/index.js | 23 +++- app/components/UI/Swaps/utils/index.js | 5 +- .../UI/Swaps/utils/useFetchTokenMetadata.js | 2 +- app/components/UI/TransactionElement/utils.js | 2 +- app/components/Views/Asset/index.js | 2 +- .../Views/WalletActions/WalletActions.tsx | 2 +- .../confirmations/SendFlow/Amount/index.js | 2 +- app/core/Engine.ts | 21 +-- app/reducers/swaps/utils.ts | 4 +- app/selectors/types.ts | 2 +- app/util/test/initial-background-state.json | 3 +- app/util/transactions/index.js | 51 +++++--- app/util/transactions/index.test.ts | 2 +- package.json | 2 +- yarn.lock | 121 +++--------------- 21 files changed, 125 insertions(+), 171 deletions(-) diff --git a/app/components/Nav/Main/RootRPCMethodsUI.js b/app/components/Nav/Main/RootRPCMethodsUI.js index 712919e682c..4483bd78df7 100644 --- a/app/components/Nav/Main/RootRPCMethodsUI.js +++ b/app/components/Nav/Main/RootRPCMethodsUI.js @@ -28,7 +28,7 @@ import { import { BN } from 'ethereumjs-util'; import Logger from '../../../util/Logger'; import TransactionTypes from '../../../core/TransactionTypes'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { query } from '@metamask/controller-utils'; import BigNumber from 'bignumber.js'; import { toLowerCaseEquals } from '../../../util/general'; diff --git a/app/components/UI/AssetOverview/AssetOverview.tsx b/app/components/UI/AssetOverview/AssetOverview.tsx index 48b455adc8e..4d887ed19c8 100644 --- a/app/components/UI/AssetOverview/AssetOverview.tsx +++ b/app/components/UI/AssetOverview/AssetOverview.tsx @@ -9,6 +9,7 @@ import AppConstants from '../../../core/AppConstants'; import Engine from '../../../core/Engine'; import { selectChainId, + selectSelectedNetworkClientId, selectTicker, } from '../../../selectors/networkController'; import { @@ -45,7 +46,6 @@ import Routes from '../../../constants/navigation/Routes'; import TokenDetails from './TokenDetails'; import { RootState } from '../../../reducers'; import useGoToBridge from '../Bridge/utils/useGoToBridge'; -import SwapsController from '@metamask/swaps-controller'; import { MetaMetricsEvents } from '../../../core/Analytics'; import { getDecimalChainId } from '../../../util/networks'; import { useMetrics } from '../../../components/hooks/useMetrics'; @@ -84,6 +84,7 @@ const AssetOverview: React.FC = ({ const tokenBalances = useSelector(selectContractBalances); const chainId = useSelector((state: RootState) => selectChainId(state)); const ticker = useSelector((state: RootState) => selectTicker(state)); + const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId); const { data: prices = [], isLoading } = useTokenHistoricalPrices({ address: asset.isETH ? zeroAddress() : asset.address, @@ -96,12 +97,12 @@ const AssetOverview: React.FC = ({ const dispatch = useDispatch(); useEffect(() => { - const { SwapsController: SwapsControllerFromEngine } = Engine.context as { - SwapsController: SwapsController; - }; + const { SwapsController } = Engine.context; const fetchTokenWithCache = async () => { try { - await SwapsControllerFromEngine.fetchTokenWithCache(); + await SwapsController.fetchTokenWithCache({ + networkClientId: selectedNetworkClientId, + }); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { @@ -112,7 +113,7 @@ const AssetOverview: React.FC = ({ } }; fetchTokenWithCache(); - }, []); + }, [selectedNetworkClientId]); const onReceive = () => { navigation.navigate(Routes.QR_TAB_SWITCHER, { diff --git a/app/components/UI/Swaps/QuotesView.js b/app/components/UI/Swaps/QuotesView.js index b0e37a6e718..2376a3a1779 100644 --- a/app/components/UI/Swaps/QuotesView.js +++ b/app/components/UI/Swaps/QuotesView.js @@ -13,7 +13,7 @@ import IonicIcon from 'react-native-vector-icons/Ionicons'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import BigNumber from 'bignumber.js'; import { useNavigation, useRoute } from '@react-navigation/native'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { WalletDevice, TransactionStatus, @@ -95,6 +95,7 @@ import { } from '../../../util/address'; import { selectChainId, + selectSelectedNetworkClientId, selectTicker, } from '../../../selectors/networkController'; import { @@ -300,6 +301,7 @@ async function resetAndStartPolling({ destinationToken, sourceAmount, walletAddress, + networkClientId, }) { if (!sourceToken || !destinationToken) { return; @@ -312,8 +314,9 @@ async function resetAndStartPolling({ destinationToken, sourceAmount, walletAddress, + networkClientId, }); - await SwapsController.stopPollingAndResetState(); + await SwapsController.stopPollingAndResetState; await SwapsController.startFetchAndSetQuotes( fetchParams, fetchParams.metaData, @@ -764,6 +767,8 @@ function SwapsQuotesView({ } }, [error, navigation]); + const selectedNetworkClientId = selectSelectedNetworkClientId(); + const handleRetryFetchQuotes = useCallback(() => { if (error?.key === swapsUtils.SwapsError.QUOTES_EXPIRED_ERROR) { navigation.setParams({ leftAction: strings('navigation.back') }); @@ -778,6 +783,7 @@ function SwapsQuotesView({ destinationToken, sourceAmount, walletAddress: selectedAddress, + networkClientId: selectedNetworkClientId, }); } else { navigation.pop(); @@ -790,6 +796,7 @@ function SwapsQuotesView({ sourceAmount, selectedAddress, navigation, + selectedNetworkClientId, ]); const updateSwapsTransactions = useCallback( @@ -1011,7 +1018,9 @@ function SwapsQuotesView({ CHAIN_IDS.LINEA_SEPOLIA, ].includes(chainId) ) { - Logger.log('Delaying submitting trade tx to make Linea confirmation more likely',); + Logger.log( + 'Delaying submitting trade tx to make Linea confirmation more likely', + ); const waitPromise = new Promise((resolve) => setTimeout(resolve, 5000), ); @@ -2156,7 +2165,11 @@ function SwapsQuotesView({ )} - + {strings('swaps.swap')} diff --git a/app/components/UI/Swaps/SwapsLiveness.ts b/app/components/UI/Swaps/SwapsLiveness.ts index 41a53f63ccd..8a35cc44f88 100644 --- a/app/components/UI/Swaps/SwapsLiveness.ts +++ b/app/components/UI/Swaps/SwapsLiveness.ts @@ -1,4 +1,4 @@ -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { useCallback, useEffect } from 'react'; import { selectChainId } from '../../../selectors/networkController'; import { AppState } from 'react-native'; diff --git a/app/components/UI/Swaps/components/ApprovalTransactionEditionModal.js b/app/components/UI/Swaps/components/ApprovalTransactionEditionModal.js index b9eb5ab1cf4..aeff6e26239 100644 --- a/app/components/UI/Swaps/components/ApprovalTransactionEditionModal.js +++ b/app/components/UI/Swaps/components/ApprovalTransactionEditionModal.js @@ -4,7 +4,7 @@ import { StyleSheet } from 'react-native'; import { connect } from 'react-redux'; import Modal from 'react-native-modal'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import EditPermission from '../../../Views/confirmations/components/ApproveTransactionReview/EditPermission'; import { fromTokenMinimalUnitString, hexToBN } from '../../../../util/number'; diff --git a/app/components/UI/Swaps/components/LoadingAnimation/index.js b/app/components/UI/Swaps/components/LoadingAnimation/index.js index ec6a1363364..9b282d42517 100644 --- a/app/components/UI/Swaps/components/LoadingAnimation/index.js +++ b/app/components/UI/Swaps/components/LoadingAnimation/index.js @@ -5,8 +5,10 @@ import React, { useRef, useState, } from 'react'; +import { useSelector } from 'react-redux'; import { Animated, View, StyleSheet, Image } from 'react-native'; import PropTypes from 'prop-types'; +import { selectSelectedNetworkClientId } from '../../../../../selectors/networkController'; import Engine from '../../../../../core/Engine'; import Logger from '../../../../../util/Logger'; import Device from '../../../../../util/device'; @@ -129,6 +131,8 @@ function LoadingAnimation({ const [renderLogos, setRenderLogos] = useState(false); const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0); + const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId); + /* References */ const foxRef = useRef(); const foxHeadPan = useRef(new Animated.ValueXY(0, 0)).current; @@ -317,9 +321,11 @@ function LoadingAnimation({ return; } if (!aggregatorMetadata) { + const { SwapsController } = Engine.context; try { - const { SwapsController } = Engine.context; - await SwapsController.fetchAggregatorMetadataWithCache(); + await SwapsController.fetchAggregatorMetadataWithCache({ + networkClientId: selectedNetworkClientId, + }); } catch (error) { Logger.error( error, @@ -337,7 +343,7 @@ function LoadingAnimation({ setShouldStart(true); } })(); - }, [aggregatorMetadata, hasStarted]); + }, [aggregatorMetadata, hasStarted, selectedNetworkClientId]); /* Delay the logos rendering to avoid navigation transition lag */ useEffect(() => { diff --git a/app/components/UI/Swaps/index.js b/app/components/UI/Swaps/index.js index eeb33ec4e44..29bae115cf7 100644 --- a/app/components/UI/Swaps/index.js +++ b/app/components/UI/Swaps/index.js @@ -13,7 +13,7 @@ import { TouchableOpacity, InteractionManager, } from 'react-native'; -import { connect } from 'react-redux'; +import { connect, useSelector } from 'react-redux'; import { useNavigation, useRoute } from '@react-navigation/native'; import { View as AnimatableView } from 'react-native-animatable'; import IonicIcon from 'react-native-vector-icons/Ionicons'; @@ -27,7 +27,7 @@ import { safeNumberToBN, } from '../../../util/number'; import { safeToChecksumAddress } from '../../../util/address'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { MetaMetricsEvents } from '../../../core/Analytics'; import { @@ -70,6 +70,7 @@ import { selectChainId, selectNetworkConfigurations, selectProviderConfig, + selectSelectedNetworkClientId, } from '../../../selectors/networkController'; import { selectConversionRate, @@ -247,6 +248,8 @@ function SwapsAmountView({ hideTokenVerificationModal, ] = useModalHandler(false); + const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId); + useEffect(() => { navigation.setOptions(getSwapsAmountNavbar(navigation, route, colors)); }, [navigation, route, colors]); @@ -295,8 +298,12 @@ function SwapsAmountView({ (async () => { const { SwapsController } = Engine.context; try { - await SwapsController.fetchAggregatorMetadataWithCache(); - await SwapsController.fetchTopAssetsWithCache(); + await SwapsController.fetchAggregatorMetadataWithCache({ + networkClientId: selectSelectedNetworkClientId, + }); + await SwapsController.fetchTopAssetsWithCache({ + networkClientId: selectSelectedNetworkClientId, + }); } catch (error) { Logger.error( error, @@ -304,7 +311,7 @@ function SwapsAmountView({ ); } })(); - }, []); + }, [selectedNetworkClientId]); useEffect(() => { (async () => { @@ -318,7 +325,9 @@ function SwapsAmountView({ setInitialLoadingTokens(true); } setLoadingTokens(true); - await SwapsController.fetchTokenWithCache(); + await SwapsController.fetchTokenWithCache({ + networkClientId: selectedNetworkClientId, + }); setLoadingTokens(false); setInitialLoadingTokens(false); } catch (error) { @@ -331,7 +340,7 @@ function SwapsAmountView({ setInitialLoadingTokens(false); } })(); - }, [swapsControllerTokens, swapsTokens]); + }, [swapsControllerTokens, swapsTokens, selectedNetworkClientId]); const canSetAnInitialSourceToken = !isSourceSet && diff --git a/app/components/UI/Swaps/utils/index.js b/app/components/UI/Swaps/utils/index.js index 665562c3f55..186b9b586cc 100644 --- a/app/components/UI/Swaps/utils/index.js +++ b/app/components/UI/Swaps/utils/index.js @@ -1,6 +1,6 @@ import { useMemo } from 'react'; import BigNumber from 'bignumber.js'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { strings } from '../../../../../locales/i18n'; import AppConstants from '../../../../core/AppConstants'; import { NETWORKS_CHAIN_ID } from '../../../../constants/network'; @@ -118,6 +118,7 @@ export function getQuotesNavigationsParams(route) { * @param {object} options.destinationToken destinationToken object from tokens API * @param {string} sourceAmount Amount in minimal token units of sourceToken to be swapped * @param {string} fromAddress Current address attempting to swap + * @param {string} networkClientId Current network client ID */ export function getFetchParams({ slippage = 1, @@ -125,6 +126,7 @@ export function getFetchParams({ destinationToken, sourceAmount, walletAddress, + networkClientId, }) { return { slippage, @@ -135,6 +137,7 @@ export function getFetchParams({ metaData: { sourceTokenInfo: sourceToken, destinationTokenInfo: destinationToken, + networkClientId, }, }; } diff --git a/app/components/UI/Swaps/utils/useFetchTokenMetadata.js b/app/components/UI/Swaps/utils/useFetchTokenMetadata.js index cfcb3fc765e..dd3ce9e713b 100644 --- a/app/components/UI/Swaps/utils/useFetchTokenMetadata.js +++ b/app/components/UI/Swaps/utils/useFetchTokenMetadata.js @@ -1,6 +1,6 @@ import { useEffect, useState } from 'react'; import axios from 'axios'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; const defaultTokenMetadata = { valid: null, diff --git a/app/components/UI/TransactionElement/utils.js b/app/components/UI/TransactionElement/utils.js index 22b0e562005..5bb24168794 100644 --- a/app/components/UI/TransactionElement/utils.js +++ b/app/components/UI/TransactionElement/utils.js @@ -28,7 +28,7 @@ import { calculateEIP1559GasFeeHexes, } from '../../../util/transactions'; import { toChecksumAddress } from 'ethereumjs-util'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { isSwapsNativeAsset } from '../Swaps/utils'; import { toLowerCaseEquals } from '../../../util/general'; import Engine from '../../../core/Engine'; diff --git a/app/components/Views/Asset/index.js b/app/components/Views/Asset/index.js index 7327ebe78a3..95340337c63 100644 --- a/app/components/Views/Asset/index.js +++ b/app/components/Views/Asset/index.js @@ -1,4 +1,4 @@ -import { swapsUtils } from '@metamask/swaps-controller/'; +import { swapsUtils } from '@metamask-previews/swaps-controller/'; import PropTypes from 'prop-types'; import React, { PureComponent } from 'react'; import { diff --git a/app/components/Views/WalletActions/WalletActions.tsx b/app/components/Views/WalletActions/WalletActions.tsx index 9f97ee82df5..b65323e73a6 100644 --- a/app/components/Views/WalletActions/WalletActions.tsx +++ b/app/components/Views/WalletActions/WalletActions.tsx @@ -1,7 +1,7 @@ // Third party dependencies. import React, { useCallback, useMemo, useRef } from 'react'; import { View } from 'react-native'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { useDispatch, useSelector } from 'react-redux'; import { useNavigation } from '@react-navigation/native'; diff --git a/app/components/Views/confirmations/SendFlow/Amount/index.js b/app/components/Views/confirmations/SendFlow/Amount/index.js index f2bd09ddc3a..f757e53e7a1 100644 --- a/app/components/Views/confirmations/SendFlow/Amount/index.js +++ b/app/components/Views/confirmations/SendFlow/Amount/index.js @@ -95,7 +95,7 @@ import Routes from '../../../../../constants/navigation/Routes'; import { getRampNetworks } from '../../../../../reducers/fiatOrders'; import { swapsLivenessSelector } from '../../../../../reducers/swaps'; import { isSwapsAllowed } from '../../../../UI/Swaps/utils'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { regex } from '../../../../../util/regex'; import { AmountViewSelectorsIDs } from '../../../../../../e2e/selectors/SendFlow/AmountView.selectors'; import { isNetworkRampNativeTokenSupported } from '../../../../../components/UI/Ramp/utils'; diff --git a/app/core/Engine.ts b/app/core/Engine.ts index c844670d288..284ec802aca 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -118,7 +118,7 @@ import { import SwapsController, { swapsUtils, SwapsControllerState, -} from '@metamask/swaps-controller'; +} from '@metamask-previews/swaps-controller'; import { PPOMController, PPOMControllerActions, @@ -1626,7 +1626,6 @@ export class Engine { swapsUtils.LINEA_CHAIN_ID, swapsUtils.BASE_CHAIN_ID, ], - // @ts-expect-error TODO: Resolve new typing for restricted controller messenger messenger: this.controllerMessenger.getRestricted({ name: 'SwapsController', // TODO: allow these internal calls once GasFeeController @@ -1634,16 +1633,14 @@ export class Engine { // allowedActions: [ // 'GasFeeController:getEIP1559GasFeeEstimates', // ], - allowedActions: [ - 'NetworkController:findNetworkClientIdByChainId', - 'NetworkController:getNetworkClientById', - ], - allowedEvents: [], + allowedActions: ['NetworkController:getNetworkClientById'], + allowedEvents: ['NetworkController:networkDidChange'], }), // TODO: Remove once GasFeeController exports this action type fetchGasFeeEstimates: () => gasFeeController.fetchGasFeeEstimates(), // @ts-expect-error TODO: Resolve mismatch between gas fee and swaps controller types fetchEstimatedMultiLayerL1Fee, + pollCountLimit: AppConstants.SWAPS.POLL_COUNT_LIMIT, }), gasFeeController, approvalController, @@ -1924,8 +1921,7 @@ export class Engine { } configureControllersOnNetworkChange() { - const { AccountTrackerController, NetworkController, SwapsController } = - this.context; + const { AccountTrackerController, NetworkController } = this.context; const { provider } = NetworkController.getProviderAndBlockTracker(); // Skip configuration if this is called before the provider is initialized @@ -1934,13 +1930,6 @@ export class Engine { } provider.sendAsync = provider.sendAsync.bind(provider); - // @ts-expect-error TODO: Resolve mismatch between base-controller versions. - SwapsController.setProvider(provider, { - chainId: NetworkController.getNetworkClientById( - NetworkController?.state.selectedNetworkClientId, - ).configuration.chainId, - pollCountLimit: AppConstants.SWAPS.POLL_COUNT_LIMIT, - }); AccountTrackerController.refresh(); } diff --git a/app/reducers/swaps/utils.ts b/app/reducers/swaps/utils.ts index 880e33d60cc..5b9f1268af3 100644 --- a/app/reducers/swaps/utils.ts +++ b/app/reducers/swaps/utils.ts @@ -1,6 +1,6 @@ -import { FeatureFlags } from '@metamask/swaps-controller/dist/types'; +import { FeatureFlags } from '@metamask-previews/swaps-controller/dist/types'; import Device from '../../util/device'; -import { CHAIN_ID_TO_NAME_MAP } from '@metamask/swaps-controller/dist/constants'; +import { CHAIN_ID_TO_NAME_MAP } from '@metamask-previews/swaps-controller/dist/constants'; export const getChainFeatureFlags = ( featureFlags: FeatureFlags, diff --git a/app/selectors/types.ts b/app/selectors/types.ts index aa29131865e..6cf2cf5b31b 100644 --- a/app/selectors/types.ts +++ b/app/selectors/types.ts @@ -9,7 +9,7 @@ import { TokensControllerState, TokenBalancesControllerState, } from '@metamask/assets-controllers'; -import SwapsController from '@metamask/swaps-controller'; +import SwapsController from '@metamask-previews/swaps-controller'; import { NetworkState } from '@metamask/network-controller'; import { AddressBookControllerState } from '@metamask/address-book-controller'; import { BaseState } from '@metamask/base-controller'; diff --git a/app/util/test/initial-background-state.json b/app/util/test/initial-background-state.json index 1c7492d5c45..f5983ee52f4 100644 --- a/app/util/test/initial-background-state.json +++ b/app/util/test/initial-background-state.json @@ -268,7 +268,8 @@ "decimals": 0, "address": "", "symbol": "" - } + }, + "networkClientId": "mainnet" }, "topAggSavings": null, "aggregatorMetadata": null, diff --git a/app/util/transactions/index.js b/app/util/transactions/index.js index a04aa9f7ebf..0ff1bcc5e04 100644 --- a/app/util/transactions/index.js +++ b/app/util/transactions/index.js @@ -8,8 +8,11 @@ import { ERC721, ERC1155, } from '@metamask/controller-utils'; -import { isEIP1559Transaction, TransactionType } from '@metamask/transaction-controller'; -import { swapsUtils } from '@metamask/swaps-controller'; +import { + isEIP1559Transaction, + TransactionType, +} from '@metamask/transaction-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import Engine from '../../core/Engine'; import I18n, { strings } from '../../../locales/i18n'; import { safeToChecksumAddress } from '../address'; @@ -124,9 +127,15 @@ const reviewActionKeys = { [SET_APPROVE_FOR_ALL_ACTION_KEY]: strings( 'transactions.tx_review_set_approval_for_all', ), - [TransactionType.stakingClaim]: strings('transactions.tx_review_staking_claim'), - [TransactionType.stakingDeposit]: strings('transactions.tx_review_staking_deposit'), - [TransactionType.stakingUnstake]: strings('transactions.tx_review_staking_unstake'), + [TransactionType.stakingClaim]: strings( + 'transactions.tx_review_staking_claim', + ), + [TransactionType.stakingDeposit]: strings( + 'transactions.tx_review_staking_deposit', + ), + [TransactionType.stakingUnstake]: strings( + 'transactions.tx_review_staking_unstake', + ), }; /** @@ -145,9 +154,15 @@ const actionKeys = { [SET_APPROVE_FOR_ALL_ACTION_KEY]: strings( 'transactions.set_approval_for_all', ), - [TransactionType.stakingClaim]: strings('transactions.tx_review_staking_claim'), - [TransactionType.stakingDeposit]: strings('transactions.tx_review_staking_deposit'), - [TransactionType.stakingUnstake]: strings('transactions.tx_review_staking_unstake'), + [TransactionType.stakingClaim]: strings( + 'transactions.tx_review_staking_claim', + ), + [TransactionType.stakingDeposit]: strings( + 'transactions.tx_review_staking_deposit', + ), + [TransactionType.stakingUnstake]: strings( + 'transactions.tx_review_staking_unstake', + ), }; /** @@ -405,7 +420,13 @@ export async function getTransactionActionKey(transaction, chainId) { const txParams = transaction.txParams ?? transaction.transaction ?? {}; const { data, to } = txParams; - if ([TransactionType.stakingClaim, TransactionType.stakingDeposit, TransactionType.stakingUnstake].includes(type)) { + if ( + [ + TransactionType.stakingClaim, + TransactionType.stakingDeposit, + TransactionType.stakingUnstake, + ].includes(type) + ) { return type; } @@ -466,11 +487,11 @@ export async function getActionKey(tx, selectedAddress, ticker, chainId) { ? strings('transactions.self_sent_unit', { unit: currencySymbol }) : strings('transactions.self_sent_ether') : currencySymbol - ? strings('transactions.received_unit', { unit: currencySymbol }) - : strings('transactions.received_ether') + ? strings('transactions.received_unit', { unit: currencySymbol }) + : strings('transactions.received_ether') : currencySymbol - ? strings('transactions.sent_unit', { unit: currencySymbol }) - : strings('transactions.sent_ether'); + ? strings('transactions.sent_unit', { unit: currencySymbol }) + : strings('transactions.sent_ether'); } const transactionActionKey = actionKeys[actionKey]; @@ -1040,7 +1061,7 @@ export const parseTransactionEIP1559 = ( maxPriorityFeeNative, nativeCurrency, Boolean(maxPriorityFeePerGasTimesGasLimitHex) && - maxPriorityFeePerGasTimesGasLimitHex !== '0x0', + maxPriorityFeePerGasTimesGasLimitHex !== '0x0', ); const renderableMaxPriorityFeeConversion = formatCurrency( maxPriorityFeeConversion, @@ -1539,7 +1560,7 @@ export const getIsSwapApproveOrSwapTransaction = ( (swapsUtils.isValidContractAddress(chainId, to) || (data?.startsWith(APPROVE_FUNCTION_SIGNATURE) && decodeApproveData(data).spenderAddress?.toLowerCase() === - swapsUtils.getSwapsContractAddress(chainId))) + swapsUtils.getSwapsContractAddress(chainId))) ); }; diff --git a/app/util/transactions/index.test.ts b/app/util/transactions/index.test.ts index 76bef96a7bc..a3a62fdebf8 100644 --- a/app/util/transactions/index.test.ts +++ b/app/util/transactions/index.test.ts @@ -1,4 +1,4 @@ -import { swapsUtils } from '@metamask/swaps-controller'; +import { swapsUtils } from '@metamask-previews/swaps-controller'; import { BN } from 'ethereumjs-util'; /* eslint-disable-next-line import/no-namespace */ diff --git a/package.json b/package.json index c7c7f5b35f1..77389496854 100644 --- a/package.json +++ b/package.json @@ -189,7 +189,7 @@ "@metamask/snaps-utils": "^8.1.1", "@metamask/stake-sdk": "^0.2.13", "@metamask/swappable-obj-proxy": "^2.1.0", - "@metamask/swaps-controller": "^10.0.0", + "@metamask-previews/swaps-controller": "11.0.0-preview-8176e4502716cfe6450c2b73be6ee403b0cea072", "@metamask/transaction-controller": "^39.1.0", "@metamask/utils": "^9.2.1", "@ngraveio/bc-ur": "^1.1.6", diff --git a/yarn.lock b/yarn.lock index dde45e15ffc..2238b13688a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4341,6 +4341,22 @@ resolved "https://registry.yarnpkg.com/@mantine/hooks/-/hooks-7.8.0.tgz#fc32e07746689459c4b049dc581d1dbda5545686" integrity sha512-+70fkgjhVJeJ+nJqnburIM3UAsfvxat1Low9HMPobLbv64FIdB4Nzu5ct3qojNQ58r5sK01tg5UoFIJYslaVrg== +"@metamask-previews/swaps-controller@11.0.0-preview-8176e4502716cfe6450c2b73be6ee403b0cea072": + version "11.0.0-preview-8176e4502716cfe6450c2b73be6ee403b0cea072" + resolved "https://registry.yarnpkg.com/@metamask-previews/swaps-controller/-/swaps-controller-11.0.0-preview-8176e4502716cfe6450c2b73be6ee403b0cea072.tgz#c43f3c529911bf133a73382f7f872e74bf0e0ae4" + integrity sha512-Y+uJxvzgtSD9qm7u1Kh+kGAYHY5Qi9oVIbZNKxhZIpki6dTwDt8VDnzplybytTYMQEbsXdjJ5m5LFyl2Q/KF2Q== + dependencies: + "@ethersproject/contracts" "^5.7.0" + "@ethersproject/providers" "^5.7.0" + "@metamask/base-controller" "^7.0.1" + "@metamask/controller-utils" "^11.3.0" + "@metamask/eth-query" "^4.0.0" + "@metamask/utils" "^10.0.0" + async-mutex "^0.5.0" + bignumber.js "^9.0.1" + bn.js "^5.2.1" + human-standard-token-abi "^2.0.0" + "@metamask/abi-utils@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@metamask/abi-utils/-/abi-utils-1.2.0.tgz#068e1b0f5e423dfae96961e0e5276a7c1babc03a" @@ -4431,14 +4447,6 @@ "@metamask/utils" "^8.1.0" immer "^9.0.6" -"@metamask/base-controller@^5.0.0", "@metamask/base-controller@^5.0.2": - version "5.0.2" - resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-5.0.2.tgz#ab3584f67d9f2ff80958df21558e61650074e565" - integrity sha512-izOaXXnLz9OXbdika0ZvIDf24pgsWNPI02Lm0E4eMU61ICpV78bzQB7YyIbMtF6MWnItw1RnX9jN6zNEmp5pdA== - dependencies: - "@metamask/utils" "^8.3.0" - immer "^9.0.6" - "@metamask/base-controller@^6.0.0", "@metamask/base-controller@^6.0.2": version "6.0.3" resolved "https://registry.yarnpkg.com/@metamask/base-controller/-/base-controller-6.0.3.tgz#9bb4e74234c1de5f99842c343ffa053c08055db1" @@ -4489,21 +4497,6 @@ resolved "https://registry.yarnpkg.com/@metamask/contract-metadata/-/contract-metadata-2.5.0.tgz#33921fa9c15eb1863f55dcd5f75467ae15614ebb" integrity sha512-+j7jEcp0P1OUMEpa/OIwfJs/ahBC/akwgWxaRTSWX2SWABvlUKBVRMtslfL94Qj2wN2xw8xjaUy5nSHqrznqDA== -"@metamask/controller-utils@^10.0.0": - version "10.0.0" - resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-10.0.0.tgz#08f6576c1533ab919b1b15b640146e9598f732ea" - integrity sha512-vO6lwIr3VSkkR/A9VCzxcpgLJhzgMvUvaAU9SF8ulXIhRIh3Eur4VDcXtcKNGNB8oTZcKbKJrsmAJCVfPZQ+zQ== - dependencies: - "@ethereumjs/util" "^8.1.0" - "@metamask/eth-query" "^4.0.0" - "@metamask/ethjs-unit" "^0.3.0" - "@metamask/utils" "^8.3.0" - "@spruceid/siwe-parser" "2.1.0" - "@types/bn.js" "^5.1.5" - bn.js "^5.2.1" - eth-ens-namehash "^2.0.8" - fast-deep-equal "^3.1.3" - "@metamask/controller-utils@^11.0.0", "@metamask/controller-utils@^11.0.2", "@metamask/controller-utils@^11.3.0", "@metamask/controller-utils@^11.4.2", "@metamask/controller-utils@^11.4.3": version "11.4.3" resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-11.4.3.tgz#5763f0bbee2f3770c1ba42dd4869786afef849bd" @@ -4520,21 +4513,6 @@ eth-ens-namehash "^2.0.8" fast-deep-equal "^3.1.3" -"@metamask/controller-utils@^9.1.0": - version "9.1.0" - resolved "https://registry.yarnpkg.com/@metamask/controller-utils/-/controller-utils-9.1.0.tgz#436ff37d339df3f4b0f31458881c6f1b1002c945" - integrity sha512-17XQhyhR1bC7NjQHJF2KhxStVeoFW8liQ/Z526cI3uVcKOgYRxxDwBiRGs+xzv9XAm7f1W73W83wnb8fcBxlxg== - dependencies: - "@ethereumjs/util" "^8.1.0" - "@metamask/eth-query" "^4.0.0" - "@metamask/ethjs-unit" "^0.3.0" - "@metamask/utils" "^8.3.0" - "@spruceid/siwe-parser" "2.1.0" - "@types/bn.js" "^5.1.5" - bn.js "^5.2.1" - eth-ens-namehash "^2.0.8" - fast-deep-equal "^3.1.3" - "@metamask/design-tokens@^4.0.0": version "4.0.0" resolved "https://registry.yarnpkg.com/@metamask/design-tokens/-/design-tokens-4.0.0.tgz#3aad7e4da21c279374668e179c0b055d93aa0552" @@ -4848,23 +4826,6 @@ is-hex-prefixed "1.0.0" strip-hex-prefix "1.0.0" -"@metamask/gas-fee-controller@^15.1.2": - version "15.1.2" - resolved "https://registry.yarnpkg.com/@metamask/gas-fee-controller/-/gas-fee-controller-15.1.2.tgz#cb8d85906efa1ff42a159ec023287ff31a63e45b" - integrity sha512-9knWAuhWvz0XKLvjImgpjbF1umCs6gNG70dc09VvWlp9BNowrniIEDRzo7bcDGvAectE2Vp0rxaohgqY8c5AOA== - dependencies: - "@metamask/base-controller" "^5.0.2" - "@metamask/controller-utils" "^9.1.0" - "@metamask/eth-query" "^4.0.0" - "@metamask/ethjs-unit" "^0.3.0" - "@metamask/network-controller" "^18.1.0" - "@metamask/polling-controller" "^6.0.2" - "@metamask/utils" "^8.3.0" - "@types/bn.js" "^5.1.5" - "@types/uuid" "^8.3.0" - bn.js "^5.2.1" - uuid "^8.3.2" - "@metamask/gas-fee-controller@^18.0.0": version "18.0.0" resolved "https://registry.yarnpkg.com/@metamask/gas-fee-controller/-/gas-fee-controller-18.0.0.tgz#a6ac49fa1a637708d36bce9306407496bf61ccce" @@ -5025,26 +4986,6 @@ resolved "https://registry.yarnpkg.com/@metamask/mobile-provider/-/mobile-provider-3.0.0.tgz#8a6a5a0874c8cbe4b468f63dfc57117d207f9595" integrity sha512-XwFJk0rd9lAZR5xS3VC7ypEhD7DvZR2gi2Ch6PHnODIqeS9Te3OdVKK5+jHI4his8v/zs6LWdFdlRtx5/jL96w== -"@metamask/network-controller@^18.1.0": - version "18.1.3" - resolved "https://registry.yarnpkg.com/@metamask/network-controller/-/network-controller-18.1.3.tgz#0aa7dbaf06c7ccf1f381a151d13850eb32d197b0" - integrity sha512-B79qGwhdNcmGtYOQWMZXKVSt88dowyP4Nf979QEX0opYe6Z4eZMZnGBezdl74cAcezEiDE1ro6X8UahB11IOTg== - dependencies: - "@metamask/base-controller" "^5.0.2" - "@metamask/controller-utils" "^10.0.0" - "@metamask/eth-block-tracker" "^9.0.2" - "@metamask/eth-json-rpc-infura" "^9.1.0" - "@metamask/eth-json-rpc-middleware" "^12.1.1" - "@metamask/eth-json-rpc-provider" "^3.0.2" - "@metamask/eth-query" "^4.0.0" - "@metamask/json-rpc-engine" "^8.0.2" - "@metamask/rpc-errors" "^6.2.1" - "@metamask/swappable-obj-proxy" "^2.2.0" - "@metamask/utils" "^8.3.0" - async-mutex "^0.5.0" - immer "^9.0.6" - uuid "^8.3.2" - "@metamask/network-controller@^19.0.0": version "19.0.0" resolved "https://registry.yarnpkg.com/@metamask/network-controller/-/network-controller-19.0.0.tgz#83cb2e6f4f8f596126b47386e45d7cd5a349803d" @@ -5204,19 +5145,6 @@ fast-json-stable-stringify "^2.1.0" uuid "^8.3.2" -"@metamask/polling-controller@^6.0.2": - version "6.0.2" - resolved "https://registry.yarnpkg.com/@metamask/polling-controller/-/polling-controller-6.0.2.tgz#dbe3c7d6610729db0749d37ce0eebf846894bd0e" - integrity sha512-q8LsV9JhV+heyO+6IIOUyaT6SqQKbyZOopRvhFNcZa37yATiJbv7TqVxy3qynVgyddguKdCQQtnxlL49Lc7Q2Q== - dependencies: - "@metamask/base-controller" "^5.0.2" - "@metamask/controller-utils" "^9.1.0" - "@metamask/network-controller" "^18.1.0" - "@metamask/utils" "^8.3.0" - "@types/uuid" "^8.3.0" - fast-json-stable-stringify "^2.1.0" - uuid "^8.3.2" - "@metamask/polling-controller@^8.0.0": version "8.0.0" resolved "https://registry.yarnpkg.com/@metamask/polling-controller/-/polling-controller-8.0.0.tgz#4dedac3ce3821d9435562d3a43523d3161c8e089" @@ -5603,23 +5531,6 @@ resolved "https://registry.yarnpkg.com/@metamask/swappable-obj-proxy/-/swappable-obj-proxy-2.2.0.tgz#31b8e0ce57e28bf9847b3b24b214996f7748cc99" integrity sha512-0OjVwQtrrPFRGipw64yDUQA0CUXCK161LWCv2KlTTDZD8BKeWSNb0gbnpDI7HvhsJ0gki5gScZj1hF3ShDnBzA== -"@metamask/swaps-controller@^10.0.0": - version "10.0.0" - resolved "https://registry.yarnpkg.com/@metamask/swaps-controller/-/swaps-controller-10.0.0.tgz#4b6bd021bd071bec742f613542bb7f1a99d6c2ff" - integrity sha512-52sghQp1dxoAXo9LXfzHclHd7UheY3NXNqSLFNruxMxgzFEQKBKiqXoLxtQkNYfmV4AoP5bUpGeZ3wELVHG8Jw== - dependencies: - "@ethersproject/contracts" "^5.7.0" - "@ethersproject/providers" "^5.7.0" - "@metamask/base-controller" "^5.0.0" - "@metamask/controller-utils" "^10.0.0" - "@metamask/eth-query" "^4.0.0" - "@metamask/gas-fee-controller" "^15.1.2" - "@metamask/utils" "^8.3.0" - async-mutex "^0.5.0" - bignumber.js "^9.0.1" - bn.js "^5.2.1" - human-standard-token-abi "^2.0.0" - "@metamask/test-dapp@^8.9.0": version "8.9.0" resolved "https://registry.yarnpkg.com/@metamask/test-dapp/-/test-dapp-8.9.0.tgz#bac680e8f0007b3a11440f7e311674d6457d37ed"