Skip to content

Commit

Permalink
fix: not properly adding dest network and token
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Oct 8, 2024
1 parent d030323 commit e881646
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
26 changes: 16 additions & 10 deletions ui/ducks/bridge/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Hex } from '@metamask/utils';
import { TransactionType } from '@metamask/transaction-controller';
import { useHistory } from 'react-router-dom';
import { BigNumber } from 'bignumber.js';
import { NetworkConfiguration } from '@metamask/network-controller';
import {
BridgeBackgroundAction,
BridgeUserAction,
Expand Down Expand Up @@ -151,13 +152,10 @@ export const submitBridgeTransaction = (

if (networkAndAccountSupports1559) {
const gasFeeEstimates = getGasFeeEstimates(state);
const {
high: { suggestedMaxFeePerGas, suggestedMaxPriorityFeePerGas },
// estimatedBaseFee = '0',
} = gasFeeEstimates;
// decEstimatedBaseFee = decGWEIToHexWEI(estimatedBaseFee);
maxFeePerGas = decGWEIToHexWEI(suggestedMaxFeePerGas);
maxPriorityFeePerGas = decGWEIToHexWEI(suggestedMaxPriorityFeePerGas);
// decEstimatedBaseFee = gasFeeEstimates.high.estimatedBaseFee;
maxFeePerGas = gasFeeEstimates?.high?.suggestedMaxFeePerGas;
maxPriorityFeePerGas =
gasFeeEstimates?.high?.suggestedMaxPriorityFeePerGas;
// baseAndPriorityFeePerGas = addHexes(
// decEstimatedBaseFee,
// maxPriorityFeePerGas,
Expand Down Expand Up @@ -398,17 +396,25 @@ export const submitBridgeTransaction = (
.toPrefixedHexString()
.toLowerCase() as `0x${string}`;
const networkConfigurations = getNetworkConfigurationsByChainId(state);
const destNetworkConfig = networkConfigurations[hexDestChainId];
const foundDestNetworkConfig: NetworkConfiguration | undefined =
networkConfigurations[hexDestChainId];
let addedDestNetworkConfig: NetworkConfiguration | undefined;

// If user has not added the network in MetaMask, add it for them silently
if (!destNetworkConfig) {
if (!foundDestNetworkConfig) {
const featuredRpc = FEATURED_RPCS.find(
(rpc) => rpc.chainId === hexDestChainId,
);
if (!featuredRpc) {
throw new Error('No featured RPC found');
}
await dispatch(addNetwork(featuredRpc));
addedDestNetworkConfig = await dispatch(addNetwork(featuredRpc));
}

const destNetworkConfig =
foundDestNetworkConfig || addedDestNetworkConfig;
if (!destNetworkConfig) {
throw new Error('No destination network configuration found');
}

// Add the token after network is guaranteed to exist
Expand Down
7 changes: 6 additions & 1 deletion ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,12 @@ export function createRetryTransaction(

export function addNetwork(
networkConfiguration: AddNetworkFields | UpdateNetworkFields,
): ThunkAction<Promise<void>, MetaMaskReduxState, unknown, AnyAction> {
): ThunkAction<
Promise<NetworkConfiguration>,
MetaMaskReduxState,
unknown,
AnyAction
> {
return async (dispatch: MetaMaskReduxDispatch) => {
log.debug(`background.addNetwork`, networkConfiguration);
try {
Expand Down

0 comments on commit e881646

Please sign in to comment.