Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC Displaying unknown token wallet #5530

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
hasAccounts,
} from "$lib/utils/accounts.utils";
import { replacePlaceholders } from "$lib/utils/i18n.utils";
import { IconDots, Island, Spinner } from "@dfinity/gix-components";
import { IconDots, Island, Spinner, Tag } from "@dfinity/gix-components";
import type { Principal } from "@dfinity/principal";
import { TokenAmountV2, isNullish, nonNullish } from "@dfinity/utils";
import type { Writable } from "svelte/store";
Expand Down Expand Up @@ -221,6 +221,12 @@
>
<slot name="header-actions" />
<SignInGuard />

{#if isImportedToken}
<Tag testId="imported-token-tag"
>{$i18n.import_token.imported_token}</Tag
>
{/if}
</WalletPageHeading>

{#if $$slots["info-card"]}
Expand Down
27 changes: 23 additions & 4 deletions frontend/src/lib/derived/icrc-canisters.derived.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { loadedImportedTokensStore } from "$lib/derived/imported-tokens.derived";
import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store";
import type { UniverseCanisterIdText } from "$lib/types/universe";
import type { Principal } from "@dfinity/principal";
import { Principal } from "@dfinity/principal";
import { derived, type Readable } from "svelte/store";
import { pageStore } from "./page.derived";

export interface IcrcCanisters {
ledgerCanisterId: Principal;
Expand All @@ -17,9 +18,13 @@ export type IcrcCanistersStoreData = Record<
export type IcrcCanistersStore = Readable<IcrcCanistersStoreData>;

export const icrcCanistersStore: IcrcCanistersStore = derived(
[defaultIcrcCanistersStore, loadedImportedTokensStore],
([defaultIcrcCanisters, loadedImportedTokens]) => {
return {
[defaultIcrcCanistersStore, loadedImportedTokensStore, pageStore],
([
defaultIcrcCanisters,
loadedImportedTokens,
{ universe: universeCanisterIdText },
]) => {
const canisters = {
...defaultIcrcCanisters,
...Object.fromEntries(
loadedImportedTokens.map(({ ledgerCanisterId, indexCanisterId }) => [
Expand All @@ -28,5 +33,19 @@ export const icrcCanistersStore: IcrcCanistersStore = derived(
])
),
};

try {
const universeCanisterId = Principal.fromText(universeCanisterIdText);
if (!canisters[universeCanisterIdText]) {
canisters[universeCanisterIdText] = {
ledgerCanisterId: universeCanisterId,
indexCanisterId: undefined,
};
}
} catch (error: unknown) {
console.error("Error parsing universe canister id", error);
}

return canisters;
}
);
8 changes: 6 additions & 2 deletions frontend/src/lib/routes/Wallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
import { i18n } from "$lib/stores/i18n";
import { layoutTitleStore } from "$lib/stores/layout.store";
import { nonNullish } from "@dfinity/utils";
import { snsProjectsStore } from "$lib/derived/sns/sns-projects.derived";

export let accountIdentifier: string | undefined | null = undefined;

let snsReady = false;
$: snsReady = $snsProjectsStore.length > 0;

layoutTitleStore.set({
title: $i18n.wallet.title,
});
Expand All @@ -29,10 +33,10 @@
<NnsWallet {accountIdentifier} />
{:else if $isCkBTCUniverseStore}
<CkBTCWallet {accountIdentifier} />
{:else if $isIcrcTokenUniverseStore}
<IcrcWallet {accountIdentifier} />
{:else if nonNullish($snsProjectSelectedStore)}
<SnsWallet {accountIdentifier} />
{:else if $isIcrcTokenUniverseStore || snsReady}
<IcrcWallet {accountIdentifier} />
{/if}

{#if $isCkBTCUniverseStore}
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/tests/lib/pages/IcrcWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CKETHSEPOLIA_INDEX_CANISTER_ID,
CKETHSEPOLIA_LEDGER_CANISTER_ID,
CKETHSEPOLIA_UNIVERSE_CANISTER_ID,
CKETH_LEDGER_CANISTER_ID,
} from "$lib/constants/cketh-canister-ids.constants";
import { AppPath } from "$lib/constants/routes.constants";
import { pageStore } from "$lib/derived/page.derived";
Expand Down Expand Up @@ -528,6 +529,24 @@ describe("IcrcWallet", () => {
});
});

it('displays "Imported token" tag', async () => {
const po = await renderWallet({});
expect(await po.getWalletPageHeadingPo().hasImportedTokenTag()).toEqual(
true
);
});

it('should not display "Imported token" tag for not imported tokens', async () => {
page.mock({
data: { universe: CKETH_LEDGER_CANISTER_ID.toText() },
routeId: AppPath.Wallet,
});
const po = await renderWallet({});
expect(await po.getWalletPageHeadingPo().hasImportedTokenTag()).toEqual(
false
);
});

it("should remove imported tokens", async () => {
let resolveSetImportedTokens;
const spyOnSetImportedTokens = vi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ export class WalletPageHeadingPo extends BasePageObject {
this.root.byTestId("wallet-page-heading-principal")
).getFullText();
}

async hasImportedTokenTag(): Promise<boolean> {
return this.root.byTestId("imported-token-tag").isPresent();
}
}
Loading