Reduce calls of the /featureFlag API#10859
Reduce calls of the /featureFlag API#10859danjm merged 17 commits intoMetaMask:developfrom dan437:swaps-feature-flag
/featureFlag API#10859Conversation
|
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/pages/swaps/index.js
Outdated
There was a problem hiding this comment.
It looks like this loading screen is only shown once, the first time the user clicks 'swaps'. On subsequent navigations to the swaps page, it will show the maintenance page or the build quote page immediately while it checks the API liveness in the background.
Was this intended? At the very least it's probably worth showing the loading screen if the last check showed the API as down.
There was a problem hiding this comment.
I had the same thought as you at first, but we actually clean up a Swaps state by calling the prepareToLeaveSwaps function from various places, e.g. here: https://github.com/MetaMask/metamask-extension/blob/develop/ui/app/pages/swaps/index.js#L178
prepareToLeaveSwaps calls the resetBackgroundSwapsState function and that one calls resetSwapsState every time a user leaves the Swaps feature. That will set the isFeatureFlagLoaded flag to false.
I've just tried this by going back by 3 different ways: clicking on Cancel, clicking on the Fox head and clicking on the "Close" button on the "Offline for maintenance" page and then every time I click on "Swaps" from the main page, I can see the page loader again.
There was a problem hiding this comment.
Huh, I hadn't realized. Good to know!
app/scripts/controllers/swaps.js
Outdated
There was a problem hiding this comment.
Does this need to be background state? 🤔 It seems to only be used in one UI component. Maybe it could be migrated to component state - set to false when the component mounts, and true when the fetchSwapsLiveness call resolves. That would make it easier to use the loading screen in more cases as well.
There was a problem hiding this comment.
That's right that it's only used in one UI component. What do you think about my code below? I'm using a recommended way to make async calls from the useEffect function: https://stackoverflow.com/questions/53332321/react-hook-warnings-for-async-function-in-useeffect-useeffect-function-must-ret
const [isFeatureFlagLoaded, setIsFeatureFlagLoaded] = useState(false);
useEffect(() => {
const fetchSwapsLivenessWrapper = async () => {
await dispatch(fetchSwapsLiveness());
setIsFeatureFlagLoaded(true);
};
fetchSwapsLivenessWrapper();
}, []);
There was a problem hiding this comment.
useEffect certainly seems appropriate!
The pattern you're using here with a "wrapper" function seems a bit odd. I don't follow what the wrapper is for 🤔
|
Only one last small comment: I think we should add a In any case, our intent is that the user should not be able to click the "Review Swap" button until the call to the |
|
Hi @danjm, so, if |


Explanation
Instead of periodically checking if the Swaps feature is enabled every 10 minutes, we will check it only when a user enters the Swaps feature. That will dramatically decrease calls to the
/featureFlagAPI.Manual testing steps
Feature is enabled:
Feature is enabled - loaded from 10 min cache without any API call to the
/featureFlagAPI:/featureFlagAPI is loaded from our 10 min cache and a user is still on the Swaps pageFeature is disabled:
false/featureFlagcall is doneScreenshots
Swap button is always visible now:

Swap page is accessible immediately by default:

Show the "Offline for maintenance" page if the Swaps feature is disabled:
