From 3c14cdb3b218a973a84daf69b5063dcf40a5299f Mon Sep 17 00:00:00 2001 From: Max Strasinsky <98811342+mstrasinskis@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:07:26 +0200 Subject: [PATCH] Ignore imported tokens for redirection when signed out (#5602) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Motivation In PR [#5596](https://github.com/dfinity/nns-dapp/pull/5596), we began checking for the loading of imported tokens to handle navigation from the wallet page for unknown tokens. This fixed the targeted issue but unintentionally broke redirection to the tokens page after sign-out. To restore the sign-out redirection, we also need to consider the login state. # Changes - Ignore imported token readiness when signed out, as we don’t load them in this state. # Tests - Added. # Todos - [ ] Add entry to changelog (if necessary). Not necessary. --- frontend/src/lib/routes/Wallet.svelte | 3 +- frontend/src/tests/lib/routes/Wallet.spec.ts | 34 +++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/frontend/src/lib/routes/Wallet.svelte b/frontend/src/lib/routes/Wallet.svelte index 2d11b752e5e..26d73074733 100644 --- a/frontend/src/lib/routes/Wallet.svelte +++ b/frontend/src/lib/routes/Wallet.svelte @@ -20,6 +20,7 @@ import { goto } from "$app/navigation"; import { snsAggregatorStore } from "$lib/stores/sns-aggregator.store"; import { importedTokensStore } from "$lib/stores/imported-tokens.store"; + import { authSignedInStore } from "$lib/derived/auth.derived"; export let accountIdentifier: string | undefined | null = undefined; @@ -36,7 +37,7 @@ // before we have the list of Sns projects. nonNullish($snsAggregatorStore.data) && // and imported tokens being loaded - nonNullish($importedTokensStore.importedTokens) && + (!$authSignedInStore || nonNullish($importedTokensStore.importedTokens)) && !nonNullish($snsProjectSelectedStore); $: if (isUnknownToken) { // This will also cover the case when the user was logged out diff --git a/frontend/src/tests/lib/routes/Wallet.spec.ts b/frontend/src/tests/lib/routes/Wallet.spec.ts index c0b694ba566..4a04434f8e0 100644 --- a/frontend/src/tests/lib/routes/Wallet.spec.ts +++ b/frontend/src/tests/lib/routes/Wallet.spec.ts @@ -15,7 +15,11 @@ import { icrcAccountsStore } from "$lib/stores/icrc-accounts.store"; import { importedTokensStore } from "$lib/stores/imported-tokens.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { page } from "$mocks/$app/stores"; -import { mockIdentity, resetIdentity } from "$tests/mocks/auth.store.mock"; +import { + mockIdentity, + resetIdentity, + setNoIdentity, +} from "$tests/mocks/auth.store.mock"; import { mockCkBTCMainAccount, mockCkBTCToken, @@ -86,6 +90,7 @@ describe("Wallet", () => { let ckEthBalance = 1000000000000000000n; const importedTokenId = principal(123); beforeEach(() => { + resetIdentity(); vi.clearAllMocks(); importedTokensStore.reset(); setCkETHCanisters(); @@ -142,10 +147,6 @@ describe("Wallet", () => { vi.spyOn(governanceApi, "queryNeurons").mockResolvedValue([]); }); - beforeAll(() => { - resetIdentity(); - }); - describe("nns context", () => { it("should render NnsWallet", () => { page.mock({ routeId: AppPath.Wallet }); @@ -352,6 +353,29 @@ describe("Wallet", () => { expect(get(pageStore).path).toEqual(AppPath.Tokens); }); + it("redirects to tokens for unknown universe when not signed in", async () => { + setNoIdentity(); + page.mock({ + data: { universe: unknownUniverseId }, + routeId: AppPath.Wallet, + }); + setSnsProjects([{}]); + expect(get(importedTokensStore)).toEqual({ + importedTokens: undefined, + certified: undefined, + }); + + expect(get(pageStore).path).toEqual(AppPath.Wallet); + + render(Wallet, { + props: { + accountIdentifier: undefined, + }, + }); + await runResolvedPromises(); + expect(get(pageStore).path).toEqual(AppPath.Tokens); + }); + it("should not redirect on valid token", async () => { page.mock({ data: { universe: importedTokenId.toText() },