Skip to content

Commit

Permalink
Merge branch 'release/3.0.0' into 5440-edit-multisig-account-none-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuGowda authored Nov 17, 2023
2 parents ae3b0aa + be561fc commit ef3b7ac
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 48 deletions.
80 changes: 33 additions & 47 deletions src/modules/account/hooks/useCurrentAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,46 @@ export function useCurrentAccount() {
(stake) => stake.confirmed !== stake.unconfirmed
);

const switchAccount = ({ encryptedAccount, relativeUrlPath, redirect, urlState }) => {
dispatch(setCurrentAccount(encryptedAccount));
dispatch(stakesReset());
toast.dismiss();
if (redirect) {
if (urlState) {
const { pathname, search } = new URL(relativeUrlPath, window.location.origin);
history.push({
pathname,
search,
state: urlState,
});
} else {
history.push(relativeUrlPath);
}
}
};

// eslint-disable-next-line max-statements
const setAccount = (encryptedAccount, referrer, redirect = true, urlState) => {
// clear stakes list during login or accounts switch
const relativeUrlPath = referrer || routes.wallet.path;

function pushUrlState() {
const { pathname, search } = new URL(relativeUrlPath, window.location.origin);
history.push({
pathname,
search,
state: urlState,
});
}

if (pendingStakes.length) {
if (urlState) {
dispatch(setCurrentAccount(encryptedAccount));
dispatch(stakesReset());
pushUrlState();
} else {
const onCancel = /* istanbul ignore next */ () =>
removeSearchParamsFromUrl(history, ['modal']);
const onConfirm = /* istanbul ignore next */ () => {
dispatch(setCurrentAccount(encryptedAccount));
const showConfirmAccountSwitchDialog = pendingStakes.length && !urlState;

dispatch(stakesReset());
// Remove toast between account switches
toast.dismiss();
history.push(relativeUrlPath);
};
const state = createConfirmSwitchState({
mode: 'pendingStakes',
type: 'account',
onCancel,
onConfirm,
});
removeThenAppendSearchParamsToUrl(
history,
{ modal: 'confirmationDialog' },
['modal'],
state
);
}
if (showConfirmAccountSwitchDialog) {
const onCancel = /* istanbul ignore next */ () =>
removeSearchParamsFromUrl(history, ['modal']);
const onConfirm = /* istanbul ignore next */ () => {
switchAccount({ encryptedAccount, relativeUrlPath, redirect, urlState });
};
const state = createConfirmSwitchState({
mode: 'pendingStakes',
type: 'account',
onCancel,
onConfirm,
});
removeThenAppendSearchParamsToUrl(history, { modal: 'confirmationDialog' }, ['modal'], state);
} else {
dispatch(setCurrentAccount(encryptedAccount));
// Remove toast between account switches
toast.dismiss();
if (redirect) {
if (urlState) {
pushUrlState();
} else {
history.push(relativeUrlPath);
}
}
switchAccount({ encryptedAccount, relativeUrlPath, redirect, urlState });
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function useCurrentApplication() {
});
removeThenAppendSearchParamsToUrl(history, { modal: 'confirmationDialog' }, ['modal'], state);
} else {
dispatch(stakesReset());
dispatch(setCurrentApplication(application));
// Remove toast between application switches
toast.dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('useCurrentApplication hook', () => {
ws: expect.stringMatching('ws'),
rest: expect.stringMatching('http'),
});
expect(mockDispatch).toHaveBeenCalledTimes(1);
expect(mockDispatch).toHaveBeenCalledTimes(2);
expect(mockDispatch).toHaveBeenCalledWith(expectedAction);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function NetworkSwitcherDropdown({ noLabel, onNetworkSwitchSuccess }) {
state
);
} else {
dispatch(stakesReset());
setValue(selectedNetwork);
// Remove toast between network switches
toast.dismiss();
Expand Down

0 comments on commit ef3b7ac

Please sign in to comment.