diff --git a/ui/ducks/bridge/actions.ts b/ui/ducks/bridge/actions.ts index 20f89c12fbb4..aa84aa886e27 100644 --- a/ui/ducks/bridge/actions.ts +++ b/ui/ducks/bridge/actions.ts @@ -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, @@ -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, @@ -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 diff --git a/ui/store/actions.ts b/ui/store/actions.ts index c4bed2665a6b..256c27d2d7d9 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -2418,7 +2418,12 @@ export function createRetryTransaction( export function addNetwork( networkConfiguration: AddNetworkFields | UpdateNetworkFields, -): ThunkAction, MetaMaskReduxState, unknown, AnyAction> { +): ThunkAction< + Promise, + MetaMaskReduxState, + unknown, + AnyAction +> { return async (dispatch: MetaMaskReduxDispatch) => { log.debug(`background.addNetwork`, networkConfiguration); try {