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

chore: Bump @metamask/swaps-controller to 12.0.0 #12378

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
14 changes: 8 additions & 6 deletions app/components/UI/AssetOverview/AssetOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import AppConstants from '../../../core/AppConstants';
import Engine from '../../../core/Engine';
import {
selectChainId,
selectNetworkClientId,
selectTicker,
selectNativeCurrencyByChainId,
} from '../../../selectors/networkController';
Expand Down Expand Up @@ -58,7 +59,7 @@ import Routes from '../../../constants/navigation/Routes';
import TokenDetails from './TokenDetails';
import { RootState } from '../../../reducers';
import useGoToBridge from '../Bridge/utils/useGoToBridge';
import SwapsController, { swapsUtils } from '@metamask/swaps-controller';
import { swapsUtils } from '@metamask/swaps-controller';
import { MetaMetricsEvents } from '../../../core/Analytics';
import {
getDecimalChainId,
Expand Down Expand Up @@ -114,6 +115,7 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
? (asset.chainId as Hex)
: selectedChainId;
const ticker = isPortfolioViewEnabled() ? nativeCurrency : selectedTicker;
const selectedNetworkClientId = useSelector(selectNetworkClientId);

let currentAddress: Hex;

Expand All @@ -136,12 +138,12 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
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) {
Expand All @@ -152,7 +154,7 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
}
};
fetchTokenWithCache();
}, []);
}, [selectedNetworkClientId]);

const onReceive = () => {
navigation.navigate(Routes.QR_TAB_SWITCHER, {
Expand Down
14 changes: 11 additions & 3 deletions app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TouchableOpacity,
Linking,
} from 'react-native';
import { connect } from 'react-redux';
import { connect, useSelector } from 'react-redux';
import IonicIcon from 'react-native-vector-icons/Ionicons';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import BigNumber from 'bignumber.js';
Expand Down Expand Up @@ -96,7 +96,7 @@ import {
import {
selectChainId,
selectIsEIP1559Network,
selectNetworkClientId,
selectSelectedNetworkClientId,
selectTicker,
} from '../../../selectors/networkController';
import {
Expand Down Expand Up @@ -304,6 +304,7 @@ async function resetAndStartPolling({
destinationToken,
sourceAmount,
walletAddress,
networkClientId,
}) {
if (!sourceToken || !destinationToken) {
return;
Expand All @@ -316,6 +317,7 @@ async function resetAndStartPolling({
destinationToken,
sourceAmount,
walletAddress,
networkClientId,
});
await SwapsController.stopPollingAndResetState();
await SwapsController.startFetchAndSetQuotes(
Expand Down Expand Up @@ -762,6 +764,8 @@ function SwapsQuotesView({
}
}, [error, navigation]);

const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId);

const handleRetryFetchQuotes = useCallback(() => {
if (error?.key === swapsUtils.SwapsError.QUOTES_EXPIRED_ERROR) {
navigation.setParams({ leftAction: strings('navigation.back') });
Expand All @@ -776,6 +780,7 @@ function SwapsQuotesView({
destinationToken,
sourceAmount,
walletAddress: selectedAddress,
networkClientId: selectedNetworkClientId,
});
} else {
navigation.pop();
Expand All @@ -788,6 +793,7 @@ function SwapsQuotesView({
sourceAmount,
selectedAddress,
navigation,
selectedNetworkClientId,
]);

const updateSwapsTransactions = useCallback(
Expand Down Expand Up @@ -1396,6 +1402,7 @@ function SwapsQuotesView({
destinationToken,
sourceAmount,
walletAddress: selectedAddress,
networkClientId: selectedNetworkClientId,
});

return () => {
Expand All @@ -1409,6 +1416,7 @@ function SwapsQuotesView({
slippage,
sourceAmount,
sourceToken.address,
selectedNetworkClientId,
]);

/** selectedQuote alert effect */
Expand Down Expand Up @@ -2384,7 +2392,7 @@ SwapsQuotesView.propTypes = {
const mapStateToProps = (state) => ({
accounts: selectAccounts(state),
chainId: selectChainId(state),
networkClientId: selectNetworkClientId(state),
networkClientId: selectSelectedNetworkClientId(state),
ticker: selectTicker(state),
balances: selectContractBalances(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
Expand Down
10 changes: 9 additions & 1 deletion app/components/UI/Swaps/QuotesView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../../../util/test/accountsControllerTestUtils';
import { SwapsViewSelectors } from '../../../../e2e/selectors/swaps/SwapsView.selectors';
import Engine from '../../../core/Engine';
import { RpcEndpointType } from '@metamask/network-controller';

jest.mock('../../../core/Engine', () => ({
context: {
Expand Down Expand Up @@ -203,7 +204,14 @@ const mockInitialState: DeepPartial<RootState> = {
defaultRpcEndpointIndex: 0,
name: 'Ethereum Mainnet',
nativeCurrency: 'ETH',
rpcEndpoints: [],
rpcEndpoints: [
{
name: 'Ethereum Mainnet',
networkClientId: 'mainnet',
type: RpcEndpointType.Infura,
url: 'https://mainnet.infura.io/v3/{infuraProjectId}',
},
],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ exports[`QuotesView should render quote screen 1`] = `
"width": 5,
},
{
"backgroundColor": "transparent",
"borderColor": "#bbc0c5",
"borderWidth": 1,
"backgroundColor": "#3cc29e",
},
]
}
Expand All @@ -215,7 +213,7 @@ exports[`QuotesView should render quote screen 1`] = `
}
}
>
Private Network
Ethereum Main Network
</Text>
</View>
</TouchableOpacity>
Expand Down
Loading
Loading