|
|
@ -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 { |
|
|
|