From 532e7b7d9dc25a9f4a661a0592cd2ca979e23500 Mon Sep 17 00:00:00 2001 From: DanutIlie <42973343+DanutIlie@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:15:27 +0200 Subject: [PATCH] Fix clear initiated login (#1301) * Fix clear initiated login * Update CHANGELOG.md --- CHANGELOG.md | 3 +- .../login/helpers/clearInitiatedLogins.ts | 28 +++++++++++++------ src/hooks/login/useCrossWindowLogin.ts | 2 +- src/hooks/login/useIframeLogin.ts | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1bdeecf5..baca62b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Fix clear initiated login](https://github.com/multiversx/mx-sdk-dapp/pull/1301) + ## [[v3.0.8](https://github.com/multiversx/mx-sdk-dapp/pull/1299)] - 2024-11-04 - [Update skip method to clear only initiated login state](https://github.com/multiversx/mx-sdk-dapp/pull/1298) - - [Updated Iframe provider imports](https://github.com/multiversx/mx-sdk-dapp/pull/1297) - [Fixed Iframe provider reload](https://github.com/multiversx/mx-sdk-dapp/pull/1295) diff --git a/src/hooks/login/helpers/clearInitiatedLogins.ts b/src/hooks/login/helpers/clearInitiatedLogins.ts index ec158e3cd..20d96caaf 100644 --- a/src/hooks/login/helpers/clearInitiatedLogins.ts +++ b/src/hooks/login/helpers/clearInitiatedLogins.ts @@ -3,19 +3,29 @@ import { IframeProvider } from 'lib/sdkWebWalletIframeProvider'; import { LoginMethodsEnum } from 'types'; export const clearInitiatedLogins = (props?: { - intiatedLoginMethod: LoginMethodsEnum; + skipLoginMethod: LoginMethodsEnum; }) => { Object.values(LoginMethodsEnum).forEach((method) => { - if (props?.intiatedLoginMethod && method !== props.intiatedLoginMethod) { + if (method === props?.skipLoginMethod) { return; } - const crossWindowProvider = CrossWindowProvider.getInstance(); - if (crossWindowProvider.isInitialized()) { - crossWindowProvider.dispose(); - } - const iframeProvider = IframeProvider.getInstance(); - if (iframeProvider.isInitialized()) { - iframeProvider.dispose(); + switch (method) { + case LoginMethodsEnum.crossWindow: { + const crossWindowProvider = CrossWindowProvider.getInstance(); + if (crossWindowProvider.isInitialized()) { + crossWindowProvider.dispose(); + } + break; + } + case LoginMethodsEnum.iframe: { + const iframeProvider = IframeProvider.getInstance(); + if (iframeProvider.isInitialized()) { + iframeProvider.dispose(); + } + break; + } + default: + break; } }); diff --git a/src/hooks/login/useCrossWindowLogin.ts b/src/hooks/login/useCrossWindowLogin.ts index 5fcecbabb..27424cf23 100644 --- a/src/hooks/login/useCrossWindowLogin.ts +++ b/src/hooks/login/useCrossWindowLogin.ts @@ -53,7 +53,7 @@ export const useCrossWindowLogin = ({ } clearInitiatedLogins({ - intiatedLoginMethod: LoginMethodsEnum.crossWindow + skipLoginMethod: LoginMethodsEnum.crossWindow }); setIsLoading(true); diff --git a/src/hooks/login/useIframeLogin.ts b/src/hooks/login/useIframeLogin.ts index 3c8fb4ea2..d44b5bfb8 100644 --- a/src/hooks/login/useIframeLogin.ts +++ b/src/hooks/login/useIframeLogin.ts @@ -50,7 +50,7 @@ export const useIframeLogin = ({ } clearInitiatedLogins({ - intiatedLoginMethod: LoginMethodsEnum.iframe + skipLoginMethod: LoginMethodsEnum.iframe }); setIsLoading(true);