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

Imported ledger input update #5607

Merged
merged 3 commits into from
Oct 11, 2024
Merged
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
29 changes: 19 additions & 10 deletions frontend/src/lib/components/accounts/ImportTokenForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { createEventDispatcher } from "svelte";
import { isNullish } from "@dfinity/utils";
import CalloutWarning from "$lib/components/common/CalloutWarning.svelte";
import ImportTokenCanisterId from "$lib/components/accounts/ImportTokenCanisterId.svelte";

export let ledgerCanisterId: Principal | undefined = undefined;
export let indexCanisterId: Principal | undefined = undefined;
Expand All @@ -24,17 +25,25 @@
<p class="description">{$i18n.import_token.description}</p>

<form on:submit|preventDefault={() => dispatch("nnsSubmit")}>
<PrincipalInput
bind:principal={ledgerCanisterId}
placeholderLabelKey="import_token.placeholder"
name="ledger-canister-id"
testId="ledger-canister-id"
disabled={addIndexCanisterMode}
>
<svelte:fragment slot="label"
>{$i18n.import_token.ledger_label}</svelte:fragment
{#if addIndexCanisterMode}
<ImportTokenCanisterId
testId="ledger-canister-id-view"
label={$i18n.import_token.ledger_label}
canisterId={ledgerCanisterId}
/>
{:else}
<PrincipalInput
bind:principal={ledgerCanisterId}
placeholderLabelKey="import_token.placeholder"
name="ledger-canister-id"
testId="ledger-canister-id"
disabled={addIndexCanisterMode}
>
</PrincipalInput>
<svelte:fragment slot="label"
>{$i18n.import_token.ledger_label}</svelte:fragment
>
</PrincipalInput>
{/if}

<PrincipalInput
bind:principal={indexCanisterId}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@
"description": "You can import a new token to your NNS dapp wallet by providing its ledger canister ID.",
"ledger_label": "Ledger Canister ID",
"index_label_optional": "Index Canister ID <span class='description'>(Optional)</span>",
"placeholder": "00000-00000-00000-00000-000",
"placeholder": "_____-_____-_____-_____-cai",
mstrasinskis marked this conversation as resolved.
Show resolved Hide resolved
"index_canister_description": "To see this token's transaction history in the NNS dapp, you need to provide its index canister. <strong>Note:</strong> not all tokens have index canisters.",
"review_token_info": "Review token info",
"warning": "<strong>Warning:</strong> Be careful what token you import! Anyone can create a token including one with the same name as existing tokens, such as ckBTC.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,18 @@ describe("ImportTokenForm", () => {
});

it("should display addIndexCanister mode ", async () => {
const ledgerCanisterId = principal(0);
const { po } = renderComponent({
ledgerCanisterId: principal(0),
ledgerCanisterId,
indexCanisterId: undefined,
addIndexCanisterMode: true,
});

expect(await po.getLedgerCanisterInputPo().isDisabled()).toEqual(true);
expect(await po.getLedgerCanisterInputPo().isPresent()).toEqual(false);
expect(await po.getLedgerCanisterIdPo().isPresent()).toEqual(true);
expect(await po.getLedgerCanisterIdPo().getCanisterIdText()).toEqual(
ledgerCanisterId.toText()
);
expect(await po.getIndexCanisterInputPo().isRequired()).toEqual(true);
expect((await po.getIndexCanisterInputPo().getText()).trim()).toEqual(
"Index Canister ID"
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/tests/lib/pages/IcrcWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ describe("IcrcWallet", () => {
expect(spyOnSetImportedTokens).toBeCalledTimes(0);
expect(await addIndexCanisterModalPo.isPresent()).toBe(true);
expect(get(busyStore)).toEqual([]);
expect(
await addIndexCanisterModalPo
.getImportTokenFormPo()
.getLedgerCanisterIdPo()
.getCanisterIdText()
).toEqual(ledgerCanisterId.toText());

await addIndexCanisterModalPo.typeIndexCanisterId(
indexCanisterId.toText()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ButtonPo } from "$tests/page-objects/Button.page-object";
import { CalloutWarningPo } from "$tests/page-objects/CalloutWarning.page-object";
import { ImportTokenCanisterIdPo } from "$tests/page-objects/ImportTokenCanisterId.page-object";
import { InputWithErrorPo } from "$tests/page-objects/InputWithError.page-object";
import { BasePageObject } from "$tests/page-objects/base.page-object";
import type { PageObjectElement } from "$tests/types/page-object.types";
Expand All @@ -18,6 +19,13 @@ export class ImportTokenFormPo extends BasePageObject {
});
}

getLedgerCanisterIdPo(): ImportTokenCanisterIdPo {
return ImportTokenCanisterIdPo.under({
element: this.root,
testId: "ledger-canister-id-view",
});
}

getIndexCanisterInputPo(): InputWithErrorPo {
return InputWithErrorPo.under({
element: this.root,
Expand Down