diff --git a/frontend/src/lib/components/ic/GetTokensModal.svelte b/frontend/src/lib/components/ic/GetTokensModal.svelte index cf948dc585b..4075bb6eb68 100644 --- a/frontend/src/lib/components/ic/GetTokensModal.svelte +++ b/frontend/src/lib/components/ic/GetTokensModal.svelte @@ -13,7 +13,7 @@ import { tokensByUniverseIdStore } from "$lib/derived/tokens.derived"; import { universesStore } from "$lib/derived/universes.derived"; import { getICPs, getBTC, getIcrcTokens } from "$lib/services/dev.services"; - import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; + import { icrcCanistersStore } from "$lib/derived/icrc-canisters.derived"; import { toastsError } from "$lib/stores/toasts.store"; import type { Universe } from "$lib/types/universe"; import { isUniverseCkBTC, isUniverseNns } from "$lib/utils/universe.utils"; diff --git a/frontend/src/lib/derived/debug.derived.ts b/frontend/src/lib/derived/debug.derived.ts index b8c752e61e5..0010c03b937 100644 --- a/frontend/src/lib/derived/debug.derived.ts +++ b/frontend/src/lib/derived/debug.derived.ts @@ -1,8 +1,8 @@ import { icpAccountsStore } from "$lib/derived/icp-accounts.derived"; import { snsProjectsStore } from "$lib/derived/sns/sns-projects.derived"; import { canistersStore } from "$lib/stores/canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { icrcAccountsStore } from "$lib/stores/icrc-accounts.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { icrcTransactionsStore } from "$lib/stores/icrc-transactions.store"; import { knownNeuronsStore } from "$lib/stores/known-neurons.store"; import { neuronsStore } from "$lib/stores/neurons.store"; @@ -117,7 +117,7 @@ export const initDebugStore = () => snsAggregatorStore, tokensStore, icrcAccountsStore, - icrcCanistersStore, + defaultIcrcCanistersStore, ], ([ $busyStore, @@ -145,7 +145,7 @@ export const initDebugStore = () => $aggregatorStore, $tokensStore, $icrcAccountsStore, - $icrcCanistersStore, + $defaultIcrcCanistersStore, ]) => ({ busy: $busyStore, accounts: $accountsStore, @@ -172,6 +172,6 @@ export const initDebugStore = () => aggregatorStore: $aggregatorStore, tokensStore: $tokensStore, icrcAccountsStore: $icrcAccountsStore, - icrcCanistersStore: $icrcCanistersStore, + defaultIcrcCanistersStore: $defaultIcrcCanistersStore, }) ); diff --git a/frontend/src/lib/derived/icrc-canisters.derived.ts b/frontend/src/lib/derived/icrc-canisters.derived.ts new file mode 100644 index 00000000000..96d84bbfd32 --- /dev/null +++ b/frontend/src/lib/derived/icrc-canisters.derived.ts @@ -0,0 +1,34 @@ +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; +import { importedTokensStore } from "$lib/stores/imported-tokens.store"; +import type { UniverseCanisterIdText } from "$lib/types/universe"; +import type { Principal } from "@dfinity/principal"; +import { derived, type Readable } from "svelte/store"; + +export interface IcrcCanisters { + ledgerCanisterId: Principal; + indexCanisterId: Principal | undefined; +} + +export type IcrcCanistersStoreData = Record< + UniverseCanisterIdText, + IcrcCanisters +>; + +export type IcrcCanistersStore = Readable; + +export const icrcCanistersStore: IcrcCanistersStore = derived( + [defaultIcrcCanistersStore, importedTokensStore], + ([defaultIcrcCanisters, importedTokensStore]) => { + return { + ...defaultIcrcCanisters, + ...Object.fromEntries( + importedTokensStore?.importedTokens?.map( + ({ ledgerCanisterId, indexCanisterId }) => [ + ledgerCanisterId.toText(), + { ledgerCanisterId, indexCanisterId }, + ] + ) ?? [] + ), + }; + } +); diff --git a/frontend/src/lib/derived/icrc-universes.derived.ts b/frontend/src/lib/derived/icrc-universes.derived.ts index cd943daae6f..358e9937ac6 100644 --- a/frontend/src/lib/derived/icrc-universes.derived.ts +++ b/frontend/src/lib/derived/icrc-universes.derived.ts @@ -8,7 +8,7 @@ import { import { icrcCanistersStore, type IcrcCanisters, -} from "$lib/stores/icrc-canisters.store"; +} from "$lib/derived/icrc-canisters.derived"; import { tokensStore, type TokensStoreData } from "$lib/stores/tokens.store"; import type { Universe } from "$lib/types/universe"; import { isNullish, nonNullish } from "@dfinity/utils"; diff --git a/frontend/src/lib/derived/selectable-universes.derived.ts b/frontend/src/lib/derived/selectable-universes.derived.ts index a7cc31532a7..49b98cf08cf 100644 --- a/frontend/src/lib/derived/selectable-universes.derived.ts +++ b/frontend/src/lib/derived/selectable-universes.derived.ts @@ -1,9 +1,9 @@ -import { pageStore, type Page } from "$lib/derived/page.derived"; import { icrcCanistersStore, type IcrcCanistersStore, type IcrcCanistersStoreData, -} from "$lib/stores/icrc-canisters.store"; +} from "$lib/derived/icrc-canisters.derived"; +import { pageStore, type Page } from "$lib/derived/page.derived"; import type { Universe } from "$lib/types/universe"; import { isAllTokensPath, isUniverseCkBTC } from "$lib/utils/universe.utils"; import { isNullish } from "@dfinity/utils"; diff --git a/frontend/src/lib/derived/selected-universe.derived.ts b/frontend/src/lib/derived/selected-universe.derived.ts index a84d2783832..820ff2135ea 100644 --- a/frontend/src/lib/derived/selected-universe.derived.ts +++ b/frontend/src/lib/derived/selected-universe.derived.ts @@ -3,17 +3,17 @@ import { OWN_CANISTER_ID_TEXT, } from "$lib/constants/canister-ids.constants"; import { CKBTC_UNIVERSE_CANISTER_ID } from "$lib/constants/ckbtc-canister-ids.constants"; +import { + icrcCanistersStore, + type IcrcCanistersStore, + type IcrcCanistersStoreData, +} from "$lib/derived/icrc-canisters.derived"; import { pageStore, type Page } from "$lib/derived/page.derived"; import { selectableUniversesStore } from "$lib/derived/selectable-universes.derived"; import { ENABLE_CKBTC, ENABLE_CKTESTBTC, } from "$lib/stores/feature-flags.store"; -import { - icrcCanistersStore, - type IcrcCanistersStore, - type IcrcCanistersStoreData, -} from "$lib/stores/icrc-canisters.store"; import type { Universe, UniverseCanisterId } from "$lib/types/universe"; import { isAllTokensPath, diff --git a/frontend/src/lib/directives/debug.directives.ts b/frontend/src/lib/directives/debug.directives.ts index 986aaf09f89..4697645b189 100644 --- a/frontend/src/lib/directives/debug.directives.ts +++ b/frontend/src/lib/directives/debug.directives.ts @@ -223,7 +223,6 @@ const anonymiseStoreState = async () => { aggregatorStore, tokensStore, icrcAccountsStore, - icrcCanistersStore, } = get(debugStore); return { @@ -291,7 +290,6 @@ const anonymiseStoreState = async () => { ), aggregatorStore, tokensStore, - icrcCanistersStore, icrcAccountsStore: await anonymizeSnsTypeStore( icrcAccountsStore, async ({ certified, accounts }) => ({ diff --git a/frontend/src/lib/pages/IcrcWallet.svelte b/frontend/src/lib/pages/IcrcWallet.svelte index 9c6090bb7e5..aab4b441e53 100644 --- a/frontend/src/lib/pages/IcrcWallet.svelte +++ b/frontend/src/lib/pages/IcrcWallet.svelte @@ -5,7 +5,7 @@ import NoTransactions from "$lib/components/accounts/NoTransactions.svelte"; import { selectedIcrcTokenUniverseIdStore } from "$lib/derived/selected-universe.derived"; import { tokensByUniverseIdStore } from "$lib/derived/tokens.derived"; - import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; + import { icrcCanistersStore } from "$lib/derived/icrc-canisters.derived"; import type { CanisterId } from "$lib/types/canister"; import type { IcrcTokenMetadata } from "$lib/types/icrc"; import type { WalletStore } from "$lib/types/wallet.context"; diff --git a/frontend/src/lib/services/icrc-canisters.services.ts b/frontend/src/lib/services/icrc-canisters.services.ts index 408e147a87c..f6c83cfb931 100644 --- a/frontend/src/lib/services/icrc-canisters.services.ts +++ b/frontend/src/lib/services/icrc-canisters.services.ts @@ -8,17 +8,17 @@ import { CKUSDC_INDEX_CANISTER_ID, CKUSDC_LEDGER_CANISTER_ID, } from "$lib/constants/ckusdc-canister-ids.constants"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { ENABLE_CKTESTBTC } from "$lib/stores/feature-flags.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { isNullish } from "@dfinity/utils"; import { get } from "svelte/store"; export const loadIcrcCanisters = async () => { - const storeData = get(icrcCanistersStore); + const storeData = get(defaultIcrcCanistersStore); // To avoid rerendering the UI and possibly triggering new requests // We don't change the store if it's already filled. if (isNullish(storeData[CKETH_LEDGER_CANISTER_ID.toText()])) { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_LEDGER_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); @@ -27,13 +27,13 @@ export const loadIcrcCanisters = async () => { get(ENABLE_CKTESTBTC) && isNullish(storeData[CKETHSEPOLIA_LEDGER_CANISTER_ID.toText()]) ) { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETHSEPOLIA_LEDGER_CANISTER_ID, indexCanisterId: CKETHSEPOLIA_INDEX_CANISTER_ID, }); } if (isNullish(storeData[CKUSDC_LEDGER_CANISTER_ID.toText()])) { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKUSDC_LEDGER_CANISTER_ID, indexCanisterId: CKUSDC_INDEX_CANISTER_ID, }); diff --git a/frontend/src/lib/services/icrc-tokens.services.ts b/frontend/src/lib/services/icrc-tokens.services.ts index a9e29748309..42ce0265cdb 100644 --- a/frontend/src/lib/services/icrc-tokens.services.ts +++ b/frontend/src/lib/services/icrc-tokens.services.ts @@ -1,4 +1,4 @@ -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { icrcCanistersStore } from "$lib/derived/icrc-canisters.derived"; import type { Unsubscriber } from "svelte/store"; import { loadIcrcToken } from "./icrc-accounts.services"; diff --git a/frontend/src/lib/stores/icrc-canisters.store.ts b/frontend/src/lib/stores/default-icrc-canisters.store.ts similarity index 70% rename from frontend/src/lib/stores/icrc-canisters.store.ts rename to frontend/src/lib/stores/default-icrc-canisters.store.ts index fd71ca0ff31..2dacf19a1e4 100644 --- a/frontend/src/lib/stores/icrc-canisters.store.ts +++ b/frontend/src/lib/stores/default-icrc-canisters.store.ts @@ -5,18 +5,19 @@ import { nonNullish } from "@dfinity/utils"; import type { Readable } from "svelte/store"; import { writable } from "svelte/store"; -export interface IcrcCanisters { +export interface DefaultIcrcCanisters { ledgerCanisterId: Principal; indexCanisterId: Principal; } -export type IcrcCanistersStoreData = Record< +export type DefaultIcrcCanistersStoreData = Record< UniverseCanisterIdText, - IcrcCanisters + DefaultIcrcCanisters >; -export interface IcrcCanistersStore extends Readable { - setCanisters: (data: IcrcCanisters) => void; +export interface IcrcCanistersStore + extends Readable { + setCanisters: (data: DefaultIcrcCanisters) => void; reset: () => void; } @@ -28,18 +29,18 @@ export interface IcrcCanistersStore extends Readable { * - reset: reset all information. * */ -const initIcrcCanistersStore = (): IcrcCanistersStore => { - const initialIcrcCanistersStoreData: IcrcCanistersStoreData = {}; +const initDefaultIcrcCanistersStore = (): IcrcCanistersStore => { + const initialIcrcCanistersStoreData: DefaultIcrcCanistersStoreData = {}; - const { subscribe, update, set } = writable( + const { subscribe, update, set } = writable( initialIcrcCanistersStoreData ); return { subscribe, - setCanisters({ ledgerCanisterId, indexCanisterId }: IcrcCanisters) { - update((state: IcrcCanistersStoreData) => ({ + setCanisters({ ledgerCanisterId, indexCanisterId }: DefaultIcrcCanisters) { + update((state: DefaultIcrcCanistersStoreData) => ({ ...state, [ledgerCanisterId.toText()]: { ledgerCanisterId, @@ -55,7 +56,7 @@ const initIcrcCanistersStore = (): IcrcCanistersStore => { }; }; -export const icrcCanistersStore = initIcrcCanistersStore(); +export const defaultIcrcCanistersStore = initDefaultIcrcCanistersStore(); // Useful to help people record coins they accidentally sent to NNS dapp, but // which are not officially supported by the NNS dapp. @@ -75,7 +76,7 @@ if (browser) { ledgerCanisterId: string, indexCanisterId?: string ) => { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: Principal.fromText(ledgerCanisterId), indexCanisterId: nonNullish(indexCanisterId) ? Principal.fromText(indexCanisterId) diff --git a/frontend/src/lib/utils/universe.utils.ts b/frontend/src/lib/utils/universe.utils.ts index 3391e63e5d6..814d46a00ac 100644 --- a/frontend/src/lib/utils/universe.utils.ts +++ b/frontend/src/lib/utils/universe.utils.ts @@ -4,9 +4,9 @@ import { CKTESTBTC_UNIVERSE_CANISTER_ID, } from "$lib/constants/ckbtc-canister-ids.constants"; import { AppPath } from "$lib/constants/routes.constants"; +import type { IcrcCanistersStoreData } from "$lib/derived/icrc-canisters.derived"; import type { Page } from "$lib/derived/page.derived"; import { i18n } from "$lib/stores/i18n"; -import type { IcrcCanistersStoreData } from "$lib/stores/icrc-canisters.store"; import type { SnsSummary } from "$lib/types/sns"; import type { Universe } from "$lib/types/universe"; import { replacePlaceholders } from "$lib/utils/i18n.utils"; diff --git a/frontend/src/routes/(app)/(nns)/tokens/+page.svelte b/frontend/src/routes/(app)/(nns)/tokens/+page.svelte index bdc08a42237..2de932f2a0b 100644 --- a/frontend/src/routes/(app)/(nns)/tokens/+page.svelte +++ b/frontend/src/routes/(app)/(nns)/tokens/+page.svelte @@ -24,7 +24,7 @@ import { icrcCanistersStore, type IcrcCanistersStoreData, - } from "$lib/stores/icrc-canisters.store"; + } from "$lib/derived/icrc-canisters.derived"; import type { Account } from "$lib/types/account"; import { ActionType, type Action } from "$lib/types/actions"; import type { CkBTCAdditionalCanisters } from "$lib/types/ckbtc-canisters"; diff --git a/frontend/src/tests/lib/derived/icrc-canisters.derived.spec.ts b/frontend/src/tests/lib/derived/icrc-canisters.derived.spec.ts new file mode 100644 index 00000000000..33344efc99e --- /dev/null +++ b/frontend/src/tests/lib/derived/icrc-canisters.derived.spec.ts @@ -0,0 +1,78 @@ +import { icrcCanistersStore } from "$lib/derived/icrc-canisters.derived"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; +import { importedTokensStore } from "$lib/stores/imported-tokens.store"; +import { principal } from "$tests/mocks/sns-projects.mock"; +import { get } from "svelte/store"; + +describe("icrcCanistersStore", () => { + const ledgerCanisterId = principal(0); + const indexCanisterId = principal(1); + const ledgerCanisterId2 = principal(2); + + beforeEach(() => { + defaultIcrcCanistersStore.reset(); + importedTokensStore.reset(); + }); + + it("returns empty object when no icrc tokens are present", () => { + expect(get(icrcCanistersStore)).toEqual({}); + }); + + it("return data from defaultIcrcCanistersStore", () => { + defaultIcrcCanistersStore.setCanisters({ + ledgerCanisterId, + indexCanisterId, + }); + + expect(get(icrcCanistersStore)).toEqual({ + [ledgerCanisterId.toText()]: { + ledgerCanisterId, + indexCanisterId, + }, + }); + }); + + it("return data from importedTokensStore", () => { + importedTokensStore.set({ + importedTokens: [ + { + ledgerCanisterId, + indexCanisterId: undefined, + }, + ], + certified: true, + }); + + expect(get(icrcCanistersStore)).toEqual({ + [ledgerCanisterId.toText()]: { + ledgerCanisterId, + }, + }); + }); + + it("return data from the defaultIcrcCanistersStore and the importedTokensStore", () => { + defaultIcrcCanistersStore.setCanisters({ + ledgerCanisterId, + indexCanisterId, + }); + importedTokensStore.set({ + importedTokens: [ + { + ledgerCanisterId: ledgerCanisterId2, + indexCanisterId: undefined, + }, + ], + certified: true, + }); + + expect(get(icrcCanistersStore)).toEqual({ + [ledgerCanisterId.toText()]: { + ledgerCanisterId, + indexCanisterId, + }, + [ledgerCanisterId2.toText()]: { + ledgerCanisterId: ledgerCanisterId2, + }, + }); + }); +}); diff --git a/frontend/src/tests/lib/derived/icrc-universes.derived.spec.ts b/frontend/src/tests/lib/derived/icrc-universes.derived.spec.ts index f48ce51743a..384e861a2e5 100644 --- a/frontend/src/tests/lib/derived/icrc-universes.derived.spec.ts +++ b/frontend/src/tests/lib/derived/icrc-universes.derived.spec.ts @@ -6,7 +6,7 @@ import { CKETH_UNIVERSE_CANISTER_ID, } from "$lib/constants/cketh-canister-ids.constants"; import { icrcTokensUniversesStore } from "$lib/derived/icrc-universes.derived"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { mockCkETHTESTToken, @@ -22,11 +22,11 @@ import { get } from "svelte/store"; describe("icrcTokensUniversesStore", () => { beforeEach(() => { tokensStore.reset(); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); }); it("returns empty array if no tokens are present", () => { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_UNIVERSE_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); @@ -54,7 +54,7 @@ describe("icrcTokensUniversesStore", () => { token: mockCkETHToken, }, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_UNIVERSE_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); @@ -72,11 +72,11 @@ describe("icrcTokensUniversesStore", () => { token: mockCkETHTESTToken, }, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_UNIVERSE_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETHSEPOLIA_LEDGER_CANISTER_ID, indexCanisterId: CKETHSEPOLIA_INDEX_CANISTER_ID, }); @@ -94,7 +94,7 @@ describe("icrcTokensUniversesStore", () => { token: mockToken, }, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: ledgerCanisterId, indexCanisterId: principal(2), }); @@ -117,7 +117,7 @@ describe("icrcTokensUniversesStore", () => { }, }, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: ledgerCanisterId, indexCanisterId: principal(2), }); diff --git a/frontend/src/tests/lib/derived/selected-universe.derived.spec.ts b/frontend/src/tests/lib/derived/selected-universe.derived.spec.ts index f435711f462..9739b83ccc3 100644 --- a/frontend/src/tests/lib/derived/selected-universe.derived.spec.ts +++ b/frontend/src/tests/lib/derived/selected-universe.derived.spec.ts @@ -17,8 +17,8 @@ import { selectedUniverseStore, } from "$lib/derived/selected-universe.derived"; import { snsProjectsCommittedStore } from "$lib/derived/sns/sns-projects.derived"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { page } from "$mocks/$app/stores"; import { mockCkETHToken } from "$tests/mocks/cketh-accounts.mock"; @@ -118,7 +118,7 @@ describe("selected universe derived stores", () => { const ledgerCanisterId = principal(0); beforeEach(() => { - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); }); it("should be ICRC Token inside ICRC Token universe", () => { @@ -126,7 +126,7 @@ describe("selected universe derived stores", () => { data: { universe: ledgerCanisterId.toText() }, routeId: AppPath.Accounts, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId, indexCanisterId: principal(1), }); @@ -139,7 +139,7 @@ describe("selected universe derived stores", () => { data: { universe: ledgerCanisterId.toText() }, routeId: AppPath.Neurons, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId, indexCanisterId: principal(1), }); @@ -262,7 +262,7 @@ describe("selected universe derived stores", () => { }, routeId: data.routeId, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: icrcCanisterId, indexCanisterId: principal(1), }); @@ -464,9 +464,9 @@ describe("selected universe derived stores", () => { const ledgerCanisterId = principal(0); beforeEach(() => { - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); tokensStore.reset(); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId, indexCanisterId: principal(1), }); diff --git a/frontend/src/tests/lib/derived/sns/sns-selected-project.derived.spec.ts b/frontend/src/tests/lib/derived/sns/sns-selected-project.derived.spec.ts index 28b01cbcf02..411c8946aa1 100644 --- a/frontend/src/tests/lib/derived/sns/sns-selected-project.derived.spec.ts +++ b/frontend/src/tests/lib/derived/sns/sns-selected-project.derived.spec.ts @@ -4,7 +4,7 @@ import { snsOnlyProjectStore, snsProjectSelectedStore, } from "$lib/derived/sns/sns-selected-project.derived"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { snsSwapCommitmentsStore } from "$lib/stores/sns.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { page } from "$mocks/$app/stores"; @@ -33,7 +33,7 @@ describe("selected sns project derived stores", () => { lifecycle: SnsSwapLifecycle.Committed, }, ]); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); tokensStore.reset(); }); diff --git a/frontend/src/tests/lib/derived/universes.derived.spec.ts b/frontend/src/tests/lib/derived/universes.derived.spec.ts index 0cae556f743..c888d4535c7 100644 --- a/frontend/src/tests/lib/derived/universes.derived.spec.ts +++ b/frontend/src/tests/lib/derived/universes.derived.spec.ts @@ -7,8 +7,8 @@ import { CKETH_LEDGER_CANISTER_ID, } from "$lib/constants/cketh-canister-ids.constants"; import { universesStore } from "$lib/derived/universes.derived"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { aggregatorCanisterLogoPath } from "$lib/utils/sns-aggregator-converters.utils"; import { @@ -32,7 +32,7 @@ describe("universes derived stores", () => { beforeEach(() => { vi.restoreAllMocks(); resetSnsProjects(); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); tokensStore.reset(); }); @@ -87,7 +87,7 @@ describe("universes derived stores", () => { }); it("should return Nns, ckBTC and ckETH", () => { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_LEDGER_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); @@ -107,11 +107,11 @@ describe("universes derived stores", () => { }); it("should return Nns, ckBTC, ckETH and ckETHSEPOLIA", () => { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_LEDGER_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETHSEPOLIA_LEDGER_CANISTER_ID, indexCanisterId: CKETHSEPOLIA_INDEX_CANISTER_ID, }); diff --git a/frontend/src/tests/lib/pages/IcrcWallet.spec.ts b/frontend/src/tests/lib/pages/IcrcWallet.spec.ts index d72813f2cdf..1b506910ef1 100644 --- a/frontend/src/tests/lib/pages/IcrcWallet.spec.ts +++ b/frontend/src/tests/lib/pages/IcrcWallet.spec.ts @@ -9,9 +9,9 @@ import { import { AppPath } from "$lib/constants/routes.constants"; import { pageStore } from "$lib/derived/page.derived"; import IcrcWallet from "$lib/pages/IcrcWallet.svelte"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; import { icrcAccountsStore } from "$lib/stores/icrc-accounts.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { page } from "$mocks/$app/stores"; import AccountsTest from "$tests/lib/pages/AccountsTest.svelte"; @@ -112,13 +112,13 @@ describe("IcrcWallet", () => { overrideFeatureFlagsStore.reset(); toastsStore.reset(); resetIdentity(); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); vi.mocked(icrcIndexApi.getTransactions).mockResolvedValue({ transactions: [], }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETHSEPOLIA_UNIVERSE_CANISTER_ID, indexCanisterId: CKETHSEPOLIA_INDEX_CANISTER_ID, }); @@ -434,7 +434,7 @@ describe("IcrcWallet", () => { it("should not display index canister link when not available", async () => { const ledgerCanisterId = principal(0); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId, indexCanisterId: undefined, }); diff --git a/frontend/src/tests/lib/services/_public/app.services.spec.ts b/frontend/src/tests/lib/services/_public/app.services.spec.ts index ceed262c654..6f04c209b17 100644 --- a/frontend/src/tests/lib/services/_public/app.services.spec.ts +++ b/frontend/src/tests/lib/services/_public/app.services.spec.ts @@ -9,8 +9,8 @@ import { } from "$lib/constants/cketh-canister-ids.constants"; import { initAppPublicData } from "$lib/services/$public/app.services"; import { loadSnsProjects } from "$lib/services/$public/sns.services"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { mockCkETHToken } from "$tests/mocks/cketh-accounts.mock"; import { get } from "svelte/store"; @@ -26,7 +26,7 @@ vi.mock("$lib/services/$public/sns.services", () => { describe("$public/app-services", () => { beforeEach(() => { vi.clearAllMocks(); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); tokensStore.reset(); vi.spyOn(icrcLedgerApi, "queryIcrcToken").mockResolvedValue(mockCkETHToken); overrideFeatureFlagsStore.setFlag("ENABLE_CKTESTBTC", false); @@ -42,7 +42,7 @@ describe("$public/app-services", () => { await initAppPublicData(); expect( - get(icrcCanistersStore)[CKETH_UNIVERSE_CANISTER_ID.toText()] + get(defaultIcrcCanistersStore)[CKETH_UNIVERSE_CANISTER_ID.toText()] ).toEqual({ ledgerCanisterId: CKETH_LEDGER_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, @@ -66,7 +66,9 @@ describe("$public/app-services", () => { await initAppPublicData(); expect( - get(icrcCanistersStore)[CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText()] + get(defaultIcrcCanistersStore)[ + CKETHSEPOLIA_UNIVERSE_CANISTER_ID.toText() + ] ).toEqual({ ledgerCanisterId: CKETHSEPOLIA_LEDGER_CANISTER_ID, indexCanisterId: CKETHSEPOLIA_INDEX_CANISTER_ID, diff --git a/frontend/src/tests/lib/services/icrc-canisters.services.spec.ts b/frontend/src/tests/lib/services/icrc-canisters.services.spec.ts index 1d94157436c..367acdbadfa 100644 --- a/frontend/src/tests/lib/services/icrc-canisters.services.spec.ts +++ b/frontend/src/tests/lib/services/icrc-canisters.services.spec.ts @@ -11,15 +11,15 @@ import { CKUSDC_UNIVERSE_CANISTER_ID, } from "$lib/constants/ckusdc-canister-ids.constants"; import { loadIcrcCanisters } from "$lib/services/icrc-canisters.services"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { get } from "svelte/store"; describe("icrc-canisters.services", () => { describe("loadIcrcCanisters", () => { beforeEach(() => { overrideFeatureFlagsStore.setFlag("ENABLE_CKTESTBTC", false); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); }); describe("if ckethtest is enabled", () => { @@ -28,10 +28,10 @@ describe("icrc-canisters.services", () => { }); it("should load cketh and ckusdc canisters", async () => { - expect(get(icrcCanistersStore)).toEqual({}); + expect(get(defaultIcrcCanistersStore)).toEqual({}); await loadIcrcCanisters(); - expect(get(icrcCanistersStore)).toEqual({ + expect(get(defaultIcrcCanistersStore)).toEqual({ [CKETH_UNIVERSE_CANISTER_ID.toText()]: { ledgerCanisterId: CKETH_UNIVERSE_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, @@ -48,31 +48,31 @@ describe("icrc-canisters.services", () => { }); it("should not load canisters if already present", async () => { - vi.spyOn(icrcCanistersStore, "setCanisters"); - icrcCanistersStore.setCanisters({ + vi.spyOn(defaultIcrcCanistersStore, "setCanisters"); + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_UNIVERSE_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETHSEPOLIA_LEDGER_CANISTER_ID, indexCanisterId: CKETHSEPOLIA_INDEX_CANISTER_ID, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKUSDC_LEDGER_CANISTER_ID, indexCanisterId: CKUSDC_INDEX_CANISTER_ID, }); - expect(icrcCanistersStore.setCanisters).toHaveBeenCalledTimes(3); + expect(defaultIcrcCanistersStore.setCanisters).toHaveBeenCalledTimes(3); await loadIcrcCanisters(); - expect(icrcCanistersStore.setCanisters).toHaveBeenCalledTimes(3); + expect(defaultIcrcCanistersStore.setCanisters).toHaveBeenCalledTimes(3); }); }); describe("if ckethtest is disabled", () => { it("should load cketh and ckusdc canisters", async () => { - expect(get(icrcCanistersStore)).toEqual({}); + expect(get(defaultIcrcCanistersStore)).toEqual({}); await loadIcrcCanisters(); - expect(get(icrcCanistersStore)).toEqual({ + expect(get(defaultIcrcCanistersStore)).toEqual({ [CKETH_UNIVERSE_CANISTER_ID.toText()]: { ledgerCanisterId: CKETH_UNIVERSE_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, diff --git a/frontend/src/tests/lib/services/icrc-tokens.services.spec.ts b/frontend/src/tests/lib/services/icrc-tokens.services.spec.ts index 054f7d520f7..90f840d2783 100644 --- a/frontend/src/tests/lib/services/icrc-tokens.services.spec.ts +++ b/frontend/src/tests/lib/services/icrc-tokens.services.spec.ts @@ -1,6 +1,6 @@ import * as icrcLedgerApi from "$lib/api/icrc-ledger.api"; import { watchIcrcTokensLoadTokenData } from "$lib/services/icrc-tokens.services"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { mockToken, principal } from "$tests/mocks/sns-projects.mock"; import { runResolvedPromises } from "$tests/utils/timers.test-utils"; @@ -17,7 +17,7 @@ describe("icrc-tokens.services", () => { const token2 = { ...mockToken, name: "Token 2" }; beforeEach(() => { - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); tokensStore.reset(); vi.spyOn(icrcLedgerApi, "queryIcrcToken").mockImplementation( async ({ canisterId }) => { @@ -33,7 +33,7 @@ describe("icrc-tokens.services", () => { it("should load tokens when icrcCanistersStore is updated", async () => { watchIcrcTokensLoadTokenData(); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: ledgerCanisterId1, indexCanisterId, }); @@ -49,12 +49,12 @@ describe("icrc-tokens.services", () => { it("should load multiple tokens when icrcCanistersStore is updated multiple times", async () => { watchIcrcTokensLoadTokenData(); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: ledgerCanisterId1, indexCanisterId, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: ledgerCanisterId2, indexCanisterId, }); diff --git a/frontend/src/tests/lib/stores/icrc-canisters.store.spec.ts b/frontend/src/tests/lib/stores/icrc-canisters.store.spec.ts index 1cd681a9423..62b9b76cf93 100644 --- a/frontend/src/tests/lib/stores/icrc-canisters.store.spec.ts +++ b/frontend/src/tests/lib/stores/icrc-canisters.store.spec.ts @@ -1,19 +1,22 @@ -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { principal } from "$tests/mocks/sns-projects.mock"; import { get } from "svelte/store"; describe("icrc canisters store", () => { beforeEach(() => { - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); }); const ledgerCanisterId = principal(0); const indexCanisterId = principal(1); it("should store one set of canisters", () => { - icrcCanistersStore.setCanisters({ ledgerCanisterId, indexCanisterId }); + defaultIcrcCanistersStore.setCanisters({ + ledgerCanisterId, + indexCanisterId, + }); - const store = get(icrcCanistersStore); + const store = get(defaultIcrcCanistersStore); expect(store[ledgerCanisterId.toText()]).toEqual({ ledgerCanisterId, indexCanisterId, @@ -23,16 +26,16 @@ describe("icrc canisters store", () => { it("should store multiple sets of canisters keyed by ledger canister id", () => { const ledgerCansisterId2 = principal(2); const indexCanisterId2 = principal(3); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId, indexCanisterId, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: ledgerCansisterId2, indexCanisterId: indexCanisterId2, }); - const store = get(icrcCanistersStore); + const store = get(defaultIcrcCanistersStore); expect(store[ledgerCanisterId.toText()]).toEqual({ ledgerCanisterId, indexCanisterId, diff --git a/frontend/src/tests/lib/utils/universes.utils.spec.ts b/frontend/src/tests/lib/utils/universes.utils.spec.ts index 743f9442e7a..0324be078de 100644 --- a/frontend/src/tests/lib/utils/universes.utils.spec.ts +++ b/frontend/src/tests/lib/utils/universes.utils.spec.ts @@ -5,7 +5,7 @@ import { } from "$lib/constants/ckbtc-canister-ids.constants"; import { AppPath } from "$lib/constants/routes.constants"; import { nnsUniverseStore } from "$lib/derived/nns-universe.derived"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { createUniverse, isAllTokensPath, @@ -160,44 +160,44 @@ describe("universes-utils", () => { describe("isIcrcTokenUniverse", () => { beforeEach(() => { - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); }); it("should return true if universe is in ICRC Canisters store", () => { const universeId = principal(0); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: universeId, indexCanisterId: principal(1), }); expect( isIcrcTokenUniverse({ universeId, - icrcCanisters: get(icrcCanistersStore), + icrcCanisters: get(defaultIcrcCanistersStore), }) ).toBe(true); }); it("should return false if universe is not in ICRC Canisters store", () => { const universeId = principal(0); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: universeId, indexCanisterId: principal(1), }); expect( isIcrcTokenUniverse({ universeId: principal(2), - icrcCanisters: get(icrcCanistersStore), + icrcCanisters: get(defaultIcrcCanistersStore), }) ).toBe(false); }); it("should return false when ICRC Canisters store is empty", () => { const universeId = principal(0); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); expect( isIcrcTokenUniverse({ universeId, - icrcCanisters: get(icrcCanistersStore), + icrcCanisters: get(defaultIcrcCanistersStore), }) ).toBe(false); }); diff --git a/frontend/src/tests/routes/app/tokens/page.spec.ts b/frontend/src/tests/routes/app/tokens/page.spec.ts index 87564d6a9e7..e59138ded17 100644 --- a/frontend/src/tests/routes/app/tokens/page.spec.ts +++ b/frontend/src/tests/routes/app/tokens/page.spec.ts @@ -14,9 +14,9 @@ import { CKUSDC_LEDGER_CANISTER_ID, CKUSDC_UNIVERSE_CANISTER_ID, } from "$lib/constants/ckusdc-canister-ids.constants"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store"; import { icrcAccountsStore } from "$lib/stores/icrc-accounts.store"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; import { importedTokensStore } from "$lib/stores/imported-tokens.store"; import { tokensStore } from "$lib/stores/tokens.store"; import type { IcrcTokenMetadata } from "$lib/types/icrc"; @@ -120,7 +120,7 @@ describe("Tokens route", () => { vi.clearAllMocks(); icrcAccountsStore.reset(); tokensStore.reset(); - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); importedTokensStore.reset(); ckBTCBalanceE8s = ckBTCDefaultBalanceE8s; ckETHBalanceUlps = ckETHDefaultBalanceUlps; @@ -196,7 +196,7 @@ describe("Tokens route", () => { main: { ...mockMainAccount, balanceUlps: icpBalanceE8s }, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKUSDC_LEDGER_CANISTER_ID, indexCanisterId: CKUSDC_INDEX_CANISTER_ID, }); @@ -605,7 +605,7 @@ describe("Tokens route", () => { canisterId: importedToken1Id, token: importedToken1Metadata, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: importedToken1Id, indexCanisterId: undefined, }); @@ -613,7 +613,7 @@ describe("Tokens route", () => { canisterId: importedToken2Id, token: importedToken2Metadata, }); - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: importedToken2Id, indexCanisterId: undefined, }); diff --git a/frontend/src/tests/utils/cketh.test-utils.ts b/frontend/src/tests/utils/cketh.test-utils.ts index 9c634227dab..73fadb0628c 100644 --- a/frontend/src/tests/utils/cketh.test-utils.ts +++ b/frontend/src/tests/utils/cketh.test-utils.ts @@ -3,12 +3,12 @@ import { CKETH_LEDGER_CANISTER_ID, CKETH_UNIVERSE_CANISTER_ID, } from "$lib/constants/cketh-canister-ids.constants"; -import { icrcCanistersStore } from "$lib/stores/icrc-canisters.store"; +import { defaultIcrcCanistersStore } from "$lib/stores/default-icrc-canisters.store"; import { tokensStore } from "$lib/stores/tokens.store"; import { mockCkETHToken } from "$tests/mocks/cketh-accounts.mock"; export const setCkETHCanisters = () => { - icrcCanistersStore.setCanisters({ + defaultIcrcCanistersStore.setCanisters({ ledgerCanisterId: CKETH_LEDGER_CANISTER_ID, indexCanisterId: CKETH_INDEX_CANISTER_ID, }); @@ -19,6 +19,6 @@ export const setCkETHCanisters = () => { }; export const resetCkETHCanisters = () => { - icrcCanistersStore.reset(); + defaultIcrcCanistersStore.reset(); tokensStore.reset(); };