Skip to content

Commit

Permalink
Remove import token flag (#5725)
Browse files Browse the repository at this point in the history
# Motivation

Since the "Import token" feature has been live in production for some
time and there are no plans to disable it, the `ENABLE_IMPORT_TOKEN`
flag has become obsolete.

# Changes

- Remove the feature flag.

# Tests

- Updated.

# Todos

- [ ] Add entry to changelog (if necessary).
not necessary.
  • Loading branch information
mstrasinskis authored Nov 5, 2024
1 parent ec1106b commit 490abd6
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 149 deletions.
1 change: 0 additions & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@
"FEATURE_FLAGS": {
"ENABLE_CKBTC": true,
"ENABLE_CKTESTBTC": false,
"ENABLE_IMPORT_TOKEN": true,
"DISABLE_IMPORT_TOKEN_VALIDATION_FOR_TESTING": false,
"ENABLE_NEURON_VISIBILITY": true
}
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/lib/components/accounts/IcrcWalletPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import { selectedUniverseStore } from "$lib/derived/selected-universe.derived";
import { syncAccounts as syncWalletAccounts } from "$lib/services/icrc-accounts.services";
import { removeImportedTokens } from "$lib/services/imported-tokens.services";
import { ENABLE_IMPORT_TOKEN } from "$lib/stores/feature-flags.store";
import { i18n } from "$lib/stores/i18n";
import { icrcAccountsStore } from "$lib/stores/icrc-accounts.store";
import { importedTokensStore } from "$lib/stores/imported-tokens.store";
Expand Down Expand Up @@ -196,16 +195,14 @@
walletAddress={$selectedAccountStore.account?.identifier}
>
<svelte:fragment slot="actions">
{#if $ENABLE_IMPORT_TOKEN}
<button
bind:this={moreButton}
class="icon-only"
data-tid="more-button"
on:click={() => (morePopupVisible = true)}
>
<IconDots />
</button>
{/if}
<button
bind:this={moreButton}
class="icon-only"
data-tid="more-button"
on:click={() => (morePopupVisible = true)}
>
<IconDots />
</button>
</svelte:fragment>
</WalletPageHeader>
<WalletPageHeading
Expand Down
1 change: 0 additions & 1 deletion frontend/src/lib/constants/environment.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const SNS_AGGREGATOR_CANISTER_URL = envVars.snsAggregatorUrl ?? "";
export interface FeatureFlags<T> {
ENABLE_CKBTC: T;
ENABLE_CKTESTBTC: T;
ENABLE_IMPORT_TOKEN: T;
DISABLE_IMPORT_TOKEN_VALIDATION_FOR_TESTING: T;
ENABLE_NEURON_VISIBILITY: T;
// Used only in tests and set up in jest-setup.ts
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/lib/pages/NnsWallet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
} from "$lib/services/icp-transactions.services";
import { listNeurons } from "$lib/services/neurons.services";
import { authStore } from "$lib/stores/auth.store";
import { ENABLE_IMPORT_TOKEN } from "$lib/stores/feature-flags.store";
import { i18n } from "$lib/stores/i18n";
import { icpAccountBalancesStore } from "$lib/stores/icp-account-balances.store";
import {
Expand Down Expand Up @@ -314,16 +313,14 @@
walletAddress={$selectedAccountStore.account?.identifier}
>
<svelte:fragment slot="actions">
{#if $ENABLE_IMPORT_TOKEN}
<button
bind:this={moreButton}
class="icon-only"
data-tid="more-button"
on:click={() => (morePopupVisible = true)}
>
<IconDots />
</button>
{/if}
<button
bind:this={moreButton}
class="icon-only"
data-tid="more-button"
on:click={() => (morePopupVisible = true)}
>
<IconDots />
</button>
</svelte:fragment>
</WalletPageHeader>
<WalletPageHeading
Expand Down
82 changes: 24 additions & 58 deletions frontend/src/lib/pages/Tokens.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
import { OWN_CANISTER_ID_TEXT } from "$lib/constants/canister-ids.constants";
import { MAX_IMPORTED_TOKENS } from "$lib/constants/imported-tokens.constants";
import ImportTokenModal from "$lib/modals/accounts/ImportTokenModal.svelte";
import { ENABLE_IMPORT_TOKEN } from "$lib/stores/feature-flags.store";
import { hideZeroBalancesStore } from "$lib/stores/hide-zero-balances.store";
import { i18n } from "$lib/stores/i18n";
import { importedTokensStore } from "$lib/stores/imported-tokens.store";
import type { ImportedTokenData } from "$lib/types/imported-tokens";
import type { UserToken } from "$lib/types/tokens-page";
import { replacePlaceholders } from "$lib/utils/i18n.utils";
import { isImportedToken } from "$lib/utils/imported-tokens.utils";
import { heightTransition } from "$lib/utils/transition.utils";
import { IconPlus, IconSettings, Tooltip } from "@dfinity/gix-components";
import { Popover } from "@dfinity/gix-components";
import { TokenAmountV2, nonNullish } from "@dfinity/utils";
Expand Down Expand Up @@ -67,8 +65,6 @@
let maximumImportedTokensReached = false;
$: maximumImportedTokensReached =
($importedTokensStore.importedTokens?.length ?? 0) >= MAX_IMPORTED_TOKENS;
// TODO(Import token): After removing ENABLE_IMPORT_TOKEN combine divs -> <div slot="last-row" class="last-row">
</script>

<TestIdWrapper testId="tokens-page-component">
Expand All @@ -86,49 +82,9 @@
on:click={openSettings}><IconSettings /></button
>
</div>
<div slot="last-row">
{#if $ENABLE_IMPORT_TOKEN}
<div class="last-row">
{#if shouldHideZeroBalances}
<div class="show-all-button-container">
{$i18n.tokens.zero_balance_hidden}
<button
data-tid="show-all-button"
class="ghost show-all"
on:click={showAll}
>
{$i18n.tokens.show_all}</button
>
</div>
{/if}

{#if nonNullish($importedTokensStore.importedTokens)}
<Tooltip
top
testId="maximum-imported-tokens-tooltip"
text={maximumImportedTokensReached
? replacePlaceholders(
$i18n.import_token.maximum_reached_tooltip,
{ $max: `${MAX_IMPORTED_TOKENS}` }
)
: undefined}
>
<button
data-tid="import-token-button"
class="ghost with-icon import-token-button"
on:click={() => (showImportTokenModal = true)}
disabled={maximumImportedTokensReached}
>
<IconPlus />{$i18n.import_token.import_token}
</button>
</Tooltip>
{/if}
</div>
{:else if shouldHideZeroBalances}
<div
class="show-all-row"
transition:heightTransition={{ duration: 250 }}
>
<div slot="last-row" class="last-row">
{#if shouldHideZeroBalances}
<div class="show-all-button-container">
{$i18n.tokens.zero_balance_hidden}
<button
data-tid="show-all-button"
Expand All @@ -139,6 +95,27 @@
>
</div>
{/if}

{#if nonNullish($importedTokensStore.importedTokens)}
<Tooltip
top
testId="maximum-imported-tokens-tooltip"
text={maximumImportedTokensReached
? replacePlaceholders($i18n.import_token.maximum_reached_tooltip, {
$max: `${MAX_IMPORTED_TOKENS}`,
})
: undefined}
>
<button
data-tid="import-token-button"
class="ghost with-icon import-token-button"
on:click={() => (showImportTokenModal = true)}
disabled={maximumImportedTokensReached}
>
<IconPlus />{$i18n.import_token.import_token}
</button>
</Tooltip>
{/if}
</div>
</TokensTable>
<Popover
Expand Down Expand Up @@ -174,17 +151,6 @@
grid-column: 1 / -1;
}
// TODO(Import token): Remove after enabling ENABLE_IMPORT_TOKEN
.show-all-row {
color: var(--text-description);
padding: var(--padding-2x);
background: var(--table-row-background);
button.show-all {
text-decoration: underline;
}
}
.last-row {
display: flex;
flex-direction: column;
Expand Down
12 changes: 4 additions & 8 deletions frontend/src/lib/services/app.services.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { loadActionableProposals } from "$lib/services/actionable-proposals.services";
import { loadActionableSnsProposals } from "$lib/services/actionable-sns-proposals.services";
import { loadImportedTokens } from "$lib/services/imported-tokens.services";
import { ENABLE_IMPORT_TOKEN } from "$lib/stores/feature-flags.store";
import { get } from "svelte/store";
import { initAccounts } from "./icp-accounts.services";
import { loadSnsProjects } from "./public/sns.services";

Expand All @@ -11,12 +9,10 @@ export const initAppPrivateData = async (): Promise<void> => {
// Reload the SNS projects even if they were loaded.
// Get latest data and create wrapper caches for the logged in identity.
const initSns: Promise<void>[] = [loadSnsProjects()];

const initImportedTokens: Promise<void>[] = get(ENABLE_IMPORT_TOKEN)
? [loadImportedTokens({ ignoreAccountNotFoundError: true })]
: [];

// TODO: load imported tokens after Nns.
// Load imported tokens
const initImportedTokens: Promise<void>[] = [
loadImportedTokens({ ignoreAccountNotFoundError: true }),
];
/**
* If Nns load but Sns load fails it is "fine" to go on because Nns are core features.
*/
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/lib/stores/feature-flags.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const assertEditableFeatureFlag = (flag: FeatureKey) => {
export const EDITABLE_FEATURE_FLAGS: Array<FeatureKey> = [
"TEST_FLAG_EDITABLE",
"ENABLE_CKTESTBTC",
"ENABLE_IMPORT_TOKEN",
"DISABLE_IMPORT_TOKEN_VALIDATION_FOR_TESTING",
"ENABLE_NEURON_VISIBILITY",
];
Expand Down Expand Up @@ -150,7 +149,6 @@ const featureFlagsStore = initFeatureFlagsStore();
export const {
ENABLE_CKBTC,
ENABLE_CKTESTBTC,
ENABLE_IMPORT_TOKEN,
DISABLE_IMPORT_TOKEN_VALIDATION_FOR_TESTING,
ENABLE_NEURON_VISIBILITY,
// Used only in tests only
Expand Down
9 changes: 0 additions & 9 deletions frontend/src/tests/lib/pages/IcrcWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 { importedTokensStore } from "$lib/stores/imported-tokens.store";
import { tokensStore } from "$lib/stores/tokens.store";
Expand Down Expand Up @@ -119,7 +118,6 @@ describe("IcrcWallet", () => {
vi.useRealTimers();
vi.restoreAllMocks();
tokensStore.reset();
overrideFeatureFlagsStore.reset();
toastsStore.reset();
resetIdentity();
defaultIcrcCanistersStore.reset();
Expand Down Expand Up @@ -407,13 +405,6 @@ describe("IcrcWallet", () => {
expect(await po.getMoreButton().isPresent()).toBe(true);
});

it("should not display more button when ENABLE_IMPORT_TOKEN disabled", async () => {
overrideFeatureFlagsStore.setFlag("ENABLE_IMPORT_TOKEN", false);

const po = await renderWallet({});
expect(await po.getMoreButton().isPresent()).toBe(false);
});

it('should have canister links in "more" popup', async () => {
const po = await renderWallet({});
const morePopoverPo = po.getWalletMorePopoverPo();
Expand Down
9 changes: 0 additions & 9 deletions frontend/src/tests/lib/pages/NnsWallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { AppPath } from "$lib/constants/routes.constants";
import { pageStore } from "$lib/derived/page.derived";
import NnsWallet from "$lib/pages/NnsWallet.svelte";
import { cancelPollAccounts } from "$lib/services/icp-accounts.services";
import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store";
import { icpTransactionsStore } from "$lib/stores/icp-transactions.store";
import { neuronsStore } from "$lib/stores/neurons.store";
import { getSwapCanisterAccount } from "$lib/utils/sns.utils";
Expand Down Expand Up @@ -105,7 +104,6 @@ describe("NnsWallet", () => {
data: { universe: OWN_CANISTER_ID_TEXT },
routeId: AppPath.Wallet,
});
overrideFeatureFlagsStore.reset();
});

const renderWallet = async (props) => {
Expand Down Expand Up @@ -251,13 +249,6 @@ describe("NnsWallet", () => {
expect(await po.getMoreButton().isPresent()).toBe(true);
});

it("should not display more button when ENABLE_IMPORT_TOKEN disabled", async () => {
overrideFeatureFlagsStore.setFlag("ENABLE_IMPORT_TOKEN", false);

const po = await renderWallet({});
expect(await po.hasMoreButton()).toBe(false);
});

it('should have canister links in "more" popup', async () => {
const po = await renderWallet({});
const morePopoverPo = po.getWalletMorePopoverPo();
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/tests/lib/pages/Tokens.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MAX_IMPORTED_TOKENS } from "$lib/constants/imported-tokens.constants";
import { NNS_TOKEN_DATA } from "$lib/constants/tokens.constants";
import TokensPage from "$lib/pages/Tokens.svelte";
import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store";
import { hideZeroBalancesStore } from "$lib/stores/hide-zero-balances.store";
import { importedTokensStore } from "$lib/stores/imported-tokens.store";
import type { UserTokenData } from "$lib/types/tokens-page";
Expand Down Expand Up @@ -67,7 +66,6 @@ describe("Tokens page", () => {
};

beforeEach(() => {
overrideFeatureFlagsStore.reset();
hideZeroBalancesStore.resetForTesting();
vi.useFakeTimers();

Expand Down Expand Up @@ -228,10 +226,6 @@ describe("Tokens page", () => {
});

describe("when import token feature flag is enabled", () => {
beforeEach(() => {
overrideFeatureFlagsStore.setFlag("ENABLE_IMPORT_TOKEN", true);
});

it("should show import token button", async () => {
const po = renderPage([positiveBalance, zeroBalance]);
expect(await po.getImportTokenButtonPo().isPresent()).toBe(true);
Expand Down Expand Up @@ -294,15 +288,4 @@ describe("Tokens page", () => {
expect(await po.getImportTokenModalPo().isPresent()).toBe(true);
});
});

describe("when import token feature flag is disabled", () => {
beforeEach(() => {
overrideFeatureFlagsStore.setFlag("ENABLE_IMPORT_TOKEN", false);
});

it("should not show import token button", async () => {
const po = renderPage([positiveBalance, zeroBalance]);
expect(await po.getImportTokenButtonPo().isPresent()).toBe(false);
});
});
});
17 changes: 0 additions & 17 deletions frontend/src/tests/lib/services/app.services.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as actionableProposalsServices from "$lib/services/actionable-proposals
import * as actionableSnsProposalsServices from "$lib/services/actionable-sns-proposals.services";
import { initAppPrivateData } from "$lib/services/app.services";
import * as importedTokensServices from "$lib/services/imported-tokens.services";
import { overrideFeatureFlagsStore } from "$lib/stores/feature-flags.store";
import type { CachedSnsDto } from "$lib/types/sns-aggregator";
import { resetIdentity } from "$tests/mocks/auth.store.mock";
import { mockAccountDetails } from "$tests/mocks/icp-accounts.store.mock";
Expand All @@ -29,7 +28,6 @@ describe("app-services", () => {
toastsStore.reset();
vi.clearAllMocks();
clearSnsAggregatorCache();
overrideFeatureFlagsStore.reset();
// resetSnsProjects();
vi.spyOn(LedgerCanister, "create").mockImplementation(
(): LedgerCanister => mockLedgerCanister
Expand Down Expand Up @@ -138,19 +136,4 @@ describe("app-services", () => {
ignoreAccountNotFoundError: true,
});
});

it("should not loadImportedTokens when ENABLE_IMPORT_TOKEN is disabled", async () => {
overrideFeatureFlagsStore.setFlag("ENABLE_IMPORT_TOKEN", false);
const spyLoadImportedTokens = vi
.spyOn(importedTokensServices, "loadImportedTokens")
.mockResolvedValue();

expect(mockNNSDappCanister.getAccount).toHaveBeenCalledTimes(0);
expect(spyLoadImportedTokens).toHaveBeenCalledTimes(0);

await initAppPrivateData();

expect(mockNNSDappCanister.getAccount).toHaveBeenCalledTimes(2);
expect(spyLoadImportedTokens).toHaveBeenCalledTimes(0);
});
});
1 change: 0 additions & 1 deletion frontend/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ vi.mock("./src/lib/utils/env-vars.utils.ts", () => ({
featureFlags: JSON.stringify({
ENABLE_CKBTC: true,
ENABLE_CKTESTBTC: true,
ENABLE_IMPORT_TOKEN: true,
DISABLE_IMPORT_TOKEN_VALIDATION_FOR_TESTING: false,
ENABLE_NEURON_VISIBILITY: true,
TEST_FLAG_EDITABLE: true,
Expand Down
Loading

0 comments on commit 490abd6

Please sign in to comment.