Skip to content

Commit

Permalink
Merge branch 'main' into fix/fix-assetOptions-bottom-sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri authored Jan 8, 2025
2 parents 61551d4 + 4449dd5 commit d8d5a3d
Show file tree
Hide file tree
Showing 19 changed files with 1,972 additions and 80 deletions.
16 changes: 9 additions & 7 deletions app/components/UI/AssetOverview/AssetOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import AppConstants from '../../../core/AppConstants';
import Engine from '../../../core/Engine';
import {
selectChainId,
selectTicker,
selectNativeCurrencyByChainId,
selectSelectedNetworkClientId,
selectTicker,
} from '../../../selectors/networkController';
import {
selectConversionRate,
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(selectSelectedNetworkClientId);

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 @@ -1412,6 +1418,7 @@ function SwapsQuotesView({
destinationToken,
sourceAmount,
walletAddress: selectedAddress,
networkClientId: selectedNetworkClientId,
});

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

/** selectedQuote alert effect */
Expand Down Expand Up @@ -2403,7 +2411,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 @@ -197,7 +197,7 @@ exports[`QuotesView should render quote screen 1`] = `
}
}
>
Private Network
Ethereum Main Network
</Text>
</View>
</TouchableOpacity>
Expand Down
Loading

0 comments on commit d8d5a3d

Please sign in to comment.