Skip to content

Commit

Permalink
fix: get chain id from collections
Browse files Browse the repository at this point in the history
  • Loading branch information
HungLV46 committed Aug 28, 2024
1 parent dab60ae commit c11c91b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/lib/apis/product/list-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ProductResponseData {
description: string;
created_at: string;
featured_at: string;
product_collections: { collection: { chain_id: string } }[];
attributes: [{ name: string; value: string }];
}

Expand Down Expand Up @@ -56,6 +57,11 @@ export async function listProduct(
owner {
name
}
product_collections {
collection {
chain_id
}
}
}
ipscan_products_aggregate(where: {name: {_ilike: $name}, category: {_eq: $category}}) {
aggregate {
Expand Down
21 changes: 8 additions & 13 deletions src/lib/ui-components/badges/ChainBadge.svelte
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<script lang="ts">
import { CHAINS } from '$lib/constants';
import { Badge } from 'flowbite-svelte';
import type { BadgeProps } from 'flowbite-svelte/Badge.svelte';
export let chainName: string;
export let chainId: string;
export let dark: boolean = false;
const chains: Record<string, string> = {
'Aura network': 'Aura network',
Ethereum: 'Ethereum',
'Arbitrum One': 'Arbitrum One',
'Avalanche C-Chain': 'Avalanche C-Chain'
};
const colors: Record<string, BadgeProps['color']> = {
'Aura network': 'green',
Ethereum: 'red',
'Arbitrum One': 'yellow',
'Avalanche C-Chain': 'purple'
'6322': 'green',
'1': 'red',
'11155111': 'yellow'
};
console.log(chainId);
</script>

<Badge color={colors[chainName] ?? 'dark'} border={dark}>{chains[chainName] ?? 'Unknown'}</Badge>
<Badge color={colors[chainId] ?? 'dark'} border={dark}>{CHAINS[chainId] ?? 'Unknown'}</Badge>
20 changes: 7 additions & 13 deletions src/routes/(sidebar)/crud/products/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<script lang="ts">
import {
Avatar,
Badge,
Breadcrumb,
BreadcrumbItem,
Button,
Checkbox,
Heading
} from 'flowbite-svelte';
import { Avatar, Badge, Breadcrumb, BreadcrumbItem, Button, Heading } from 'flowbite-svelte';
import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead } from 'flowbite-svelte';
import { TableHeadCell, Toolbar, ToolbarButton } from 'flowbite-svelte';
import { EyeOutline, FilterSolid, SearchSolid } from 'flowbite-svelte-icons';
Expand Down Expand Up @@ -35,8 +27,10 @@
export let form;
export let data: ListWithPagingResponse<ProductResponseData>;
const extractChainNames = (product: ProductResponseData) =>
product.attributes.filter((att) => att.name === 'Chain').map((att) => att.value);
const extractChainIds = (product: ProductResponseData) =>
product.product_collections.map(
(pc: { collection: { chain_id: string } }) => pc.collection.chain_id
);
let searchConditions: ListProductQuery = _.omit(data.paging, 'total');
async function handleSearch(pageQuery?: { limit: number; offset: number }) {
Expand Down Expand Up @@ -136,8 +130,8 @@
</TableBodyCell>

<TableBodyCell class="p-4">
{#each extractChainNames(product) as chainName, index}
<ChainBadge {chainName} />
{#each extractChainIds(product) as chainId, index}
<ChainBadge {chainId} />
<!-- new line for each 2 chains-->
{#if index % 2 === 1}
<br />
Expand Down

0 comments on commit c11c91b

Please sign in to comment.