From 4ac650480ab940e3e84999a63eebdd0bef6bead5 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Wed, 20 Nov 2024 16:27:10 +0100 Subject: [PATCH] feat(frontend): remove indexCanisterVersion (#3620) # Motivation All SNSes have upgraded their Index Canister version to `-ng` several months ago. Therefore, the `indexCanisterVersion` information is no longer necessary. # Notes The weekly job was interesting because it reported Index Canisters as "outdated" when they were out of cycles. However, detecting such issues is not entirely our responsibility. Additionally, the job incorrectly flagged them as "outdated" due to a failing assertion that checked the error message to determine if they were out of cycles. This assertion stopped working because the error message text had changed. Long story short, we decided to remove the check. # Changes - Remove assertion from bi-weekly script. - Remove type and usage of `indexCanisterVersion` in code. --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> --- scripts/build.tokens.sns.mjs | 52 +---------- .../src/env/schema/env-sns-token.schema.ts | 5 +- src/frontend/src/env/tokens.sns.json | 90 +++++++------------ .../tokens/IcManageTokenToggle.svelte | 38 ++------ .../services/icrc-custom-tokens.services.ts | 4 +- .../src/icp/types/icrc-custom-token.ts | 4 +- src/frontend/src/icp/utils/icrc.utils.ts | 3 - src/frontend/src/lib/i18n/en.json | 1 - src/frontend/src/lib/types/i18n.d.ts | 2 +- .../src/lib/utils/token-toggle.utils.ts | 3 +- .../tests/icp/services/icrc.services.spec.ts | 1 - .../lib/utils/token-toggle.utils.spec.ts | 11 --- .../tests/mocks/icrc-custom-tokens.mock.ts | 3 +- 13 files changed, 44 insertions(+), 173 deletions(-) diff --git a/scripts/build.tokens.sns.mjs b/scripts/build.tokens.sns.mjs index d91ddc66ee..f7c768deef 100644 --- a/scripts/build.tokens.sns.mjs +++ b/scripts/build.tokens.sns.mjs @@ -1,12 +1,8 @@ #!/usr/bin/env node -import { AnonymousIdentity } from '@dfinity/agent'; -import { Ed25519KeyIdentity } from '@dfinity/identity'; -import { IcrcIndexNgCanister, IcrcMetadataResponseEntries } from '@dfinity/ledger-icrc'; -import { Principal } from '@dfinity/principal'; +import { IcrcMetadataResponseEntries } from '@dfinity/ledger-icrc'; import { candidNumberArrayToBigInt, - createAgent, fromNullable, isNullish, jsonReplacer, @@ -115,34 +111,6 @@ const mapOptionalToken = (response) => { return nullishToken; }; -const assertIndexCanister = async (indexCanisterId) => { - try { - const agent = await createAgent({ - identity: new AnonymousIdentity(), - host: 'https://icp-api.io' - }); - - const { getTransactions } = IcrcIndexNgCanister.create({ - agent, - canisterId: Principal.fromText(indexCanisterId) - }); - - const { balance } = await getTransactions({ - certified: true, - max_results: 0n, - account: { owner: Ed25519KeyIdentity.generate().getPrincipal() } - }); - - return balance >= 0n; - } catch (err) { - if (err.response?.body?.reject_message?.includes('out of cycles')) { - throw new Error(err.response.body.reject_message); - } - - return false; - } -}; - export const findSnses = async () => { const data = await querySnsAggregator(); @@ -199,23 +167,7 @@ export const findSnses = async () => { { tokens: [], icons: [] } ); - const indexCanisterVersion = async (token) => { - const { indexCanisterId } = token; - - const valid = await assertIndexCanister(indexCanisterId); - - return { - ...token, - indexCanisterVersion: valid ? 'up-to-date' : 'outdated' - }; - }; - - const enhancedTokens = await Promise.all(tokens.map(indexCanisterVersion)); - - writeFileSync( - join(DATA_FOLDER, 'tokens.sns.json'), - JSON.stringify(enhancedTokens, jsonReplacer, 8) - ); + writeFileSync(join(DATA_FOLDER, 'tokens.sns.json'), JSON.stringify(tokens, jsonReplacer, 8)); await saveLogos(icons); }; diff --git a/src/frontend/src/env/schema/env-sns-token.schema.ts b/src/frontend/src/env/schema/env-sns-token.schema.ts index d2840473d1..5f61d0f4e6 100644 --- a/src/frontend/src/env/schema/env-sns-token.schema.ts +++ b/src/frontend/src/env/schema/env-sns-token.schema.ts @@ -1,12 +1,9 @@ import { EnvIcrcTokenMetadataSchema, EnvIcTokenSchema } from '$env/schema/env-icrc-token.schema'; import { z } from 'zod'; -const IndexCanisterVersionSchema = z.union([z.literal('up-to-date'), z.literal('outdated')]); - export const EnvSnsTokenSchema = EnvIcTokenSchema.extend({ rootCanisterId: z.string(), - metadata: EnvIcrcTokenMetadataSchema, - indexCanisterVersion: IndexCanisterVersionSchema + metadata: EnvIcrcTokenMetadataSchema }); export const EnvSnsTokensSchema = z.array(EnvSnsTokenSchema); diff --git a/src/frontend/src/env/tokens.sns.json b/src/frontend/src/env/tokens.sns.json index 560cf17bf6..0b738ade8d 100644 --- a/src/frontend/src/env/tokens.sns.json +++ b/src/frontend/src/env/tokens.sns.json @@ -12,8 +12,7 @@ }, "alternativeName": "Dragginz", "url": "https://dragginz.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "2ouva-viaaa-aaaaq-aaamq-cai", @@ -28,8 +27,7 @@ }, "alternativeName": "OpenChat", "url": "https://oc.app" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "73mez-iiaaa-aaaaq-aaasq-cai", @@ -44,8 +42,7 @@ }, "alternativeName": "Kinic", "url": "https://kinic.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "6rdgd-kyaaa-aaaaq-aaavq-cai", @@ -60,8 +57,7 @@ }, "alternativeName": "YRAL", "url": "https://yral.com" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "4c4fd-caaaa-aaaaq-aaa3a-cai", @@ -76,8 +72,7 @@ }, "alternativeName": "ICGhost", "url": "https://yadjb-mqaaa-aaaan-qaqlq-cai.raw.ic0.app/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "xsi2v-cyaaa-aaaaq-aabfq-cai", @@ -92,8 +87,7 @@ }, "alternativeName": "DecideAI DAO", "url": "https://decideai.xyz" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "vtrom-gqaaa-aaaaq-aabia-cai", @@ -108,8 +102,7 @@ }, "alternativeName": "BOOM DAO", "url": "https://boomdao.xyz/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "uf2wh-taaaa-aaaaq-aabna-cai", @@ -124,8 +117,7 @@ }, "alternativeName": "Catalyze", "url": "https://catalyze.one" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "rffwt-piaaa-aaaaq-aabqq-cai", @@ -140,8 +132,7 @@ }, "alternativeName": "Seers AI", "url": "https://seers.social" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "rxdbk-dyaaa-aaaaq-aabtq-cai", @@ -156,8 +147,7 @@ }, "alternativeName": "Nuance", "url": "https://nuance.xyz" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "qbizb-wiaaa-aaaaq-aabwq-cai", @@ -172,8 +162,7 @@ }, "alternativeName": "SONIC", "url": "https://app.sonic.ooo" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "tyyy3-4aaaa-aaaaq-aab7a-cai", @@ -188,8 +177,7 @@ }, "alternativeName": "Gold DAO", "url": "https://www.gold-dao.org" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "emww2-4yaaa-aaaaq-aacbq-cai", @@ -204,8 +192,7 @@ }, "alternativeName": "TRAX", "url": "https://trax.so" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "f54if-eqaaa-aaaaq-aacea-cai", @@ -220,8 +207,7 @@ }, "alternativeName": "Neutrinite", "url": "https://icpcoins.com" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "hvgxa-wqaaa-aaaaq-aacia-cai", @@ -236,8 +222,7 @@ }, "alternativeName": "Sneed", "url": "https://4pk43-5qaaa-aaaag-qc44a-cai.icp0.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "hhaaz-2aaaa-aaaaq-aacla-cai", @@ -252,8 +237,7 @@ }, "alternativeName": "ICLighthouse DAO", "url": "https://iclight.io" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "gemj7-oyaaa-aaaaq-aacnq-cai", @@ -268,8 +252,7 @@ }, "alternativeName": "ELNA AI", "url": "https://dapp.elna.ai" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "ddsp7-7iaaa-aaaaq-aacqq-cai", @@ -284,8 +267,7 @@ }, "alternativeName": "OpenFPL", "url": "https://openfpl.xyz/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "druyg-tyaaa-aaaaq-aactq-cai", @@ -300,8 +282,7 @@ }, "alternativeName": "ICPanda DAO", "url": "https://panda.fans" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "ca6gz-lqaaa-aaaaq-aacwa-cai", @@ -316,8 +297,7 @@ }, "alternativeName": "ICPSwap", "url": "https://www.icpswap.com" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "atbfz-diaaa-aaaaq-aacyq-cai", @@ -332,8 +312,7 @@ }, "alternativeName": "Yuku DAO", "url": "https://yuku.app/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "bliq2-niaaa-aaaaq-aac4q-cai", @@ -348,8 +327,7 @@ }, "alternativeName": "EstateDAO", "url": "https://wbdy5-yyaaa-aaaap-abysq-cai.icp0.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "k45jy-aiaaa-aaaaq-aadcq-cai", @@ -364,8 +342,7 @@ }, "alternativeName": "Motoko", "url": "https://2uktw-yiaaa-aaaah-adwxq-cai.icp0.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "lrtnw-paaaa-aaaaq-aadfa-cai", @@ -380,8 +357,7 @@ }, "alternativeName": "ICPCC DAO LLC", "url": "https://osjzm-oaaaa-aaaal-ajcoq-cai.icp0.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "lkwrt-vyaaa-aaaaq-aadhq-cai", @@ -396,8 +372,7 @@ }, "alternativeName": "ORIGYN", "url": "https://www.origyn.com/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "jcmow-hyaaa-aaaaq-aadlq-cai", @@ -412,8 +387,7 @@ }, "alternativeName": "WaterNeuron", "url": "https://waterneuron.fi/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "itgqj-7qaaa-aaaaq-aadoa-cai", @@ -428,8 +402,7 @@ }, "alternativeName": "CYCLES-TRANSFER-STATION", "url": "https://cycles-transfer-station.com" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "np5km-uyaaa-aaaaq-aadrq-cai", @@ -444,8 +417,7 @@ }, "alternativeName": "DOGMI", "url": "https://qu2gy-uqaaa-aaaal-qcv6a-cai.icp0.io" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "m6xut-mqaaa-aaaaq-aadua-cai", @@ -460,8 +432,7 @@ }, "alternativeName": "ICVC", "url": "https://mnc6b-aaaaa-aaaap-qhnrq-cai.icp0.io/" - }, - "indexCanisterVersion": "up-to-date" + } }, { "ledgerCanisterId": "o7oak-iyaaa-aaaaq-aadzq-cai", @@ -476,7 +447,6 @@ }, "alternativeName": "KongSwap", "url": "https://www.kongswap.io/" - }, - "indexCanisterVersion": "up-to-date" + } } ] diff --git a/src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte b/src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte index 79a07292dc..efa2b8bbea 100644 --- a/src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte +++ b/src/frontend/src/icp/components/tokens/IcManageTokenToggle.svelte @@ -3,15 +3,10 @@ import { createEventDispatcher } from 'svelte'; import { type IcrcCustomToken } from '$icp/types/icrc-custom-token'; import { i18n } from '$lib/stores/i18n.store'; - import { toastsShow } from '$lib/stores/toasts.store'; - import { replaceOisyPlaceholders, replacePlaceholders } from '$lib/utils/i18n.utils'; import { isIcrcTokenToggleDisabled } from '$lib/utils/token-toggle.utils'; export let token: IcrcCustomToken; - let outdated = false; - $: outdated = token.indexCanisterVersion === 'outdated'; - let disabled = false; $: disabled = isIcrcTokenToggleDisabled(token); @@ -32,32 +27,11 @@ enabled: checked }); }; - - const onClick = () => { - if (!outdated) { - return; - } - - toastsShow({ - text: replacePlaceholders( - replaceOisyPlaceholders($i18n.tokens.manage.info.outdated_index_canister), - { - $token: token.name - } - ), - level: 'info', - duration: 5000 - }); - }; - - -
- -
+ diff --git a/src/frontend/src/icp/services/icrc-custom-tokens.services.ts b/src/frontend/src/icp/services/icrc-custom-tokens.services.ts index 240868c365..a24cfe3a1c 100644 --- a/src/frontend/src/icp/services/icrc-custom-tokens.services.ts +++ b/src/frontend/src/icp/services/icrc-custom-tokens.services.ts @@ -63,7 +63,6 @@ export const buildIcrcCustomTokens = (): IcTokenWithoutIdExtended[] => { const mapIcrcCustomToken = ({ ledgerCanisterId, indexCanisterId, - indexCanisterVersion, rootCanisterId, metadata: { name, decimals, symbol, fee, alternativeName } }: EnvSnsToken): IcTokenWithoutIdExtended => ({ @@ -80,6 +79,5 @@ const mapIcrcCustomToken = ({ icon: `/icons/sns/${ledgerCanisterId}.png`, fee, alternativeName, - explorerUrl: `${SNS_EXPLORER_URL}/${rootCanisterId}`, - indexCanisterVersion + explorerUrl: `${SNS_EXPLORER_URL}/${rootCanisterId}` }); diff --git a/src/frontend/src/icp/types/icrc-custom-token.ts b/src/frontend/src/icp/types/icrc-custom-token.ts index 717b5e953a..fe8ebe81c7 100644 --- a/src/frontend/src/icp/types/icrc-custom-token.ts +++ b/src/frontend/src/icp/types/icrc-custom-token.ts @@ -1,11 +1,9 @@ import type { EnvIcrcTokenMetadata } from '$env/types/env-icrc-token'; -import type { EnvSnsToken } from '$env/types/env-sns-token'; import type { IcToken, IcTokenWithoutId } from '$icp/types/ic-token'; import type { TokenToggleable, UserTokenState } from '$lib/types/token-toggleable'; import type { Option } from '$lib/types/utils'; -export type IcrcCustomTokenExtra = Pick & - Partial>; +export type IcrcCustomTokenExtra = Pick; export type IcTokenWithoutIdExtended = IcTokenWithoutId & IcrcCustomTokenExtra; diff --git a/src/frontend/src/icp/utils/icrc.utils.ts b/src/frontend/src/icp/utils/icrc.utils.ts index e07b56a437..e8ef64fa40 100644 --- a/src/frontend/src/icp/utils/icrc.utils.ts +++ b/src/frontend/src/icp/utils/icrc.utils.ts @@ -44,9 +44,6 @@ export const mapIcrcToken = ({ ...(nonNullish(icrcCustomTokens?.[ledgerCanisterId]?.alternativeName) && { alternativeName: icrcCustomTokens[ledgerCanisterId].alternativeName }), - ...(nonNullish(icrcCustomTokens?.[ledgerCanisterId]?.indexCanisterVersion) && { - indexCanisterVersion: icrcCustomTokens[ledgerCanisterId].indexCanisterVersion - }), ledgerCanisterId, ...metadataToken, ...rest diff --git a/src/frontend/src/lib/i18n/en.json b/src/frontend/src/lib/i18n/en.json index c6493147e9..d45d6f4aaa 100644 --- a/src/frontend/src/lib/i18n/en.json +++ b/src/frontend/src/lib/i18n/en.json @@ -485,7 +485,6 @@ "select_network": "Select the network" }, "info": { - "outdated_index_canister": "$token Index canister is outdated and incompatible with $oisy_name. Contact the project team to propose an upgrade.", "no_changes": "No changes need to be saved." }, "error": { diff --git a/src/frontend/src/lib/types/i18n.d.ts b/src/frontend/src/lib/types/i18n.d.ts index bfc89aee53..b2412ccf63 100644 --- a/src/frontend/src/lib/types/i18n.d.ts +++ b/src/frontend/src/lib/types/i18n.d.ts @@ -437,7 +437,7 @@ interface I18nTokens { all_tokens_zero_balance: string; }; placeholder: { select_network: string }; - info: { outdated_index_canister: string; no_changes: string }; + info: { no_changes: string }; error: { unexpected_build: string; empty: string }; }; hide: { title: string; token: string; info: string; confirm: string; hiding: string }; diff --git a/src/frontend/src/lib/utils/token-toggle.utils.ts b/src/frontend/src/lib/utils/token-toggle.utils.ts index 819c66da96..668272fff0 100644 --- a/src/frontend/src/lib/utils/token-toggle.utils.ts +++ b/src/frontend/src/lib/utils/token-toggle.utils.ts @@ -15,8 +15,7 @@ export function isEthereumTokenToggleEnabled(token: EthereumUserToken): boolean // TODO: Like above - check why this functionality is used. export function isIcrcTokenToggleDisabled(token: IcrcCustomToken): boolean { return nonNullish(token) - ? token.indexCanisterVersion === 'outdated' || - (token.category === 'default' && token.standard === 'icp') || + ? (token.category === 'default' && token.standard === 'icp') || ICRC_CHAIN_FUSION_DEFAULT_LEDGER_CANISTER_IDS.includes(token.ledgerCanisterId) : false; } diff --git a/src/frontend/src/tests/icp/services/icrc.services.spec.ts b/src/frontend/src/tests/icp/services/icrc.services.spec.ts index 801200e632..89ee90f2b2 100644 --- a/src/frontend/src/tests/icp/services/icrc.services.spec.ts +++ b/src/frontend/src/tests/icp/services/icrc.services.spec.ts @@ -161,7 +161,6 @@ describe('icrc.services', () => { fee: 100000n, icon: '/icons/sns/zfcdd-tqaaa-aaaaq-aaaga-cai.png', indexCanisterId: dragginzIndexCanisterId, - indexCanisterVersion: 'up-to-date', ledgerCanisterId: dragginzLedgerCanisterId, name: 'Draggin Karma Points' }) diff --git a/src/frontend/src/tests/lib/utils/token-toggle.utils.spec.ts b/src/frontend/src/tests/lib/utils/token-toggle.utils.spec.ts index 4db69951e1..50af312f35 100644 --- a/src/frontend/src/tests/lib/utils/token-toggle.utils.spec.ts +++ b/src/frontend/src/tests/lib/utils/token-toggle.utils.spec.ts @@ -46,17 +46,6 @@ describe('isIcrcCustomTokenDisabled', () => { expect(isIcrcTokenToggleDisabled(token)).toBe(false); }); - it('should check if outdated custom icp custom token is disabled for token toggle', () => { - const token: IcrcCustomToken = { - ...ICP_TOKEN, - enabled: false, - category: 'custom', - ledgerCanisterId: 'mxzaz-hqaaa-aaaar-qaadu-cai', - indexCanisterVersion: 'outdated' - }; - expect(isIcrcTokenToggleDisabled(token)).toBe(true); - }); - it('should check if icrc default token is disabled for token toggle', () => { const token: IcrcCustomToken = { ...ICP_TOKEN, standard: 'icrc', enabled: false }; expect(isIcrcTokenToggleDisabled(token)).toBe(false); diff --git a/src/frontend/src/tests/mocks/icrc-custom-tokens.mock.ts b/src/frontend/src/tests/mocks/icrc-custom-tokens.mock.ts index 67c8f74779..b168bb18c6 100644 --- a/src/frontend/src/tests/mocks/icrc-custom-tokens.mock.ts +++ b/src/frontend/src/tests/mocks/icrc-custom-tokens.mock.ts @@ -5,8 +5,7 @@ import { mockValidIcToken } from '$tests/mocks/ic-tokens.mock'; export const mockIcrcCustomToken: IcrcCustomToken = { enabled: false, ...mockValidIcToken, - alternativeName: 'test', - indexCanisterVersion: 'up-to-date' + alternativeName: 'test' }; export const mockIcrcCustomTokens: IcrcCustomToken[] = [