Ensure swaps gas prices are fetched from the correct chain specific endpoint#10744
Ensure swaps gas prices are fetched from the correct chain specific endpoint#10744
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
ui/app/ducks/swaps/swaps.js
Outdated
| priceEstimates = await fetchSwapsGasPrices(chainId); | ||
| } else { | ||
| const cachedPriceEstimates = await getStorageItem( | ||
| 'METASWAP_GAS_PRICE_ESTIMATES', |
There was a problem hiding this comment.
This cache isn't chainId-aware either. It needs to be, otherwise cached values from the wrong chain will end up being used.
There was a problem hiding this comment.
I thought it was chainId aware, to the extent that a different url will be used on a different chain. fetchWithCache keys the local storage cache by const cacheKey = cachedFetch:${url};, so a different url's for different chains would get different values from the cache, or trigger fresh requests if no key matching the url is already in the cache.
There was a problem hiding this comment.
Right, but look at this line though. getStorageItem is only being passed METASWAP_GAS_PRICE_ESTIMATES. No URL, no chainId.
This wasn't cached by ChainID before because it used to only be used for one.
The METASWAP_GAS_PRICE_ESTIMATES_LAST_RETRIEVED entry has the same issue.
There was a problem hiding this comment.
Perhaps the best solution here would be to get rid of METASWAP_GAS_PRICE_ESTIMATES and METASWAP_GAS_PRICE_ESTIMATES_LAST_RETRIEVED, and rely upon fetchWithCache for our cache.
That would require passing through the desired cache interval to fetchSwapsGasPrices, or changing it to be 30000`, if that's what's desired (that's what we're using now).
Builds ready [23e0ca4]
Page Load Metrics (606 ± 58 ms)
|
…ectly using storage in getSwapsPriceEstimatesLastRetrieved
Builds ready [23e0ca4]
Page Load Metrics (540 ± 39 ms)
|
Builds ready [9996f7a]
Page Load Metrics (1004 ± 185 ms)
|
Fixes an issue found by @tmashuang when QAing v9.3.0
The chainId was not being passed to the
fetchSwapsGasPricesfunction, resulting in the incorrect gas prices being fetched.