Skip to content

Commit ed8fb95

Browse files
authored
Merge pull request #1011 from tradingstrategy-ai/extended-chains-3
Update blockchain index and sitemap with extended chains
2 parents b337377 + 3892efd commit ed8fb95

File tree

10 files changed

+87
-54
lines changed

10 files changed

+87
-54
lines changed

src/routes/trading-view/[chain=slug]/+layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { error } from '@sveltejs/kit';
22
import { chainsUnderMaintenance } from '$lib/config';
3-
import { getChain } from '$lib/helpers/chain.js';
3+
import { getChain } from '$lib/helpers/chain';
44

55
export async function load({ params }) {
66
const { chain: chainSlug } = params;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { error } from '@sveltejs/kit';
2+
3+
// This route and sub-routes require chain to have backend data
4+
export async function load({ parent }) {
5+
const { chain } = await parent();
6+
if (!chain.hasBackendData) error(404, 'Not Found');
7+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { fetchPublicApi } from '$lib/helpers/public-api';
2+
import { error } from '@sveltejs/kit';
23

34
// https://tradingstrategy.ai/api/explorer/#/Exchange/web_exchanges
4-
export async function load({ fetch, params }) {
5-
return await fetchPublicApi(fetch, 'exchanges', { chain_slug: params.chain });
5+
export async function load({ fetch, parent }) {
6+
const { chain } = await parent();
7+
if (!chain.hasBackendData) error(404, 'Not Found');
8+
9+
return await fetchPublicApi(fetch, 'exchanges', { chain_slug: chain.slug });
610
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { error } from '@sveltejs/kit';
2+
3+
// This route and sub-routes require chain to have backend data
4+
export async function load({ parent }) {
5+
const { chain } = await parent();
6+
if (!chain.hasBackendData) error(404, 'Not Found');
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { error } from '@sveltejs/kit';
2+
3+
// This route and sub-routes require chain to have backend data
4+
export async function load({ parent }) {
5+
const { chain } = await parent();
6+
if (!chain.hasBackendData) error(404, 'Not Found');
7+
}

src/routes/trading-view/[chain=slug]/trading-pairs/+page.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import { error } from '@sveltejs/kit';
12
import { fetchPairs } from '$lib/explorer/pair-client';
23
import { getNumberParam, getStringParam } from '$lib/helpers/url-params';
34
import { sortOptions } from '$lib/explorer/PairTable.svelte';
45

5-
export async function load({ fetch, params, url }) {
6+
export async function load({ fetch, params, parent, url }) {
7+
const { chain } = await parent();
8+
if (!chain.hasBackendData) error(404, 'Not Found');
9+
610
const { searchParams } = url;
711
const page = getNumberParam(searchParams, 'page', 0);
812
const sort = getStringParam(searchParams, 'sort', sortOptions.keys);

src/routes/trading-view/blockchains/+page.svelte

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
-->
44
<script lang="ts">
55
import Breadcrumbs from '$lib/breadcrumb/Breadcrumbs.svelte';
6+
import Button from '$lib/components/Button.svelte';
7+
import HeroBanner from '$lib/components/HeroBanner.svelte';
8+
import Section from '$lib/components/Section.svelte';
9+
import { chains } from '$lib/helpers/chain';
610
import { getLogoUrl } from '$lib/helpers/assets';
7-
import { formatAmount } from '$lib/helpers/formatters';
8-
import { Button, ContentCard, ContentCardsSection, ContentCardsTemplate, HeroBanner } from '$lib/components';
9-
10-
export let data;
1111
</script>
1212

1313
<svelte:head>
@@ -17,33 +17,49 @@
1717

1818
<Breadcrumbs labels={{ blockchains: 'Blockchains' }} />
1919

20-
<ContentCardsTemplate pageTitle="DEX trading view" pageDescription="DEX trading view">
21-
<HeroBanner slot="hero" title="Blockchains" subtitle="List of currently active blockchains producing trading data." />
22-
23-
<ContentCardsSection cols={4} --button-width="100%">
24-
{#each data.chains as chain}
25-
<ContentCard href={`/trading-view/${chain.chain_slug}`} testId="chain-{chain.chain_id}-{chain.chain_slug}">
26-
<img
27-
slot="icon"
28-
class="blockchain-logo"
29-
alt={`${chain.chain_name} logo`}
30-
src={getLogoUrl('blockchain', chain.chain_slug)}
31-
/>
32-
<h3 slot="title" class="blockchain-title">{chain.chain_name}</h3>
33-
<p>{formatAmount(chain.exchanges)} exchanges</p>
34-
<Button label="Details" />
35-
</ContentCard>
36-
{/each}
37-
</ContentCardsSection>
38-
</ContentCardsTemplate>
20+
<main class="blockchains-page">
21+
<Section>
22+
<HeroBanner title="Blockchains" subtitle="List of currently active blockchains producing trading data." />
23+
</Section>
24+
25+
<Section>
26+
<div class="chains">
27+
{#each chains as chain (chain.id)}
28+
<a class="tile b" href={`/trading-view/${chain.slug}`}>
29+
<img class="tile c" alt={`${chain.name} logo`} src={getLogoUrl('blockchain', chain.slug)} />
30+
<h3>{chain.name}</h3>
31+
<Button>View details</Button>
32+
</a>
33+
{/each}
34+
</div>
35+
</Section>
36+
</main>
3937

4038
<style>
41-
.blockchain-logo {
42-
height: 3rem;
43-
width: 3rem;
44-
}
39+
.chains {
40+
display: grid;
41+
grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
42+
gap: 1.5rem;
43+
margin-top: 1rem;
44+
45+
a {
46+
display: grid;
47+
padding: 1.5rem;
48+
gap: 1rem;
49+
justify-items: center;
50+
--button-width: clamp(10rem, 50%, 15rem);
51+
}
52+
53+
img {
54+
height: 5rem;
55+
width: 5rem;
56+
border-radius: 50%;
57+
margin-bottom: 0.5rem;
58+
padding: 1rem;
59+
}
4560
46-
h3.blockchain-title {
47-
font: var(--f-heading-md-medium);
61+
h3 {
62+
font: var(--f-heading-md-medium);
63+
}
4864
}
4965
</style>

src/routes/trading-view/blockchains/+page.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/routes/trading-view/blockchains/sitemap.xml/+server.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
* Generate sitemap with entries for each chain
33
*/
44
import { SitemapStream } from 'sitemap';
5-
import { fetchPublicApi } from '$lib/helpers/public-api';
5+
import { chains } from '$lib/helpers/chain';
66

7-
const chainPages = ['', 'exchanges', 'lending', 'tokens', 'trading-pairs'];
87
const path = 'trading-view';
98
const priority = 0.8;
109

1110
export async function GET({ fetch, setHeaders, url, route }) {
12-
const chains = await fetchPublicApi(fetch, 'chains');
13-
1411
const stream = new SitemapStream({ hostname: url.origin });
1512

16-
for (const { chain_slug } of chains) {
17-
for (const page of chainPages) {
18-
const url = [path, chain_slug, page].filter(Boolean).join('/');
13+
for (const chain of chains) {
14+
const chainUrl = `${path}/${chain.slug}`;
15+
stream.write({ url: chainUrl, priority });
16+
17+
const pages = chain.hasBackendData ? ['exchanges', 'lending', 'tokens', 'trading-pairs', 'vaults'] : ['vaults'];
18+
19+
for (const page of pages) {
20+
const url = `${chainUrl}/${page}`;
1921
stream.write({ url, priority });
2022
}
2123
}

tests/e2e/trading-view/chain-index.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ test.describe('chain index page', () => {
66
await page.goto('/trading-view/blockchains');
77
});
88

9-
test('tiles should include exchange count', async ({ page }) => {
10-
const blockchains = page.getByRole('link', { name: /[\d,]+ exchanges/ });
11-
const count = await blockchains.count();
12-
expect(count).toBeGreaterThan(0);
13-
});
14-
159
test('chain tile should link to chain details', async ({ page }) => {
1610
const chain = page.getByRole('link', { name: /Ethereum/ });
1711
await chain.click();

0 commit comments

Comments
 (0)