Skip to content

Commit

Permalink
Merge branch 'main' into refactor(frontend)/remove-deprecated-logged-…
Browse files Browse the repository at this point in the history
…out-status-in-Transactions
  • Loading branch information
AntonioVentilii-DFINITY authored Nov 5, 2024
2 parents 68e700a + 15de402 commit 6579b90
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
12 changes: 0 additions & 12 deletions src/frontend/src/lib/components/tokens/TokenCardSignedOut.svelte

This file was deleted.

18 changes: 6 additions & 12 deletions src/frontend/src/lib/components/tokens/Tokens.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,25 @@
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';
</script>

<div class:pointer-events-none={$authNotSignedIn} class:blur-[1.5px]={$authNotSignedIn}>
<div>
<Header>
{#if $testnetsEnabled}
<NetworksSwitcher disabled={$authNotSignedIn} />
<NetworksSwitcher />
{:else}
<h2 class="text-base">{$i18n.tokens.text.title}</h2>
{/if}

<TokensMenu slot="end" />
</Header>

{#if $authSignedIn}
<TokensSignedIn />
<TokensSignedIn />

<div transition:fade class="mb-4 mt-12 flex w-full justify-center sm:w-auto">
<ManageTokensButton />
</div>
{:else}
<TokensSignedOut />
{/if}
<div transition:fade class="mb-4 mt-12 flex w-full justify-center sm:w-auto">
<ManageTokensButton />
</div>
</div>
17 changes: 0 additions & 17 deletions src/frontend/src/lib/components/tokens/TokensSignedOut.svelte

This file was deleted.

4 changes: 3 additions & 1 deletion src/frontend/src/lib/types/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof CoingeckoCoinsIdSchema>;

// 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
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/lib/validation/coingecko.validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { z } from 'zod';

export const CoingeckoCoinsIdSchema = z.enum(['ethereum', 'bitcoin', 'internet-computer']);
39 changes: 39 additions & 0 deletions src/frontend/src/tests/lib/validation/coingecko.validation.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});

0 comments on commit 6579b90

Please sign in to comment.