Skip to content

Commit

Permalink
Fixed cancel action in cross window does not close child window (#1345)
Browse files Browse the repository at this point in the history
* yarn.lock

* Fixed cancel action in cross window

* Fixed cancel action in cross window does not close child window
  • Loading branch information
razvantomegea authored Dec 11, 2024
1 parent b1270eb commit fa7f275
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Fixed cancel action in cross window does not close child window](https://github.com/multiversx/mx-sdk-dapp/pull/1345)

## [[v3.1.2](https://github.com/multiversx/mx-sdk-dapp/pull/1344)] - 2024-12-09

- [Add pagination item count support to "AddressTable"](https://github.com/multiversx/mx-sdk-dapp/pull/1343)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import { DataTestIdsEnum } from 'constants/index';
import { withStyles, WithStylesImportType } from 'hocs/withStyles';
import { useClearTransactionsToSignWithWarning } from 'hooks/transactions/helpers/useClearTransactionsToSignWithWarning';
import { useCancelCrossWindowAction } from 'hooks/transactions/useCancelCrossWindowAction';
import { SignModalPropsType } from 'types';
import { ModalContainer } from 'UI/ModalContainer/ModalContainer';
import { PageState } from 'UI/PageState';
Expand All @@ -24,6 +25,8 @@ const SignWaitingScreenModalComponent = ({
globalStyles,
styles
}: SignWaitingScreenModalPropsType & WithStylesImportType) => {
const cancelAction = useCancelCrossWindowAction();

const clearTransactionsToSignWithWarning =
useClearTransactionsToSignWithWarning();

Expand All @@ -39,10 +42,11 @@ const SignWaitingScreenModalComponent = ({
)
};

const close = (event: MouseEvent) => {
const close = async (event: MouseEvent) => {
event.preventDefault();
handleClose();
clearTransactionsToSignWithWarning(sessionId);
await cancelAction();
handleClose();
};

return (
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/transactions/useCancelCrossWindowAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CrossWindowProvider } from '@multiversx/sdk-web-wallet-cross-window-provider/out';
import { useGetAccountProvider } from 'hooks/account/useGetAccountProvider';
import { LoginMethodsEnum } from 'types';
import { getIsProviderEqualTo } from 'utils/account/getIsProviderEqualTo';

export function useCancelCrossWindowAction() {
const { provider } = useGetAccountProvider();

return async () => {
if (!provider) {
return;
}

if (getIsProviderEqualTo(LoginMethodsEnum.crossWindow)) {
const crossWindowProvider = provider as unknown as CrossWindowProvider;
await crossWindowProvider.cancelAction();
await crossWindowProvider.dispose();
}
};
}

0 comments on commit fa7f275

Please sign in to comment.