diff --git a/src/frontend/src/lib/components/tokens/TokenCardSignedOut.svelte b/src/frontend/src/lib/components/tokens/TokenCardSignedOut.svelte deleted file mode 100644 index 0b905facb1..0000000000 --- a/src/frontend/src/lib/components/tokens/TokenCardSignedOut.svelte +++ /dev/null @@ -1,12 +0,0 @@ - - - - -/- - - -/- - diff --git a/src/frontend/src/lib/components/tokens/Tokens.svelte b/src/frontend/src/lib/components/tokens/Tokens.svelte index 663738df6c..5aeb9e88f3 100644 --- a/src/frontend/src/lib/components/tokens/Tokens.svelte +++ b/src/frontend/src/lib/components/tokens/Tokens.svelte @@ -4,17 +4,15 @@ import ManageTokensButton from '$lib/components/tokens/ManageTokensButton.svelte'; import TokensMenu from '$lib/components/tokens/TokensMenu.svelte'; import TokensSignedIn from '$lib/components/tokens/TokensSignedIn.svelte'; - import TokensSignedOut from '$lib/components/tokens/TokensSignedOut.svelte'; import Header from '$lib/components/ui/Header.svelte'; - import { authNotSignedIn, authSignedIn } from '$lib/derived/auth.derived'; import { testnetsEnabled } from '$lib/derived/settings.derived'; import { i18n } from '$lib/stores/i18n.store'; -
+
{#if $testnetsEnabled} - + {:else}

{$i18n.tokens.text.title}

{/if} @@ -22,13 +20,9 @@
- {#if $authSignedIn} - + -
- -
- {:else} - - {/if} +
+ +
diff --git a/src/frontend/src/lib/components/tokens/TokensSignedOut.svelte b/src/frontend/src/lib/components/tokens/TokensSignedOut.svelte deleted file mode 100644 index 9fd9495a59..0000000000 --- a/src/frontend/src/lib/components/tokens/TokensSignedOut.svelte +++ /dev/null @@ -1,17 +0,0 @@ - - -
- {#each $combinedDerivedSortedNetworkTokens as token (token.id)} - - - - {/each} -
diff --git a/src/frontend/src/lib/types/coingecko.ts b/src/frontend/src/lib/types/coingecko.ts index 18e2bb7d90..57d1a06eb0 100644 --- a/src/frontend/src/lib/types/coingecko.ts +++ b/src/frontend/src/lib/types/coingecko.ts @@ -4,8 +4,10 @@ // *refers to curl -l https://api.coingecko.com/api/v3/coins/list import type { LedgerCanisterIdText } from '$icp/types/canister'; import type { EthAddress } from '$lib/types/address'; +import type { CoingeckoCoinsIdSchema } from '$lib/validation/coingecko.validation'; +import { z } from 'zod'; -export type CoingeckoCoinsId = 'ethereum' | 'bitcoin' | 'internet-computer'; +export type CoingeckoCoinsId = z.infer; // We are interested only in the ERC20 <> USD on Ethereum and in the ICRC <> USD on Internet Computer, therefore not an exhaustive list. // *refers to curl -l https://api.coingecko.com/api/v3/asset_platforms diff --git a/src/frontend/src/lib/validation/coingecko.validation.ts b/src/frontend/src/lib/validation/coingecko.validation.ts new file mode 100644 index 0000000000..bb3256b30e --- /dev/null +++ b/src/frontend/src/lib/validation/coingecko.validation.ts @@ -0,0 +1,3 @@ +import { z } from 'zod'; + +export const CoingeckoCoinsIdSchema = z.enum(['ethereum', 'bitcoin', 'internet-computer']); diff --git a/src/frontend/src/tests/lib/validation/coingecko.validation.spec.ts b/src/frontend/src/tests/lib/validation/coingecko.validation.spec.ts new file mode 100644 index 0000000000..6706a5ade3 --- /dev/null +++ b/src/frontend/src/tests/lib/validation/coingecko.validation.spec.ts @@ -0,0 +1,39 @@ +import { CoingeckoCoinsIdSchema } from '$lib/validation/coingecko.validation'; +import { describe, expect, it } from 'vitest'; + +describe('CoingeckoCoinsIdSchema', () => { + it('should pass validation for "ethereum"', () => { + const validData = 'ethereum'; + expect(CoingeckoCoinsIdSchema.parse(validData)).toEqual(validData); + }); + + it('should pass validation for "bitcoin"', () => { + const validData = 'bitcoin'; + expect(CoingeckoCoinsIdSchema.parse(validData)).toEqual(validData); + }); + + it('should pass validation for "internet-computer"', () => { + const validData = 'internet-computer'; + expect(CoingeckoCoinsIdSchema.parse(validData)).toEqual(validData); + }); + + it('should fail validation for an unsupported coin ID', () => { + const invalidData = 'dogecoin'; + expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); + }); + + it('should fail validation for a number instead of a string', () => { + const invalidData = 123; + expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); + }); + + it('should fail validation for null', () => { + const invalidData = null; + expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); + }); + + it('should fail validation for undefined', () => { + const invalidData = undefined; + expect(() => CoingeckoCoinsIdSchema.parse(invalidData)).toThrow(); + }); +});