-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default icrc canisters store (#5383)
# 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.
- Loading branch information
1 parent
4c55d52
commit 6481f7b
Showing
26 changed files
with
222 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IcrcCanistersStoreData>; | ||
|
||
export const icrcCanistersStore: IcrcCanistersStore = derived( | ||
[defaultIcrcCanistersStore, importedTokensStore], | ||
([defaultIcrcCanisters, importedTokensStore]) => { | ||
return { | ||
...defaultIcrcCanisters, | ||
...Object.fromEntries( | ||
importedTokensStore?.importedTokens?.map( | ||
({ ledgerCanisterId, indexCanisterId }) => [ | ||
ledgerCanisterId.toText(), | ||
{ ledgerCanisterId, indexCanisterId }, | ||
] | ||
) ?? [] | ||
), | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
frontend/src/tests/lib/derived/icrc-canisters.derived.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.