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