From b4ea570146781e174d4efd693ebdfd6d21e7f65d Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Wed, 21 Aug 2024 05:55:00 +0300 Subject: [PATCH] fix redirect_after_login --- ng-app/src/lib/FullLayout.svelte | 23 +++++++++++++++-------- ng-app/src/lib/MobileBottomBarItem.svelte | 11 +++++++++-- ng-app/src/routes/User.svelte | 3 ++- ng-app/src/routes/WalletLogin.svelte | 17 +++++++++++++---- ng-app/src/store.ts | 3 +++ 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ng-app/src/lib/FullLayout.svelte b/ng-app/src/lib/FullLayout.svelte index b34f3e4..381ccf5 100644 --- a/ng-app/src/lib/FullLayout.svelte +++ b/ng-app/src/lib/FullLayout.svelte @@ -35,6 +35,9 @@ import Message from "./components/Message.svelte"; import Signature from "./popups/Signature.svelte"; + import { + get, + } from "svelte/store"; // @ts-ignore import { t } from "svelte-i18n"; @@ -47,7 +50,7 @@ in_private_store, show_doc_popup, cur_doc_popup, open_doc_popup } from "../tab"; import { active_session, redirect_after_login, toasts, check_has_camera, toast_error, - reset_toasts, + reset_toasts, redirect_if_wallet_is, active_wallet, display_error, openModalCreate } from "../store"; import ZeraIcon from "./icons/ZeraIcon.svelte"; @@ -368,6 +371,7 @@ let shareMenu; let toolsMenu; let unsub; + let unsub2; async function scrollToTop() { await tick(); if (top) top.scrollIntoView(); @@ -398,19 +402,22 @@ reset_toasts(); } }); + + unsub2 = active_session.subscribe((as) => { + if(!as) { + $redirect_after_login = $location; + $redirect_if_wallet_is = get(active_wallet)?.id + push("#/"); + } + }) }); onDestroy(() => { if (unsub) unsub(); + if (unsub2) unsub2(); }); - active_session.subscribe((as) => { if(!as) { - //console.log($location); - if ($location!="/user") { - $redirect_after_login = $location; - } - push("#/"); - } }) + $: activeUrl = "#" + $location; diff --git a/ng-app/src/lib/MobileBottomBarItem.svelte b/ng-app/src/lib/MobileBottomBarItem.svelte index 5d92544..4f52afd 100644 --- a/ng-app/src/lib/MobileBottomBarItem.svelte +++ b/ng-app/src/lib/MobileBottomBarItem.svelte @@ -13,6 +13,7 @@ import { getContext } from "svelte"; import type { ComponentType } from "svelte"; import { Icon } from "svelte-heros-v2"; + import { onMount, onDestroy, tick } from "svelte"; export let href: string = ""; export let icon: ComponentType; @@ -22,8 +23,14 @@ }; let sidebarUrl = ""; - activeUrlStore.subscribe((value) => { - sidebarUrl = value; + let unsub; + onMount( () => { + unsub = activeUrlStore.subscribe((value) => { + sidebarUrl = value; + }); + }); + onDestroy( () => { + if (unsub) unsub(); }); $: active = sidebarUrl ? href === sidebarUrl : false; diff --git a/ng-app/src/routes/User.svelte b/ng-app/src/routes/User.svelte index b796cb7..b2182b0 100644 --- a/ng-app/src/routes/User.svelte +++ b/ng-app/src/routes/User.svelte @@ -59,7 +59,7 @@ reconnect, display_error, } from "../store"; - + import { NG_EU_BSP, NG_NET_BSP, @@ -88,6 +88,7 @@ }); async function logout() { + await close_active_wallet(); } diff --git a/ng-app/src/routes/WalletLogin.svelte b/ng-app/src/routes/WalletLogin.svelte index 48c77c5..ea31bfd 100644 --- a/ng-app/src/routes/WalletLogin.svelte +++ b/ng-app/src/routes/WalletLogin.svelte @@ -34,7 +34,8 @@ has_wallets, display_error, wallet_from_import, - redirect_after_login + redirect_after_login, + redirect_if_wallet_is } from "../store"; import { CheckBadge, ExclamationTriangle, QrCode } from "svelte-heros-v2"; @@ -110,10 +111,18 @@ async function loggedin() { step = "loggedin"; + if ($redirect_after_login) { - let redir=$redirect_after_login; - $redirect_after_login=undefined; - push("#"+redir); + if (!$redirect_if_wallet_is || $redirect_if_wallet_is == $active_wallet?.id) { + let redir=$redirect_after_login; + $redirect_after_login=undefined; + $redirect_if_wallet_is=undefined; + push("#"+redir); + } else { + $redirect_after_login=undefined; + $redirect_if_wallet_is=undefined; + push("#/"); + } } else { push("#/"); } diff --git a/ng-app/src/store.ts b/ng-app/src/store.ts index a3c605b..426add4 100644 --- a/ng-app/src/store.ts +++ b/ng-app/src/store.ts @@ -162,6 +162,7 @@ export const connections: Writable> = writable({}); export const active_session = writable(undefined); export const redirect_after_login = writable(undefined); +export const redirect_if_wallet_is = writable(undefined); export const connection_status: Writable<"disconnected" | "connected" | "connecting" | "starting"> = writable("starting"); @@ -285,6 +286,8 @@ export const set_active_session = function(session) { export { writable, readonly, derived }; export const close_active_wallet = async function() { + redirect_after_login.set(undefined); + redirect_if_wallet_is.set(undefined); if (next_reconnect) { clearTimeout(next_reconnect); next_reconnect = null;