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

Fix: Adds an override for the name and token.symbol values for abandoned SNS #5915

Merged
merged 8 commits into from
Dec 4, 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
2 changes: 2 additions & 0 deletions CHANGELOG-Nns-Dapp-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ proposal is successful, the changes it released will be moved from this file to

#### Fixed

- Adds an override for the name and token.symbol values for abandoned SNS

#### Security

#### Not Published
Expand Down
58 changes: 52 additions & 6 deletions frontend/src/lib/stores/sns-aggregator.store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { CachedSnsDto } from "$lib/types/sns-aggregator";
import type {
CachedSnsDto,
CachedSnsTokenMetadataDto,
} from "$lib/types/sns-aggregator";
import { SnsSwapLifecycle } from "@dfinity/sns";
import { nonNullish } from "@dfinity/utils";
import { derived, writable, type Readable } from "svelte/store";
Expand Down Expand Up @@ -35,10 +38,53 @@ export const snsAggregatorIncludingAbortedProjectsStore =
export const snsAggregatorStore: SnsAggregatorStore = derived(
snsAggregatorIncludingAbortedProjectsStore,
(store) => ({
data: store.data?.filter(
(sns) =>
nonNullish(sns.lifecycle) &&
sns.lifecycle.lifecycle !== SnsSwapLifecycle.Aborted
),
data: store.data
?.filter(
(sns) =>
nonNullish(sns.lifecycle) &&
sns.lifecycle.lifecycle !== SnsSwapLifecycle.Aborted
)
.map(fixBrokenSnsMetadataBasedOnId),
})
yhabib marked this conversation as resolved.
Show resolved Hide resolved
);

// TODO: Find a better way to fix broken SNS metadata.
const brokenSnsOverrides: Record<
string,
{ name: string; tokenSymbol: string }
> = {
// Overrided for CYCLES_TRANSFER_STATION as discussed in https://dfinity.slack.com/archives/C039M7YS6F6/p1733302975333649
"ibahq-taaaa-aaaaq-aadna-cai": {
name: "CYCLES_TRANSFER_STATION",
tokenSymbol: "CTS",
},
};

const fixBrokenSnsMetadataBasedOnId = (sns: CachedSnsDto): CachedSnsDto => {
const override = brokenSnsOverrides[sns.list_sns_canisters.root];
if (!nonNullish(override)) return sns;
const newMeta = {
...sns.meta,
name: `${sns.meta.name} (formerly ${override.name})`,
};

const newIcrc1Metadata = sns.icrc1_metadata.map<
[string, CachedSnsTokenMetadataDto[0][1]]
>(([name, value]) => {
if (name === "icrc1:symbol" && "Text" in value) {
return [
name,
{
Text: `${value.Text} (${override.tokenSymbol})`,
},
];
}
return [name, value];
});

return {
...sns,
meta: { ...newMeta },
icrc1_metadata: [...newIcrc1Metadata],
};
};
55 changes: 55 additions & 0 deletions frontend/src/tests/lib/stores/sns-aggregator.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,59 @@ describe("sns-aggregator store", () => {
expect(get(snsAggregatorStore).data).toEqual(nonAbortedData);
});
});

describe("brokenSnsOverrides", () => {
const withBrokenSns = ({
sns,
rootCanisterId,
}: {
sns: CachedSnsDto;
rootCanisterId: string;
}) => ({
...sns,
list_sns_canisters: {
...sns.list_sns_canisters,
root: rootCanisterId,
},
});

it("should override information for SNS with rootCanisterId ibahq-taaaa-aaaaq-aadna-cai", () => {
const mockedSns = aggregatorMockSnsesDataDto[0];
const brokenSns = withBrokenSns({
sns: {
...mockedSns,
meta: {
...mockedSns.meta,
name: "---",
},
icrc1_metadata: [...mockedSns.icrc1_metadata].map(([name, value]) => {
if (name === "icrc1:symbol" && "Text" in value) {
return [
name,
{
Text: "---",
},
];
}
return [name, value];
}),
},
rootCanisterId: "ibahq-taaaa-aaaaq-aadna-cai",
});

const data = [brokenSns];
snsAggregatorIncludingAbortedProjectsStore.setData(data);
expect(
get(snsAggregatorIncludingAbortedProjectsStore).data[0].meta.name
).toBe("---");
expect(
get(snsAggregatorIncludingAbortedProjectsStore).data[0]
.icrc1_metadata[3][1]
).toEqual({ Text: "---" });

const result = get(snsAggregatorStore).data[0];
expect(result.meta.name).toBe("--- (formerly CYCLES_TRANSFER_STATION)");
expect(result.icrc1_metadata[3][1]).toEqual({ Text: "--- (CTS)" });
});
});
});
Loading