Skip to content

Commit 14b8bf9

Browse files
committed
WIP - Bump swaps-controller
1 parent fec0c4e commit 14b8bf9

File tree

21 files changed

+124
-172
lines changed

21 files changed

+124
-172
lines changed

app/components/Nav/Main/RootRPCMethodsUI.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { BN } from 'ethereumjs-util';
2929
import Logger from '../../../util/Logger';
3030
import TransactionTypes from '../../../core/TransactionTypes';
31-
import { swapsUtils } from '@metamask/swaps-controller';
31+
import { swapsUtils } from '@metamask-previews/swaps-controller';
3232
import { query } from '@metamask/controller-utils';
3333
import BigNumber from 'bignumber.js';
3434
import { toLowerCaseEquals } from '../../../util/general';

app/components/UI/AssetOverview/AssetOverview.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import AppConstants from '../../../core/AppConstants';
99
import Engine from '../../../core/Engine';
1010
import {
1111
selectChainId,
12+
selectSelectedNetworkClientId,
1213
selectTicker,
1314
} from '../../../selectors/networkController';
1415
import {
@@ -45,7 +46,6 @@ import Routes from '../../../constants/navigation/Routes';
4546
import TokenDetails from './TokenDetails';
4647
import { RootState } from '../../../reducers';
4748
import useGoToBridge from '../Bridge/utils/useGoToBridge';
48-
import SwapsController from '@metamask/swaps-controller';
4949
import { MetaMetricsEvents } from '../../../core/Analytics';
5050
import { getDecimalChainId } from '../../../util/networks';
5151
import { useMetrics } from '../../../components/hooks/useMetrics';
@@ -84,6 +84,7 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
8484
const tokenBalances = useSelector(selectContractBalances);
8585
const chainId = useSelector((state: RootState) => selectChainId(state));
8686
const ticker = useSelector((state: RootState) => selectTicker(state));
87+
const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId);
8788

8889
const { data: prices = [], isLoading } = useTokenHistoricalPrices({
8990
address: asset.isETH ? zeroAddress() : asset.address,
@@ -96,12 +97,12 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
9697
const dispatch = useDispatch();
9798

9899
useEffect(() => {
99-
const { SwapsController: SwapsControllerFromEngine } = Engine.context as {
100-
SwapsController: SwapsController;
101-
};
100+
const { SwapsController } = Engine.context;
102101
const fetchTokenWithCache = async () => {
103102
try {
104-
await SwapsControllerFromEngine.fetchTokenWithCache();
103+
await SwapsController.fetchTokenWithCache({
104+
networkClientId: selectedNetworkClientId,
105+
});
105106
// TODO: Replace "any" with type
106107
// eslint-disable-next-line @typescript-eslint/no-explicit-any
107108
} catch (error: any) {
@@ -112,7 +113,7 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
112113
}
113114
};
114115
fetchTokenWithCache();
115-
}, []);
116+
}, [selectedNetworkClientId]);
116117

117118
const onReceive = () => {
118119
navigation.navigate(Routes.QR_TAB_SWITCHER, {

app/components/UI/Swaps/QuotesView.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import IonicIcon from 'react-native-vector-icons/Ionicons';
1313
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
1414
import BigNumber from 'bignumber.js';
1515
import { useNavigation, useRoute } from '@react-navigation/native';
16-
import { swapsUtils } from '@metamask/swaps-controller';
16+
import { swapsUtils } from '@metamask-previews/swaps-controller';
1717
import {
1818
WalletDevice,
1919
TransactionStatus,
@@ -95,6 +95,7 @@ import {
9595
} from '../../../util/address';
9696
import {
9797
selectChainId,
98+
selectSelectedNetworkClientId,
9899
selectTicker,
99100
} from '../../../selectors/networkController';
100101
import {
@@ -300,6 +301,7 @@ async function resetAndStartPolling({
300301
destinationToken,
301302
sourceAmount,
302303
walletAddress,
304+
networkClientId,
303305
}) {
304306
if (!sourceToken || !destinationToken) {
305307
return;
@@ -312,8 +314,9 @@ async function resetAndStartPolling({
312314
destinationToken,
313315
sourceAmount,
314316
walletAddress,
317+
networkClientId,
315318
});
316-
await SwapsController.stopPollingAndResetState();
319+
await SwapsController.stopPollingAndResetState;
317320
await SwapsController.startFetchAndSetQuotes(
318321
fetchParams,
319322
fetchParams.metaData,
@@ -764,6 +767,8 @@ function SwapsQuotesView({
764767
}
765768
}, [error, navigation]);
766769

770+
const selectedNetworkClientId = selectSelectedNetworkClientId();
771+
767772
const handleRetryFetchQuotes = useCallback(() => {
768773
if (error?.key === swapsUtils.SwapsError.QUOTES_EXPIRED_ERROR) {
769774
navigation.setParams({ leftAction: strings('navigation.back') });
@@ -778,6 +783,7 @@ function SwapsQuotesView({
778783
destinationToken,
779784
sourceAmount,
780785
walletAddress: selectedAddress,
786+
networkClientId: selectedNetworkClientId,
781787
});
782788
} else {
783789
navigation.pop();
@@ -790,6 +796,7 @@ function SwapsQuotesView({
790796
sourceAmount,
791797
selectedAddress,
792798
navigation,
799+
selectedNetworkClientId,
793800
]);
794801

795802
const updateSwapsTransactions = useCallback(
@@ -1011,7 +1018,9 @@ function SwapsQuotesView({
10111018
CHAIN_IDS.LINEA_SEPOLIA,
10121019
].includes(chainId)
10131020
) {
1014-
Logger.log('Delaying submitting trade tx to make Linea confirmation more likely',);
1021+
Logger.log(
1022+
'Delaying submitting trade tx to make Linea confirmation more likely',
1023+
);
10151024
const waitPromise = new Promise((resolve) =>
10161025
setTimeout(resolve, 5000),
10171026
);
@@ -2156,7 +2165,11 @@ function SwapsQuotesView({
21562165
</QuotesSummary.Body>
21572166
</QuotesSummary>
21582167
)}
2159-
<StyledButton type="confirm" onPress={handleCompleteSwap} disabled={unableToSwap || isHandlingSwap || isAnimating}>
2168+
<StyledButton
2169+
type="confirm"
2170+
onPress={handleCompleteSwap}
2171+
disabled={unableToSwap || isHandlingSwap || isAnimating}
2172+
>
21602173
{strings('swaps.swap')}
21612174
</StyledButton>
21622175
<TouchableOpacity onPress={handleTermsPress} style={styles.termsButton}>

app/components/UI/Swaps/SwapsLiveness.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { swapsUtils } from '@metamask/swaps-controller';
1+
import { swapsUtils } from '@metamask-previews/swaps-controller';
22
import { useCallback, useEffect } from 'react';
33
import { selectChainId } from '../../../selectors/networkController';
44
import { AppState } from 'react-native';

app/components/UI/Swaps/components/ApprovalTransactionEditionModal.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { StyleSheet } from 'react-native';
44
import { connect } from 'react-redux';
55
import Modal from 'react-native-modal';
66
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
7-
import { swapsUtils } from '@metamask/swaps-controller';
7+
import { swapsUtils } from '@metamask-previews/swaps-controller';
88

99
import EditPermission from '../../../Views/confirmations/components/ApproveTransactionReview/EditPermission';
1010
import { fromTokenMinimalUnitString, hexToBN } from '../../../../util/number';

app/components/UI/Swaps/components/LoadingAnimation/index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import React, {
55
useRef,
66
useState,
77
} from 'react';
8+
import { useSelector } from 'react-redux';
89
import { Animated, View, StyleSheet, Image } from 'react-native';
910
import PropTypes from 'prop-types';
11+
import { selectSelectedNetworkClientId } from '../../../../../selectors/networkController';
1012
import Engine from '../../../../../core/Engine';
1113
import Logger from '../../../../../util/Logger';
1214
import Device from '../../../../../util/device';
@@ -129,6 +131,8 @@ function LoadingAnimation({
129131
const [renderLogos, setRenderLogos] = useState(false);
130132
const [currentQuoteIndex, setCurrentQuoteIndex] = useState(0);
131133

134+
const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId);
135+
132136
/* References */
133137
const foxRef = useRef();
134138
const foxHeadPan = useRef(new Animated.ValueXY(0, 0)).current;
@@ -317,9 +321,11 @@ function LoadingAnimation({
317321
return;
318322
}
319323
if (!aggregatorMetadata) {
324+
const { SwapsController } = Engine.context;
320325
try {
321-
const { SwapsController } = Engine.context;
322-
await SwapsController.fetchAggregatorMetadataWithCache();
326+
await SwapsController.fetchAggregatorMetadataWithCache({
327+
networkClientId: selectedNetworkClientId,
328+
});
323329
} catch (error) {
324330
Logger.error(
325331
error,
@@ -337,7 +343,7 @@ function LoadingAnimation({
337343
setShouldStart(true);
338344
}
339345
})();
340-
}, [aggregatorMetadata, hasStarted]);
346+
}, [aggregatorMetadata, hasStarted, selectedNetworkClientId]);
341347

342348
/* Delay the logos rendering to avoid navigation transition lag */
343349
useEffect(() => {

app/components/UI/Swaps/index.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
TouchableOpacity,
1414
InteractionManager,
1515
} from 'react-native';
16-
import { connect } from 'react-redux';
16+
import { connect, useSelector } from 'react-redux';
1717
import { useNavigation, useRoute } from '@react-navigation/native';
1818
import { View as AnimatableView } from 'react-native-animatable';
1919
import IonicIcon from 'react-native-vector-icons/Ionicons';
@@ -27,7 +27,7 @@ import {
2727
safeNumberToBN,
2828
} from '../../../util/number';
2929
import { safeToChecksumAddress } from '../../../util/address';
30-
import { swapsUtils } from '@metamask/swaps-controller';
30+
import { swapsUtils } from '@metamask-previews/swaps-controller';
3131
import { MetaMetricsEvents } from '../../../core/Analytics';
3232

3333
import {
@@ -70,6 +70,7 @@ import {
7070
selectChainId,
7171
selectNetworkConfigurations,
7272
selectProviderConfig,
73+
selectSelectedNetworkClientId,
7374
} from '../../../selectors/networkController';
7475
import {
7576
selectConversionRate,
@@ -247,6 +248,8 @@ function SwapsAmountView({
247248
hideTokenVerificationModal,
248249
] = useModalHandler(false);
249250

251+
const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId);
252+
250253
useEffect(() => {
251254
navigation.setOptions(getSwapsAmountNavbar(navigation, route, colors));
252255
}, [navigation, route, colors]);
@@ -295,16 +298,20 @@ function SwapsAmountView({
295298
(async () => {
296299
const { SwapsController } = Engine.context;
297300
try {
298-
await SwapsController.fetchAggregatorMetadataWithCache();
299-
await SwapsController.fetchTopAssetsWithCache();
301+
await SwapsController.fetchAggregatorMetadataWithCache({
302+
networkClientId: selectSelectedNetworkClientId,
303+
});
304+
await SwapsController.fetchTopAssetsWithCache({
305+
networkClientId: selectSelectedNetworkClientId,
306+
});
300307
} catch (error) {
301308
Logger.error(
302309
error,
303310
'Swaps: Error while updating agg metadata and top assets in amount view',
304311
);
305312
}
306313
})();
307-
}, []);
314+
}, [selectedNetworkClientId]);
308315

309316
useEffect(() => {
310317
(async () => {
@@ -318,7 +325,7 @@ function SwapsAmountView({
318325
setInitialLoadingTokens(true);
319326
}
320327
setLoadingTokens(true);
321-
await SwapsController.fetchTokenWithCache();
328+
await SwapsController.fetchTokenWithCache({ networkClientId });
322329
setLoadingTokens(false);
323330
setInitialLoadingTokens(false);
324331
} catch (error) {
@@ -331,7 +338,7 @@ function SwapsAmountView({
331338
setInitialLoadingTokens(false);
332339
}
333340
})();
334-
}, [swapsControllerTokens, swapsTokens]);
341+
}, [swapsControllerTokens, swapsTokens, networkClientId]);
335342

336343
const canSetAnInitialSourceToken =
337344
!isSourceSet &&

app/components/UI/Swaps/utils/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react';
22
import BigNumber from 'bignumber.js';
3-
import { swapsUtils } from '@metamask/swaps-controller';
3+
import { swapsUtils } from '@metamask-previews/swaps-controller';
44
import { strings } from '../../../../../locales/i18n';
55
import AppConstants from '../../../../core/AppConstants';
66
import { NETWORKS_CHAIN_ID } from '../../../../constants/network';
@@ -118,13 +118,15 @@ export function getQuotesNavigationsParams(route) {
118118
* @param {object} options.destinationToken destinationToken object from tokens API
119119
* @param {string} sourceAmount Amount in minimal token units of sourceToken to be swapped
120120
* @param {string} fromAddress Current address attempting to swap
121+
* @param {string} networkClientId Current network client ID
121122
*/
122123
export function getFetchParams({
123124
slippage = 1,
124125
sourceToken,
125126
destinationToken,
126127
sourceAmount,
127128
walletAddress,
129+
networkClientId,
128130
}) {
129131
return {
130132
slippage,
@@ -135,6 +137,7 @@ export function getFetchParams({
135137
metaData: {
136138
sourceTokenInfo: sourceToken,
137139
destinationTokenInfo: destinationToken,
140+
networkClientId,
138141
},
139142
};
140143
}

app/components/UI/Swaps/utils/useFetchTokenMetadata.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from 'react';
22
import axios from 'axios';
3-
import { swapsUtils } from '@metamask/swaps-controller';
3+
import { swapsUtils } from '@metamask-previews/swaps-controller';
44

55
const defaultTokenMetadata = {
66
valid: null,

app/components/UI/TransactionElement/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
calculateEIP1559GasFeeHexes,
2929
} from '../../../util/transactions';
3030
import { toChecksumAddress } from 'ethereumjs-util';
31-
import { swapsUtils } from '@metamask/swaps-controller';
31+
import { swapsUtils } from '@metamask-previews/swaps-controller';
3232
import { isSwapsNativeAsset } from '../Swaps/utils';
3333
import { toLowerCaseEquals } from '../../../util/general';
3434
import Engine from '../../../core/Engine';

app/components/Views/Asset/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { swapsUtils } from '@metamask/swaps-controller/';
1+
import { swapsUtils } from '@metamask-previews/swaps-controller/';
22
import PropTypes from 'prop-types';
33
import React, { PureComponent } from 'react';
44
import {

app/components/Views/WalletActions/WalletActions.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Third party dependencies.
22
import React, { useCallback, useMemo, useRef } from 'react';
33
import { View } from 'react-native';
4-
import { swapsUtils } from '@metamask/swaps-controller';
4+
import { swapsUtils } from '@metamask-previews/swaps-controller';
55
import { useDispatch, useSelector } from 'react-redux';
66
import { useNavigation } from '@react-navigation/native';
77

app/components/Views/confirmations/SendFlow/Amount/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import Routes from '../../../../../constants/navigation/Routes';
9595
import { getRampNetworks } from '../../../../../reducers/fiatOrders';
9696
import { swapsLivenessSelector } from '../../../../../reducers/swaps';
9797
import { isSwapsAllowed } from '../../../../UI/Swaps/utils';
98-
import { swapsUtils } from '@metamask/swaps-controller';
98+
import { swapsUtils } from '@metamask-previews/swaps-controller';
9999
import { regex } from '../../../../../util/regex';
100100
import { AmountViewSelectorsIDs } from '../../../../../../e2e/selectors/SendFlow/AmountView.selectors';
101101
import { isNetworkRampNativeTokenSupported } from '../../../../../components/UI/Ramp/utils';

0 commit comments

Comments
 (0)