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

Populate icrc store with imported tokens #5378

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mstrasinskis
Copy link
Contributor

@mstrasinskis mstrasinskis commented Aug 30, 2024

Motivation

The imported tokens are ICRC tokens. The only new difference is that the index canister is optional. To make the NNS-dapp work with them, the only change needed is to modify the ICRC store to support entries without the index canister (here).

Once the ICRC store supports tokens without an index canister, we can add imported tokens to the ICRC store, and they will be displayed in the tokens table and on the wallet page.

Changes

  • Make indexCanisterId optional in IcrcCanistersStore.
  • Add imported tokens to IcrcCanistersStore after loading them.

Tests

  • Unit test that the icrsStore was populated after imported tokens loading.
  • Other parts were tested manually:

The existence of the work-around suggests that not specifying an index canister already works.

The index canister is optional in IcrcWallet.

The transaction list is now shown when no index canister.

{#if nonNullish($selectedAccountStore.account) && nonNullish($selectedIcrcTokenUniverseIdStore) && nonNullish(indexCanisterId)}
  <IcrcWalletTransactionsList

Index canister is not used in GetTokensModal.

The index canister is not used in the logic of derived stores that uses icrcStore:

  • icrc-universes.derived
  • selectable-universe.derived
  • selected-universe.derived store

Todos

  • Add entry to changelog (if necessary).
    Not necessary.

@mstrasinskis mstrasinskis marked this pull request as ready for review August 30, 2024 10:21
@mstrasinskis mstrasinskis requested a review from a team as a code owner August 30, 2024 10:21
@mstrasinskis mstrasinskis requested a review from dskloetd August 30, 2024 10:21
@mstrasinskis mstrasinskis changed the title Mstr/populate icrc store with imported tokens Populate icrc store with imported tokens Aug 30, 2024
}),
});

if (!certified && notForceCallStrategy()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is importedTokensStore populated regardless of certified but icrcCanistersStore only if certified?

Copy link
Contributor Author

@mstrasinskis mstrasinskis Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a certified property in the importedTokensStore, so that we always know the version. Since we skip adding a token when it’s already in the store, I thought it made sense to use only the certified version. However, it’s not a strong opinion. Especially now, when only query request is used.

for (const { ledgerCanisterId, indexCanisterId } of importedTokens) {
// If the imported token is not already in the store, add it.
if (isNullish(get(icrcCanistersStore)[ledgerCanisterId.toText()])) {
icrcCanistersStore.setCanisters({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't populated 2 different stores with the same data. Instead we should have a derived store which combines the relevant stores.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like AllIcrcCanistersStore ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, or we rename icrcCanisterStore to something else like, defaultIcrcCanistersStore or something.

@@ -7,7 +7,7 @@ import { writable } from "svelte/store";

export interface IcrcCanisters {
ledgerCanisterId: Principal;
indexCanisterId: Principal;
indexCanisterId: Principal | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the work-around can now be removed, right?

: (undefined as unknown as Principal) /* use at your own risk */,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only after the feature in not behind the flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come? With this change, the type of indexCanisterId is Principal | undefined regardless of whether the feature flag is enabled.

@mstrasinskis mstrasinskis mentioned this pull request Sep 1, 2024
1 task
github-merge-queue bot pushed a commit that referenced this pull request Sep 2, 2024
# Motivation

We need to make the NNS-dapp treat imported tokens as ICRC tokens, just
as it does with the current tokens, since imported tokens follow the
ICRC standard. The only differences are that the index canister is
optional (and the nns-dapp already handles this), and they are added by
the user.

Note: This PR includes a solution suggested in [another approach
PR](#5378 (comment)).

# Changes

1. Rename icrcCanistersStore to defaultIcrcCanistersStore.
2. Introduce a new derived store that contains both the current ICRC
canister IDs and imported token IDs, and give this store the old name
icrcCanistersStore.
3. Adjust the NNS-dapp code so that it reads the canister IDs from the
derived store and writes to the renamed defaultIcrcCanistersStore.

# Tests

- Adjust tests to reflect the changes.
- Test for icrcCanistersStore.
- Tested manually that there are not current functionality changes.

# Todos

- [ ] Add entry to changelog (if necessary).
Not necessary.
@mstrasinskis mstrasinskis marked this pull request as draft September 24, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants