1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Swaps / STX improvements (#14622)

This commit is contained in:
Daniel 2022-05-09 18:48:14 +02:00 committed by GitHub
parent 9e401b14bf
commit 2bd7127433
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 104 additions and 40 deletions

View File

@ -19,6 +19,11 @@ import {
SWAPS_CHAINID_CONTRACT_ADDRESS_MAP, SWAPS_CHAINID_CONTRACT_ADDRESS_MAP,
} from '../../../shared/constants/swaps'; } from '../../../shared/constants/swaps';
import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas'; import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas';
import {
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
FALLBACK_SMART_TRANSACTIONS_DEADLINE,
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
} from '../../../shared/constants/smartTransactions';
import { isSwapsDefaultTokenAddress } from '../../../shared/modules/swaps.utils'; import { isSwapsDefaultTokenAddress } from '../../../shared/modules/swaps.utils';
@ -41,8 +46,6 @@ const POLL_COUNT_LIMIT = 3;
// If for any reason the MetaSwap API fails to provide a refresh time, // If for any reason the MetaSwap API fails to provide a refresh time,
// provide a reasonable fallback to avoid further errors // provide a reasonable fallback to avoid further errors
const FALLBACK_QUOTE_REFRESH_TIME = MINUTE; const FALLBACK_QUOTE_REFRESH_TIME = MINUTE;
const FALLBACK_SMART_TRANSACTION_REFRESH_TIME = SECOND * 10;
const FALLBACK_SMART_TRANSACTIONS_DEADLINE = 180;
function calculateGasEstimateWithRefund( function calculateGasEstimateWithRefund(
maxGas = MAX_GAS_LIMIT, maxGas = MAX_GAS_LIMIT,
@ -86,8 +89,9 @@ const initialState = {
saveFetchedQuotes: false, saveFetchedQuotes: false,
swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME, swapsQuoteRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
swapsQuotePrefetchingRefreshTime: FALLBACK_QUOTE_REFRESH_TIME, swapsQuotePrefetchingRefreshTime: FALLBACK_QUOTE_REFRESH_TIME,
swapsStxBatchStatusRefreshTime: FALLBACK_SMART_TRANSACTION_REFRESH_TIME, swapsStxBatchStatusRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxGetTransactionsRefreshTime: FALLBACK_SMART_TRANSACTION_REFRESH_TIME, swapsStxGetTransactionsRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxMaxFeeMultiplier: FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
swapsFeatureFlags: {}, swapsFeatureFlags: {},
}, },
}; };
@ -129,13 +133,13 @@ export default class SwapsController {
}); });
} }
async fetchSwapsRefreshRates(chainId) { async fetchSwapsNetworkConfig(chainId) {
const response = await fetchWithCache( const response = await fetchWithCache(
getBaseApi('network', chainId), getBaseApi('network', chainId),
{ method: 'GET' }, { method: 'GET' },
{ cacheRefreshTime: 600000 }, { cacheRefreshTime: 600000 },
); );
const { refreshRates } = response || {}; const { refreshRates, parameters = {} } = response || {};
if ( if (
!refreshRates || !refreshRates ||
typeof refreshRates.quotes !== 'number' || typeof refreshRates.quotes !== 'number' ||
@ -152,35 +156,39 @@ export default class SwapsController {
stxGetTransactions: refreshRates.stxGetTransactions * 1000, stxGetTransactions: refreshRates.stxGetTransactions * 1000,
stxBatchStatus: refreshRates.stxBatchStatus * 1000, stxBatchStatus: refreshRates.stxBatchStatus * 1000,
stxStatusDeadline: refreshRates.stxStatusDeadline, stxStatusDeadline: refreshRates.stxStatusDeadline,
stxMaxFeeMultiplier: parameters.stxMaxFeeMultiplier,
}; };
} }
// Sets the refresh rate for quote updates from the MetaSwap API // Sets the network config from the MetaSwap API.
async _setSwapsRefreshRates() { async _setSwapsNetworkConfig() {
const chainId = this._getCurrentChainId(); const chainId = this._getCurrentChainId();
let swapsRefreshRates; let swapsNetworkConfig;
try { try {
swapsRefreshRates = await this.fetchSwapsRefreshRates(chainId); swapsNetworkConfig = await this.fetchSwapsNetworkConfig(chainId);
} catch (e) { } catch (e) {
console.error('Request for swaps quote refresh time failed: ', e); console.error('Request for Swaps network config failed: ', e);
} }
const { swapsState: latestSwapsState } = this.store.getState(); const { swapsState: latestSwapsState } = this.store.getState();
this.store.updateState({ this.store.updateState({
swapsState: { swapsState: {
...latestSwapsState, ...latestSwapsState,
swapsQuoteRefreshTime: swapsQuoteRefreshTime:
swapsRefreshRates?.quotes || FALLBACK_QUOTE_REFRESH_TIME, swapsNetworkConfig?.quotes || FALLBACK_QUOTE_REFRESH_TIME,
swapsQuotePrefetchingRefreshTime: swapsQuotePrefetchingRefreshTime:
swapsRefreshRates?.quotesPrefetching || FALLBACK_QUOTE_REFRESH_TIME, swapsNetworkConfig?.quotesPrefetching || FALLBACK_QUOTE_REFRESH_TIME,
swapsStxGetTransactionsRefreshTime: swapsStxGetTransactionsRefreshTime:
swapsRefreshRates?.stxGetTransactions || swapsNetworkConfig?.stxGetTransactions ||
FALLBACK_SMART_TRANSACTION_REFRESH_TIME, FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxBatchStatusRefreshTime: swapsStxBatchStatusRefreshTime:
swapsRefreshRates?.stxBatchStatus || swapsNetworkConfig?.stxBatchStatus ||
FALLBACK_SMART_TRANSACTION_REFRESH_TIME, FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxStatusDeadline: swapsStxStatusDeadline:
swapsRefreshRates?.stxStatusDeadline || swapsNetworkConfig?.stxStatusDeadline ||
FALLBACK_SMART_TRANSACTIONS_DEADLINE, FALLBACK_SMART_TRANSACTIONS_DEADLINE,
swapsStxMaxFeeMultiplier:
swapsNetworkConfig?.stxMaxFeeMultiplier ||
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
}, },
}); });
} }
@ -253,7 +261,7 @@ export default class SwapsController {
this._fetchTradesInfo(fetchParams, { this._fetchTradesInfo(fetchParams, {
...fetchParamsMetaData, ...fetchParamsMetaData,
}), }),
this._setSwapsRefreshRates(), this._setSwapsNetworkConfig(),
]); ]);
const { const {

View File

@ -13,6 +13,10 @@ import { ETH_SWAPS_TOKEN_OBJECT } from '../../../shared/constants/swaps';
import { createTestProviderTools } from '../../../test/stub/provider'; import { createTestProviderTools } from '../../../test/stub/provider';
import { SECOND } from '../../../shared/constants/time'; import { SECOND } from '../../../shared/constants/time';
import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas'; import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas';
import {
FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
} from '../../../shared/constants/smartTransactions';
import SwapsController, { utils } from './swaps'; import SwapsController, { utils } from './swaps';
import { NETWORK_EVENTS } from './network'; import { NETWORK_EVENTS } from './network';
@ -134,8 +138,9 @@ const EMPTY_INIT_STATE = {
swapsFeatureFlags: {}, swapsFeatureFlags: {},
swapsQuoteRefreshTime: 60000, swapsQuoteRefreshTime: 60000,
swapsQuotePrefetchingRefreshTime: 60000, swapsQuotePrefetchingRefreshTime: 60000,
swapsStxBatchStatusRefreshTime: 10000, swapsStxBatchStatusRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxGetTransactionsRefreshTime: 10000, swapsStxGetTransactionsRefreshTime: FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME,
swapsStxMaxFeeMultiplier: FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER,
swapsUserFeeLevel: '', swapsUserFeeLevel: '',
saveFetchedQuotes: false, saveFetchedQuotes: false,
}, },

View File

@ -18,10 +18,12 @@ import {
getChainType, getChainType,
} from '../../lib/util'; } from '../../lib/util';
import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/helpers/constants/error-keys'; import { TRANSACTION_NO_CONTRACT_ERROR_KEY } from '../../../../ui/helpers/constants/error-keys';
import { calcGasTotal } from '../../../../ui/pages/send/send.utils';
import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/pages/swaps/swaps.util'; import { getSwapsTokensReceivedFromTxMeta } from '../../../../ui/pages/swaps/swaps.util';
import { import {
hexWEIToDecGWEI, hexWEIToDecGWEI,
decimalToHex, decimalToHex,
hexWEIToDecETH,
} from '../../../../ui/helpers/utils/conversions.util'; } from '../../../../ui/helpers/utils/conversions.util';
import { import {
TRANSACTION_STATUSES, TRANSACTION_STATUSES,
@ -1877,6 +1879,30 @@ export default class TransactionController extends EventEmitter {
this.memStore.updateState({ unapprovedTxs, currentNetworkTxList }); this.memStore.updateState({ unapprovedTxs, currentNetworkTxList });
} }
_calculateTransactionsCost(txMeta, approvalTxMeta) {
let approvalGasCost = '0x0';
if (approvalTxMeta?.txReceipt) {
approvalGasCost = calcGasTotal(
approvalTxMeta.txReceipt.gasUsed,
approvalTxMeta.txReceipt.effectiveGasPrice,
);
}
const tradeGasCost = calcGasTotal(
txMeta.txReceipt.gasUsed,
txMeta.txReceipt.effectiveGasPrice,
);
const tradeAndApprovalGasCost = new BigNumber(tradeGasCost, 16)
.plus(approvalGasCost, 16)
.toString(16);
return {
approvalGasCostInEth: Number(hexWEIToDecETH(approvalGasCost)),
tradeGasCostInEth: Number(hexWEIToDecETH(tradeGasCost)),
tradeAndApprovalGasCostInEth: Number(
hexWEIToDecETH(tradeAndApprovalGasCost),
),
};
}
_trackSwapsMetrics(txMeta, approvalTxMeta) { _trackSwapsMetrics(txMeta, approvalTxMeta) {
if (this._getParticipateInMetrics() && txMeta.swapMetaData) { if (this._getParticipateInMetrics() && txMeta.swapMetaData) {
if (txMeta.txReceipt.status === '0x0') { if (txMeta.txReceipt.status === '0x0') {
@ -1911,6 +1937,11 @@ export default class TransactionController extends EventEmitter {
.round(2)}%` .round(2)}%`
: null; : null;
const transactionsCost = this._calculateTransactionsCost(
txMeta,
approvalTxMeta,
);
this._trackMetaMetricsEvent({ this._trackMetaMetricsEvent({
event: 'Swap Completed', event: 'Swap Completed',
category: EVENT.CATEGORIES.SWAPS, category: EVENT.CATEGORIES.SWAPS,
@ -1919,6 +1950,10 @@ export default class TransactionController extends EventEmitter {
token_to_amount_received: tokensReceived, token_to_amount_received: tokensReceived,
quote_vs_executionRatio: quoteVsExecutionRatio, quote_vs_executionRatio: quoteVsExecutionRatio,
estimated_vs_used_gasRatio: estimatedVsUsedGasRatio, estimated_vs_used_gasRatio: estimatedVsUsedGasRatio,
approval_gas_cost_in_eth: transactionsCost.approvalGasCostInEth,
trade_gas_cost_in_eth: transactionsCost.tradeGasCostInEth,
trade_and_approval_gas_cost_in_eth:
transactionsCost.tradeAndApprovalGasCostInEth,
}, },
}); });
} }

View File

@ -0,0 +1,5 @@
import { SECOND } from './time';
export const FALLBACK_SMART_TRANSACTIONS_REFRESH_TIME = SECOND * 10;
export const FALLBACK_SMART_TRANSACTIONS_DEADLINE = 180;
export const FALLBACK_SMART_TRANSACTIONS_MAX_FEE_MULTIPLIER = 2;

View File

@ -445,13 +445,14 @@ export const getSmartTransactionEstimatedGas = (state) => {
return state.metamask.smartTransactionsState?.estimatedGas; return state.metamask.smartTransactionsState?.estimatedGas;
}; };
export const getSwapsRefreshStates = (state) => { export const getSwapsNetworkConfig = (state) => {
const { const {
swapsQuoteRefreshTime, swapsQuoteRefreshTime,
swapsQuotePrefetchingRefreshTime, swapsQuotePrefetchingRefreshTime,
swapsStxGetTransactionsRefreshTime, swapsStxGetTransactionsRefreshTime,
swapsStxBatchStatusRefreshTime, swapsStxBatchStatusRefreshTime,
swapsStxStatusDeadline, swapsStxStatusDeadline,
swapsStxMaxFeeMultiplier,
} = state.metamask.swapsState; } = state.metamask.swapsState;
return { return {
quoteRefreshTime: swapsQuoteRefreshTime, quoteRefreshTime: swapsQuoteRefreshTime,
@ -459,6 +460,7 @@ export const getSwapsRefreshStates = (state) => {
stxGetTransactionsRefreshTime: swapsStxGetTransactionsRefreshTime, stxGetTransactionsRefreshTime: swapsStxGetTransactionsRefreshTime,
stxBatchStatusRefreshTime: swapsStxBatchStatusRefreshTime, stxBatchStatusRefreshTime: swapsStxBatchStatusRefreshTime,
stxStatusDeadline: swapsStxStatusDeadline, stxStatusDeadline: swapsStxStatusDeadline,
stxMaxFeeMultiplier: swapsStxMaxFeeMultiplier,
}; };
}; };
@ -855,12 +857,12 @@ export const signAndSendSwapsSmartTransaction = ({
const { metaData, value: swapTokenValue, slippage } = fetchParams; const { metaData, value: swapTokenValue, slippage } = fetchParams;
const { sourceTokenInfo = {}, destinationTokenInfo = {} } = metaData; const { sourceTokenInfo = {}, destinationTokenInfo = {} } = metaData;
const usedQuote = getUsedQuote(state); const usedQuote = getUsedQuote(state);
const swapsRefreshStates = getSwapsRefreshStates(state); const swapsNetworkConfig = getSwapsNetworkConfig(state);
const chainId = getCurrentChainId(state); const chainId = getCurrentChainId(state);
dispatch( dispatch(
setSmartTransactionsRefreshInterval( setSmartTransactionsRefreshInterval(
swapsRefreshStates?.stxBatchStatusRefreshTime, swapsNetworkConfig?.stxBatchStatusRefreshTime,
), ),
); );

View File

@ -12,7 +12,7 @@ import {
getSmartTransactionsOptInStatus, getSmartTransactionsOptInStatus,
getSmartTransactionsEnabled, getSmartTransactionsEnabled,
getCurrentSmartTransactionsEnabled, getCurrentSmartTransactionsEnabled,
getSwapsRefreshStates, getSwapsNetworkConfig,
cancelSwapsSmartTransaction, cancelSwapsSmartTransaction,
} from '../../../ducks/swaps/swaps'; } from '../../../ducks/swaps/swaps';
import { import {
@ -71,7 +71,7 @@ export default function SmartTransactionStatus() {
const smartTransactionsOptInStatus = useSelector( const smartTransactionsOptInStatus = useSelector(
getSmartTransactionsOptInStatus, getSmartTransactionsOptInStatus,
); );
const swapsRefreshRates = useSelector(getSwapsRefreshStates); const swapsNetworkConfig = useSelector(getSwapsNetworkConfig);
const smartTransactionsEnabled = useSelector(getSmartTransactionsEnabled); const smartTransactionsEnabled = useSelector(getSmartTransactionsEnabled);
const currentSmartTransactionsEnabled = useSelector( const currentSmartTransactionsEnabled = useSelector(
getCurrentSmartTransactionsEnabled, getCurrentSmartTransactionsEnabled,
@ -89,7 +89,7 @@ export default function SmartTransactionStatus() {
} }
const [timeLeftForPendingStxInSec, setTimeLeftForPendingStxInSec] = useState( const [timeLeftForPendingStxInSec, setTimeLeftForPendingStxInSec] = useState(
swapsRefreshRates.stxStatusDeadline, swapsNetworkConfig.stxStatusDeadline,
); );
const sensitiveProperties = { const sensitiveProperties = {
@ -139,13 +139,13 @@ export default function SmartTransactionStatus() {
const secondsAfterStxSubmission = Math.round( const secondsAfterStxSubmission = Math.round(
(Date.now() - latestSmartTransaction.time) / 1000, (Date.now() - latestSmartTransaction.time) / 1000,
); );
if (secondsAfterStxSubmission > swapsRefreshRates.stxStatusDeadline) { if (secondsAfterStxSubmission > swapsNetworkConfig.stxStatusDeadline) {
setTimeLeftForPendingStxInSec(0); setTimeLeftForPendingStxInSec(0);
clearInterval(intervalId); clearInterval(intervalId);
return; return;
} }
setTimeLeftForPendingStxInSec( setTimeLeftForPendingStxInSec(
swapsRefreshRates.stxStatusDeadline - secondsAfterStxSubmission, swapsNetworkConfig.stxStatusDeadline - secondsAfterStxSubmission,
); );
}; };
intervalId = setInterval(calculateRemainingTime, 1000); intervalId = setInterval(calculateRemainingTime, 1000);
@ -158,7 +158,7 @@ export default function SmartTransactionStatus() {
isSmartTransactionPending, isSmartTransactionPending,
latestSmartTransactionUuid, latestSmartTransactionUuid,
latestSmartTransaction.time, latestSmartTransaction.time,
swapsRefreshRates.stxStatusDeadline, swapsNetworkConfig.stxStatusDeadline,
]); ]);
useEffect(() => { useEffect(() => {
@ -358,8 +358,8 @@ export default function SmartTransactionStatus() {
className="smart-transaction-status__loading-bar" className="smart-transaction-status__loading-bar"
style={{ style={{
width: `${ width: `${
(100 / swapsRefreshRates.stxStatusDeadline) * (100 / swapsNetworkConfig.stxStatusDeadline) *
(swapsRefreshRates.stxStatusDeadline - (swapsNetworkConfig.stxStatusDeadline -
timeLeftForPendingStxInSec) timeLeftForPendingStxInSec)
}%`, }%`,
}} }}

View File

@ -500,6 +500,7 @@ export const getFeeForSmartTransaction = ({
chainId, chainId,
currentCurrency, currentCurrency,
conversionRate, conversionRate,
USDConversionRate,
nativeCurrencySymbol, nativeCurrencySymbol,
feeInWeiDec, feeInWeiDec,
}) => { }) => {
@ -522,7 +523,7 @@ export const getFeeForSmartTransaction = ({
feeInUsd = getValueFromWeiHex({ feeInUsd = getValueFromWeiHex({
value: feeInWeiHex, value: feeInWeiHex,
toCurrency: USD_CURRENCY_CODE, toCurrency: USD_CURRENCY_CODE,
conversionRate, conversionRate: USDConversionRate,
numberOfDecimals: 2, numberOfDecimals: 2,
}); });
} }
@ -543,6 +544,7 @@ export function getRenderableNetworkFeesForQuote({
gasPrice, gasPrice,
currentCurrency, currentCurrency,
conversionRate, conversionRate,
USDConversionRate,
tradeValue, tradeValue,
sourceSymbol, sourceSymbol,
sourceAmount, sourceAmount,
@ -585,7 +587,7 @@ export function getRenderableNetworkFeesForQuote({
feeInUsd = getValueFromWeiHex({ feeInUsd = getValueFromWeiHex({
value: totalWeiCost, value: totalWeiCost,
toCurrency: USD_CURRENCY_CODE, toCurrency: USD_CURRENCY_CODE,
conversionRate, conversionRate: USDConversionRate,
numberOfDecimals: 2, numberOfDecimals: 2,
}); });
} }

View File

@ -43,7 +43,7 @@ import {
getReviewSwapClickedTimestamp, getReviewSwapClickedTimestamp,
getSmartTransactionsOptInStatus, getSmartTransactionsOptInStatus,
signAndSendSwapsSmartTransaction, signAndSendSwapsSmartTransaction,
getSwapsRefreshStates, getSwapsNetworkConfig,
getSmartTransactionsEnabled, getSmartTransactionsEnabled,
getCurrentSmartTransactionsError, getCurrentSmartTransactionsError,
getCurrentSmartTransactionsErrorMessageDismissed, getCurrentSmartTransactionsErrorMessageDismissed,
@ -62,6 +62,7 @@ import {
getHardwareWalletType, getHardwareWalletType,
checkNetworkAndAccountSupports1559, checkNetworkAndAccountSupports1559,
getEIP1559V2Enabled, getEIP1559V2Enabled,
getUSDConversionRate,
} from '../../../selectors'; } from '../../../selectors';
import { getNativeCurrency, getTokens } from '../../../ducks/metamask/metamask'; import { getNativeCurrency, getTokens } from '../../../ducks/metamask/metamask';
@ -171,6 +172,7 @@ export default function ViewQuote() {
const memoizedTokenConversionRates = useEqualityCheck(tokenConversionRates); const memoizedTokenConversionRates = useEqualityCheck(tokenConversionRates);
const { balance: ethBalance } = useSelector(getSelectedAccount, shallowEqual); const { balance: ethBalance } = useSelector(getSelectedAccount, shallowEqual);
const conversionRate = useSelector(conversionRateSelector); const conversionRate = useSelector(conversionRateSelector);
const USDConversionRate = useSelector(getUSDConversionRate);
const currentCurrency = useSelector(getCurrentCurrency); const currentCurrency = useSelector(getCurrentCurrency);
const swapsTokens = useSelector(getTokens, isEqual); const swapsTokens = useSelector(getTokens, isEqual);
const networkAndAccountSupports1559 = useSelector( const networkAndAccountSupports1559 = useSelector(
@ -209,7 +211,7 @@ export default function ViewQuote() {
const smartTransactionEstimatedGas = useSelector( const smartTransactionEstimatedGas = useSelector(
getSmartTransactionEstimatedGas, getSmartTransactionEstimatedGas,
); );
const swapsRefreshRates = useSelector(getSwapsRefreshStates); const swapsNetworkConfig = useSelector(getSwapsNetworkConfig);
const unsignedTransaction = usedQuote.trade; const unsignedTransaction = usedQuote.trade;
let gasFeeInputs; let gasFeeInputs;
@ -360,6 +362,7 @@ export default function ViewQuote() {
: gasPrice, : gasPrice,
currentCurrency, currentCurrency,
conversionRate, conversionRate,
USDConversionRate,
tradeValue, tradeValue,
sourceSymbol: sourceTokenSymbol, sourceSymbol: sourceTokenSymbol,
sourceAmount: usedQuote.sourceAmount, sourceAmount: usedQuote.sourceAmount,
@ -375,6 +378,7 @@ export default function ViewQuote() {
gasPrice: maxFeePerGas || gasPrice, gasPrice: maxFeePerGas || gasPrice,
currentCurrency, currentCurrency,
conversionRate, conversionRate,
USDConversionRate,
tradeValue, tradeValue,
sourceSymbol: sourceTokenSymbol, sourceSymbol: sourceTokenSymbol,
sourceAmount: usedQuote.sourceAmount, sourceAmount: usedQuote.sourceAmount,
@ -399,11 +403,13 @@ export default function ViewQuote() {
const stxEstimatedFeeInWeiDec = const stxEstimatedFeeInWeiDec =
smartTransactionEstimatedGas.txData.feeEstimate + smartTransactionEstimatedGas.txData.feeEstimate +
(smartTransactionEstimatedGas.approvalTxData?.feeEstimate || 0); (smartTransactionEstimatedGas.approvalTxData?.feeEstimate || 0);
const stxMaxFeeInWeiDec = stxEstimatedFeeInWeiDec * 2; const stxMaxFeeInWeiDec =
stxEstimatedFeeInWeiDec * swapsNetworkConfig.stxMaxFeeMultiplier;
({ feeInFiat, feeInEth, rawEthFee, feeInUsd } = getFeeForSmartTransaction({ ({ feeInFiat, feeInEth, rawEthFee, feeInUsd } = getFeeForSmartTransaction({
chainId, chainId,
currentCurrency, currentCurrency,
conversionRate, conversionRate,
USDConversionRate,
nativeCurrencySymbol, nativeCurrencySymbol,
feeInWeiDec: stxEstimatedFeeInWeiDec, feeInWeiDec: stxEstimatedFeeInWeiDec,
})); }));
@ -420,6 +426,7 @@ export default function ViewQuote() {
chainId, chainId,
currentCurrency, currentCurrency,
conversionRate, conversionRate,
USDConversionRate,
nativeCurrencySymbol, nativeCurrencySymbol,
feeInWeiDec: stxMaxFeeInWeiDec, feeInWeiDec: stxMaxFeeInWeiDec,
})); }));
@ -835,7 +842,7 @@ export default function ViewQuote() {
dispatch( dispatch(
estimateSwapsSmartTransactionsGas(unsignedTx, approveTxParams), estimateSwapsSmartTransactionsGas(unsignedTx, approveTxParams),
); );
}, swapsRefreshRates.stxGetTransactionsRefreshTime); }, swapsNetworkConfig.stxGetTransactionsRefreshTime);
dispatch(estimateSwapsSmartTransactionsGas(unsignedTx, approveTxParams)); dispatch(estimateSwapsSmartTransactionsGas(unsignedTx, approveTxParams));
} else if (intervalId) { } else if (intervalId) {
clearInterval(intervalId); clearInterval(intervalId);
@ -852,7 +859,7 @@ export default function ViewQuote() {
unsignedTransaction.gas, unsignedTransaction.gas,
unsignedTransaction.to, unsignedTransaction.to,
chainId, chainId,
swapsRefreshRates.stxGetTransactionsRefreshTime, swapsNetworkConfig.stxGetTransactionsRefreshTime,
isSwapButtonDisabled, isSwapButtonDisabled,
]); ]);

View File

@ -671,7 +671,7 @@ export function getSwapsDefaultToken(state) {
export function getIsSwapsChain(state) { export function getIsSwapsChain(state) {
const chainId = getCurrentChainId(state); const chainId = getCurrentChainId(state);
const isNotDevelopment = const isNotDevelopment =
process.env.METAMASK_ENVIRONMENT !== 'development' || process.env.METAMASK_ENVIRONMENT !== 'development' &&
process.env.METAMASK_ENVIRONMENT !== 'testing'; process.env.METAMASK_ENVIRONMENT !== 'testing';
return isNotDevelopment return isNotDevelopment
? ALLOWED_PROD_SWAPS_CHAIN_IDS.includes(chainId) ? ALLOWED_PROD_SWAPS_CHAIN_IDS.includes(chainId)