Skip to content

Commit

Permalink
Ignore imported tokens for redirection when signed out (#5602)
Browse files Browse the repository at this point in the history
# Motivation

In PR [#5596](#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.
  • Loading branch information
mstrasinskis authored Oct 10, 2024
1 parent 55fec50 commit 3c14cdb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion frontend/src/lib/routes/Wallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
34 changes: 29 additions & 5 deletions frontend/src/tests/lib/routes/Wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -86,6 +90,7 @@ describe("Wallet", () => {
let ckEthBalance = 1000000000000000000n;
const importedTokenId = principal(123);
beforeEach(() => {
resetIdentity();
vi.clearAllMocks();
importedTokensStore.reset();
setCkETHCanisters();
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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() },
Expand Down

0 comments on commit 3c14cdb

Please sign in to comment.