diff --git a/CHANGELOG-Nns-Dapp-unreleased.md b/CHANGELOG-Nns-Dapp-unreleased.md index 9a37cd65b4f..2b95531075a 100644 --- a/CHANGELOG-Nns-Dapp-unreleased.md +++ b/CHANGELOG-Nns-Dapp-unreleased.md @@ -38,6 +38,7 @@ proposal is successful, the changes it released will be moved from this file to - Min dissolve delay button updates not only for the first time. - Fix scrollbar in multiline toast message. - Go back to accounts page for incorrect account identifier in SNS wallet page. +- Stay on the same universe when navigating back from wallet to the accounts page. #### Security diff --git a/frontend/src/lib/components/accounts/IcrcWalletPage.svelte b/frontend/src/lib/components/accounts/IcrcWalletPage.svelte index ec522a361e6..54e1cf2767f 100644 --- a/frontend/src/lib/components/accounts/IcrcWalletPage.svelte +++ b/frontend/src/lib/components/accounts/IcrcWalletPage.svelte @@ -12,7 +12,7 @@ import { replacePlaceholders } from "$lib/utils/i18n.utils"; import { i18n } from "$lib/stores/i18n"; import { goto } from "$app/navigation"; - import { AppPath } from "$lib/constants/routes.constants"; + import { buildAccountsUrl } from "$lib/utils/navigation.utils"; import type { UniverseCanisterId } from "$lib/types/universe"; import { selectedUniverseStore } from "$lib/derived/selected-universe.derived"; import IcrcBalancesObserver from "$lib/components/accounts/IcrcBalancesObserver.svelte"; @@ -31,7 +31,12 @@ const reloadOnlyAccountFromStore = () => setSelectedAccount(); - const goBack = (): Promise => goto(AppPath.Accounts); + const goBack = async (): Promise => + goto( + buildAccountsUrl({ + universe: $selectedUniverseStore.canisterId, + }) + ); // e.g. is called from "Receive" modal after user click "Done" export const reloadAccount = async () => { diff --git a/frontend/src/tests/lib/pages/IcrcWallet.spec.ts b/frontend/src/tests/lib/pages/IcrcWallet.spec.ts index 40be27c2b91..b97417a950d 100644 --- a/frontend/src/tests/lib/pages/IcrcWallet.spec.ts +++ b/frontend/src/tests/lib/pages/IcrcWallet.spec.ts @@ -14,6 +14,7 @@ import { tokensStore } from "$lib/stores/tokens.store"; import type { Account } from "$lib/types/account"; import { page } from "$mocks/$app/stores"; import AccountsTest from "$tests/lib/pages/AccountsTest.svelte"; +import WalletTest from "$tests/lib/pages/WalletTest.svelte"; import { resetIdentity } from "$tests/mocks/auth.store.mock"; import { mockCkETHMainAccount, @@ -25,6 +26,7 @@ import { ReceiveModalPo } from "$tests/page-objects/ReceiveModal.page-object"; import { JestPageObjectElement } from "$tests/page-objects/jest.page-object"; import { blockAllCallsTo } from "$tests/utils/module.test-utils"; import { runResolvedPromises } from "$tests/utils/timers.test-utils"; +import { toastsStore } from "@dfinity/gix-components"; import { render } from "@testing-library/svelte"; import { get } from "svelte/store"; @@ -81,7 +83,10 @@ describe("IcrcWallet", () => { const renderWallet = async (props: { accountIdentifier: string; }): Promise => { - const { container } = render(IcrcWallet, props); + const { container } = render(WalletTest, { + ...props, + testComponent: IcrcWallet, + }); await runResolvedPromises(); return IcrcWalletPo.under(new JestPageObjectElement(container)); }; @@ -105,6 +110,7 @@ describe("IcrcWallet", () => { vi.clearAllTimers(); tokensStore.reset(); overrideFeatureFlagsStore.reset(); + toastsStore.reset(); resetIdentity(); vi.mocked(icrcIndexApi.getTransactions).mockResolvedValue({ @@ -231,27 +237,58 @@ describe("IcrcWallet", () => { }); it("should nagigate to accounts when account identifier is missing", async () => { - expect(get(pageStore).path).toEqual(AppPath.Wallet); + expect(get(pageStore)).toEqual({ + path: AppPath.Wallet, + universe: CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText(), + }); await renderWallet({ accountIdentifier: undefined, }); - expect(get(pageStore).path).toEqual(AppPath.Accounts); + expect(get(pageStore)).toEqual({ + path: AppPath.Accounts, + universe: CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText(), + }); + expect(get(toastsStore)).toMatchObject([ + { + level: "error", + text: 'Sorry, the account "" was not found', + }, + ]); }); it("should nagigate to accounts when account identifier is invalid", async () => { - expect(get(pageStore).path).toEqual(AppPath.Wallet); + expect(get(pageStore)).toEqual({ + path: AppPath.Wallet, + universe: CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText(), + }); await renderWallet({ accountIdentifier: "invalid-account-identifier", }); - expect(get(pageStore).path).toEqual(AppPath.Accounts); + expect(get(pageStore)).toEqual({ + path: AppPath.Accounts, + universe: CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText(), + }); + expect(get(toastsStore)).toMatchObject([ + { + level: "error", + text: 'Sorry, the account "invalid-account-identifier" was not found', + }, + ]); }); it("should stay on the wallet page when account identifier is valid", async () => { - expect(get(pageStore).path).toEqual(AppPath.Wallet); + expect(get(pageStore)).toEqual({ + path: AppPath.Wallet, + universe: CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText(), + }); await renderWallet({ accountIdentifier: mockCkETHMainAccount.identifier, }); - expect(get(pageStore).path).toEqual(AppPath.Wallet); + expect(get(pageStore)).toEqual({ + path: AppPath.Wallet, + universe: CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText(), + }); + expect(get(toastsStore)).toEqual([]); }); }); }); diff --git a/frontend/src/tests/lib/pages/WalletTest.svelte b/frontend/src/tests/lib/pages/WalletTest.svelte new file mode 100644 index 00000000000..bd4f8d59c78 --- /dev/null +++ b/frontend/src/tests/lib/pages/WalletTest.svelte @@ -0,0 +1,15 @@ + + +{#if currentAppPath === AppPath.Wallet} + +{/if}