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

Redirect to homepage from Swaps asap without waiting for state cleanup (#20236)

This commit is contained in:
Daniel 2023-08-01 15:28:11 +02:00 committed by GitHub
parent 4e52fe2494
commit 2ad2827bab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 4 deletions

View File

@ -154,6 +154,7 @@ export default class Home extends PureComponent {
haveSwapsQuotes: PropTypes.bool.isRequired,
showAwaitingSwapScreen: PropTypes.bool.isRequired,
swapsFetchParams: PropTypes.object,
location: PropTypes.object,
shouldShowWeb3ShimUsageNotification: PropTypes.bool.isRequired,
setWeb3ShimUsageAlertDismissed: PropTypes.func.isRequired,
originOfCurrentTab: PropTypes.string,
@ -218,7 +219,9 @@ export default class Home extends PureComponent {
hasWatchNftPendingApprovals,
swapsFetchParams,
hasTransactionPendingApprovals,
location,
} = this.props;
const stayOnHomePage = Boolean(location?.state?.stayOnHomePage);
if (shouldCloseNotificationPopup(props)) {
this.state.notificationClosing = true;
@ -229,6 +232,7 @@ export default class Home extends PureComponent {
hasWatchTokenPendingApprovals ||
hasWatchNftPendingApprovals ||
(!isNotification &&
!stayOnHomePage &&
(showAwaitingSwapScreen || haveSwapsQuotes || swapsFetchParams))
) {
this.state.redirecting = true;
@ -289,19 +293,22 @@ export default class Home extends PureComponent {
haveSwapsQuotes,
showAwaitingSwapScreen,
swapsFetchParams,
location,
pendingConfirmations,
hasApprovalFlows,
} = this.props;
const stayOnHomePage = Boolean(location?.state?.stayOnHomePage);
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
this.shouldCloseCurrentWindow();
///: END:ONLY_INCLUDE_IN
if (!isNotification && showAwaitingSwapScreen) {
const canRedirect = !isNotification && !stayOnHomePage;
if (canRedirect && showAwaitingSwapScreen) {
history.push(AWAITING_SWAP_ROUTE);
} else if (!isNotification && haveSwapsQuotes) {
} else if (canRedirect && haveSwapsQuotes) {
history.push(VIEW_QUOTE_ROUTE);
} else if (!isNotification && swapsFetchParams) {
} else if (canRedirect && swapsFetchParams) {
history.push(BUILD_QUOTE_ROUTE);
} else if (firstPermissionsRequestId) {
history.push(`${CONNECT_ROUTE}/${firstPermissionsRequestId}`);

View File

@ -349,9 +349,12 @@ export default function Swap() {
}
const redirectToDefaultRoute = async () => {
history.push({
pathname: DEFAULT_ROUTE,
state: { stayOnHomePage: true },
});
dispatch(clearSwapsState());
await dispatch(resetBackgroundSwapsState());
history.push(DEFAULT_ROUTE);
};
return (